Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

refactor(ingestion): split framework_edges.py into per-framework handlers (#260)

Swati Ahuja4c73a251b83d
diff --git a/docs/LANGUAGE_SUPPORT.md b/docs/LANGUAGE_SUPPORT.md
index 85f1d88b2..ba65bb7eb 100644
--- a/docs/LANGUAGE_SUPPORT.md
+++ b/docs/LANGUAGE_SUPPORT.md
@@ -365,7 +365,10 @@ ingestion/
scala.py # package-to-directory mapping
php.py # namespace/PSR-4 resolution
generic.py # stem-matching fallback
- framework_edges.py # Django, FastAPI, Flask, pytest, ASP.NET, Rails, Laravel, TYPO3, Spring, Express, Gin, Axum detection
+ framework_edges/ # Framework convention edges (one module per framework + base.py)
+ # __init__.py re-exports add_framework_edges; iterates FrameworkHandler list
+ # django/fastapi/flask/aspnet/rails/laravel/spring/express/go/rust/typo3
+ # + pytest_edges (conftest); base.py = read_text, _add_edge_if_new, name→file maps
dynamic_hints/ # Per-language dynamic-edge extractors
base.py # DynamicHintExtractor + DynamicEdge
registry.py # HintRegistry
diff --git a/packages/core/src/repowise/core/ingestion/framework_edges.py b/packages/core/src/repowise/core/ingestion/framework_edges.py
deleted file mode 100644
index 3ec2bfedc..000000000
--- a/packages/core/src/repowise/core/ingestion/framework_edges.py
+++ /dev/null
@@ -1,1311 +0,0 @@
-"""Framework-aware synthetic edge detection.
-
-Extracted from ``graph.py`` — detects Django, FastAPI, Flask, and pytest
-convention-based relationships and adds ``edge_type="framework"`` edges.
-"""
-
-from __future__ import annotations
-
-import fnmatch
-import json
-import re
-from pathlib import Path
-from typing import TYPE_CHECKING, Any
-
-from .resolvers import ResolverContext, resolve_import
-
-if TYPE_CHECKING:
- import networkx as nx
-
- from .models import ParsedFile
-
-
-def add_framework_edges(
- graph: nx.DiGraph,
- parsed_files: dict[str, ParsedFile],
- ctx: ResolverContext,
- tech_stack: list[str] | None = None,
-) -> int:
- """Add synthetic edges for framework-mediated relationships.
-
- Returns the number of edges added.
- """
- count = 0
- path_set = set(parsed_files.keys())
-
- # Always run: pytest conftest detection
- count += _add_conftest_edges(graph, path_set)
-
- stack_lower = {s.lower() for s in (tech_stack or [])}
-
- if "django" in stack_lower:
- count += _add_django_edges(graph, path_set)
- if "fastapi" in stack_lower or "starlette" in stack_lower:
- count += _add_fastapi_edges(graph, parsed_files, ctx, path_set)
- if "flask" in stack_lower:
- count += _add_flask_edges(graph, parsed_files, ctx, path_set)
-
- # ASP.NET framework edges run when the tech stack hints at .NET web,
- # OR when any .cs file imports Microsoft.AspNetCore.* (cheap fallback
- # so we don't depend on detect_tech_stack catching the project).
- aspnet_in_stack = any(
- token in stack_lower
- for token in ("aspnet", "asp.net", "aspnetcore", "asp.net core")
- )
- if aspnet_in_stack or _has_aspnet_imports(parsed_files):
- count += _add_aspnet_edges(graph, parsed_files, path_set)
-
- # Host-builder extension-method calls (``app.MapCatalogApi()`` etc.)
- # run on ANY C# repo — desktop .NET (WPF/WinUI) defines its own
- # extension methods on ``IServiceCollection`` / module hosts even
- # when ASP.NET Core is absent. The host-type allowlist inside
- # ``aspnet_extensions`` keeps this safe to run unconditionally.
- if _has_csharp_files(parsed_files):
- count += _add_csharp_extension_edges(graph, parsed_files, path_set)
-
- if "rails" in stack_lower or "config/application.rb" in path_set:
- count += _add_rails_edges(graph, parsed_files, ctx, path_set)
-
- if (
- "laravel" in stack_lower
- or "routes/web.php" in path_set
- or "routes/api.php" in path_set
- ):
- count += _add_laravel_edges(graph, parsed_files, ctx, path_set)
-
- spring_in_stack = any(
- token in stack_lower for token in ("spring", "springboot", "spring-boot", "spring boot")
- )
- if spring_in_stack or _has_spring_imports(parsed_files):
- count += _add_spring_edges(graph, parsed_files, path_set)
-
- express_in_stack = any(
- token in stack_lower for token in ("express", "nestjs", "nest", "nest.js")
- )
- if express_in_stack or _has_express_imports(parsed_files):
- count += _add_express_edges(graph, parsed_files, ctx, path_set)
-
- go_router_in_stack = any(token in stack_lower for token in ("gin", "echo", "chi"))
- if go_router_in_stack or _has_go_router_imports(parsed_files):
- count += _add_go_router_edges(graph, parsed_files, path_set)
-
- rust_router_in_stack = any(token in stack_lower for token in ("axum", "actix", "actix-web"))
- if rust_router_in_stack or _has_rust_router_imports(parsed_files):
- count += _add_rust_router_edges(graph, parsed_files, path_set)
-
- # TYPO3: detect via composer.json `"type": "typo3-cms-extension"` or any
- # `ext_emconf.php` (legacy fallback for non-composer installs).
- if "typo3" in stack_lower or _has_typo3_extension(ctx, path_set):
- count += _add_typo3_edges(graph, parsed_files, ctx, path_set)
-
- return count
-
-
-def _add_edge_if_new(graph: nx.DiGraph, source: str, target: str) -> bool:
- """Add a framework edge if no edge already exists. Returns True if added."""
- if source == target:
- return False
- if graph.has_edge(source, target):
- return False
- graph.add_edge(source, target, edge_type="framework", imported_names=[])
- return True
-
-
-def _add_conftest_edges(graph: nx.DiGraph, path_set: set[str]) -> int:
- """conftest.py -> test files in the same or child directories."""
- count = 0
- conftest_paths = [p for p in path_set if Path(p).name == "conftest.py"]
-
- for conf in conftest_paths:
- conf_dir = Path(conf).parent.as_posix()
- prefix = f"{conf_dir}/" if conf_dir != "." else ""
- for p in path_set:
- if p == conf:
- continue
- node = graph.nodes.get(p, {})
- if not node.get("is_test", False):
- continue
- if (p.startswith(prefix) or (prefix == "" and "/" not in p)) and _add_edge_if_new(
- graph, p, conf
- ):
- count += 1
- return count
-
-
-def _add_django_edges(graph: nx.DiGraph, path_set: set[str]) -> int:
- """Django conventions: admin->models, urls->views in the same directory."""
- count = 0
- by_dir: dict[str, dict[str, str]] = {}
- for p in path_set:
- pp = Path(p)
- d = pp.parent.as_posix()
- by_dir.setdefault(d, {})[pp.stem] = p
-
- for _d, stems in by_dir.items():
- if (
- "admin" in stems
- and "models" in stems
- and _add_edge_if_new(graph, stems["admin"], stems["models"])
- ):
- count += 1
- if (
- "urls" in stems
- and "views" in stems
- and _add_edge_if_new(graph, stems["urls"], stems["views"])
- ):
- count += 1
- if (
- "forms" in stems
- and "models" in stems
- and _add_edge_if_new(graph, stems["forms"], stems["models"])
- ):
- count += 1
- if (
- "serializers" in stems
- and "models" in stems
- and _add_edge_if_new(graph, stems["serializers"], stems["models"])
- ):
- count += 1
- return count
-
-
-def _add_fastapi_edges(
- graph: nx.DiGraph,
- parsed_files: dict[str, Any],
- ctx: ResolverContext,
- path_set: set[str],
-) -> int:
- """Detect include_router() calls and link app files to router modules."""
- count = 0
- var_to_file: dict[str, str] = {}
-
- for path, parsed in parsed_files.items():
- for imp in parsed.imports:
- for name in imp.imported_names:
- if name.lower().endswith("router") or name.lower().endswith("app"):
- resolved = resolve_import(
- imp.module_path,
- path,
- parsed.file_info.language,
- ctx,
- )
- if resolved and resolved in path_set:
- var_to_file[name] = resolved
-
- router_re = re.compile(r"(?:include_router|add_api_route)\s*\(\s*(\w+)")
- for path, parsed in parsed_files.items():
- if parsed.file_info.language != "python":
- continue
- try:
- source = Path(parsed.file_info.abs_path).read_text(errors="ignore")
- except Exception:
- continue
- for match in router_re.finditer(source):
- var_name = match.group(1)
- target = var_to_file.get(var_name)
- if target and target in path_set and _add_edge_if_new(graph, path, target):
- count += 1
- return count
-
-
-def _add_flask_edges(
- graph: nx.DiGraph,
- parsed_files: dict[str, Any],
- ctx: ResolverContext,
- path_set: set[str],
-) -> int:
- """Detect register_blueprint() calls and link app files to blueprint modules."""
- count = 0
- var_to_file: dict[str, str] = {}
-
- for path, parsed in parsed_files.items():
- for imp in parsed.imports:
- for name in imp.imported_names:
- if "blueprint" in name.lower() or name.lower().endswith("bp"):
- resolved = resolve_import(
- imp.module_path,
- path,
- parsed.file_info.language,
- ctx,
- )
- if resolved and resolved in path_set:
- var_to_file[name] = resolved
-
- bp_re = re.compile(r"register_blueprint\s*\(\s*(\w+)")
- for path, parsed in parsed_files.items():
- if parsed.file_info.language != "python":
- continue
- try:
- source = Path(parsed.file_info.abs_path).read_text(errors="ignore")
- except Exception:
- continue
- for match in bp_re.finditer(source):
- var_name = match.group(1)
- target = var_to_file.get(var_name)
- if target and target in path_set and _add_edge_if_new(graph, path, target):
- count += 1
- return count
-
-
-# ---------------------------------------------------------------------------
-# ASP.NET / .NET framework edges
-# ---------------------------------------------------------------------------
-
-# A class becomes a controller when it is annotated [ApiController] OR its
-# class name ends in "Controller" (the MVC discovery convention). The first
-# is preferred — it produces zero false positives.
-_ASPNET_CONTROLLER_ATTR_RE = re.compile(r"\[\s*ApiController\b")
-_ASPNET_ROUTE_RE = re.compile(r"\[\s*(?:Http(?:Get|Post|Put|Delete|Patch|Options|Head)|Route)\b")
-_ASPNET_MAP_CALL_RE = re.compile(
- r"\.\s*Map(?:Get|Post|Put|Delete|Patch|Controllers|Hub|GrpcService|Razor|Fallback)\s*[<(]"
-)
-_ASPNET_USE_MIDDLEWARE_RE = re.compile(r"\.\s*UseMiddleware\s*<\s*(\w+)")
-_DBCONTEXT_DECL_RE = re.compile(r"class\s+\w+\s*:\s*[\w.<>,\s]*\bDbContext\b")
-_DBSET_RE = re.compile(r"\bDbSet\s*<\s*([A-Z]\w*)\s*>")
-
-
-def _has_aspnet_imports(parsed_files: dict[str, Any]) -> bool:
- """True if any parsed file imports Microsoft.AspNetCore.* — cheap signal."""
- for parsed in parsed_files.values():
- if parsed.file_info.language != "csharp":
- continue
- for imp in parsed.imports:
- if imp.module_path.startswith("Microsoft.AspNetCore"):
- return True
- return False
-
-
-def _read_cs_text(parsed: Any) -> str:
- try:
- return Path(parsed.file_info.abs_path).read_text(encoding="utf-8-sig", errors="ignore")
- except OSError:
- return ""
-
-
-def _add_aspnet_edges(
- graph: nx.DiGraph,
- parsed_files: dict[str, Any],
- path_set: set[str],
-) -> int:
- """Add edges representing ASP.NET wiring.
-
- Three independent signal sources are merged:
-
- 1. Application entry point (``Program.cs``/``Startup.cs``) → every
- controller file. ``MapControllers()`` is the discovery anchor;
- individual controllers are not statically referenced from
- ``Program.cs`` but the framework wires them at runtime.
-
- 2. Application entry point → handler files for any ``app.MapGet(...)``
- / ``MapPost(...)`` minimal API call. We can't resolve the handler
- expression statically, so we approximate by linking to every file
- whose class is named in the handler argument (heuristic only).
-
- 3. ``DbContext`` subclasses → files declaring the entity types named
- in their ``DbSet<T>`` properties. This surfaces EF Core's implicit
- persistence model wiring that no static import edge captures.
-
- Returns the number of edges added.
- """
- count = 0
- cs_files = [
- (path, parsed)
- for path, parsed in parsed_files.items()
- if parsed.file_info.language == "csharp" and path in path_set
- ]
- if not cs_files:
- return 0
-
- # ---- 1. Discover controllers and entry points ----
- controllers: list[str] = []
- entry_points: list[str] = []
- dbcontext_files: list[tuple[str, str]] = [] # (path, source)
- type_decl_to_file: dict[str, str] = {} # ClassName -> defining file path
-
- for path, parsed in cs_files:
- # Index every named class/struct/record this file declares so the
- # DbSet<T> step can resolve targets without re-parsing.
- for sym in parsed.symbols:
- if sym.kind in ("class", "struct", "record"):
- # Last-write wins is fine — duplicates are rare in well-formed code.
- type_decl_to_file[sym.name] = path
-
- text = _read_cs_text(parsed)
- if not text:
- continue
- if _ASPNET_CONTROLLER_ATTR_RE.search(text) or path.endswith("Controller.cs"):
- controllers.append(path)
- name = Path(path).name
- if name in ("Program.cs", "Startup.cs"):
- entry_points.append(path)
- if _DBCONTEXT_DECL_RE.search(text):
- dbcontext_files.append((path, text))
-
- # ---- 2. Entry point → controllers (MapControllers / UseEndpoints) ----
- for entry in entry_points:
- for ctrl in controllers:
- if ctrl == entry:
- continue
- if _add_edge_if_new(graph, entry, ctrl):
- count += 1
-
- # ---- 3. Entry point → file containing handler class referenced in MapXxx ----
- handler_arg_re = re.compile(
- r"\.\s*Map(?:Get|Post|Put|Delete|Patch)\s*\(\s*[\"'][^\"']+[\"']\s*,\s*([A-Za-z_]\w*)"
- )
- for entry in entry_points:
- text = _read_cs_text(parsed_files[entry])
- if not text:
- continue
- for match in handler_arg_re.finditer(text):
- ident = match.group(1)
- target = type_decl_to_file.get(ident)
- if target and target in path_set and _add_edge_if_new(graph, entry, target):
- count += 1
-
- # ---- 4. UseMiddleware<T>() ----
- middleware_re = _ASPNET_USE_MIDDLEWARE_RE
- for entry in entry_points:
- text = _read_cs_text(parsed_files[entry])
- if not text:
- continue
- for match in middleware_re.finditer(text):
- target = type_decl_to_file.get(match.group(1))
- if target and target in path_set and _add_edge_if_new(graph, entry, target):
- count += 1
-
- # ---- 5. DbContext → DbSet<T> entity files ----
- for db_path, db_text in dbcontext_files:
- for match in _DBSET_RE.finditer(db_text):
- entity = match.group(1)
- target = type_decl_to_file.get(entity)
- if target and target in path_set and _add_edge_if_new(graph, db_path, target):
- count += 1
-
- # NOTE: host-builder extension-method scanning (``app.MapCatalogApi()``)
- # moved to ``_add_csharp_extension_edges`` so it fires on desktop .NET
- # (WPF/WinUI) too, not just ASP.NET — see audit item #28.
-
- return count
-
-
-def _has_csharp_files(parsed_files: dict[str, Any]) -> bool:
- return any(p.file_info.language == "csharp" for p in parsed_files.values())
-
-
-def _add_csharp_extension_edges(
- graph: nx.DiGraph,
- parsed_files: dict[str, Any],
- path_set: set[str],
-) -> int:
- """Run the host-builder extension-method scan on any C# repo.
-
- Lifted out of ``_add_aspnet_edges`` so it also fires on desktop .NET
- (WPF / WinUI / WinForms) where ``Microsoft.AspNetCore.*`` is never
- imported but ``IServiceCollection`` / ``IModuleHost`` extension
- methods are still common. The host-type allowlist inside
- ``aspnet_extensions`` keeps false positives from generic ``Map(...)``
- LINQ calls at bay.
- """
- from .aspnet_extensions import add_extension_method_edges, collect_csharp_texts
-
- cs_texts = collect_csharp_texts(parsed_files, path_set)
- return add_extension_method_edges(graph, cs_texts, path_set)
-
-
-# ---------------------------------------------------------------------------
-# Helpers shared across the F1–F6 slices
-# ---------------------------------------------------------------------------
-
-
-def _read_text(parsed: Any) -> str:
- try:
- return Path(parsed.file_info.abs_path).read_text(encoding="utf-8", errors="ignore")
- except OSError:
- return ""
-
-
-def _build_class_to_file(parsed_files: dict[str, Any], languages: tuple[str, ...]) -> dict[str, str]:
- """Map declared class/interface/struct/enum/record names → file path."""
- result: dict[str, str] = {}
- for path, parsed in parsed_files.items():
- if parsed.file_info.language not in languages:
- continue
- for sym in parsed.symbols:
- if sym.kind in ("class", "interface", "struct", "record", "enum", "trait"):
- result.setdefault(sym.name, path)
- return result
-
-
-def _build_function_to_file(
- parsed_files: dict[str, Any], languages: tuple[str, ...]
-) -> dict[str, list[str]]:
- """Map declared function/method names → list of file paths declaring them."""
- result: dict[str, list[str]] = {}
- for path, parsed in parsed_files.items():
- if parsed.file_info.language not in languages:
- continue
- for sym in parsed.symbols:
- if sym.kind in ("function", "method"):
- result.setdefault(sym.name, []).append(path)
- return result
-
-
-# ---------------------------------------------------------------------------
-# F2 — Rails framework edges
-# ---------------------------------------------------------------------------
-
-
-_RAILS_RESOURCES_RE = re.compile(r"\bresources?\s+:(\w+)")
-_RAILS_GET_TO_RE = re.compile(
- r"\b(?:get|post|put|patch|delete|match)\s+[^\n]+?(?:to:\s*|=>\s*)['\"]([\w/]+)#\w+['\"]"
-)
-_RAILS_NAMESPACE_RE = re.compile(r"\bnamespace\s+:(\w+)\b")
-_RAILS_AR_RELATION_RE = re.compile(r"\b(?:belongs_to|has_many|has_one|has_and_belongs_to_many)\s+:(\w+)")
-
-
-def _singularize(word: str) -> str:
- """Very rough Rails inflector — sufficient for routes/AR lookups."""
- if word.endswith("ies") and len(word) > 3:
- return word[:-3] + "y"
- if word.endswith("ses") or word.endswith("xes") or word.endswith("zes"):
- return word[:-2]
- if word.endswith("s") and not word.endswith("ss"):
- return word[:-1]
- return word
-
-
-def _camelize(word: str) -> str:
- return "".join(part.capitalize() for part in word.split("_"))
-
-
-def _add_rails_edges(
- graph: nx.DiGraph,
- parsed_files: dict[str, Any],
- ctx: ResolverContext,
- path_set: set[str],
-) -> int:
- count = 0
-
- # ---- routes.rb → controller files ----
- routes_path = "config/routes.rb"
- if routes_path in path_set:
- try:
- text = Path(parsed_files[routes_path].file_info.abs_path).read_text(
- encoding="utf-8", errors="ignore"
- )
- except (OSError, KeyError):
- text = ""
- if text:
- # Parse line-by-line to track namespace nesting (indent-agnostic; we
- # use the order of opening keywords vs `end`).
- namespace_stack: list[str] = []
- for raw_line in text.splitlines():
- line = raw_line.strip()
- if not line or line.startswith("#"):
- continue
- ns_match = _RAILS_NAMESPACE_RE.search(line)
- if ns_match and ("do" in line or line.endswith("do")):
- namespace_stack.append(ns_match.group(1))
- continue
- if line == "end" and namespace_stack:
- namespace_stack.pop()
- continue
- # resources :users → users_controller
- for m in _RAILS_RESOURCES_RE.finditer(line):
- resource = m.group(1)
- target = _resolve_rails_controller(ctx, namespace_stack, resource, path_set)
- if target and _add_edge_if_new(graph, routes_path, target):
- count += 1
- # get "/foo", to: "users#index"
- for m in _RAILS_GET_TO_RE.finditer(line):
- ctrl_path = m.group(1)
- target = _resolve_rails_controller_path(ctx, namespace_stack, ctrl_path, path_set)
- if target and _add_edge_if_new(graph, routes_path, target):
- count += 1
-
- # ---- ActiveRecord relationships: model → model ----
- for path, parsed in parsed_files.items():
- if parsed.file_info.language != "ruby":
- continue
- if "/models/" not in path and not path.startswith("app/models/"):
- continue
- text = _read_text(parsed)
- if not text:
- continue
- for m in _RAILS_AR_RELATION_RE.finditer(text):
- assoc_name = m.group(1)
- target = _resolve_rails_relation(ctx, assoc_name, path_set)
- if target and _add_edge_if_new(graph, path, target):
- count += 1
-
- return count
-
-
-def _resolve_rails_controller(
- ctx: ResolverContext, namespace_stack: list[str], resource: str, path_set: set[str]
-) -> str | None:
- """`resources :users` (with optional `namespace :admin do`) → controller path."""
- namespace_segs = [seg for seg in namespace_stack]
- candidate_path = "/".join([*namespace_segs, f"{resource}_controller"])
- expected = f"app/controllers/{candidate_path}.rb"
- if expected in path_set:
- return expected
- # Try via Rails autoload index (heritage)
- constant = "::".join(_camelize(seg) for seg in [*namespace_segs, f"{resource}_controller"])
- return ctx.rails_lookup(constant)
-
-
-def _resolve_rails_controller_path(
- ctx: ResolverContext, namespace_stack: list[str], controller_token: str, path_set: set[str]
-) -> str | None:
- """`to: "users#index"` or `to: "admin/users#index"` → controller path."""
- expected = f"app/controllers/{controller_token}_controller.rb"
- if expected in path_set:
- return expected
- parts = controller_token.split("/")
- constant = "::".join(_camelize(p) for p in [*parts[:-1], f"{parts[-1]}_controller"])
- return ctx.rails_lookup(constant)
-
-
-def _resolve_rails_relation(
- ctx: ResolverContext, assoc_name: str, path_set: set[str]
-) -> str | None:
- """`belongs_to :user` / `has_many :orders` → model file."""
- singular = _singularize(assoc_name)
- expected = f"app/models/{singular}.rb"
- if expected in path_set:
- return expected
- return ctx.rails_lookup(_camelize(singular))
-
-
-# ---------------------------------------------------------------------------
-# F3 — Laravel framework edges
-# ---------------------------------------------------------------------------
-
-
-_LARAVEL_ROUTE_ARRAY_RE = re.compile(
- r"Route::(?:get|post|put|patch|delete|any|match|resource|apiResource)\s*\([^,]*,\s*\[\s*([\w\\]+)::class"
-)
-_LARAVEL_ROUTE_LEGACY_RE = re.compile(
- r"Route::(?:get|post|put|patch|delete|any|match)\s*\([^,]*,\s*['\"]([\w\\]+)@\w+['\"]"
-)
-_LARAVEL_ROUTE_RESOURCE_RE = re.compile(
- r"Route::(?:resource|apiResource)\s*\(\s*['\"][^'\"]+['\"]\s*,\s*([\w\\]+)::class"
-)
-_LARAVEL_BIND_RE = re.compile(
- r"->\s*(?:bind|singleton|instance)\s*\(\s*([\w\\]+)::class\s*,\s*([\w\\]+)::class"
-)
-_LARAVEL_ELOQUENT_RE = re.compile(
- r"\$this->\s*(?:hasMany|hasOne|belongsTo|belongsToMany|morphMany|morphOne|morphTo)\s*\(\s*([\w\\]+)::class"
-)
-
-
-def _resolve_laravel_class(
- ctx: ResolverContext, fqn: str, class_to_file: dict[str, str], path_set: set[str]
-) -> str | None:
- """Resolve `Foo\\Bar\\Baz` (or short `Bar`) to repo-relative .php path."""
- from .resolvers.php_composer import resolve_via_psr4
-
- if "\\" in fqn:
- result = resolve_via_psr4(fqn, ctx)
- if result and result in path_set:
- return result
- short = fqn.rsplit("\\", 1)[-1]
- return class_to_file.get(short)
-
-
-def _add_laravel_edges(
- graph: nx.DiGraph,
- parsed_files: dict[str, Any],
- ctx: ResolverContext,
- path_set: set[str],
-) -> int:
- count = 0
- class_to_file = _build_class_to_file(parsed_files, ("php",))
-
- # ---- routes/web.php / routes/api.php → controllers ----
- for routes_path in ("routes/web.php", "routes/api.php"):
- if routes_path not in path_set:
- continue
- try:
- text = Path(parsed_files[routes_path].file_info.abs_path).read_text(
- encoding="utf-8", errors="ignore"
- )
- except (OSError, KeyError):
- continue
- seen_targets: set[str] = set()
- for regex in (
- _LARAVEL_ROUTE_ARRAY_RE,
- _LARAVEL_ROUTE_LEGACY_RE,
- _LARAVEL_ROUTE_RESOURCE_RE,
- ):
- for m in regex.finditer(text):
- target = _resolve_laravel_class(ctx, m.group(1), class_to_file, path_set)
- if target and target in path_set and target not in seen_targets:
- seen_targets.add(target)
- if _add_edge_if_new(graph, routes_path, target):
- count += 1
-
- # ---- Service providers → bound classes ----
- for path, parsed in parsed_files.items():
- if parsed.file_info.language != "php":
- continue
- if not path.endswith("ServiceProvider.php"):
- continue
- text = _read_text(parsed)
- if not text:
- continue
- for m in _LARAVEL_BIND_RE.finditer(text):
- for fqn in (m.group(1), m.group(2)):
- target = _resolve_laravel_class(ctx, fqn, class_to_file, path_set)
- if target and target in path_set and _add_edge_if_new(graph, path, target):
- count += 1
-
- # ---- Eloquent relationships: model → related model ----
- for path, parsed in parsed_files.items():
- if parsed.file_info.language != "php":
- continue
- text = _read_text(parsed)
- if not text:
- continue
- for m in _LARAVEL_ELOQUENT_RE.finditer(text):
- target = _resolve_laravel_class(ctx, m.group(1), class_to_file, path_set)
- if target and target in path_set and _add_edge_if_new(graph, path, target):
- count += 1
-
- return count
-
-
-# ---------------------------------------------------------------------------
-# F1 — Spring Boot framework edges
-# ---------------------------------------------------------------------------
-
-
-_SPRING_BEAN_ANNOT = ("@Component", "@Service", "@Repository", "@Controller", "@RestController", "@Configuration")
-_SPRING_AUTOWIRED_FIELD_RE = re.compile(
- r"@Autowired\s+(?:private|protected|public|final|\s)*\s*([A-Z]\w*)\s+\w+"
-)
-_SPRING_CTOR_PARAM_RE = re.compile(r"\b([A-Z]\w*)\s+\w+\s*[,)]")
-_SPRING_BEAN_METHOD_RE = re.compile(
- r"@Bean\b[^\n]*\n\s*(?:public|protected|private|static|final|\s)+\s*([A-Z]\w*)\s+\w+\s*\("
-)
-_SPRING_BEAN_METHOD_KOTLIN_RE = re.compile(
- r"@Bean\b[^\n]*\n\s*(?:public|protected|private|internal|fun|open|\s)+\s*\w+\s*\([^)]*\)\s*:\s*([A-Z]\w*)"
-)
-
-
-def _has_spring_imports(parsed_files: dict[str, Any]) -> bool:
- for parsed in parsed_files.values():
- if parsed.file_info.language not in ("java", "kotlin"):
- continue
- for imp in parsed.imports:
- if imp.module_path.startswith("org.springframework"):
- return True
- return False
-
-
-def _add_spring_edges(
- graph: nx.DiGraph,
- parsed_files: dict[str, Any],
- path_set: set[str],
-) -> int:
- count = 0
- class_to_file = _build_class_to_file(parsed_files, ("java", "kotlin"))
-
- # Build interface → list of impl files map from heritage
- impl_map: dict[str, list[str]] = {}
- for path, parsed in parsed_files.items():
- if parsed.file_info.language not in ("java", "kotlin"):
- continue
- for rel in parsed.heritage:
- if rel.kind in ("implements", "extends"):
- impl_map.setdefault(rel.parent_name, []).append(path)
-
- def _resolve_type(type_name: str) -> list[str]:
- results: list[str] = []
- own = class_to_file.get(type_name)
- if own:
- results.append(own)
- for impl in impl_map.get(type_name, []):
- if impl not in results:
- results.append(impl)
- return results
-
- for path, parsed in parsed_files.items():
- if parsed.file_info.language not in ("java", "kotlin"):
- continue
- text = _read_text(parsed)
- if not text:
- continue
- is_bean = any(annot in text for annot in _SPRING_BEAN_ANNOT)
- if not is_bean:
- continue
-
- # @Autowired field injection
- for m in _SPRING_AUTOWIRED_FIELD_RE.finditer(text):
- type_name = m.group(1)
- for target in _resolve_type(type_name):
- if target in path_set and _add_edge_if_new(graph, path, target):
- count += 1
-
- # Constructor parameter injection: collect param types from any @Autowired
- # constructor or any single public constructor in a bean (Spring 4.3+ omits
- # the annotation when the class has only one constructor).
- for ctor_match in re.finditer(
- r"(?:@Autowired\s*\n\s*)?(?:public|protected|private|\s)*"
- + re.escape(Path(path).stem)
- + r"\s*\(([^)]*)\)",
- text,
- ):
- params = ctor_match.group(1)
- if not params.strip():
- continue
- for pm in _SPRING_CTOR_PARAM_RE.finditer(params + ","):
- type_name = pm.group(1)
- if type_name in ("String", "Integer", "Long", "Boolean", "Double", "Float"):
- continue
- for target in _resolve_type(type_name):
- if target in path_set and _add_edge_if_new(graph, path, target):
- count += 1
-
- # @Bean factory methods → return-type file
- if "@Configuration" in text:
- for m in _SPRING_BEAN_METHOD_RE.finditer(text):
- for target in _resolve_type(m.group(1)):
- if target in path_set and _add_edge_if_new(graph, path, target):
- count += 1
- for m in _SPRING_BEAN_METHOD_KOTLIN_RE.finditer(text):
- for target in _resolve_type(m.group(1)):
- if target in path_set and _add_edge_if_new(graph, path, target):
- count += 1
-
- return count
-
-
-# ---------------------------------------------------------------------------
-# F4 — Express / NestJS framework edges
-# ---------------------------------------------------------------------------
-
-
-_EXPRESS_USE_RE = re.compile(r"\.\s*use\s*\(\s*(?:['\"][^'\"]+['\"]\s*,\s*)?(\w+)\s*[,)]")
-_NEST_MODULE_RE = re.compile(r"@Module\s*\(\s*\{([^}]*)\}\s*\)", re.DOTALL)
-_NEST_ARRAY_FIELD_RE = re.compile(
- r"\b(?:controllers|providers|imports|exports)\s*:\s*\[([^\]]*)\]"
-)
-_IDENT_RE = re.compile(r"\b([A-Z]\w*)\b")
-
-
-def _has_express_imports(parsed_files: dict[str, Any]) -> bool:
- for parsed in parsed_files.values():
- if parsed.file_info.language not in ("typescript", "javascript"):
- continue
- for imp in parsed.imports:
- mp = imp.module_path
- if mp == "express" or mp.startswith("@nestjs/"):
- return True
- return False
-
-
-def _add_express_edges(
- graph: nx.DiGraph,
- parsed_files: dict[str, Any],
- ctx: ResolverContext,
- path_set: set[str],
-) -> int:
- count = 0
- class_to_file = _build_class_to_file(parsed_files, ("typescript", "javascript"))
-
- # ---- Express: app.use(routerVar) ----
- for path, parsed in parsed_files.items():
- if parsed.file_info.language not in ("typescript", "javascript"):
- continue
- text = _read_text(parsed)
- if not text:
- continue
-
- # Build local var → source file map for this file
- var_to_file: dict[str, str] = {}
- for imp in parsed.imports:
- for name in imp.imported_names:
- resolved = resolve_import(
- imp.module_path,
- path,
- parsed.file_info.language,
- ctx,
- )
- if resolved and resolved in path_set:
- var_to_file[name] = resolved
-
- if "express" in text or any(
- imp.module_path == "express" for imp in parsed.imports
- ):
- for m in _EXPRESS_USE_RE.finditer(text):
- var_name = m.group(1)
- target = var_to_file.get(var_name)
- if target and target in path_set and _add_edge_if_new(graph, path, target):
- count += 1
-
- # ---- NestJS: @Module({ controllers: [...], providers: [...], imports: [...] }) ----
- for mod_match in _NEST_MODULE_RE.finditer(text):
- body = mod_match.group(1)
- for arr_match in _NEST_ARRAY_FIELD_RE.finditer(body):
- for ident_match in _IDENT_RE.finditer(arr_match.group(1)):
- cls = ident_match.group(1)
- target = var_to_file.get(cls) or class_to_file.get(cls)
- if target and target in path_set and _add_edge_if_new(graph, path, target):
- count += 1
-
- return count
-
-
-# ---------------------------------------------------------------------------
-# F5 — Gin / Echo / Chi framework edges (Go)
-# ---------------------------------------------------------------------------
-
-
-_GO_ROUTER_PKG_PATTERNS = (
- "github.com/gin-gonic/gin",
- "github.com/labstack/echo",
- "github.com/go-chi/chi",
-)
-_GO_ROUTE_CALL_RE = re.compile(
- r"\.\s*(?:GET|POST|PUT|DELETE|PATCH|OPTIONS|HEAD|HandleFunc|Handle|Any)"
- r"\s*\(\s*[\"'][^\"']*[\"']\s*,\s*([\w.]+)"
-)
-
-
-def _has_go_router_imports(parsed_files: dict[str, Any]) -> bool:
- for parsed in parsed_files.values():
- if parsed.file_info.language != "go":
- continue
- for imp in parsed.imports:
- mp = imp.module_path
- if any(mp.startswith(pkg) for pkg in _GO_ROUTER_PKG_PATTERNS):
- return True
- return False
-
-
-def _add_go_router_edges(
- graph: nx.DiGraph,
- parsed_files: dict[str, Any],
- path_set: set[str],
-) -> int:
- count = 0
- func_to_files = _build_function_to_file(parsed_files, ("go",))
- class_to_file = _build_class_to_file(parsed_files, ("go",))
-
- for path, parsed in parsed_files.items():
- if parsed.file_info.language != "go":
- continue
- text = _read_text(parsed)
- if not text:
- continue
- if not any(
- imp.module_path.startswith(pkg)
- for pkg in _GO_ROUTER_PKG_PATTERNS
- for imp in parsed.imports
- ):
- # Allow if some other go file in the repo imports a router (router
- # setup may be split across files); be conservative and only emit
- # edges for files that themselves reference router calls.
- pass
-
- for m in _GO_ROUTE_CALL_RE.finditer(text):
- handler = m.group(1)
- targets = _resolve_go_handler(handler, parsed, func_to_files, class_to_file)
- for target in targets:
- if target != path and target in path_set and _add_edge_if_new(graph, path, target):
- count += 1
-
- return count
-
-
-def _resolve_go_handler(
- handler: str,
- parsed: Any,
- func_to_files: dict[str, list[str]],
- class_to_file: dict[str, str],
-) -> list[str]:
- """Resolve `pkg.Func` / `recv.Method` / `Func` to candidate file paths."""
- if "." in handler:
- prefix, name = handler.rsplit(".", 1)
- # First: was prefix imported as a package?
- for imp in parsed.imports:
- short = imp.module_path.rsplit("/", 1)[-1]
- if short == prefix and imp.resolved_file:
- # Find file declaring `name` whose path starts with the resolved package dir
- pkg_dir = "/".join(imp.resolved_file.split("/")[:-1])
- results = [
- p
- for p in func_to_files.get(name, [])
- if p.startswith(pkg_dir + "/") or p == imp.resolved_file
- ]
- if results:
- return results
- # Second: receiver-method — try the receiver's type file
- type_file = class_to_file.get(prefix.title())
- if type_file:
- return [type_file]
- # Third: fall back to any file declaring the bare name
- return list(func_to_files.get(name, []))
- return list(func_to_files.get(handler, []))
-
-
-# ---------------------------------------------------------------------------
-# F6 — Axum / Actix framework edges (Rust)
-# ---------------------------------------------------------------------------
-
-
-_RUST_AXUM_ROUTE_RE = re.compile(
- r"\.\s*route\s*\(\s*[\"'][^\"']*[\"']\s*,\s*"
- r"(?:get|post|put|delete|patch|head|options|on)\s*\(\s*([\w:]+)\s*\)"
-)
-_RUST_ACTIX_TO_RE = re.compile(r"web::\s*(?:get|post|put|delete|patch|head)\(\)\s*\.\s*to\s*\(\s*([\w:]+)\s*\)")
-_RUST_ACTIX_SERVICE_RE = re.compile(r"\.\s*service\s*\(\s*([\w:]+)\s*\)")
-_RUST_SCOPE_CONFIGURE_RE = re.compile(r"\.\s*configure\s*\(\s*([\w:]+)\s*\)")
-_RUST_NEST_RE = re.compile(r"\.\s*nest\s*\(\s*[\"'][^\"']*[\"']\s*,\s*([\w:]+)\s*\)")
-_RUST_LAYER_RE = re.compile(r"\.\s*layer\s*\(\s*(?:axum::middleware::from_fn\s*\(\s*)?([\w:]+)\s*\)")
-_RUST_FALLBACK_RE = re.compile(r"\.\s*fallback\s*\(\s*([\w:]+)\s*\)")
-_RUST_WITH_STATE_RE = re.compile(r"\.\s*with_state\s*\(\s*([\w:]+)\s*\)")
-_RUST_ROCKET_MOUNT_RE = re.compile(r"\.\s*mount\s*\(\s*[\"'][^\"']*[\"']\s*,\s*routes!\s*\[([^\]]+)\]")
-
-
-def _has_rust_router_imports(parsed_files: dict[str, Any]) -> bool:
- for parsed in parsed_files.values():
- if parsed.file_info.language != "rust":
- continue
- for imp in parsed.imports:
- mp = imp.module_path
- if mp.startswith(("axum", "actix_web", "actix-web", "rocket")):
- return True
- return False
-
-
-def _add_rust_router_edges(
- graph: nx.DiGraph,
- parsed_files: dict[str, Any],
- path_set: set[str],
-) -> int:
- count = 0
- func_to_files = _build_function_to_file(parsed_files, ("rust",))
-
- def _resolve(handler: str) -> list[str]:
- name = handler.rsplit("::", 1)[-1]
- return list(func_to_files.get(name, []))
-
- for path, parsed in parsed_files.items():
- if parsed.file_info.language != "rust":
- continue
- text = _read_text(parsed)
- if not text:
- continue
- for regex in (
- _RUST_AXUM_ROUTE_RE,
- _RUST_ACTIX_TO_RE,
- _RUST_ACTIX_SERVICE_RE,
- _RUST_SCOPE_CONFIGURE_RE,
- _RUST_NEST_RE,
- _RUST_LAYER_RE,
- _RUST_FALLBACK_RE,
- _RUST_WITH_STATE_RE,
- ):
- for m in regex.finditer(text):
- for target in _resolve(m.group(1)):
- if target != path and target in path_set and _add_edge_if_new(graph, path, target):
- count += 1
-
- # Rocket routes![] macro lists multiple handlers comma-separated
- for m in _RUST_ROCKET_MOUNT_RE.finditer(text):
- for handler in m.group(1).split(","):
- handler = handler.strip()
- if handler:
- for target in _resolve(handler):
- if target != path and target in path_set and _add_edge_if_new(graph, path, target):
- count += 1
-
- return count
-
-
-# ---------------------------------------------------------------------------
-# F8 — TYPO3 framework edges
-#
-# TYPO3 loads a fixed set of convention-named files from each extension at
-# bootstrap (``ext_localconf.php``, ``Configuration/TCA/*.php``, etc.). These
-# files are never imported via PHP/JS imports, so the static graph reports
-# ``in_degree=0`` and the dead-code analyzer flags them as unreachable.
-#
-# We attach a ``framework:typo3-core`` synthetic source to each convention
-# file present in an extension. ``Configuration/JavaScriptModules.php`` is
-# also parsed to add edges to the JS modules it registers (CKEditor plugins,
-# backend modules, etc.).
-#
-# Discovery signal: ``composer.json`` with ``"type": "typo3-cms-extension"``
-# (canonical for v11-v14) or, as fallback, any ``ext_emconf.php`` (legacy
-# non-composer installs).
-# ---------------------------------------------------------------------------
-
-_TYPO3_EXTERNAL_NODE = "framework:typo3-core"
-
-# Convention files at the extension root (matched by basename).
-_TYPO3_ROOT_FILES: tuple[str, ...] = (
- "ext_localconf.php",
- "ext_emconf.php",
- "ext_tables.php", # legacy v11-v13; absent in v14
- "ext_tables.sql",
-)
-
-# Convention files / globs under ``Configuration/`` (matched relative to the
-# extension root, with forward-slash separators).
-_TYPO3_CONFIG_GLOBS: tuple[str, ...] = (
- "Configuration/JavaScriptModules.php",
- "Configuration/ContentSecurityPolicies.php",
- "Configuration/RequestMiddlewares.php",
- "Configuration/Icons.php",
- "Configuration/Services.php",
- "Configuration/Services.yaml",
- "Configuration/Services.yml",
- "Configuration/TCA/*.php",
- "Configuration/TCA/Overrides/*.php",
- "Configuration/Backend/*.php",
- "Configuration/RTE/*.yaml",
- "Configuration/RTE/*.yml",
-)
-
-# JavaScriptModules.php registers JS files via entries like
-# ``'@vendor/ext/MyModule' => 'EXT:ext_key/Resources/Public/JavaScript/My.js'``.
-# We extract the right-hand value to add edges to the registered files.
-_TYPO3_JS_MODULE_VALUE_RE = re.compile(
- r"""['"]EXT:(?P<ext>[a-z0-9_]+)/(?P<rel>[^'"]+\.(?:js|mjs))['"]""",
- re.IGNORECASE,
-)
-
-
-def _has_typo3_extension(ctx: ResolverContext, path_set: set[str]) -> bool:
- """Return True if the repo contains at least one TYPO3 extension.
-
- Checks ``composer.json`` ``type`` field first (canonical across v11-v14);
- falls back to any ``ext_emconf.php`` in path_set for legacy installs.
- """
- return bool(_find_typo3_extension_roots(ctx, path_set))
-
-
-def _find_typo3_extension_roots(
- ctx: ResolverContext, path_set: set[str]
-) -> set[str]:
- """Return the set of extension root directories (repo-relative, posix).
-
- Sources, in order of authority:
- 1. Any ``composer.json`` with ``"type": "typo3-cms-extension"``.
- 2. Any ``ext_emconf.php`` (legacy fallback when composer.json is missing).
- """
- roots: set[str] = set()
-
- # 1. composer.json based discovery — walk the filesystem from repo root,
- # bounded depth to avoid deep vendor/node_modules traversal during tests.
- repo_path = getattr(ctx, "repo_path", None)
- if repo_path is not None:
- try:
- for composer in _iter_composer_jsons(Path(repo_path)):
- try:
- data = json.loads(composer.read_text(encoding="utf-8", errors="ignore"))
- except (OSError, ValueError):
- continue
- if not isinstance(data, dict):
- continue
- if data.get("type") != "typo3-cms-extension":
- continue
- ext_root = composer.parent.resolve()
- rel = _to_repo_relative(repo_path, ext_root)
- if rel is not None:
- roots.add(rel)
- except OSError:
- pass
-
- # 2. ext_emconf.php fallback for repos without a composer.json (legacy
- # non-composer installs, mostly v11 and earlier).
- for p in path_set:
- if Path(p).name == "ext_emconf.php":
- parent = Path(p).parent.as_posix()
- roots.add("" if parent == "." else parent)
-
- return roots
-
-
-def _iter_composer_jsons(root: Path):
- """Yield composer.json paths likely to declare a TYPO3 extension.
-
- Searched locations:
- - ``<root>/composer.json``
- - ``<root>/<dir>/composer.json`` (single-level, for monorepos of extensions)
- - ``<root>/vendor/<vendor>/<package>/composer.json`` (project-mode TYPO3
- installs where extensions live under ``vendor/``)
-
- ``node_modules``, ``.git``, ``.bare``, and ``Build`` are skipped. Hidden
- directories are skipped at the top level only — vendor packages keep their
- nested layout.
- """
- skip_top = {"node_modules", ".git", ".bare", "var", "Build"}
- if (root / "composer.json").is_file():
- yield root / "composer.json"
-
- try:
- children = list(root.iterdir())
- except OSError:
- return
-
- for child in children:
- if not child.is_dir():
- continue
- if child.name == "vendor":
- yield from _iter_vendor_composer_jsons(child)
- continue
- if child.name in skip_top or child.name.startswith("."):
- continue
- candidate = child / "composer.json"
- if candidate.is_file():
- yield candidate
-
-
-def _iter_vendor_composer_jsons(vendor_root: Path):
- """Yield composer.json files at ``vendor/<vendor>/<package>/composer.json``.
-
- Bounded to two levels deep — composer's flat layout means we never need
- to recurse further. Symlinks are followed at most once.
- """
- try:
- vendors = list(vendor_root.iterdir())
- except OSError:
- return
- for vendor_dir in vendors:
- if not vendor_dir.is_dir() or vendor_dir.name.startswith("."):
- continue
- try:
- packages = list(vendor_dir.iterdir())
- except OSError:
- continue
- for pkg_dir in packages:
- if not pkg_dir.is_dir() or pkg_dir.name.startswith("."):
- continue
- candidate = pkg_dir / "composer.json"
- if candidate.is_file():
- yield candidate
-
-
-def _to_repo_relative(repo_path: Path, abs_path: Path) -> str | None:
- try:
- rel = abs_path.relative_to(Path(repo_path).resolve()).as_posix()
- except ValueError:
- return None
- return "" if rel == "." else rel
-
-
-def _add_typo3_edges(
- graph: nx.DiGraph,
- parsed_files: dict[str, Any],
- ctx: ResolverContext,
- path_set: set[str],
-) -> int:
- """Add framework edges for each detected TYPO3 extension.
-
- Edges added:
- - ``framework:typo3-core`` → each convention file present in the extension.
- - ``Configuration/JavaScriptModules.php`` → each JS file it registers.
- """
- count = 0
- roots = _find_typo3_extension_roots(ctx, path_set)
- if not roots:
- return 0
-
- if _TYPO3_EXTERNAL_NODE not in graph:
- graph.add_node(_TYPO3_EXTERNAL_NODE, language="external")
-
- for root in roots:
- for basename in _TYPO3_ROOT_FILES:
- target = f"{root}/{basename}" if root else basename
- if target in path_set and _add_edge_if_new(graph, _TYPO3_EXTERNAL_NODE, target):
- count += 1
-
- for glob in _TYPO3_CONFIG_GLOBS:
- prefix = f"{root}/" if root else ""
- pat = f"{prefix}{glob}"
- for p in path_set:
- if fnmatch.fnmatch(p, pat) and _add_edge_if_new(graph, _TYPO3_EXTERNAL_NODE, p):
- count += 1
-
- # Parse JavaScriptModules.php for registered JS files.
- js_modules_path = f"{root}/Configuration/JavaScriptModules.php" if root else "Configuration/JavaScriptModules.php"
- if js_modules_path in path_set:
- count += _add_typo3_js_module_edges(
- graph, parsed_files, path_set, root, js_modules_path
- )
-
- return count
-
-
-def _add_typo3_js_module_edges(
- graph: nx.DiGraph,
- parsed_files: dict[str, Any],
- path_set: set[str],
- ext_root: str,
- js_modules_path: str,
-) -> int:
- """Parse JavaScriptModules.php and add edges to each registered JS file.
-
- Resolves ``EXT:<ext_key>/<rel>`` to a repo-relative path under ``ext_root``
- when the extension is local; cross-extension references are ignored.
- """
- parsed = parsed_files.get(js_modules_path)
- if parsed is None:
- return 0
- text = _read_text(parsed)
- if not text:
- return 0
-
- own_ext_key = _extract_ext_key_from_composer(parsed_files, ext_root)
-
- count = 0
- for m in _TYPO3_JS_MODULE_VALUE_RE.finditer(text):
- ext_key = m.group("ext").lower()
- rel = m.group("rel")
- if own_ext_key is not None and ext_key != own_ext_key:
- continue
- target = f"{ext_root}/{rel}" if ext_root else rel
- if target in path_set and _add_edge_if_new(graph, js_modules_path, target):
- count += 1
- return count
-
-
-def _extract_ext_key_from_composer(
- parsed_files: dict[str, Any], ext_root: str
-) -> str | None:
- """Best-effort extraction of the TYPO3 extension key from composer.json.
-
- Reads ``extra.typo3/cms.extension-key`` first (canonical), falls back to
- deriving the key from the package name (``vendor/ext-key`` → ``ext_key``).
- Returns ``None`` if composer.json is missing or unreadable.
- """
- composer_path = f"{ext_root}/composer.json" if ext_root else "composer.json"
- parsed = parsed_files.get(composer_path)
- abs_path: Path | None = None
- if parsed is not None:
- abs_path = Path(parsed.file_info.abs_path)
- if abs_path is None or not abs_path.is_file():
- return None
- try:
- data = json.loads(abs_path.read_text(encoding="utf-8", errors="ignore"))
- except (OSError, ValueError):
- return None
- if not isinstance(data, dict):
- return None
- extra_raw = data.get("extra")
- extra: dict[str, Any] = extra_raw if isinstance(extra_raw, dict) else {}
- typo3_raw = extra.get("typo3/cms")
- typo3: dict[str, Any] = typo3_raw if isinstance(typo3_raw, dict) else {}
- key = typo3.get("extension-key")
- if isinstance(key, str) and key:
- return key.lower()
- name = data.get("name")
- if isinstance(name, str) and "/" in name:
- return name.split("/", 1)[1].replace("-", "_").lower()
- return None
diff --git a/packages/core/src/repowise/core/ingestion/framework_edges/__init__.py b/packages/core/src/repowise/core/ingestion/framework_edges/__init__.py
new file mode 100644
index 000000000..f3bf069ae
--- /dev/null
+++ b/packages/core/src/repowise/core/ingestion/framework_edges/__init__.py
@@ -0,0 +1,92 @@
+"""Framework-aware synthetic edge detection.
+
+Detects convention-based relationships (Django, FastAPI, Flask, ASP.NET, Rails,
+Laravel, Spring, Express/Nest, Gin/Echo/Chi, Axum/Actix/Rocket, TYPO3, and
+pytest ``conftest.py``) and adds ``edge_type="framework"`` edges that no static
+import graph captures.
+
+Previously a single ``framework_edges.py`` module; split (PR 3.5) into one
+module per framework behind this façade. The public entry point —
+``add_framework_edges`` — is unchanged; it now iterates an ordered list of
+:class:`~.base.FrameworkHandler` objects, preserving the original detection
+order (and therefore which framework "wins" a shared edge via
+:func:`~.base._add_edge_if_new`).
+"""
+
+from __future__ import annotations
+
+from typing import TYPE_CHECKING
+
+from . import (
+ aspnet,
+ django,
+ express,
+ fastapi,
+ flask,
+ go,
+ laravel,
+ pytest_edges,
+ rails,
+ rust,
+ spring,
+ typo3,
+)
+from .base import DetectionContext, FrameworkHandler, _add_edge_if_new, read_text
+
+if TYPE_CHECKING:
+ import networkx as nx
+
+ from ..models import ParsedFile
+ from ..resolvers import ResolverContext
+
+# Ordered exactly as the original ``add_framework_edges`` invoked them — the
+# order is load-bearing because ``_add_edge_if_new`` is first-wins.
+_HANDLERS: list[FrameworkHandler] = [
+ *pytest_edges.HANDLERS, # always runs
+ *django.HANDLERS,
+ *fastapi.HANDLERS,
+ *flask.HANDLERS,
+ *aspnet.HANDLERS, # ASP.NET edges, then the any-C# extension-method scan
+ *rails.HANDLERS,
+ *laravel.HANDLERS,
+ *spring.HANDLERS,
+ *express.HANDLERS,
+ *go.HANDLERS,
+ *rust.HANDLERS,
+ *typo3.HANDLERS,
+]
+
+
+def add_framework_edges(
+ graph: nx.DiGraph,
+ parsed_files: dict[str, ParsedFile],
+ ctx: ResolverContext,
+ tech_stack: list[str] | None = None,
+) -> int:
+ """Add synthetic edges for framework-mediated relationships.
+
+ Returns the number of edges added.
+ """
+ path_set = set(parsed_files.keys())
+ stack_lower = {s.lower() for s in (tech_stack or [])}
+ dctx = DetectionContext(
+ stack_lower=stack_lower,
+ parsed_files=parsed_files,
+ ctx=ctx,
+ path_set=path_set,
+ )
+
+ count = 0
+ for handler in _HANDLERS:
+ if handler.detect(dctx):
+ count += handler.add_edges(graph, parsed_files, ctx, path_set)
+ return count
+
+
+__all__ = [
+ "DetectionContext",
+ "FrameworkHandler",
+ "_add_edge_if_new",
+ "add_framework_edges",
+ "read_text",
+]
diff --git a/packages/core/src/repowise/core/ingestion/framework_edges/aspnet.py b/packages/core/src/repowise/core/ingestion/framework_edges/aspnet.py
new file mode 100644
index 000000000..352ec5edb
--- /dev/null
+++ b/packages/core/src/repowise/core/ingestion/framework_edges/aspnet.py
@@ -0,0 +1,213 @@
+"""ASP.NET / .NET framework edges.
+
+Split out of ``framework_edges.py`` (PR 3.5) — behaviour-preserving move.
+"""
+
+from __future__ import annotations
+
+import re
+from pathlib import Path
+from typing import TYPE_CHECKING, Any
+
+from ..resolvers import ResolverContext
+from .base import (
+ DetectionContext,
+ FrameworkHandler,
+ _add_edge_if_new,
+ read_text,
+)
+
+if TYPE_CHECKING:
+ import networkx as nx
+
+
+# A class becomes a controller when it is annotated [ApiController] OR its
+# class name ends in "Controller" (the MVC discovery convention). The first
+# is preferred — it produces zero false positives.
+_ASPNET_CONTROLLER_ATTR_RE = re.compile(r"\[\s*ApiController\b")
+_ASPNET_ROUTE_RE = re.compile(r"\[\s*(?:Http(?:Get|Post|Put|Delete|Patch|Options|Head)|Route)\b")
+_ASPNET_MAP_CALL_RE = re.compile(
+ r"\.\s*Map(?:Get|Post|Put|Delete|Patch|Controllers|Hub|GrpcService|Razor|Fallback)\s*[<(]"
+)
+_ASPNET_USE_MIDDLEWARE_RE = re.compile(r"\.\s*UseMiddleware\s*<\s*(\w+)")
+_DBCONTEXT_DECL_RE = re.compile(r"class\s+\w+\s*:\s*[\w.<>,\s]*\bDbContext\b")
+_DBSET_RE = re.compile(r"\bDbSet\s*<\s*([A-Z]\w*)\s*>")
+
+
+def _has_aspnet_imports(parsed_files: dict[str, Any]) -> bool:
+ """True if any parsed file imports Microsoft.AspNetCore.* — cheap signal."""
+ for parsed in parsed_files.values():
+ if parsed.file_info.language != "csharp":
+ continue
+ for imp in parsed.imports:
+ if imp.module_path.startswith("Microsoft.AspNetCore"):
+ return True
+ return False
+
+
+def _add_aspnet_edges(
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ path_set: set[str],
+) -> int:
+ """Add edges representing ASP.NET wiring.
+
+ Three independent signal sources are merged:
+
+ 1. Application entry point (``Program.cs``/``Startup.cs``) → every
+ controller file. ``MapControllers()`` is the discovery anchor;
+ individual controllers are not statically referenced from
+ ``Program.cs`` but the framework wires them at runtime.
+
+ 2. Application entry point → handler files for any ``app.MapGet(...)``
+ / ``MapPost(...)`` minimal API call. We can't resolve the handler
+ expression statically, so we approximate by linking to every file
+ whose class is named in the handler argument (heuristic only).
+
+ 3. ``DbContext`` subclasses → files declaring the entity types named
+ in their ``DbSet<T>`` properties. This surfaces EF Core's implicit
+ persistence model wiring that no static import edge captures.
+
+ Returns the number of edges added.
+ """
+ count = 0
+ cs_files = [
+ (path, parsed)
+ for path, parsed in parsed_files.items()
+ if parsed.file_info.language == "csharp" and path in path_set
+ ]
+ if not cs_files:
+ return 0
+
+ # ---- 1. Discover controllers and entry points ----
+ controllers: list[str] = []
+ entry_points: list[str] = []
+ dbcontext_files: list[tuple[str, str]] = [] # (path, source)
+ type_decl_to_file: dict[str, str] = {} # ClassName -> defining file path
+
+ for path, parsed in cs_files:
+ # Index every named class/struct/record this file declares so the
+ # DbSet<T> step can resolve targets without re-parsing.
+ for sym in parsed.symbols:
+ if sym.kind in ("class", "struct", "record"):
+ # Last-write wins is fine — duplicates are rare in well-formed code.
+ type_decl_to_file[sym.name] = path
+
+ text = read_text(parsed, encoding="utf-8-sig")
+ if not text:
+ continue
+ if _ASPNET_CONTROLLER_ATTR_RE.search(text) or path.endswith("Controller.cs"):
+ controllers.append(path)
+ name = Path(path).name
+ if name in ("Program.cs", "Startup.cs"):
+ entry_points.append(path)
+ if _DBCONTEXT_DECL_RE.search(text):
+ dbcontext_files.append((path, text))
+
+ # ---- 2. Entry point → controllers (MapControllers / UseEndpoints) ----
+ for entry in entry_points:
+ for ctrl in controllers:
+ if ctrl == entry:
+ continue
+ if _add_edge_if_new(graph, entry, ctrl):
+ count += 1
+
+ # ---- 3. Entry point → file containing handler class referenced in MapXxx ----
+ handler_arg_re = re.compile(
+ r"\.\s*Map(?:Get|Post|Put|Delete|Patch)\s*\(\s*[\"'][^\"']+[\"']\s*,\s*([A-Za-z_]\w*)"
+ )
+ for entry in entry_points:
+ text = read_text(parsed_files[entry], encoding="utf-8-sig")
+ if not text:
+ continue
+ for match in handler_arg_re.finditer(text):
+ ident = match.group(1)
+ target = type_decl_to_file.get(ident)
+ if target and target in path_set and _add_edge_if_new(graph, entry, target):
+ count += 1
+
+ # ---- 4. UseMiddleware<T>() ----
+ middleware_re = _ASPNET_USE_MIDDLEWARE_RE
+ for entry in entry_points:
+ text = read_text(parsed_files[entry], encoding="utf-8-sig")
+ if not text:
+ continue
+ for match in middleware_re.finditer(text):
+ target = type_decl_to_file.get(match.group(1))
+ if target and target in path_set and _add_edge_if_new(graph, entry, target):
+ count += 1
+
+ # ---- 5. DbContext → DbSet<T> entity files ----
+ for db_path, db_text in dbcontext_files:
+ for match in _DBSET_RE.finditer(db_text):
+ entity = match.group(1)
+ target = type_decl_to_file.get(entity)
+ if target and target in path_set and _add_edge_if_new(graph, db_path, target):
+ count += 1
+
+ # NOTE: host-builder extension-method scanning (``app.MapCatalogApi()``)
+ # moved to ``_add_csharp_extension_edges`` so it fires on desktop .NET
+ # (WPF/WinUI) too, not just ASP.NET — see audit item #28.
+
+ return count
+
+
+def _has_csharp_files(parsed_files: dict[str, Any]) -> bool:
+ return any(p.file_info.language == "csharp" for p in parsed_files.values())
+
+
+def _add_csharp_extension_edges(
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ path_set: set[str],
+) -> int:
+ """Run the host-builder extension-method scan on any C# repo.
+
+ Lifted out of ``_add_aspnet_edges`` so it also fires on desktop .NET
+ (WPF / WinUI / WinForms) where ``Microsoft.AspNetCore.*`` is never
+ imported but ``IServiceCollection`` / ``IModuleHost`` extension
+ methods are still common. The host-type allowlist inside
+ ``aspnet_extensions`` keeps false positives from generic ``Map(...)``
+ LINQ calls at bay.
+ """
+ from ..aspnet_extensions import add_extension_method_edges, collect_csharp_texts
+
+ cs_texts = collect_csharp_texts(parsed_files, path_set)
+ return add_extension_method_edges(graph, cs_texts, path_set)
+
+
+class _AspNetHandler:
+ def detect(self, dctx: DetectionContext) -> bool:
+ aspnet_in_stack = any(
+ token in dctx.stack_lower
+ for token in ("aspnet", "asp.net", "aspnetcore", "asp.net core")
+ )
+ return aspnet_in_stack or _has_aspnet_imports(dctx.parsed_files)
+
+ def add_edges(
+ self,
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+ ) -> int:
+ return _add_aspnet_edges(graph, parsed_files, path_set)
+
+
+class _CSharpExtensionHandler:
+ """Host-builder extension-method scan — runs on ANY C# repo (desktop .NET too)."""
+
+ def detect(self, dctx: DetectionContext) -> bool:
+ return _has_csharp_files(dctx.parsed_files)
+
+ def add_edges(
+ self,
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+ ) -> int:
+ return _add_csharp_extension_edges(graph, parsed_files, path_set)
+
+
+HANDLERS: list[FrameworkHandler] = [_AspNetHandler(), _CSharpExtensionHandler()]
diff --git a/packages/core/src/repowise/core/ingestion/framework_edges/base.py b/packages/core/src/repowise/core/ingestion/framework_edges/base.py
new file mode 100644
index 000000000..01aebd61a
--- /dev/null
+++ b/packages/core/src/repowise/core/ingestion/framework_edges/base.py
@@ -0,0 +1,101 @@
+"""Shared helpers and the ``FrameworkHandler`` protocol for framework-edge detection.
+
+Split out of ``framework_edges.py`` (PR 3.5). Holds the cross-framework
+primitives: the dedup ``_add_edge_if_new`` guard, the unified ``read_text``
+file reader (collapses the old ``_read_text`` / ``_read_cs_text`` variants),
+the class/function-name → file maps, and the ``FrameworkHandler`` protocol the
+dispatcher iterates over.
+"""
+
+from __future__ import annotations
+
+from dataclasses import dataclass
+from pathlib import Path
+from typing import TYPE_CHECKING, Any, Protocol
+
+if TYPE_CHECKING:
+ import networkx as nx
+
+ from ..resolvers import ResolverContext
+
+
+@dataclass(frozen=True)
+class DetectionContext:
+ """Inputs every handler's ``detect()`` may consult.
+
+ Bundled once per ``add_framework_edges`` call so the dispatcher can iterate
+ handlers uniformly regardless of which signal a given framework keys off.
+ """
+
+ stack_lower: set[str]
+ parsed_files: dict[str, Any]
+ ctx: ResolverContext
+ path_set: set[str]
+
+
+class FrameworkHandler(Protocol):
+ """A single framework's detection + edge-emission pair."""
+
+ def detect(self, dctx: DetectionContext) -> bool:
+ """Return True when this framework's edges should be emitted."""
+ ...
+
+ def add_edges(
+ self,
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+ ) -> int:
+ """Emit this framework's synthetic edges; return the count added."""
+ ...
+
+
+def _add_edge_if_new(graph: nx.DiGraph, source: str, target: str) -> bool:
+ """Add a framework edge if no edge already exists. Returns True if added."""
+ if source == target:
+ return False
+ if graph.has_edge(source, target):
+ return False
+ graph.add_edge(source, target, edge_type="framework", imported_names=[])
+ return True
+
+
+def read_text(parsed: Any, encoding: str = "utf-8") -> str:
+ """Read a parsed file's source text, returning ``""`` on read failure.
+
+ Collapses the former ``_read_text`` (utf-8) and ``_read_cs_text``
+ (utf-8-sig) helpers — pass ``encoding="utf-8-sig"`` for C# BOM files.
+ """
+ try:
+ return Path(parsed.file_info.abs_path).read_text(encoding=encoding, errors="ignore")
+ except OSError:
+ return ""
+
+
+def _build_class_to_file(
+ parsed_files: dict[str, Any], languages: tuple[str, ...]
+) -> dict[str, str]:
+ """Map declared class/interface/struct/enum/record names → file path."""
+ result: dict[str, str] = {}
+ for path, parsed in parsed_files.items():
+ if parsed.file_info.language not in languages:
+ continue
+ for sym in parsed.symbols:
+ if sym.kind in ("class", "interface", "struct", "record", "enum", "trait"):
+ result.setdefault(sym.name, path)
+ return result
+
+
+def _build_function_to_file(
+ parsed_files: dict[str, Any], languages: tuple[str, ...]
+) -> dict[str, list[str]]:
+ """Map declared function/method names → list of file paths declaring them."""
+ result: dict[str, list[str]] = {}
+ for path, parsed in parsed_files.items():
+ if parsed.file_info.language not in languages:
+ continue
+ for sym in parsed.symbols:
+ if sym.kind in ("function", "method"):
+ result.setdefault(sym.name, []).append(path)
+ return result
diff --git a/packages/core/src/repowise/core/ingestion/framework_edges/django.py b/packages/core/src/repowise/core/ingestion/framework_edges/django.py
new file mode 100644
index 000000000..db9668781
--- /dev/null
+++ b/packages/core/src/repowise/core/ingestion/framework_edges/django.py
@@ -0,0 +1,73 @@
+"""Django convention edges.
+
+Split out of ``framework_edges.py`` (PR 3.5) — behaviour-preserving move.
+"""
+
+from __future__ import annotations
+
+from pathlib import Path
+from typing import TYPE_CHECKING, Any
+
+from ..resolvers import ResolverContext
+from .base import (
+ DetectionContext,
+ FrameworkHandler,
+ _add_edge_if_new,
+)
+
+if TYPE_CHECKING:
+ import networkx as nx
+
+
+def _add_django_edges(graph: nx.DiGraph, path_set: set[str]) -> int:
+ """Django conventions: admin->models, urls->views in the same directory."""
+ count = 0
+ by_dir: dict[str, dict[str, str]] = {}
+ for p in path_set:
+ pp = Path(p)
+ d = pp.parent.as_posix()
+ by_dir.setdefault(d, {})[pp.stem] = p
+
+ for _d, stems in by_dir.items():
+ if (
+ "admin" in stems
+ and "models" in stems
+ and _add_edge_if_new(graph, stems["admin"], stems["models"])
+ ):
+ count += 1
+ if (
+ "urls" in stems
+ and "views" in stems
+ and _add_edge_if_new(graph, stems["urls"], stems["views"])
+ ):
+ count += 1
+ if (
+ "forms" in stems
+ and "models" in stems
+ and _add_edge_if_new(graph, stems["forms"], stems["models"])
+ ):
+ count += 1
+ if (
+ "serializers" in stems
+ and "models" in stems
+ and _add_edge_if_new(graph, stems["serializers"], stems["models"])
+ ):
+ count += 1
+ return count
+
+
+class _DjangoHandler:
+ def detect(self, dctx: DetectionContext) -> bool:
+ return "django" in dctx.stack_lower
+
+ def add_edges(
+ self,
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+ ) -> int:
+ return _add_django_edges(graph, path_set)
+
+
+HANDLERS: list[FrameworkHandler] = [_DjangoHandler()]
diff --git a/packages/core/src/repowise/core/ingestion/framework_edges/express.py b/packages/core/src/repowise/core/ingestion/framework_edges/express.py
new file mode 100644
index 000000000..8b1cf61cf
--- /dev/null
+++ b/packages/core/src/repowise/core/ingestion/framework_edges/express.py
@@ -0,0 +1,108 @@
+"""Express / NestJS convention edges.
+
+Split out of ``framework_edges.py`` (PR 3.5) — behaviour-preserving move.
+"""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING, Any
+
+from ..resolvers import ResolverContext, resolve_import
+from .base import (
+ DetectionContext,
+ FrameworkHandler,
+ _add_edge_if_new,
+ _build_class_to_file,
+ read_text,
+)
+
+if TYPE_CHECKING:
+ import networkx as nx
+
+
+_EXPRESS_USE_RE = re.compile(r"\.\s*use\s*\(\s*(?:['\"][^'\"]+['\"]\s*,\s*)?(\w+)\s*[,)]")
+_NEST_MODULE_RE = re.compile(r"@Module\s*\(\s*\{([^}]*)\}\s*\)", re.DOTALL)
+_NEST_ARRAY_FIELD_RE = re.compile(r"\b(?:controllers|providers|imports|exports)\s*:\s*\[([^\]]*)\]")
+_IDENT_RE = re.compile(r"\b([A-Z]\w*)\b")
+
+
+def _has_express_imports(parsed_files: dict[str, Any]) -> bool:
+ for parsed in parsed_files.values():
+ if parsed.file_info.language not in ("typescript", "javascript"):
+ continue
+ for imp in parsed.imports:
+ mp = imp.module_path
+ if mp == "express" or mp.startswith("@nestjs/"):
+ return True
+ return False
+
+
+def _add_express_edges(
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+) -> int:
+ count = 0
+ class_to_file = _build_class_to_file(parsed_files, ("typescript", "javascript"))
+
+ # ---- Express: app.use(routerVar) ----
+ for path, parsed in parsed_files.items():
+ if parsed.file_info.language not in ("typescript", "javascript"):
+ continue
+ text = read_text(parsed)
+ if not text:
+ continue
+
+ # Build local var → source file map for this file
+ var_to_file: dict[str, str] = {}
+ for imp in parsed.imports:
+ for name in imp.imported_names:
+ resolved = resolve_import(
+ imp.module_path,
+ path,
+ parsed.file_info.language,
+ ctx,
+ )
+ if resolved and resolved in path_set:
+ var_to_file[name] = resolved
+
+ if "express" in text or any(imp.module_path == "express" for imp in parsed.imports):
+ for m in _EXPRESS_USE_RE.finditer(text):
+ var_name = m.group(1)
+ target = var_to_file.get(var_name)
+ if target and target in path_set and _add_edge_if_new(graph, path, target):
+ count += 1
+
+ # ---- NestJS: @Module({ controllers: [...], providers: [...], imports: [...] }) ----
+ for mod_match in _NEST_MODULE_RE.finditer(text):
+ body = mod_match.group(1)
+ for arr_match in _NEST_ARRAY_FIELD_RE.finditer(body):
+ for ident_match in _IDENT_RE.finditer(arr_match.group(1)):
+ cls = ident_match.group(1)
+ target = var_to_file.get(cls) or class_to_file.get(cls)
+ if target and target in path_set and _add_edge_if_new(graph, path, target):
+ count += 1
+
+ return count
+
+
+class _ExpressHandler:
+ def detect(self, dctx: DetectionContext) -> bool:
+ express_in_stack = any(
+ token in dctx.stack_lower for token in ("express", "nestjs", "nest", "nest.js")
+ )
+ return express_in_stack or _has_express_imports(dctx.parsed_files)
+
+ def add_edges(
+ self,
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+ ) -> int:
+ return _add_express_edges(graph, parsed_files, ctx, path_set)
+
+
+HANDLERS: list[FrameworkHandler] = [_ExpressHandler()]
diff --git a/packages/core/src/repowise/core/ingestion/framework_edges/fastapi.py b/packages/core/src/repowise/core/ingestion/framework_edges/fastapi.py
new file mode 100644
index 000000000..f2fdc93e1
--- /dev/null
+++ b/packages/core/src/repowise/core/ingestion/framework_edges/fastapi.py
@@ -0,0 +1,76 @@
+"""FastAPI ``include_router`` convention edges.
+
+Split out of ``framework_edges.py`` (PR 3.5) — behaviour-preserving move.
+"""
+
+from __future__ import annotations
+
+import re
+from pathlib import Path
+from typing import TYPE_CHECKING, Any
+
+from ..resolvers import ResolverContext, resolve_import
+from .base import (
+ DetectionContext,
+ FrameworkHandler,
+ _add_edge_if_new,
+)
+
+if TYPE_CHECKING:
+ import networkx as nx
+
+
+def _add_fastapi_edges(
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+) -> int:
+ """Detect include_router() calls and link app files to router modules."""
+ count = 0
+ var_to_file: dict[str, str] = {}
+
+ for path, parsed in parsed_files.items():
+ for imp in parsed.imports:
+ for name in imp.imported_names:
+ if name.lower().endswith("router") or name.lower().endswith("app"):
+ resolved = resolve_import(
+ imp.module_path,
+ path,
+ parsed.file_info.language,
+ ctx,
+ )
+ if resolved and resolved in path_set:
+ var_to_file[name] = resolved
+
+ router_re = re.compile(r"(?:include_router|add_api_route)\s*\(\s*(\w+)")
+ for path, parsed in parsed_files.items():
+ if parsed.file_info.language != "python":
+ continue
+ try:
+ source = Path(parsed.file_info.abs_path).read_text(errors="ignore")
+ except Exception:
+ continue
+ for match in router_re.finditer(source):
+ var_name = match.group(1)
+ target = var_to_file.get(var_name)
+ if target and target in path_set and _add_edge_if_new(graph, path, target):
+ count += 1
+ return count
+
+
+class _FastApiHandler:
+ def detect(self, dctx: DetectionContext) -> bool:
+ return "fastapi" in dctx.stack_lower or "starlette" in dctx.stack_lower
+
+ def add_edges(
+ self,
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+ ) -> int:
+ return _add_fastapi_edges(graph, parsed_files, ctx, path_set)
+
+
+HANDLERS: list[FrameworkHandler] = [_FastApiHandler()]
diff --git a/packages/core/src/repowise/core/ingestion/framework_edges/flask.py b/packages/core/src/repowise/core/ingestion/framework_edges/flask.py
new file mode 100644
index 000000000..625314a16
--- /dev/null
+++ b/packages/core/src/repowise/core/ingestion/framework_edges/flask.py
@@ -0,0 +1,76 @@
+"""Flask ``register_blueprint`` convention edges.
+
+Split out of ``framework_edges.py`` (PR 3.5) — behaviour-preserving move.
+"""
+
+from __future__ import annotations
+
+import re
+from pathlib import Path
+from typing import TYPE_CHECKING, Any
+
+from ..resolvers import ResolverContext, resolve_import
+from .base import (
+ DetectionContext,
+ FrameworkHandler,
+ _add_edge_if_new,
+)
+
+if TYPE_CHECKING:
+ import networkx as nx
+
+
+def _add_flask_edges(
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+) -> int:
+ """Detect register_blueprint() calls and link app files to blueprint modules."""
+ count = 0
+ var_to_file: dict[str, str] = {}
+
+ for path, parsed in parsed_files.items():
+ for imp in parsed.imports:
+ for name in imp.imported_names:
+ if "blueprint" in name.lower() or name.lower().endswith("bp"):
+ resolved = resolve_import(
+ imp.module_path,
+ path,
+ parsed.file_info.language,
+ ctx,
+ )
+ if resolved and resolved in path_set:
+ var_to_file[name] = resolved
+
+ bp_re = re.compile(r"register_blueprint\s*\(\s*(\w+)")
+ for path, parsed in parsed_files.items():
+ if parsed.file_info.language != "python":
+ continue
+ try:
+ source = Path(parsed.file_info.abs_path).read_text(errors="ignore")
+ except Exception:
+ continue
+ for match in bp_re.finditer(source):
+ var_name = match.group(1)
+ target = var_to_file.get(var_name)
+ if target and target in path_set and _add_edge_if_new(graph, path, target):
+ count += 1
+ return count
+
+
+class _FlaskHandler:
+ def detect(self, dctx: DetectionContext) -> bool:
+ return "flask" in dctx.stack_lower
+
+ def add_edges(
+ self,
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+ ) -> int:
+ return _add_flask_edges(graph, parsed_files, ctx, path_set)
+
+
+HANDLERS: list[FrameworkHandler] = [_FlaskHandler()]
diff --git a/packages/core/src/repowise/core/ingestion/framework_edges/go.py b/packages/core/src/repowise/core/ingestion/framework_edges/go.py
new file mode 100644
index 000000000..e29b7a56d
--- /dev/null
+++ b/packages/core/src/repowise/core/ingestion/framework_edges/go.py
@@ -0,0 +1,128 @@
+"""Gin / Echo / Chi (Go) router convention edges.
+
+Split out of ``framework_edges.py`` (PR 3.5) — behaviour-preserving move.
+"""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING, Any
+
+from ..resolvers import ResolverContext
+from .base import (
+ DetectionContext,
+ FrameworkHandler,
+ _add_edge_if_new,
+ _build_class_to_file,
+ _build_function_to_file,
+ read_text,
+)
+
+if TYPE_CHECKING:
+ import networkx as nx
+
+
+_GO_ROUTER_PKG_PATTERNS = (
+ "github.com/gin-gonic/gin",
+ "github.com/labstack/echo",
+ "github.com/go-chi/chi",
+)
+_GO_ROUTE_CALL_RE = re.compile(
+ r"\.\s*(?:GET|POST|PUT|DELETE|PATCH|OPTIONS|HEAD|HandleFunc|Handle|Any)"
+ r"\s*\(\s*[\"'][^\"']*[\"']\s*,\s*([\w.]+)"
+)
+
+
+def _has_go_router_imports(parsed_files: dict[str, Any]) -> bool:
+ for parsed in parsed_files.values():
+ if parsed.file_info.language != "go":
+ continue
+ for imp in parsed.imports:
+ mp = imp.module_path
+ if any(mp.startswith(pkg) for pkg in _GO_ROUTER_PKG_PATTERNS):
+ return True
+ return False
+
+
+def _add_go_router_edges(
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ path_set: set[str],
+) -> int:
+ count = 0
+ func_to_files = _build_function_to_file(parsed_files, ("go",))
+ class_to_file = _build_class_to_file(parsed_files, ("go",))
+
+ for path, parsed in parsed_files.items():
+ if parsed.file_info.language != "go":
+ continue
+ text = read_text(parsed)
+ if not text:
+ continue
+ if not any(
+ imp.module_path.startswith(pkg)
+ for pkg in _GO_ROUTER_PKG_PATTERNS
+ for imp in parsed.imports
+ ):
+ # Allow if some other go file in the repo imports a router (router
+ # setup may be split across files); be conservative and only emit
+ # edges for files that themselves reference router calls.
+ pass
+
+ for m in _GO_ROUTE_CALL_RE.finditer(text):
+ handler = m.group(1)
+ targets = _resolve_go_handler(handler, parsed, func_to_files, class_to_file)
+ for target in targets:
+ if target != path and target in path_set and _add_edge_if_new(graph, path, target):
+ count += 1
+
+ return count
+
+
+def _resolve_go_handler(
+ handler: str,
+ parsed: Any,
+ func_to_files: dict[str, list[str]],
+ class_to_file: dict[str, str],
+) -> list[str]:
+ """Resolve `pkg.Func` / `recv.Method` / `Func` to candidate file paths."""
+ if "." in handler:
+ prefix, name = handler.rsplit(".", 1)
+ # First: was prefix imported as a package?
+ for imp in parsed.imports:
+ short = imp.module_path.rsplit("/", 1)[-1]
+ if short == prefix and imp.resolved_file:
+ # Find file declaring `name` whose path starts with the resolved package dir
+ pkg_dir = "/".join(imp.resolved_file.split("/")[:-1])
+ results = [
+ p
+ for p in func_to_files.get(name, [])
+ if p.startswith(pkg_dir + "/") or p == imp.resolved_file
+ ]
+ if results:
+ return results
+ # Second: receiver-method — try the receiver's type file
+ type_file = class_to_file.get(prefix.title())
+ if type_file:
+ return [type_file]
+ # Third: fall back to any file declaring the bare name
+ return list(func_to_files.get(name, []))
+ return list(func_to_files.get(handler, []))
+
+
+class _GoRouterHandler:
+ def detect(self, dctx: DetectionContext) -> bool:
+ go_router_in_stack = any(token in dctx.stack_lower for token in ("gin", "echo", "chi"))
+ return go_router_in_stack or _has_go_router_imports(dctx.parsed_files)
+
+ def add_edges(
+ self,
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+ ) -> int:
+ return _add_go_router_edges(graph, parsed_files, path_set)
+
+
+HANDLERS: list[FrameworkHandler] = [_GoRouterHandler()]
diff --git a/packages/core/src/repowise/core/ingestion/framework_edges/laravel.py b/packages/core/src/repowise/core/ingestion/framework_edges/laravel.py
new file mode 100644
index 000000000..d05694f70
--- /dev/null
+++ b/packages/core/src/repowise/core/ingestion/framework_edges/laravel.py
@@ -0,0 +1,132 @@
+"""Laravel routes / service-provider / Eloquent convention edges.
+
+Split out of ``framework_edges.py`` (PR 3.5) — behaviour-preserving move.
+"""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING, Any
+
+from ..resolvers import ResolverContext
+from .base import (
+ DetectionContext,
+ FrameworkHandler,
+ _add_edge_if_new,
+ _build_class_to_file,
+ read_text,
+)
+
+if TYPE_CHECKING:
+ import networkx as nx
+
+
+_LARAVEL_ROUTE_ARRAY_RE = re.compile(
+ r"Route::(?:get|post|put|patch|delete|any|match|resource|apiResource)\s*\([^,]*,\s*\[\s*([\w\\]+)::class"
+)
+_LARAVEL_ROUTE_LEGACY_RE = re.compile(
+ r"Route::(?:get|post|put|patch|delete|any|match)\s*\([^,]*,\s*['\"]([\w\\]+)@\w+['\"]"
+)
+_LARAVEL_ROUTE_RESOURCE_RE = re.compile(
+ r"Route::(?:resource|apiResource)\s*\(\s*['\"][^'\"]+['\"]\s*,\s*([\w\\]+)::class"
+)
+_LARAVEL_BIND_RE = re.compile(
+ r"->\s*(?:bind|singleton|instance)\s*\(\s*([\w\\]+)::class\s*,\s*([\w\\]+)::class"
+)
+_LARAVEL_ELOQUENT_RE = re.compile(
+ r"\$this->\s*(?:hasMany|hasOne|belongsTo|belongsToMany|morphMany|morphOne|morphTo)\s*\(\s*([\w\\]+)::class"
+)
+
+
+def _resolve_laravel_class(
+ ctx: ResolverContext, fqn: str, class_to_file: dict[str, str], path_set: set[str]
+) -> str | None:
+ """Resolve `Foo\\Bar\\Baz` (or short `Bar`) to repo-relative .php path."""
+ from ..resolvers.php_composer import resolve_via_psr4
+
+ if "\\" in fqn:
+ result = resolve_via_psr4(fqn, ctx)
+ if result and result in path_set:
+ return result
+ short = fqn.rsplit("\\", 1)[-1]
+ return class_to_file.get(short)
+
+
+def _add_laravel_edges(
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+) -> int:
+ count = 0
+ class_to_file = _build_class_to_file(parsed_files, ("php",))
+
+ # ---- routes/web.php / routes/api.php → controllers ----
+ for routes_path in ("routes/web.php", "routes/api.php"):
+ if routes_path not in path_set:
+ continue
+ text = read_text(parsed_files[routes_path])
+ if not text:
+ continue
+ seen_targets: set[str] = set()
+ for regex in (
+ _LARAVEL_ROUTE_ARRAY_RE,
+ _LARAVEL_ROUTE_LEGACY_RE,
+ _LARAVEL_ROUTE_RESOURCE_RE,
+ ):
+ for m in regex.finditer(text):
+ target = _resolve_laravel_class(ctx, m.group(1), class_to_file, path_set)
+ if target and target in path_set and target not in seen_targets:
+ seen_targets.add(target)
+ if _add_edge_if_new(graph, routes_path, target):
+ count += 1
+
+ # ---- Service providers → bound classes ----
+ for path, parsed in parsed_files.items():
+ if parsed.file_info.language != "php":
+ continue
+ if not path.endswith("ServiceProvider.php"):
+ continue
+ text = read_text(parsed)
+ if not text:
+ continue
+ for m in _LARAVEL_BIND_RE.finditer(text):
+ for fqn in (m.group(1), m.group(2)):
+ target = _resolve_laravel_class(ctx, fqn, class_to_file, path_set)
+ if target and target in path_set and _add_edge_if_new(graph, path, target):
+ count += 1
+
+ # ---- Eloquent relationships: model → related model ----
+ for path, parsed in parsed_files.items():
+ if parsed.file_info.language != "php":
+ continue
+ text = read_text(parsed)
+ if not text:
+ continue
+ for m in _LARAVEL_ELOQUENT_RE.finditer(text):
+ target = _resolve_laravel_class(ctx, m.group(1), class_to_file, path_set)
+ if target and target in path_set and _add_edge_if_new(graph, path, target):
+ count += 1
+
+ return count
+
+
+class _LaravelHandler:
+ def detect(self, dctx: DetectionContext) -> bool:
+ return (
+ "laravel" in dctx.stack_lower
+ or "routes/web.php" in dctx.path_set
+ or "routes/api.php" in dctx.path_set
+ )
+
+ def add_edges(
+ self,
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+ ) -> int:
+ return _add_laravel_edges(graph, parsed_files, ctx, path_set)
+
+
+HANDLERS: list[FrameworkHandler] = [_LaravelHandler()]
diff --git a/packages/core/src/repowise/core/ingestion/framework_edges/pytest_edges.py b/packages/core/src/repowise/core/ingestion/framework_edges/pytest_edges.py
new file mode 100644
index 000000000..62ea21b54
--- /dev/null
+++ b/packages/core/src/repowise/core/ingestion/framework_edges/pytest_edges.py
@@ -0,0 +1,59 @@
+"""pytest conftest convention edges.
+
+Split out of ``framework_edges.py`` (PR 3.5) — behaviour-preserving move.
+"""
+
+from __future__ import annotations
+
+from pathlib import Path
+from typing import TYPE_CHECKING, Any
+
+from ..resolvers import ResolverContext
+from .base import (
+ DetectionContext,
+ FrameworkHandler,
+ _add_edge_if_new,
+)
+
+if TYPE_CHECKING:
+ import networkx as nx
+
+
+def _add_conftest_edges(graph: nx.DiGraph, path_set: set[str]) -> int:
+ """conftest.py -> test files in the same or child directories."""
+ count = 0
+ conftest_paths = [p for p in path_set if Path(p).name == "conftest.py"]
+
+ for conf in conftest_paths:
+ conf_dir = Path(conf).parent.as_posix()
+ prefix = f"{conf_dir}/" if conf_dir != "." else ""
+ for p in path_set:
+ if p == conf:
+ continue
+ node = graph.nodes.get(p, {})
+ if not node.get("is_test", False):
+ continue
+ if (p.startswith(prefix) or (prefix == "" and "/" not in p)) and _add_edge_if_new(
+ graph, p, conf
+ ):
+ count += 1
+ return count
+
+
+class _ConftestHandler:
+ """pytest ``conftest.py`` fixtures are imported implicitly by collection."""
+
+ def detect(self, dctx: DetectionContext) -> bool:
+ return True
+
+ def add_edges(
+ self,
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+ ) -> int:
+ return _add_conftest_edges(graph, path_set)
+
+
+HANDLERS: list[FrameworkHandler] = [_ConftestHandler()]
diff --git a/packages/core/src/repowise/core/ingestion/framework_edges/rails.py b/packages/core/src/repowise/core/ingestion/framework_edges/rails.py
new file mode 100644
index 000000000..9408cf8ee
--- /dev/null
+++ b/packages/core/src/repowise/core/ingestion/framework_edges/rails.py
@@ -0,0 +1,159 @@
+"""Rails routes / ActiveRecord convention edges.
+
+Split out of ``framework_edges.py`` (PR 3.5) — behaviour-preserving move.
+"""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING, Any
+
+from ..resolvers import ResolverContext
+from .base import (
+ DetectionContext,
+ FrameworkHandler,
+ _add_edge_if_new,
+ read_text,
+)
+
+if TYPE_CHECKING:
+ import networkx as nx
+
+
+_RAILS_RESOURCES_RE = re.compile(r"\bresources?\s+:(\w+)")
+_RAILS_GET_TO_RE = re.compile(
+ r"\b(?:get|post|put|patch|delete|match)\s+[^\n]+?(?:to:\s*|=>\s*)['\"]([\w/]+)#\w+['\"]"
+)
+_RAILS_NAMESPACE_RE = re.compile(r"\bnamespace\s+:(\w+)\b")
+_RAILS_AR_RELATION_RE = re.compile(
+ r"\b(?:belongs_to|has_many|has_one|has_and_belongs_to_many)\s+:(\w+)"
+)
+
+
+def _singularize(word: str) -> str:
+ """Very rough Rails inflector — sufficient for routes/AR lookups."""
+ if word.endswith("ies") and len(word) > 3:
+ return word[:-3] + "y"
+ if word.endswith("ses") or word.endswith("xes") or word.endswith("zes"):
+ return word[:-2]
+ if word.endswith("s") and not word.endswith("ss"):
+ return word[:-1]
+ return word
+
+
+def _camelize(word: str) -> str:
+ return "".join(part.capitalize() for part in word.split("_"))
+
+
+def _add_rails_edges(
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+) -> int:
+ count = 0
+
+ # ---- routes.rb → controller files ----
+ routes_path = "config/routes.rb"
+ if routes_path in path_set:
+ text = read_text(parsed_files[routes_path])
+ if text:
+ # Parse line-by-line to track namespace nesting (indent-agnostic; we
+ # use the order of opening keywords vs `end`).
+ namespace_stack: list[str] = []
+ for raw_line in text.splitlines():
+ line = raw_line.strip()
+ if not line or line.startswith("#"):
+ continue
+ ns_match = _RAILS_NAMESPACE_RE.search(line)
+ if ns_match and ("do" in line or line.endswith("do")):
+ namespace_stack.append(ns_match.group(1))
+ continue
+ if line == "end" and namespace_stack:
+ namespace_stack.pop()
+ continue
+ # resources :users → users_controller
+ for m in _RAILS_RESOURCES_RE.finditer(line):
+ resource = m.group(1)
+ target = _resolve_rails_controller(ctx, namespace_stack, resource, path_set)
+ if target and _add_edge_if_new(graph, routes_path, target):
+ count += 1
+ # get "/foo", to: "users#index"
+ for m in _RAILS_GET_TO_RE.finditer(line):
+ ctrl_path = m.group(1)
+ target = _resolve_rails_controller_path(
+ ctx, namespace_stack, ctrl_path, path_set
+ )
+ if target and _add_edge_if_new(graph, routes_path, target):
+ count += 1
+
+ # ---- ActiveRecord relationships: model → model ----
+ for path, parsed in parsed_files.items():
+ if parsed.file_info.language != "ruby":
+ continue
+ if "/models/" not in path and not path.startswith("app/models/"):
+ continue
+ text = read_text(parsed)
+ if not text:
+ continue
+ for m in _RAILS_AR_RELATION_RE.finditer(text):
+ assoc_name = m.group(1)
+ target = _resolve_rails_relation(ctx, assoc_name, path_set)
+ if target and _add_edge_if_new(graph, path, target):
+ count += 1
+
+ return count
+
+
+def _resolve_rails_controller(
+ ctx: ResolverContext, namespace_stack: list[str], resource: str, path_set: set[str]
+) -> str | None:
+ """`resources :users` (with optional `namespace :admin do`) → controller path."""
+ namespace_segs = [seg for seg in namespace_stack]
+ candidate_path = "/".join([*namespace_segs, f"{resource}_controller"])
+ expected = f"app/controllers/{candidate_path}.rb"
+ if expected in path_set:
+ return expected
+ # Try via Rails autoload index (heritage)
+ constant = "::".join(_camelize(seg) for seg in [*namespace_segs, f"{resource}_controller"])
+ return ctx.rails_lookup(constant)
+
+
+def _resolve_rails_controller_path(
+ ctx: ResolverContext, namespace_stack: list[str], controller_token: str, path_set: set[str]
+) -> str | None:
+ """`to: "users#index"` or `to: "admin/users#index"` → controller path."""
+ expected = f"app/controllers/{controller_token}_controller.rb"
+ if expected in path_set:
+ return expected
+ parts = controller_token.split("/")
+ constant = "::".join(_camelize(p) for p in [*parts[:-1], f"{parts[-1]}_controller"])
+ return ctx.rails_lookup(constant)
+
+
+def _resolve_rails_relation(
+ ctx: ResolverContext, assoc_name: str, path_set: set[str]
+) -> str | None:
+ """`belongs_to :user` / `has_many :orders` → model file."""
+ singular = _singularize(assoc_name)
+ expected = f"app/models/{singular}.rb"
+ if expected in path_set:
+ return expected
+ return ctx.rails_lookup(_camelize(singular))
+
+
+class _RailsHandler:
+ def detect(self, dctx: DetectionContext) -> bool:
+ return "rails" in dctx.stack_lower or "config/application.rb" in dctx.path_set
+
+ def add_edges(
+ self,
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+ ) -> int:
+ return _add_rails_edges(graph, parsed_files, ctx, path_set)
+
+
+HANDLERS: list[FrameworkHandler] = [_RailsHandler()]
diff --git a/packages/core/src/repowise/core/ingestion/framework_edges/rust.py b/packages/core/src/repowise/core/ingestion/framework_edges/rust.py
new file mode 100644
index 000000000..dc7a5c0cb
--- /dev/null
+++ b/packages/core/src/repowise/core/ingestion/framework_edges/rust.py
@@ -0,0 +1,125 @@
+"""Axum / Actix / Rocket (Rust) router convention edges.
+
+Split out of ``framework_edges.py`` (PR 3.5) — behaviour-preserving move.
+"""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING, Any
+
+from ..resolvers import ResolverContext
+from .base import (
+ DetectionContext,
+ FrameworkHandler,
+ _add_edge_if_new,
+ _build_function_to_file,
+ read_text,
+)
+
+if TYPE_CHECKING:
+ import networkx as nx
+
+
+_RUST_AXUM_ROUTE_RE = re.compile(
+ r"\.\s*route\s*\(\s*[\"'][^\"']*[\"']\s*,\s*"
+ r"(?:get|post|put|delete|patch|head|options|on)\s*\(\s*([\w:]+)\s*\)"
+)
+_RUST_ACTIX_TO_RE = re.compile(
+ r"web::\s*(?:get|post|put|delete|patch|head)\(\)\s*\.\s*to\s*\(\s*([\w:]+)\s*\)"
+)
+_RUST_ACTIX_SERVICE_RE = re.compile(r"\.\s*service\s*\(\s*([\w:]+)\s*\)")
+_RUST_SCOPE_CONFIGURE_RE = re.compile(r"\.\s*configure\s*\(\s*([\w:]+)\s*\)")
+_RUST_NEST_RE = re.compile(r"\.\s*nest\s*\(\s*[\"'][^\"']*[\"']\s*,\s*([\w:]+)\s*\)")
+_RUST_LAYER_RE = re.compile(
+ r"\.\s*layer\s*\(\s*(?:axum::middleware::from_fn\s*\(\s*)?([\w:]+)\s*\)"
+)
+_RUST_FALLBACK_RE = re.compile(r"\.\s*fallback\s*\(\s*([\w:]+)\s*\)")
+_RUST_WITH_STATE_RE = re.compile(r"\.\s*with_state\s*\(\s*([\w:]+)\s*\)")
+_RUST_ROCKET_MOUNT_RE = re.compile(
+ r"\.\s*mount\s*\(\s*[\"'][^\"']*[\"']\s*,\s*routes!\s*\[([^\]]+)\]"
+)
+
+
+def _has_rust_router_imports(parsed_files: dict[str, Any]) -> bool:
+ for parsed in parsed_files.values():
+ if parsed.file_info.language != "rust":
+ continue
+ for imp in parsed.imports:
+ mp = imp.module_path
+ if mp.startswith(("axum", "actix_web", "actix-web", "rocket")):
+ return True
+ return False
+
+
+def _add_rust_router_edges(
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ path_set: set[str],
+) -> int:
+ count = 0
+ func_to_files = _build_function_to_file(parsed_files, ("rust",))
+
+ def _resolve(handler: str) -> list[str]:
+ name = handler.rsplit("::", 1)[-1]
+ return list(func_to_files.get(name, []))
+
+ for path, parsed in parsed_files.items():
+ if parsed.file_info.language != "rust":
+ continue
+ text = read_text(parsed)
+ if not text:
+ continue
+ for regex in (
+ _RUST_AXUM_ROUTE_RE,
+ _RUST_ACTIX_TO_RE,
+ _RUST_ACTIX_SERVICE_RE,
+ _RUST_SCOPE_CONFIGURE_RE,
+ _RUST_NEST_RE,
+ _RUST_LAYER_RE,
+ _RUST_FALLBACK_RE,
+ _RUST_WITH_STATE_RE,
+ ):
+ for m in regex.finditer(text):
+ for target in _resolve(m.group(1)):
+ if (
+ target != path
+ and target in path_set
+ and _add_edge_if_new(graph, path, target)
+ ):
+ count += 1
+
+ # Rocket routes![] macro lists multiple handlers comma-separated
+ for m in _RUST_ROCKET_MOUNT_RE.finditer(text):
+ for handler in m.group(1).split(","):
+ handler = handler.strip()
+ if handler:
+ for target in _resolve(handler):
+ if (
+ target != path
+ and target in path_set
+ and _add_edge_if_new(graph, path, target)
+ ):
+ count += 1
+
+ return count
+
+
+class _RustRouterHandler:
+ def detect(self, dctx: DetectionContext) -> bool:
+ rust_router_in_stack = any(
+ token in dctx.stack_lower for token in ("axum", "actix", "actix-web")
+ )
+ return rust_router_in_stack or _has_rust_router_imports(dctx.parsed_files)
+
+ def add_edges(
+ self,
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+ ) -> int:
+ return _add_rust_router_edges(graph, parsed_files, path_set)
+
+
+HANDLERS: list[FrameworkHandler] = [_RustRouterHandler()]
diff --git a/packages/core/src/repowise/core/ingestion/framework_edges/spring.py b/packages/core/src/repowise/core/ingestion/framework_edges/spring.py
new file mode 100644
index 000000000..a732e45b4
--- /dev/null
+++ b/packages/core/src/repowise/core/ingestion/framework_edges/spring.py
@@ -0,0 +1,151 @@
+"""Spring Boot dependency-injection convention edges.
+
+Split out of ``framework_edges.py`` (PR 3.5) — behaviour-preserving move.
+"""
+
+from __future__ import annotations
+
+import re
+from pathlib import Path
+from typing import TYPE_CHECKING, Any
+
+from ..resolvers import ResolverContext
+from .base import (
+ DetectionContext,
+ FrameworkHandler,
+ _add_edge_if_new,
+ _build_class_to_file,
+ read_text,
+)
+
+if TYPE_CHECKING:
+ import networkx as nx
+
+
+_SPRING_BEAN_ANNOT = (
+ "@Component",
+ "@Service",
+ "@Repository",
+ "@Controller",
+ "@RestController",
+ "@Configuration",
+)
+_SPRING_AUTOWIRED_FIELD_RE = re.compile(
+ r"@Autowired\s+(?:private|protected|public|final|\s)*\s*([A-Z]\w*)\s+\w+"
+)
+_SPRING_CTOR_PARAM_RE = re.compile(r"\b([A-Z]\w*)\s+\w+\s*[,)]")
+_SPRING_BEAN_METHOD_RE = re.compile(
+ r"@Bean\b[^\n]*\n\s*(?:public|protected|private|static|final|\s)+\s*([A-Z]\w*)\s+\w+\s*\("
+)
+_SPRING_BEAN_METHOD_KOTLIN_RE = re.compile(
+ r"@Bean\b[^\n]*\n\s*(?:public|protected|private|internal|fun|open|\s)+\s*\w+\s*\([^)]*\)\s*:\s*([A-Z]\w*)"
+)
+
+
+def _has_spring_imports(parsed_files: dict[str, Any]) -> bool:
+ for parsed in parsed_files.values():
+ if parsed.file_info.language not in ("java", "kotlin"):
+ continue
+ for imp in parsed.imports:
+ if imp.module_path.startswith("org.springframework"):
+ return True
+ return False
+
+
+def _add_spring_edges(
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ path_set: set[str],
+) -> int:
+ count = 0
+ class_to_file = _build_class_to_file(parsed_files, ("java", "kotlin"))
+
+ # Build interface → list of impl files map from heritage
+ impl_map: dict[str, list[str]] = {}
+ for path, parsed in parsed_files.items():
+ if parsed.file_info.language not in ("java", "kotlin"):
+ continue
+ for rel in parsed.heritage:
+ if rel.kind in ("implements", "extends"):
+ impl_map.setdefault(rel.parent_name, []).append(path)
+
+ def _resolve_type(type_name: str) -> list[str]:
+ results: list[str] = []
+ own = class_to_file.get(type_name)
+ if own:
+ results.append(own)
+ for impl in impl_map.get(type_name, []):
+ if impl not in results:
+ results.append(impl)
+ return results
+
+ for path, parsed in parsed_files.items():
+ if parsed.file_info.language not in ("java", "kotlin"):
+ continue
+ text = read_text(parsed)
+ if not text:
+ continue
+ is_bean = any(annot in text for annot in _SPRING_BEAN_ANNOT)
+ if not is_bean:
+ continue
+
+ # @Autowired field injection
+ for m in _SPRING_AUTOWIRED_FIELD_RE.finditer(text):
+ type_name = m.group(1)
+ for target in _resolve_type(type_name):
+ if target in path_set and _add_edge_if_new(graph, path, target):
+ count += 1
+
+ # Constructor parameter injection: collect param types from any @Autowired
+ # constructor or any single public constructor in a bean (Spring 4.3+ omits
+ # the annotation when the class has only one constructor).
+ for ctor_match in re.finditer(
+ r"(?:@Autowired\s*\n\s*)?(?:public|protected|private|\s)*"
+ + re.escape(Path(path).stem)
+ + r"\s*\(([^)]*)\)",
+ text,
+ ):
+ params = ctor_match.group(1)
+ if not params.strip():
+ continue
+ for pm in _SPRING_CTOR_PARAM_RE.finditer(params + ","):
+ type_name = pm.group(1)
+ if type_name in ("String", "Integer", "Long", "Boolean", "Double", "Float"):
+ continue
+ for target in _resolve_type(type_name):
+ if target in path_set and _add_edge_if_new(graph, path, target):
+ count += 1
+
+ # @Bean factory methods → return-type file
+ if "@Configuration" in text:
+ for m in _SPRING_BEAN_METHOD_RE.finditer(text):
+ for target in _resolve_type(m.group(1)):
+ if target in path_set and _add_edge_if_new(graph, path, target):
+ count += 1
+ for m in _SPRING_BEAN_METHOD_KOTLIN_RE.finditer(text):
+ for target in _resolve_type(m.group(1)):
+ if target in path_set and _add_edge_if_new(graph, path, target):
+ count += 1
+
+ return count
+
+
+class _SpringHandler:
+ def detect(self, dctx: DetectionContext) -> bool:
+ spring_in_stack = any(
+ token in dctx.stack_lower
+ for token in ("spring", "springboot", "spring-boot", "spring boot")
+ )
+ return spring_in_stack or _has_spring_imports(dctx.parsed_files)
+
+ def add_edges(
+ self,
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+ ) -> int:
+ return _add_spring_edges(graph, parsed_files, path_set)
+
+
+HANDLERS: list[FrameworkHandler] = [_SpringHandler()]
diff --git a/packages/core/src/repowise/core/ingestion/framework_edges/typo3.py b/packages/core/src/repowise/core/ingestion/framework_edges/typo3.py
new file mode 100644
index 000000000..aa3e78844
--- /dev/null
+++ b/packages/core/src/repowise/core/ingestion/framework_edges/typo3.py
@@ -0,0 +1,324 @@
+"""TYPO3 extension convention-file edges.
+
+Split out of ``framework_edges.py`` (PR 3.5) — behaviour-preserving move.
+"""
+
+from __future__ import annotations
+
+import fnmatch
+import json
+import re
+from pathlib import Path
+from typing import TYPE_CHECKING, Any
+
+from ..resolvers import ResolverContext
+from .base import (
+ DetectionContext,
+ FrameworkHandler,
+ _add_edge_if_new,
+ read_text,
+)
+
+if TYPE_CHECKING:
+ import networkx as nx
+
+
+# ---------------------------------------------------------------------------
+# F8 — TYPO3 framework edges
+#
+# TYPO3 loads a fixed set of convention-named files from each extension at
+# bootstrap (``ext_localconf.php``, ``Configuration/TCA/*.php``, etc.). These
+# files are never imported via PHP/JS imports, so the static graph reports
+# ``in_degree=0`` and the dead-code analyzer flags them as unreachable.
+#
+# We attach a ``framework:typo3-core`` synthetic source to each convention
+# file present in an extension. ``Configuration/JavaScriptModules.php`` is
+# also parsed to add edges to the JS modules it registers (CKEditor plugins,
+# backend modules, etc.).
+#
+# Discovery signal: ``composer.json`` with ``"type": "typo3-cms-extension"``
+# (canonical for v11-v14) or, as fallback, any ``ext_emconf.php`` (legacy
+# non-composer installs).
+# ---------------------------------------------------------------------------
+
+_TYPO3_EXTERNAL_NODE = "framework:typo3-core"
+
+# Convention files at the extension root (matched by basename).
+_TYPO3_ROOT_FILES: tuple[str, ...] = (
+ "ext_localconf.php",
+ "ext_emconf.php",
+ "ext_tables.php", # legacy v11-v13; absent in v14
+ "ext_tables.sql",
+)
+
+# Convention files / globs under ``Configuration/`` (matched relative to the
+# extension root, with forward-slash separators).
+_TYPO3_CONFIG_GLOBS: tuple[str, ...] = (
+ "Configuration/JavaScriptModules.php",
+ "Configuration/ContentSecurityPolicies.php",
+ "Configuration/RequestMiddlewares.php",
+ "Configuration/Icons.php",
+ "Configuration/Services.php",
+ "Configuration/Services.yaml",
+ "Configuration/Services.yml",
+ "Configuration/TCA/*.php",
+ "Configuration/TCA/Overrides/*.php",
+ "Configuration/Backend/*.php",
+ "Configuration/RTE/*.yaml",
+ "Configuration/RTE/*.yml",
+)
+
+# JavaScriptModules.php registers JS files via entries like
+# ``'@vendor/ext/MyModule' => 'EXT:ext_key/Resources/Public/JavaScript/My.js'``.
+# We extract the right-hand value to add edges to the registered files.
+_TYPO3_JS_MODULE_VALUE_RE = re.compile(
+ r"""['"]EXT:(?P<ext>[a-z0-9_]+)/(?P<rel>[^'"]+\.(?:js|mjs))['"]""",
+ re.IGNORECASE,
+)
+
+
+def _has_typo3_extension(ctx: ResolverContext, path_set: set[str]) -> bool:
+ """Return True if the repo contains at least one TYPO3 extension.
+
+ Checks ``composer.json`` ``type`` field first (canonical across v11-v14);
+ falls back to any ``ext_emconf.php`` in path_set for legacy installs.
+ """
+ return bool(_find_typo3_extension_roots(ctx, path_set))
+
+
+def _find_typo3_extension_roots(ctx: ResolverContext, path_set: set[str]) -> set[str]:
+ """Return the set of extension root directories (repo-relative, posix).
+
+ Sources, in order of authority:
+ 1. Any ``composer.json`` with ``"type": "typo3-cms-extension"``.
+ 2. Any ``ext_emconf.php`` (legacy fallback when composer.json is missing).
+ """
+ roots: set[str] = set()
+
+ # 1. composer.json based discovery — walk the filesystem from repo root,
+ # bounded depth to avoid deep vendor/node_modules traversal during tests.
+ repo_path = getattr(ctx, "repo_path", None)
+ if repo_path is not None:
+ try:
+ for composer in _iter_composer_jsons(Path(repo_path)):
+ try:
+ data = json.loads(composer.read_text(encoding="utf-8", errors="ignore"))
+ except (OSError, ValueError):
+ continue
+ if not isinstance(data, dict):
+ continue
+ if data.get("type") != "typo3-cms-extension":
+ continue
+ ext_root = composer.parent.resolve()
+ rel = _to_repo_relative(repo_path, ext_root)
+ if rel is not None:
+ roots.add(rel)
+ except OSError:
+ pass
+
+ # 2. ext_emconf.php fallback for repos without a composer.json (legacy
+ # non-composer installs, mostly v11 and earlier).
+ for p in path_set:
+ if Path(p).name == "ext_emconf.php":
+ parent = Path(p).parent.as_posix()
+ roots.add("" if parent == "." else parent)
+
+ return roots
+
+
+def _iter_composer_jsons(root: Path):
+ """Yield composer.json paths likely to declare a TYPO3 extension.
+
+ Searched locations:
+ - ``<root>/composer.json``
+ - ``<root>/<dir>/composer.json`` (single-level, for monorepos of extensions)
+ - ``<root>/vendor/<vendor>/<package>/composer.json`` (project-mode TYPO3
+ installs where extensions live under ``vendor/``)
+
+ ``node_modules``, ``.git``, ``.bare``, and ``Build`` are skipped. Hidden
+ directories are skipped at the top level only — vendor packages keep their
+ nested layout.
+ """
+ skip_top = {"node_modules", ".git", ".bare", "var", "Build"}
+ if (root / "composer.json").is_file():
+ yield root / "composer.json"
+
+ try:
+ children = list(root.iterdir())
+ except OSError:
+ return
+
+ for child in children:
+ if not child.is_dir():
+ continue
+ if child.name == "vendor":
+ yield from _iter_vendor_composer_jsons(child)
+ continue
+ if child.name in skip_top or child.name.startswith("."):
+ continue
+ candidate = child / "composer.json"
+ if candidate.is_file():
+ yield candidate
+
+
+def _iter_vendor_composer_jsons(vendor_root: Path):
+ """Yield composer.json files at ``vendor/<vendor>/<package>/composer.json``.
+
+ Bounded to two levels deep — composer's flat layout means we never need
+ to recurse further. Symlinks are followed at most once.
+ """
+ try:
+ vendors = list(vendor_root.iterdir())
+ except OSError:
+ return
+ for vendor_dir in vendors:
+ if not vendor_dir.is_dir() or vendor_dir.name.startswith("."):
+ continue
+ try:
+ packages = list(vendor_dir.iterdir())
+ except OSError:
+ continue
+ for pkg_dir in packages:
+ if not pkg_dir.is_dir() or pkg_dir.name.startswith("."):
+ continue
+ candidate = pkg_dir / "composer.json"
+ if candidate.is_file():
+ yield candidate
+
+
+def _to_repo_relative(repo_path: Path, abs_path: Path) -> str | None:
+ try:
+ rel = abs_path.relative_to(Path(repo_path).resolve()).as_posix()
+ except ValueError:
+ return None
+ return "" if rel == "." else rel
+
+
+def _add_typo3_edges(
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+) -> int:
+ """Add framework edges for each detected TYPO3 extension.
+
+ Edges added:
+ - ``framework:typo3-core`` → each convention file present in the extension.
+ - ``Configuration/JavaScriptModules.php`` → each JS file it registers.
+ """
+ count = 0
+ roots = _find_typo3_extension_roots(ctx, path_set)
+ if not roots:
+ return 0
+
+ if _TYPO3_EXTERNAL_NODE not in graph:
+ graph.add_node(_TYPO3_EXTERNAL_NODE, language="external")
+
+ for root in roots:
+ for basename in _TYPO3_ROOT_FILES:
+ target = f"{root}/{basename}" if root else basename
+ if target in path_set and _add_edge_if_new(graph, _TYPO3_EXTERNAL_NODE, target):
+ count += 1
+
+ for glob in _TYPO3_CONFIG_GLOBS:
+ prefix = f"{root}/" if root else ""
+ pat = f"{prefix}{glob}"
+ for p in path_set:
+ if fnmatch.fnmatch(p, pat) and _add_edge_if_new(graph, _TYPO3_EXTERNAL_NODE, p):
+ count += 1
+
+ # Parse JavaScriptModules.php for registered JS files.
+ js_modules_path = (
+ f"{root}/Configuration/JavaScriptModules.php"
+ if root
+ else "Configuration/JavaScriptModules.php"
+ )
+ if js_modules_path in path_set:
+ count += _add_typo3_js_module_edges(
+ graph, parsed_files, path_set, root, js_modules_path
+ )
+
+ return count
+
+
+def _add_typo3_js_module_edges(
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ path_set: set[str],
+ ext_root: str,
+ js_modules_path: str,
+) -> int:
+ """Parse JavaScriptModules.php and add edges to each registered JS file.
+
+ Resolves ``EXT:<ext_key>/<rel>`` to a repo-relative path under ``ext_root``
+ when the extension is local; cross-extension references are ignored.
+ """
+ parsed = parsed_files.get(js_modules_path)
+ if parsed is None:
+ return 0
+ text = read_text(parsed)
+ if not text:
+ return 0
+
+ own_ext_key = _extract_ext_key_from_composer(parsed_files, ext_root)
+
+ count = 0
+ for m in _TYPO3_JS_MODULE_VALUE_RE.finditer(text):
+ ext_key = m.group("ext").lower()
+ rel = m.group("rel")
+ if own_ext_key is not None and ext_key != own_ext_key:
+ continue
+ target = f"{ext_root}/{rel}" if ext_root else rel
+ if target in path_set and _add_edge_if_new(graph, js_modules_path, target):
+ count += 1
+ return count
+
+
+def _extract_ext_key_from_composer(parsed_files: dict[str, Any], ext_root: str) -> str | None:
+ """Best-effort extraction of the TYPO3 extension key from composer.json.
+
+ Reads ``extra.typo3/cms.extension-key`` first (canonical), falls back to
+ deriving the key from the package name (``vendor/ext-key`` → ``ext_key``).
+ Returns ``None`` if composer.json is missing or unreadable.
+ """
+ composer_path = f"{ext_root}/composer.json" if ext_root else "composer.json"
+ parsed = parsed_files.get(composer_path)
+ abs_path: Path | None = None
+ if parsed is not None:
+ abs_path = Path(parsed.file_info.abs_path)
+ if abs_path is None or not abs_path.is_file():
+ return None
+ try:
+ data = json.loads(abs_path.read_text(encoding="utf-8", errors="ignore"))
+ except (OSError, ValueError):
+ return None
+ if not isinstance(data, dict):
+ return None
+ extra_raw = data.get("extra")
+ extra: dict[str, Any] = extra_raw if isinstance(extra_raw, dict) else {}
+ typo3_raw = extra.get("typo3/cms")
+ typo3: dict[str, Any] = typo3_raw if isinstance(typo3_raw, dict) else {}
+ key = typo3.get("extension-key")
+ if isinstance(key, str) and key:
+ return key.lower()
+ name = data.get("name")
+ if isinstance(name, str) and "/" in name:
+ return name.split("/", 1)[1].replace("-", "_").lower()
+ return None
+
+
+class _Typo3Handler:
+ def detect(self, dctx: DetectionContext) -> bool:
+ return "typo3" in dctx.stack_lower or _has_typo3_extension(dctx.ctx, dctx.path_set)
+
+ def add_edges(
+ self,
+ graph: nx.DiGraph,
+ parsed_files: dict[str, Any],
+ ctx: ResolverContext,
+ path_set: set[str],
+ ) -> int:
+ return _add_typo3_edges(graph, parsed_files, ctx, path_set)
+
+
+HANDLERS: list[FrameworkHandler] = [_Typo3Handler()]