diff --git a/auto-claude/analyzers/route_detector.py b/auto-claude/analyzers/route_detector.py index e4dfd33d..ea0fd6b3 100644 --- a/auto-claude/analyzers/route_detector.py +++ b/auto-claude/analyzers/route_detector.py @@ -18,9 +18,16 @@ from .base import BaseAnalyzer class RouteDetector(BaseAnalyzer): """Detects API routes across multiple web frameworks.""" + # Directories to exclude from route detection + EXCLUDED_DIRS = {'node_modules', '.venv', 'venv', '__pycache__', '.git'} + def __init__(self, path: Path): super().__init__(path) + def _should_include_file(self, file_path: Path) -> bool: + """Check if file should be included (not in excluded directories).""" + return not any(part in self.EXCLUDED_DIRS for part in file_path.parts) + def detect_all_routes(self) -> list[dict]: """Detect all API routes across different frameworks.""" routes = [] @@ -51,7 +58,7 @@ class RouteDetector(BaseAnalyzer): def _detect_fastapi_routes(self) -> list[dict]: """Detect FastAPI routes.""" routes = [] - files_to_check = list(self.path.glob("**/*.py")) + files_to_check = [f for f in self.path.glob("**/*.py") if self._should_include_file(f)] for file_path in files_to_check: try: @@ -113,7 +120,7 @@ class RouteDetector(BaseAnalyzer): def _detect_flask_routes(self) -> list[dict]: """Detect Flask routes.""" routes = [] - files_to_check = list(self.path.glob("**/*.py")) + files_to_check = [f for f in self.path.glob("**/*.py") if self._should_include_file(f)] for file_path in files_to_check: try: @@ -160,7 +167,7 @@ class RouteDetector(BaseAnalyzer): def _detect_django_routes(self) -> list[dict]: """Detect Django routes from urls.py files.""" routes = [] - url_files = list(self.path.glob("**/urls.py")) + url_files = [f for f in self.path.glob("**/urls.py") if self._should_include_file(f)] for file_path in url_files: try: @@ -194,10 +201,9 @@ class RouteDetector(BaseAnalyzer): def _detect_express_routes(self) -> list[dict]: """Detect Express/Fastify/Koa routes.""" routes = [] - files_to_check = list(self.path.glob("**/*.js")) + list( - self.path.glob("**/*.ts") - ) - + js_files = [f for f in self.path.glob("**/*.js") if self._should_include_file(f)] + ts_files = [f for f in self.path.glob("**/*.ts") if self._should_include_file(f)] + files_to_check = js_files + ts_files for file_path in files_to_check: try: content = file_path.read_text() @@ -250,7 +256,8 @@ class RouteDetector(BaseAnalyzer): app_dir = self.path / "app" if app_dir.exists(): # Find all route.ts/js files - for route_file in app_dir.glob("**/route.{ts,js,tsx,jsx}"): + route_files = [f for f in app_dir.glob("**/route.{ts,js,tsx,jsx}") if self._should_include_file(f)] + for route_file in route_files: # Convert file path to route path # app/api/users/[id]/route.ts -> /api/users/:id relative_path = route_file.parent.relative_to(app_dir) @@ -283,9 +290,9 @@ class RouteDetector(BaseAnalyzer): # Next.js Pages Router (pages/api directory) pages_api = self.path / "pages" / "api" if pages_api.exists(): - for api_file in pages_api.glob("**/*.{ts,js,tsx,jsx}"): - if api_file.name.startswith("_"): - continue + api_files = [f for f in pages_api.glob("**/*.{ts,js,tsx,jsx}") if self._should_include_file(f)] + for api_file in api_files: + if api_file.name.startswith('_'): continue # Convert file path to route relative_path = api_file.relative_to(pages_api) @@ -314,7 +321,7 @@ class RouteDetector(BaseAnalyzer): def _detect_go_routes(self) -> list[dict]: """Detect Go framework routes (Gin, Echo, Chi, Fiber).""" routes = [] - go_files = list(self.path.glob("**/*.go")) + go_files = [f for f in self.path.glob("**/*.go") if self._should_include_file(f)] for file_path in go_files: try: @@ -348,7 +355,7 @@ class RouteDetector(BaseAnalyzer): def _detect_rust_routes(self) -> list[dict]: """Detect Rust framework routes (Axum, Actix).""" routes = [] - rust_files = list(self.path.glob("**/*.rs")) + rust_files = [f for f in self.path.glob("**/*.rs") if self._should_include_file(f)] for file_path in rust_files: try: