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(workspace): split contract extractors into per-framework dialects (#505)

Raghav Chamadiya650cc962548b
diff --git a/docs/LANGUAGE_SUPPORT.md b/docs/LANGUAGE_SUPPORT.md
index 38bc787da..575e3cab3 100644
--- a/docs/LANGUAGE_SUPPORT.md
+++ b/docs/LANGUAGE_SUPPORT.md
@@ -501,6 +501,51 @@ relevant `__init__.py` dispatcher / dict.
---
+## Workspace contract extraction
+
+In **workspace mode** (multiple repos indexed together), repowise links
+service-to-service API contracts — HTTP routes and gRPC services — so a
+provider endpoint in one repo connects to its consumers in another. The
+extractors live in `core/workspace/extractors/` and follow the same
+dialect-plugin shape as the rest of the language pipeline: the orchestrator
+owns only the file walk, and each framework / client library is an
+independent module registered in a tuple.
+
+```
+workspace/extractors/
+ base.py # iter_source_files walk + ScanContext (shared by all)
+ langs.py # registry-derived extension sets (JS_TS, PYTHON, RUST, …)
+ http/
+ dialect.py # HttpDialect protocol + build_provider/consumer_contract
+ paths.py # normalize_http_path + URL helpers
+ express.py fastapi.py spring.py laravel.py go.py aspnet.py # providers
+ js_clients.py python_clients.py csharp_http.py # consumers
+ __init__.py # HttpExtractor + PROVIDER_DIALECTS / CONSUMER_DIALECTS
+ grpc/
+ dialect.py # GrpcDialect protocol + make_grpc_contract
+ proto.py go.py java.py python.py typescript.py csharp.py
+ __init__.py # GrpcExtractor + DIALECTS
+```
+
+A dialect declares the file extensions it understands (via `langs.py`) and
+turns regex matches into `Contract`s through the shared builders, so every
+dialect emits identically-shaped providers/consumers and the path-normalization
+rules live in one place. Framework-specific quirks stay local to the dialect —
+Spring/ASP.NET class-prefix stitching, Go `HandleFunc` → `*` method, fetch
+GET/method de-duplication.
+
+**Adding a framework or client** means dropping one module into `http/` or
+`grpc/` and appending its dialect to the relevant registry tuple
+(`PROVIDER_DIALECTS`, `CONSUMER_DIALECTS`, or `DIALECTS`) — no orchestrator
+edits. The current coverage:
+
+| Contract | Providers | Consumers |
+|----------|-----------|-----------|
+| **HTTP** | Express, FastAPI, Spring, Laravel, Go (gin/echo/chi/net-http), ASP.NET (attribute + minimal) | `fetch` / `axios` (JS/TS), `requests` / `httpx` (Python), `HttpClient` (C#) |
+| **gRPC** | `.proto` IDL, Go, Java, Python, NestJS (`@GrpcMethod`), C# (gRPC-dotnet) | Go, Java, Python, C# |
+
+---
+
## Roadmap
| Language | Target Tier | Status |
diff --git a/packages/core/src/repowise/core/workspace/extractors/base.py b/packages/core/src/repowise/core/workspace/extractors/base.py
new file mode 100644
index 000000000..aad8049a6
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/base.py
@@ -0,0 +1,84 @@
+"""Shared file-scanning primitives for contract extractors.
+
+Both the HTTP and gRPC extractors walk a repository the same way: skip a fixed
+set of build/vendor directories, ignore files above a size cap, and read each
+candidate file as UTF-8. That traversal lives here once so the per-contract-type
+orchestrators only declare *which* extensions they care about.
+"""
+
+from __future__ import annotations
+
+import os
+from collections.abc import Iterator
+from dataclasses import dataclass
+from pathlib import Path
+
+# Directories that never contain first-party source worth scanning.
+BLOCKED_DIRS = frozenset(
+ {
+ ".git",
+ "node_modules",
+ "__pycache__",
+ ".venv",
+ "venv",
+ "dist",
+ "build",
+ "target",
+ "vendor",
+ ".next",
+ ".nuxt",
+ ".tox",
+ ".mypy_cache",
+ ".gradle",
+ ".mvn",
+ "out",
+ "bin",
+ }
+)
+
+MAX_FILE_SIZE = 512 * 1024 # 512 KB
+
+
+@dataclass(frozen=True)
+class ScanContext:
+ """A single source file presented to a dialect.
+
+ ``rel_path`` is POSIX-relative to the repo root; ``suffix`` is the
+ lower-cased file extension (including the dot); ``content`` is the decoded
+ file text.
+ """
+
+ repo_alias: str
+ rel_path: str
+ suffix: str
+ content: str
+
+
+def iter_source_files(
+ repo_root: Path, extensions: frozenset[str]
+) -> Iterator[tuple[str, str, str]]:
+ """Yield ``(rel_path, suffix, content)`` for each scannable source file.
+
+ Walks *repo_root*, pruning :data:`BLOCKED_DIRS` and dotfile directories,
+ skipping files whose extension is not in *extensions* or that exceed
+ :data:`MAX_FILE_SIZE`, and reading the rest as UTF-8 (replacing undecodable
+ bytes). Unreadable files are silently skipped.
+ """
+ root = repo_root.resolve()
+ for dirpath, dirnames, filenames in os.walk(root):
+ dirnames[:] = [d for d in dirnames if d not in BLOCKED_DIRS and not d.startswith(".")]
+ for fname in filenames:
+ fpath = Path(dirpath) / fname
+ suffix = fpath.suffix.lower()
+ if suffix not in extensions:
+ continue
+ try:
+ if fpath.stat().st_size > MAX_FILE_SIZE:
+ continue
+ except OSError:
+ continue
+ try:
+ content = fpath.read_text(encoding="utf-8", errors="replace")
+ except OSError:
+ continue
+ yield fpath.relative_to(root).as_posix(), suffix, content
diff --git a/packages/core/src/repowise/core/workspace/extractors/grpc/__init__.py b/packages/core/src/repowise/core/workspace/extractors/grpc/__init__.py
new file mode 100644
index 000000000..ae8e3ebc9
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/grpc/__init__.py
@@ -0,0 +1,64 @@
+"""gRPC contract extraction.
+
+Scans ``.proto`` files for service/rpc declarations (providers) and
+language-specific source files for gRPC server registrations (providers) and
+client stubs (consumers). Each language is an independent *dialect* module
+registered in :data:`DIALECTS`; :class:`GrpcExtractor` owns only the file walk
+and dispatch.
+"""
+
+from __future__ import annotations
+
+from typing import TYPE_CHECKING
+
+from ..base import ScanContext, iter_source_files
+from .csharp import CSharpGrpcDialect
+from .dialect import GrpcDialect
+from .go import GoGrpcDialect
+from .java import JavaGrpcDialect
+from .proto import ProtoDialect, _extract_service_blocks
+from .python import PythonGrpcDialect
+from .typescript import TypeScriptGrpcDialect
+
+if TYPE_CHECKING:
+ from pathlib import Path
+
+ from repowise.core.workspace.contracts import Contract
+
+# One dialect per language/IDL; extension sets are disjoint, so exactly one runs
+# per file.
+DIALECTS: tuple[GrpcDialect, ...] = (
+ ProtoDialect(),
+ GoGrpcDialect(),
+ JavaGrpcDialect(),
+ PythonGrpcDialect(),
+ TypeScriptGrpcDialect(),
+ CSharpGrpcDialect(),
+)
+
+
+def _union_extensions(dialects: tuple[GrpcDialect, ...]) -> frozenset[str]:
+ out: set[str] = set()
+ for d in dialects:
+ out |= d.extensions
+ return frozenset(out)
+
+
+class GrpcExtractor:
+ """Extract gRPC contracts from proto files and language-specific source."""
+
+ dialects: tuple[GrpcDialect, ...] = DIALECTS
+
+ def extract(self, repo_path: Path, repo_alias: str = "") -> list[Contract]:
+ all_exts = _union_extensions(self.dialects)
+
+ contracts: list[Contract] = []
+ for rel_path, suffix, content in iter_source_files(repo_path, all_exts):
+ ctx = ScanContext(repo_alias, rel_path, suffix, content)
+ for dialect in self.dialects:
+ if suffix in dialect.extensions:
+ contracts.extend(dialect.extract(ctx))
+ return contracts
+
+
+__all__ = ["DIALECTS", "GrpcExtractor", "_extract_service_blocks"]
diff --git a/packages/core/src/repowise/core/workspace/extractors/grpc/csharp.py b/packages/core/src/repowise/core/workspace/extractors/grpc/csharp.py
new file mode 100644
index 000000000..e9c90d4ae
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/grpc/csharp.py
@@ -0,0 +1,76 @@
+"""C# (gRPC-dotnet) dialect.
+
+Providers come from explicit ``MapGrpcService<T>()`` registration and from the
+generated server-base convention ``class Impl : ServiceName.ServiceNameBase``.
+Consumers come from ``new XxxClient(...)`` generated stubs.
+"""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING
+
+from ..langs import CSHARP
+from .dialect import make_grpc_contract
+
+if TYPE_CHECKING:
+ from repowise.core.workspace.contracts import Contract
+
+ from ..base import ScanContext
+
+# app.MapGrpcService<GreeterService>()
+_CSHARP_GRPC_MAP_RE = re.compile(r"\.\s*MapGrpcService\s*<\s*(\w+)\s*>")
+# class Impl : ServiceName.ServiceNameBase
+_CSHARP_GRPC_BASE_RE = re.compile(r"class\s+\w+\s*:\s*(?:[\w.]+\.)?(\w+?)\s*\.\s*\1Base\b")
+# new AuthServiceClient(channel) — generated stub class ending in "Client".
+_CSHARP_GRPC_CLIENT_RE = re.compile(r"\bnew\s+(\w+)Client\s*\(")
+
+# Generic-class false positives — test doubles and non-gRPC clients.
+_CONSUMER_FALSE_PREFIXES = ("mock", "test", "fake", "http")
+
+
+class CSharpGrpcDialect:
+ name = "csharp"
+ extensions = CSHARP
+
+ def extract(self, ctx: ScanContext) -> list[Contract]:
+ out: list[Contract] = []
+ for m in _CSHARP_GRPC_MAP_RE.finditer(ctx.content):
+ svc = m.group(1)
+ out.append(
+ make_grpc_contract(
+ ctx,
+ contract_id=f"grpc::{svc}/*",
+ role="provider",
+ symbol_name=f"cs:MapGrpcService<{svc}>",
+ confidence=0.8,
+ meta={"service": svc, "source": "csharp_mapgrpc"},
+ )
+ )
+ for m in _CSHARP_GRPC_BASE_RE.finditer(ctx.content):
+ svc = m.group(1)
+ out.append(
+ make_grpc_contract(
+ ctx,
+ contract_id=f"grpc::{svc}/*",
+ role="provider",
+ symbol_name=f"cs:extends {svc}.{svc}ServiceBase",
+ confidence=0.8,
+ meta={"service": svc, "source": "csharp_base"},
+ )
+ )
+ for m in _CSHARP_GRPC_CLIENT_RE.finditer(ctx.content):
+ svc = m.group(1)
+ if svc.lower().startswith(_CONSUMER_FALSE_PREFIXES):
+ continue
+ out.append(
+ make_grpc_contract(
+ ctx,
+ contract_id=f"grpc::{svc}/*",
+ role="consumer",
+ symbol_name=f"cs:new {svc}Client",
+ confidence=0.65,
+ meta={"service": svc, "source": "csharp_client"},
+ )
+ )
+ return out
diff --git a/packages/core/src/repowise/core/workspace/extractors/grpc/dialect.py b/packages/core/src/repowise/core/workspace/extractors/grpc/dialect.py
new file mode 100644
index 000000000..2685892fc
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/grpc/dialect.py
@@ -0,0 +1,52 @@
+"""gRPC dialect protocol and the shared contract builder.
+
+Each language (and the ``.proto`` IDL) is one dialect keyed on its own file
+extensions, so exactly one dialect runs per file. Service identity is carried in
+the ``contract_id`` (``grpc::<service>/<method-or-*>``).
+"""
+
+from __future__ import annotations
+
+from typing import TYPE_CHECKING, Protocol, runtime_checkable
+
+from ..base import ScanContext
+
+if TYPE_CHECKING:
+ from repowise.core.workspace.contracts import Contract
+
+
+@runtime_checkable
+class GrpcDialect(Protocol):
+ """A gRPC recogniser for a set of file extensions."""
+
+ name: str
+ extensions: frozenset[str]
+
+ def extract(self, ctx: ScanContext) -> list[Contract]:
+ """Return the gRPC contracts found in *ctx* (may be empty)."""
+ ...
+
+
+def make_grpc_contract(
+ ctx: ScanContext,
+ *,
+ contract_id: str,
+ role: str,
+ symbol_name: str,
+ confidence: float,
+ meta: dict,
+) -> Contract:
+ """Build a gRPC :class:`Contract` with the common fields filled in."""
+ from repowise.core.workspace.contracts import Contract
+
+ return Contract(
+ repo=ctx.repo_alias,
+ contract_id=contract_id,
+ contract_type="grpc",
+ role=role,
+ file_path=ctx.rel_path,
+ symbol_name=symbol_name,
+ confidence=confidence,
+ service=None,
+ meta=meta,
+ )
diff --git a/packages/core/src/repowise/core/workspace/extractors/grpc/go.py b/packages/core/src/repowise/core/workspace/extractors/grpc/go.py
new file mode 100644
index 000000000..ec89cdd6f
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/grpc/go.py
@@ -0,0 +1,52 @@
+"""Go gRPC dialect — ``RegisterXxxServer`` providers / ``NewXxxClient`` consumers."""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING
+
+from ..langs import GO
+from .dialect import make_grpc_contract
+
+if TYPE_CHECKING:
+ from repowise.core.workspace.contracts import Contract
+
+ from ..base import ScanContext
+
+# pb.RegisterAuthServiceServer(grpcServer, &impl{})
+_GO_PROVIDER_RE = re.compile(r"\.Register(\w+)Server\s*\(")
+# pb.NewAuthServiceClient(conn)
+_GO_CONSUMER_RE = re.compile(r"\.New(\w+)Client\s*\(")
+
+
+class GoGrpcDialect:
+ name = "go"
+ extensions = GO
+
+ def extract(self, ctx: ScanContext) -> list[Contract]:
+ out: list[Contract] = []
+ for m in _GO_PROVIDER_RE.finditer(ctx.content):
+ svc = m.group(1)
+ out.append(
+ make_grpc_contract(
+ ctx,
+ contract_id=f"grpc::{svc}/*",
+ role="provider",
+ symbol_name=f"go:Register{svc}Server",
+ confidence=0.8,
+ meta={"service": svc, "source": "go_register"},
+ )
+ )
+ for m in _GO_CONSUMER_RE.finditer(ctx.content):
+ svc = m.group(1)
+ out.append(
+ make_grpc_contract(
+ ctx,
+ contract_id=f"grpc::{svc}/*",
+ role="consumer",
+ symbol_name=f"go:New{svc}Client",
+ confidence=0.7,
+ meta={"service": svc, "source": "go_client"},
+ )
+ )
+ return out
diff --git a/packages/core/src/repowise/core/workspace/extractors/grpc/java.py b/packages/core/src/repowise/core/workspace/extractors/grpc/java.py
new file mode 100644
index 000000000..4402b2fda
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/grpc/java.py
@@ -0,0 +1,52 @@
+"""Java gRPC dialect — ``extends XxxGrpc.XxxImplBase`` / ``XxxGrpc.newStub``."""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING
+
+from ..langs import JAVA
+from .dialect import make_grpc_contract
+
+if TYPE_CHECKING:
+ from repowise.core.workspace.contracts import Contract
+
+ from ..base import ScanContext
+
+# extends AuthServiceGrpc.AuthServiceImplBase
+_JAVA_PROVIDER_RE = re.compile(r"extends\s+(\w+)Grpc\.(\w+)ImplBase")
+# AuthServiceGrpc.newBlockingStub(channel)
+_JAVA_CONSUMER_RE = re.compile(r"(\w+)Grpc\.new(?:Blocking|Future)?Stub\s*\(")
+
+
+class JavaGrpcDialect:
+ name = "java"
+ extensions = JAVA
+
+ def extract(self, ctx: ScanContext) -> list[Contract]:
+ out: list[Contract] = []
+ for m in _JAVA_PROVIDER_RE.finditer(ctx.content):
+ svc = m.group(1)
+ out.append(
+ make_grpc_contract(
+ ctx,
+ contract_id=f"grpc::{svc}/*",
+ role="provider",
+ symbol_name=f"java:extends {svc}Grpc.ImplBase",
+ confidence=0.8,
+ meta={"service": svc, "source": "java_extends"},
+ )
+ )
+ for m in _JAVA_CONSUMER_RE.finditer(ctx.content):
+ svc = m.group(1)
+ out.append(
+ make_grpc_contract(
+ ctx,
+ contract_id=f"grpc::{svc}/*",
+ role="consumer",
+ symbol_name=f"java:{svc}Grpc.newStub",
+ confidence=0.7,
+ meta={"service": svc, "source": "java_stub"},
+ )
+ )
+ return out
diff --git a/packages/core/src/repowise/core/workspace/extractors/grpc/proto.py b/packages/core/src/repowise/core/workspace/extractors/grpc/proto.py
new file mode 100644
index 000000000..d835ff803
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/grpc/proto.py
@@ -0,0 +1,110 @@
+"""Protobuf IDL gRPC provider dialect.
+
+Parses ``.proto`` service/rpc declarations into provider contracts. Uses a
+brace-depth counter so braces inside comments, options, or message bodies don't
+break service-block extraction.
+"""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING
+
+from ..langs import PROTO
+from .dialect import make_grpc_contract
+
+if TYPE_CHECKING:
+ from repowise.core.workspace.contracts import Contract
+
+ from ..base import ScanContext
+
+
+def _extract_service_blocks(content: str) -> list[tuple[str, str]]:
+ """Extract ``(service_name, body)`` pairs from a ``.proto`` file.
+
+ Uses brace-depth counting so nested braces in comments, options, or
+ message bodies don't break parsing.
+ """
+ results: list[tuple[str, str]] = []
+ header_re = re.compile(r"service\s+(\w+)\s*\{")
+
+ for header_match in header_re.finditer(content):
+ service_name = header_match.group(1)
+ body_start = header_match.end()
+ depth = 1
+ pos = body_start
+ in_line_comment = False
+ in_block_comment = False
+ while pos < len(content) and depth > 0:
+ ch = content[pos]
+ # Track comment state to ignore braces inside comments
+ if in_line_comment:
+ if ch == "\n":
+ in_line_comment = False
+ elif in_block_comment:
+ if ch == "*" and pos + 1 < len(content) and content[pos + 1] == "/":
+ in_block_comment = False
+ pos += 1 # skip the '/'
+ elif ch == "/" and pos + 1 < len(content):
+ if content[pos + 1] == "/":
+ in_line_comment = True
+ elif content[pos + 1] == "*":
+ in_block_comment = True
+ pos += 1 # skip the '*'
+ elif ch == "{":
+ depth += 1
+ elif ch == "}":
+ depth -= 1
+ pos += 1
+ if depth != 0:
+ continue # incomplete/malformed service block
+ body = content[body_start : pos - 1]
+ results.append((service_name, body))
+
+ return results
+
+
+def _parse_proto_file(content: str) -> tuple[str, list[tuple[str, str, list[str]]]]:
+ """Parse a proto file, returning ``(package, services)``.
+
+ Each service is ``(service_name, full_service_path, [method_names])``.
+ """
+ pkg_match = re.search(r"^\s*package\s+([\w.]+)\s*;", content, re.MULTILINE)
+ package = pkg_match.group(1) if pkg_match else ""
+
+ services: list[tuple[str, str, list[str]]] = []
+ rpc_re = re.compile(r"rpc\s+(\w+)\s*\(")
+
+ for svc_name, body in _extract_service_blocks(content):
+ full_path = f"{package}.{svc_name}" if package else svc_name
+ methods = [m.group(1) for m in rpc_re.finditer(body)]
+ services.append((svc_name, full_path, methods))
+
+ return package, services
+
+
+class ProtoDialect:
+ name = "proto"
+ extensions = PROTO
+
+ def extract(self, ctx: ScanContext) -> list[Contract]:
+ package, services = _parse_proto_file(ctx.content)
+ out: list[Contract] = []
+ for svc_name, full_path, methods in services:
+ for method in methods:
+ out.append(
+ make_grpc_contract(
+ ctx,
+ contract_id=f"grpc::{full_path}/{method}",
+ role="provider",
+ symbol_name=f"{full_path}/{method}",
+ confidence=0.85,
+ meta={
+ "package": package,
+ "service": svc_name,
+ "method": method,
+ "source": "proto",
+ },
+ )
+ )
+ return out
diff --git a/packages/core/src/repowise/core/workspace/extractors/grpc/python.py b/packages/core/src/repowise/core/workspace/extractors/grpc/python.py
new file mode 100644
index 000000000..cdf6b0586
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/grpc/python.py
@@ -0,0 +1,57 @@
+"""Python gRPC dialect — ``add_XxxServicer_to_server`` / ``XxxStub``."""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING
+
+from ..langs import PYTHON
+from .dialect import make_grpc_contract
+
+if TYPE_CHECKING:
+ from repowise.core.workspace.contracts import Contract
+
+ from ..base import ScanContext
+
+# add_AuthServiceServicer_to_server(servicer, server)
+_PY_PROVIDER_RE = re.compile(r"add_(\w+?)Servicer_to_server\s*\(")
+# AuthServiceStub(channel)
+_PY_CONSUMER_RE = re.compile(r"(\w+)Stub\s*\(")
+
+# Common stub false positives — test doubles, not real clients.
+_CONSUMER_FALSE_PREFIXES = ("mock", "test", "fake")
+
+
+class PythonGrpcDialect:
+ name = "python"
+ extensions = PYTHON
+
+ def extract(self, ctx: ScanContext) -> list[Contract]:
+ out: list[Contract] = []
+ for m in _PY_PROVIDER_RE.finditer(ctx.content):
+ svc = m.group(1)
+ out.append(
+ make_grpc_contract(
+ ctx,
+ contract_id=f"grpc::{svc}/*",
+ role="provider",
+ symbol_name=f"py:add_{svc}Servicer_to_server",
+ confidence=0.8,
+ meta={"service": svc, "source": "py_servicer"},
+ )
+ )
+ for m in _PY_CONSUMER_RE.finditer(ctx.content):
+ svc = m.group(1)
+ if svc.lower().startswith(_CONSUMER_FALSE_PREFIXES):
+ continue
+ out.append(
+ make_grpc_contract(
+ ctx,
+ contract_id=f"grpc::{svc}/*",
+ role="consumer",
+ symbol_name=f"py:{svc}Stub",
+ confidence=0.7,
+ meta={"service": svc, "source": "py_stub"},
+ )
+ )
+ return out
diff --git a/packages/core/src/repowise/core/workspace/extractors/grpc/typescript.py b/packages/core/src/repowise/core/workspace/extractors/grpc/typescript.py
new file mode 100644
index 000000000..b617fd4f6
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/grpc/typescript.py
@@ -0,0 +1,39 @@
+"""TypeScript / JavaScript gRPC dialect — NestJS ``@GrpcMethod`` providers."""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING
+
+from ..langs import JS_TS
+from .dialect import make_grpc_contract
+
+if TYPE_CHECKING:
+ from repowise.core.workspace.contracts import Contract
+
+ from ..base import ScanContext
+
+# @GrpcMethod('AuthService', 'Login')
+_TS_PROVIDER_RE = re.compile(r"@GrpcMethod\s*\(\s*'(\w+)'\s*,\s*'(\w+)'\s*\)")
+
+
+class TypeScriptGrpcDialect:
+ name = "typescript"
+ extensions = JS_TS
+
+ def extract(self, ctx: ScanContext) -> list[Contract]:
+ out: list[Contract] = []
+ for m in _TS_PROVIDER_RE.finditer(ctx.content):
+ svc = m.group(1)
+ method = m.group(2)
+ out.append(
+ make_grpc_contract(
+ ctx,
+ contract_id=f"grpc::{svc}/{method}",
+ role="provider",
+ symbol_name=f"ts:@GrpcMethod('{svc}', '{method}')",
+ confidence=0.8,
+ meta={"service": svc, "method": method, "source": "ts_decorator"},
+ )
+ )
+ return out
diff --git a/packages/core/src/repowise/core/workspace/extractors/grpc_extractor.py b/packages/core/src/repowise/core/workspace/extractors/grpc_extractor.py
index 779c491d2..c16dc8436 100644
--- a/packages/core/src/repowise/core/workspace/extractors/grpc_extractor.py
+++ b/packages/core/src/repowise/core/workspace/extractors/grpc_extractor.py
@@ -1,418 +1,12 @@
-"""gRPC contract extraction.
+"""Backwards-compatible re-exports for the gRPC contract extractor.
-Scans ``.proto`` files for service/rpc declarations (providers) and
-language-specific source files for gRPC server registrations (providers) and
-client stubs (consumers).
+The implementation moved into the :mod:`.grpc` dialect package. This shim keeps
+``from ...extractors.grpc_extractor import GrpcExtractor, _extract_service_blocks``
+working for existing imports.
"""
from __future__ import annotations
-import logging
-import os
-import re
-from pathlib import Path
-from typing import TYPE_CHECKING
+from .grpc import GrpcExtractor, _extract_service_blocks
-from repowise.core.ingestion.languages.registry import REGISTRY as _LANG_REGISTRY
-
-if TYPE_CHECKING:
- from repowise.core.workspace.contracts import Contract
-
-_log = logging.getLogger("repowise.workspace.extractors.grpc")
-
-# ---------------------------------------------------------------------------
-# Constants
-# ---------------------------------------------------------------------------
-
-_BLOCKED_DIRS = frozenset(
- {
- ".git",
- "node_modules",
- "__pycache__",
- ".venv",
- "venv",
- "dist",
- "build",
- "target",
- "vendor",
- ".next",
- ".nuxt",
- ".tox",
- ".mypy_cache",
- ".gradle",
- ".mvn",
- "out",
- "bin",
- }
-)
-
-_MAX_FILE_SIZE = 512 * 1024
-
-_PROTO_EXTENSIONS = _LANG_REGISTRY.extensions_for(["proto"])
-
-_SOURCE_EXTENSIONS = _LANG_REGISTRY.extensions_for(
- ["go", "java", "python", "typescript", "javascript", "csharp"]
-)
-
-_ALL_EXTENSIONS = _PROTO_EXTENSIONS | _SOURCE_EXTENSIONS
-
-
-# ---------------------------------------------------------------------------
-# Proto parsing (brace-depth counter)
-# ---------------------------------------------------------------------------
-
-
-def _extract_service_blocks(content: str) -> list[tuple[str, str]]:
- """Extract ``(service_name, body)`` pairs from a ``.proto`` file.
-
- Uses brace-depth counting so nested braces in comments, options, or
- message bodies don't break parsing.
- """
- results: list[tuple[str, str]] = []
- header_re = re.compile(r"service\s+(\w+)\s*\{")
-
- for header_match in header_re.finditer(content):
- service_name = header_match.group(1)
- body_start = header_match.end()
- depth = 1
- pos = body_start
- in_line_comment = False
- in_block_comment = False
- while pos < len(content) and depth > 0:
- ch = content[pos]
- # Track comment state to ignore braces inside comments
- if in_line_comment:
- if ch == "\n":
- in_line_comment = False
- elif in_block_comment:
- if ch == "*" and pos + 1 < len(content) and content[pos + 1] == "/":
- in_block_comment = False
- pos += 1 # skip the '/'
- elif ch == "/" and pos + 1 < len(content):
- if content[pos + 1] == "/":
- in_line_comment = True
- elif content[pos + 1] == "*":
- in_block_comment = True
- pos += 1 # skip the '*'
- elif ch == "{":
- depth += 1
- elif ch == "}":
- depth -= 1
- pos += 1
- if depth != 0:
- continue # incomplete/malformed service block
- body = content[body_start : pos - 1]
- results.append((service_name, body))
-
- return results
-
-
-def _parse_proto_file(content: str) -> tuple[str, list[tuple[str, str, list[str]]]]:
- """Parse a proto file, returning ``(package, services)``.
-
- Each service is ``(service_name, full_service_path, [method_names])``.
- """
- # Extract package
- pkg_match = re.search(r"^\s*package\s+([\w.]+)\s*;", content, re.MULTILINE)
- package = pkg_match.group(1) if pkg_match else ""
-
- services: list[tuple[str, str, list[str]]] = []
- rpc_re = re.compile(r"rpc\s+(\w+)\s*\(")
-
- for svc_name, body in _extract_service_blocks(content):
- full_path = f"{package}.{svc_name}" if package else svc_name
- methods = [m.group(1) for m in rpc_re.finditer(body)]
- services.append((svc_name, full_path, methods))
-
- return package, services
-
-
-# ---------------------------------------------------------------------------
-# Language-specific patterns
-# ---------------------------------------------------------------------------
-
-# Go providers: pb.RegisterAuthServiceServer(grpcServer, &impl{})
-_GO_PROVIDER_RE = re.compile(r"\.Register(\w+)Server\s*\(")
-# Go consumers: pb.NewAuthServiceClient(conn)
-_GO_CONSUMER_RE = re.compile(r"\.New(\w+)Client\s*\(")
-
-# Java providers: extends AuthServiceGrpc.AuthServiceImplBase
-_JAVA_PROVIDER_RE = re.compile(r"extends\s+(\w+)Grpc\.(\w+)ImplBase")
-# Java @GrpcService annotation
-_JAVA_GRPC_SERVICE_RE = re.compile(r"@GrpcService")
-# Java consumers: AuthServiceGrpc.newBlockingStub(channel)
-_JAVA_CONSUMER_RE = re.compile(r"(\w+)Grpc\.new(?:Blocking|Future)?Stub\s*\(")
-
-# Python providers: add_AuthServiceServicer_to_server(servicer, server)
-_PY_PROVIDER_RE = re.compile(r"add_(\w+?)Servicer_to_server\s*\(")
-# Python consumers: AuthServiceStub(channel)
-_PY_CONSUMER_RE = re.compile(r"(\w+)Stub\s*\(")
-
-# TypeScript providers: @GrpcMethod('AuthService', 'Login')
-_TS_PROVIDER_RE = re.compile(r"@GrpcMethod\s*\(\s*'(\w+)'\s*,\s*'(\w+)'\s*\)")
-
-# C# / gRPC-dotnet providers: app.MapGrpcService<GreeterService>() — explicit
-# service registration. The generated server-base class follows the
-# convention `class Impl : ServiceName.ServiceNameBase` where ServiceName
-# matches the .proto service name (e.g. `Greeter.GreeterBase`,
-# `AuthService.AuthServiceBase`). We capture the prefix as the service id.
-_CSHARP_GRPC_MAP_RE = re.compile(r"\.\s*MapGrpcService\s*<\s*(\w+)\s*>")
-_CSHARP_GRPC_BASE_RE = re.compile(
- r"class\s+\w+\s*:\s*(?:[\w.]+\.)?(\w+?)\s*\.\s*\1Base\b"
-)
-# C# consumers: new AuthServiceClient(channel) / new GreeterClient(channel).
-# The generated stub class always ends in "Client" and follows a `new` keyword.
-_CSHARP_GRPC_CLIENT_RE = re.compile(r"\bnew\s+(\w+)Client\s*\(")
-
-
-# ---------------------------------------------------------------------------
-# Extractor
-# ---------------------------------------------------------------------------
-
-
-class GrpcExtractor:
- """Extract gRPC contracts from proto files and language-specific source."""
-
- def extract(self, repo_path: Path, repo_alias: str = "") -> list[Contract]:
- from repowise.core.workspace.contracts import Contract
-
- contracts: list[Contract] = []
- repo_root = repo_path.resolve()
-
- for dirpath, dirnames, filenames in os.walk(repo_root):
- dirnames[:] = [d for d in dirnames if d not in _BLOCKED_DIRS and not d.startswith(".")]
- for fname in filenames:
- fpath = Path(dirpath) / fname
- suffix = fpath.suffix.lower()
- if suffix not in _ALL_EXTENSIONS:
- continue
- try:
- if fpath.stat().st_size > _MAX_FILE_SIZE:
- continue
- except OSError:
- continue
-
- try:
- content = fpath.read_text(encoding="utf-8", errors="replace")
- except OSError:
- continue
-
- rel_path = fpath.relative_to(repo_root).as_posix()
-
- # --- Proto files → providers ---
- if suffix in _PROTO_EXTENSIONS:
- _package, services = _parse_proto_file(content)
- for _svc_name, full_path, methods in services:
- for method in methods:
- contract_id = f"grpc::{full_path}/{method}"
- contracts.append(
- Contract(
- repo=repo_alias,
- contract_id=contract_id,
- contract_type="grpc",
- role="provider",
- file_path=rel_path,
- symbol_name=f"{full_path}/{method}",
- confidence=0.85,
- service=None,
- meta={
- "package": _package,
- "service": _svc_name,
- "method": method,
- "source": "proto",
- },
- )
- )
-
- # --- Go ---
- elif suffix == ".go":
- for m in _GO_PROVIDER_RE.finditer(content):
- svc = m.group(1)
- contract_id = f"grpc::{svc}/*"
- contracts.append(
- Contract(
- repo=repo_alias,
- contract_id=contract_id,
- contract_type="grpc",
- role="provider",
- file_path=rel_path,
- symbol_name=f"go:Register{svc}Server",
- confidence=0.8,
- service=None,
- meta={"service": svc, "source": "go_register"},
- )
- )
-
- for m in _GO_CONSUMER_RE.finditer(content):
- svc = m.group(1)
- contract_id = f"grpc::{svc}/*"
- contracts.append(
- Contract(
- repo=repo_alias,
- contract_id=contract_id,
- contract_type="grpc",
- role="consumer",
- file_path=rel_path,
- symbol_name=f"go:New{svc}Client",
- confidence=0.7,
- service=None,
- meta={"service": svc, "source": "go_client"},
- )
- )
-
- # --- Java ---
- elif suffix == ".java":
- for m in _JAVA_PROVIDER_RE.finditer(content):
- svc = m.group(1)
- contract_id = f"grpc::{svc}/*"
- contracts.append(
- Contract(
- repo=repo_alias,
- contract_id=contract_id,
- contract_type="grpc",
- role="provider",
- file_path=rel_path,
- symbol_name=f"java:extends {svc}Grpc.ImplBase",
- confidence=0.8,
- service=None,
- meta={"service": svc, "source": "java_extends"},
- )
- )
-
- for m in _JAVA_CONSUMER_RE.finditer(content):
- svc = m.group(1)
- contract_id = f"grpc::{svc}/*"
- contracts.append(
- Contract(
- repo=repo_alias,
- contract_id=contract_id,
- contract_type="grpc",
- role="consumer",
- file_path=rel_path,
- symbol_name=f"java:{svc}Grpc.newStub",
- confidence=0.7,
- service=None,
- meta={"service": svc, "source": "java_stub"},
- )
- )
-
- # --- Python ---
- elif suffix == ".py":
- for m in _PY_PROVIDER_RE.finditer(content):
- svc = m.group(1)
- contract_id = f"grpc::{svc}/*"
- contracts.append(
- Contract(
- repo=repo_alias,
- contract_id=contract_id,
- contract_type="grpc",
- role="provider",
- file_path=rel_path,
- symbol_name=f"py:add_{svc}Servicer_to_server",
- confidence=0.8,
- service=None,
- meta={"service": svc, "source": "py_servicer"},
- )
- )
-
- for m in _PY_CONSUMER_RE.finditer(content):
- svc = m.group(1)
- # Filter common false positives (Mock*, Test*, Fake* prefixes)
- svc_lower = svc.lower()
- if any(svc_lower.startswith(p) for p in ("mock", "test", "fake")):
- continue
- contract_id = f"grpc::{svc}/*"
- contracts.append(
- Contract(
- repo=repo_alias,
- contract_id=contract_id,
- contract_type="grpc",
- role="consumer",
- file_path=rel_path,
- symbol_name=f"py:{svc}Stub",
- confidence=0.7,
- service=None,
- meta={"service": svc, "source": "py_stub"},
- )
- )
-
- # --- TypeScript ---
- elif suffix in (".ts", ".tsx", ".js", ".jsx"):
- for m in _TS_PROVIDER_RE.finditer(content):
- svc = m.group(1)
- method = m.group(2)
- contract_id = f"grpc::{svc}/{method}"
- contracts.append(
- Contract(
- repo=repo_alias,
- contract_id=contract_id,
- contract_type="grpc",
- role="provider",
- file_path=rel_path,
- symbol_name=f"ts:@GrpcMethod('{svc}', '{method}')",
- confidence=0.8,
- service=None,
- meta={
- "service": svc,
- "method": method,
- "source": "ts_decorator",
- },
- )
- )
-
- # --- C# (gRPC-dotnet) ---
- elif suffix == ".cs":
- for m in _CSHARP_GRPC_MAP_RE.finditer(content):
- svc = m.group(1)
- contract_id = f"grpc::{svc}/*"
- contracts.append(
- Contract(
- repo=repo_alias,
- contract_id=contract_id,
- contract_type="grpc",
- role="provider",
- file_path=rel_path,
- symbol_name=f"cs:MapGrpcService<{svc}>",
- confidence=0.8,
- service=None,
- meta={"service": svc, "source": "csharp_mapgrpc"},
- )
- )
-
- for m in _CSHARP_GRPC_BASE_RE.finditer(content):
- svc = m.group(1)
- contract_id = f"grpc::{svc}/*"
- contracts.append(
- Contract(
- repo=repo_alias,
- contract_id=contract_id,
- contract_type="grpc",
- role="provider",
- file_path=rel_path,
- symbol_name=f"cs:extends {svc}.{svc}ServiceBase",
- confidence=0.8,
- service=None,
- meta={"service": svc, "source": "csharp_base"},
- )
- )
-
- for m in _CSHARP_GRPC_CLIENT_RE.finditer(content):
- svc = m.group(1)
- if svc.lower().startswith(("mock", "test", "fake", "http")):
- continue
- contract_id = f"grpc::{svc}/*"
- contracts.append(
- Contract(
- repo=repo_alias,
- contract_id=contract_id,
- contract_type="grpc",
- role="consumer",
- file_path=rel_path,
- symbol_name=f"cs:new {svc}Client",
- confidence=0.65,
- service=None,
- meta={"service": svc, "source": "csharp_client"},
- )
- )
-
- return contracts
+__all__ = ["GrpcExtractor", "_extract_service_blocks"]
diff --git a/packages/core/src/repowise/core/workspace/extractors/http/__init__.py b/packages/core/src/repowise/core/workspace/extractors/http/__init__.py
new file mode 100644
index 000000000..9f850aaf6
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/http/__init__.py
@@ -0,0 +1,82 @@
+"""HTTP route contract extraction.
+
+Scans source files for route handler declarations (providers) and HTTP client
+calls (consumers). Each framework / client library is an independent *dialect*
+module registered in :data:`PROVIDER_DIALECTS` / :data:`CONSUMER_DIALECTS`; the
+:class:`HttpExtractor` orchestrator owns only the file walk and dispatch. Adding
+a framework means dropping one dialect module and appending it to a registry —
+no orchestrator edits.
+"""
+
+from __future__ import annotations
+
+from typing import TYPE_CHECKING
+
+from ..base import ScanContext, iter_source_files
+from .aspnet import AspNetDialect
+from .csharp_http import CSharpHttpDialect
+from .dialect import HttpDialect
+from .express import ExpressDialect
+from .fastapi import FastApiDialect
+from .go import GoDialect
+from .js_clients import JsClientsDialect
+from .laravel import LaravelDialect
+from .paths import normalize_http_path
+from .python_clients import PythonClientsDialect
+from .spring import SpringDialect
+
+if TYPE_CHECKING:
+ from pathlib import Path
+
+ from repowise.core.workspace.contracts import Contract
+
+# Route-declaration recognisers (one framework each).
+PROVIDER_DIALECTS: tuple[HttpDialect, ...] = (
+ ExpressDialect(),
+ FastApiDialect(),
+ SpringDialect(),
+ LaravelDialect(),
+ GoDialect(),
+ AspNetDialect(),
+)
+
+# HTTP-client call recognisers (one client/language each).
+CONSUMER_DIALECTS: tuple[HttpDialect, ...] = (
+ JsClientsDialect(),
+ PythonClientsDialect(),
+ CSharpHttpDialect(),
+)
+
+
+def _union_extensions(dialects: tuple[HttpDialect, ...]) -> frozenset[str]:
+ out: set[str] = set()
+ for d in dialects:
+ out |= d.extensions
+ return frozenset(out)
+
+
+class HttpExtractor:
+ """Extract HTTP route contracts from source files via registered dialects."""
+
+ provider_dialects: tuple[HttpDialect, ...] = PROVIDER_DIALECTS
+ consumer_dialects: tuple[HttpDialect, ...] = CONSUMER_DIALECTS
+
+ def extract(self, repo_path: Path, repo_alias: str = "") -> list[Contract]:
+ """Scan all source files in *repo_path* and return Contract instances."""
+ all_exts = _union_extensions(self.provider_dialects) | _union_extensions(
+ self.consumer_dialects
+ )
+
+ contracts: list[Contract] = []
+ for rel_path, suffix, content in iter_source_files(repo_path, all_exts):
+ ctx = ScanContext(repo_alias, rel_path, suffix, content)
+ for dialect in self.provider_dialects:
+ if suffix in dialect.extensions:
+ contracts.extend(dialect.extract(ctx))
+ for dialect in self.consumer_dialects:
+ if suffix in dialect.extensions:
+ contracts.extend(dialect.extract(ctx))
+ return contracts
+
+
+__all__ = ["CONSUMER_DIALECTS", "PROVIDER_DIALECTS", "HttpExtractor", "normalize_http_path"]
diff --git a/packages/core/src/repowise/core/workspace/extractors/http/aspnet.py b/packages/core/src/repowise/core/workspace/extractors/http/aspnet.py
new file mode 100644
index 000000000..5bf38696a
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/http/aspnet.py
@@ -0,0 +1,94 @@
+"""ASP.NET (C#) HTTP provider dialect.
+
+Covers three shapes that can co-exist in one file:
+
+* attribute routing — ``[HttpGet("path")]`` stitched onto the class
+ ``[Route("api/users")]`` prefix;
+* parameterless attributes — ``[HttpPost]`` whose route is the class prefix;
+* minimal APIs — ``app.MapGet("/users", ...)`` (not inside a controller, so
+ never prefix-stitched).
+"""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING
+
+from ..langs import CSHARP
+from .dialect import METHODS, build_provider_contract, nearest_prefix
+
+if TYPE_CHECKING:
+ from repowise.core.workspace.contracts import Contract
+
+ from ..base import ScanContext
+
+# [HttpGet("path")], [HttpPost("path")], etc. The leading bracket may be on its
+# own line, so we anchor on the attribute name.
+_ASPNET_METHOD_RE = re.compile(
+ r"""\[\s*Http(Get|Post|Put|Delete|Patch)\s*\(\s*['"]([^'"]+)['"]""",
+ re.IGNORECASE,
+)
+
+# Parameterless attribute: [HttpPost] / [HttpGet] — the route is the class
+# prefix only.
+_ASPNET_BARE_METHOD_RE = re.compile(
+ r"""\[\s*Http(Get|Post|Put|Delete|Patch)\s*\]""",
+ re.IGNORECASE,
+)
+
+# Class-level prefix: [Route("api/users")] above an [ApiController] class.
+_ASPNET_CLASS_ROUTE_RE = re.compile(
+ r"""\[\s*Route\s*\(\s*['"]([^'"]+)['"]""",
+)
+
+# Minimal API: app.MapGet("/users", ...) — same shape, different method names.
+_ASPNET_MINIMAL_RE = re.compile(
+ rf"""\.\s*Map({METHODS})\s*\(\s*['"]([^'"]+)['"]""",
+ re.IGNORECASE,
+)
+
+
+class AspNetDialect:
+ name = "aspnet"
+ extensions = CSHARP
+
+ def extract(self, ctx: ScanContext) -> list[Contract]:
+ content = ctx.content
+ class_mappings: list[tuple[int, str]] = [
+ (cm.start(), cm.group(1).rstrip("/")) for cm in _ASPNET_CLASS_ROUTE_RE.finditer(content)
+ ]
+
+ out: list[Contract] = []
+
+ # Attribute routing — stitched onto the nearest class [Route(...)].
+ for m in _ASPNET_METHOD_RE.finditer(content):
+ method = m.group(1).upper()
+ path_raw = m.group(2)
+ prefix = nearest_prefix(class_mappings, m.start())
+ if prefix:
+ path_raw = prefix + "/" + path_raw.lstrip("/")
+ c = build_provider_contract(ctx, method=method, path_raw=path_raw, framework="aspnet")
+ if c is not None:
+ out.append(c)
+
+ # Minimal API — not inside a controller, never prefix-stitched.
+ for m in _ASPNET_MINIMAL_RE.finditer(content):
+ c = build_provider_contract(
+ ctx, method=m.group(1).upper(), path_raw=m.group(2), framework="aspnet-minimal"
+ )
+ if c is not None:
+ out.append(c)
+
+ # Parameterless [HttpPost] — route is whichever class [Route("...")]
+ # precedes it. Without a class route there is no useful path to record.
+ if class_mappings:
+ for m in _ASPNET_BARE_METHOD_RE.finditer(content):
+ method = m.group(1).upper()
+ prefix = nearest_prefix(class_mappings, m.start())
+ if not prefix:
+ continue
+ c = build_provider_contract(ctx, method=method, path_raw=prefix, framework="aspnet")
+ if c is not None:
+ out.append(c)
+
+ return out
diff --git a/packages/core/src/repowise/core/workspace/extractors/http/csharp_http.py b/packages/core/src/repowise/core/workspace/extractors/http/csharp_http.py
new file mode 100644
index 000000000..f0553b785
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/http/csharp_http.py
@@ -0,0 +1,42 @@
+"""C# HTTP consumer dialect — ``HttpClient`` ``client.GetAsync("/api/users")``."""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING
+
+from ..langs import CSHARP
+from .dialect import METHODS, build_consumer_contract
+
+if TYPE_CHECKING:
+ from repowise.core.workspace.contracts import Contract
+
+ from ..base import ScanContext
+
+# client.GetAsync("/api/users") / PostAsync / PutAsync / DeleteAsync.
+_HTTPCLIENT_RE = re.compile(
+ rf"""\.\s*({METHODS})Async\s*\(\s*['"]([^'"]+)['"]""",
+ re.IGNORECASE,
+)
+
+
+class CSharpHttpDialect:
+ name = "csharp-http"
+ extensions = CSHARP
+
+ def extract(self, ctx: ScanContext) -> list[Contract]:
+ out: list[Contract] = []
+ for m in _HTTPCLIENT_RE.finditer(ctx.content):
+ url = m.group(2)
+ if "/" not in url:
+ continue # Avoid matching non-URL strings.
+ out.append(
+ build_consumer_contract(
+ ctx,
+ method=m.group(1).upper(),
+ url=url,
+ client="httpclient",
+ confidence=0.70,
+ )
+ )
+ return out
diff --git a/packages/core/src/repowise/core/workspace/extractors/http/dialect.py b/packages/core/src/repowise/core/workspace/extractors/http/dialect.py
new file mode 100644
index 000000000..36f92990a
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/http/dialect.py
@@ -0,0 +1,116 @@
+"""HTTP dialect protocol and the shared contract builders.
+
+A *dialect* is one framework's or client library's view of a source file. It
+declares the file extensions it understands and turns raw regex matches into
+:class:`Contract` instances via the two builders here, so every dialect emits
+identically-shaped providers/consumers and the normalization rules live in one
+place.
+"""
+
+from __future__ import annotations
+
+from typing import TYPE_CHECKING, Protocol, runtime_checkable
+
+from ..base import ScanContext
+from .paths import (
+ consumer_meta,
+ extract_path_from_url,
+ normalize_http_path,
+ strip_leading_base_expr,
+)
+
+if TYPE_CHECKING:
+ from repowise.core.workspace.contracts import Contract
+
+# Regex fragments for the HTTP method verbs, shared by every dialect's patterns.
+METHODS = r"get|post|put|delete|patch"
+METHODS_UPPER = r"GET|POST|PUT|DELETE|PATCH"
+
+
+@runtime_checkable
+class HttpDialect(Protocol):
+ """A framework/client recogniser for a set of file extensions."""
+
+ name: str
+ extensions: frozenset[str]
+
+ def extract(self, ctx: ScanContext) -> list[Contract]:
+ """Return the contracts found in *ctx* (may be empty)."""
+ ...
+
+
+def nearest_prefix(mappings: list[tuple[int, str]], pos: int) -> str:
+ """Return the prefix of the nearest class mapping declared before *pos*.
+
+ *mappings* is ``(start_offset, prefix)`` in ascending offset order (as
+ produced by :func:`re.finditer`). Used by frameworks where a class-level
+ route prefix (`@RequestMapping` / `[Route(...)]`) stitches onto each
+ method-level route below it.
+ """
+ prefix = ""
+ for cls_pos, cls_prefix in mappings:
+ if cls_pos < pos:
+ prefix = cls_prefix
+ else:
+ break
+ return prefix
+
+
+def build_provider_contract(
+ ctx: ScanContext,
+ *,
+ method: str,
+ path_raw: str,
+ framework: str,
+ confidence: float = 0.85,
+) -> Contract | None:
+ """Build a provider contract, or ``None`` if the path is unusable.
+
+ A match whose path normalizes to bare ``/`` only counts when the raw text
+ actually carried a path — a template-variable-only or empty route is
+ dropped, matching the legacy extractor's skip rule.
+ """
+ from repowise.core.workspace.contracts import Contract
+
+ norm_path = normalize_http_path(path_raw)
+ if (not norm_path or norm_path == "/") and not path_raw.strip("/"):
+ return None
+
+ return Contract(
+ repo=ctx.repo_alias,
+ contract_id=f"http::{method}::{norm_path}",
+ contract_type="http",
+ role="provider",
+ file_path=ctx.rel_path,
+ symbol_name=f"{framework}:{method} {path_raw}",
+ confidence=confidence,
+ service=None,
+ meta={"method": method, "path": norm_path, "framework": framework},
+ )
+
+
+def build_consumer_contract(
+ ctx: ScanContext,
+ *,
+ method: str,
+ url: str,
+ client: str,
+ confidence: float = 0.75,
+) -> Contract:
+ """Build a consumer contract from a raw client-call URL."""
+ from repowise.core.workspace.contracts import Contract
+
+ path = extract_path_from_url(url)
+ path, base_stripped = strip_leading_base_expr(path)
+ norm_path = normalize_http_path(path)
+ return Contract(
+ repo=ctx.repo_alias,
+ contract_id=f"http::{method}::{norm_path}",
+ contract_type="http",
+ role="consumer",
+ file_path=ctx.rel_path,
+ symbol_name=f"{client}:{method} {url}",
+ confidence=confidence,
+ service=None,
+ meta=consumer_meta(method, norm_path, client, base_stripped),
+ )
diff --git a/packages/core/src/repowise/core/workspace/extractors/http/express.py b/packages/core/src/repowise/core/workspace/extractors/http/express.py
new file mode 100644
index 000000000..38a3175c4
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/http/express.py
@@ -0,0 +1,36 @@
+"""Express / Node.js HTTP provider dialect — ``router.get('/path', ...)``."""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING
+
+from ..langs import JS_TS
+from .dialect import METHODS, build_provider_contract
+
+if TYPE_CHECKING:
+ from repowise.core.workspace.contracts import Contract
+
+ from ..base import ScanContext
+
+# router.get('/path', ...) or app.post('/path', ...). The negative lookbehind for
+# ``@`` keeps FastAPI decorators (``@app.get``) from matching here.
+_EXPRESS_RE = re.compile(
+ rf"""(?<!@)(?:router|app)\.({METHODS})\s*\(\s*['"]([^'"]+)['"]""",
+ re.IGNORECASE,
+)
+
+
+class ExpressDialect:
+ name = "express"
+ extensions = JS_TS
+
+ def extract(self, ctx: ScanContext) -> list[Contract]:
+ out: list[Contract] = []
+ for m in _EXPRESS_RE.finditer(ctx.content):
+ c = build_provider_contract(
+ ctx, method=m.group(1).upper(), path_raw=m.group(2), framework="express"
+ )
+ if c is not None:
+ out.append(c)
+ return out
diff --git a/packages/core/src/repowise/core/workspace/extractors/http/fastapi.py b/packages/core/src/repowise/core/workspace/extractors/http/fastapi.py
new file mode 100644
index 000000000..e7d00f14c
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/http/fastapi.py
@@ -0,0 +1,35 @@
+"""FastAPI / Python HTTP provider dialect — ``@app.get('/path')``."""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING
+
+from ..langs import PYTHON
+from .dialect import METHODS, build_provider_contract
+
+if TYPE_CHECKING:
+ from repowise.core.workspace.contracts import Contract
+
+ from ..base import ScanContext
+
+# @app.get('/path') or @router.post('/path')
+_FASTAPI_RE = re.compile(
+ rf"""@(?:app|router)\.({METHODS})\s*\(\s*['"]([^'"]+)['"]""",
+ re.IGNORECASE,
+)
+
+
+class FastApiDialect:
+ name = "fastapi"
+ extensions = PYTHON
+
+ def extract(self, ctx: ScanContext) -> list[Contract]:
+ out: list[Contract] = []
+ for m in _FASTAPI_RE.finditer(ctx.content):
+ c = build_provider_contract(
+ ctx, method=m.group(1).upper(), path_raw=m.group(2), framework="fastapi"
+ )
+ if c is not None:
+ out.append(c)
+ return out
diff --git a/packages/core/src/repowise/core/workspace/extractors/http/go.py b/packages/core/src/repowise/core/workspace/extractors/http/go.py
new file mode 100644
index 000000000..af81ae757
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/http/go.py
@@ -0,0 +1,37 @@
+"""Go HTTP provider dialect — gin/echo/chi ``r.GET("/path", ...)`` and
+stdlib ``.HandleFunc("/path", ...)`` (which carries no method, recorded as
+``*``)."""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING
+
+from ..langs import GO
+from .dialect import METHODS_UPPER, build_provider_contract
+
+if TYPE_CHECKING:
+ from repowise.core.workspace.contracts import Contract
+
+ from ..base import ScanContext
+
+# r.GET("/path", ...) or .HandleFunc("/path", ...)
+_GO_ROUTE_RE = re.compile(
+ rf"""\.({METHODS_UPPER}|Handle|HandleFunc)\s*\(\s*['"]([^'"]+)['"]""",
+)
+
+
+class GoDialect:
+ name = "go"
+ extensions = GO
+
+ def extract(self, ctx: ScanContext) -> list[Contract]:
+ out: list[Contract] = []
+ for m in _GO_ROUTE_RE.finditer(ctx.content):
+ method_raw = m.group(1)
+ # Handle/HandleFunc don't carry a method verb.
+ method = "*" if method_raw in ("Handle", "HandleFunc") else method_raw.upper()
+ c = build_provider_contract(ctx, method=method, path_raw=m.group(2), framework="go")
+ if c is not None:
+ out.append(c)
+ return out
diff --git a/packages/core/src/repowise/core/workspace/extractors/http/js_clients.py b/packages/core/src/repowise/core/workspace/extractors/http/js_clients.py
new file mode 100644
index 000000000..20c8df9ea
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/http/js_clients.py
@@ -0,0 +1,64 @@
+"""JavaScript / TypeScript HTTP consumer dialect — ``fetch`` and ``axios``."""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING
+
+from ..langs import JS_TS
+from .dialect import METHODS, build_consumer_contract
+
+if TYPE_CHECKING:
+ from repowise.core.workspace.contracts import Contract
+
+ from ..base import ScanContext
+
+# fetch('/api/users') or fetch('/api/users', { method: 'POST' })
+_FETCH_RE = re.compile(
+ r"""fetch\s*\(\s*['"`]([^'"`]+)['"`]""",
+)
+_FETCH_METHOD_RE = re.compile(
+ r"""fetch\s*\(\s*['"`]([^'"`]+)['"`]\s*,\s*\{[^}]*method\s*:\s*['"](\w+)['"]""",
+ re.DOTALL,
+)
+
+# axios.get('/api/users')
+_AXIOS_RE = re.compile(
+ rf"""axios\.({METHODS})\s*\(\s*['"]([^'"]+)['"]""",
+ re.IGNORECASE,
+)
+
+
+class JsClientsDialect:
+ name = "js-clients"
+ extensions = JS_TS
+
+ def extract(self, ctx: ScanContext) -> list[Contract]:
+ content = ctx.content
+ out: list[Contract] = []
+
+ # fetch() with an explicit method.
+ for m in _FETCH_METHOD_RE.finditer(content):
+ out.append(
+ build_consumer_contract(
+ ctx, method=m.group(2).upper(), url=m.group(1), client="fetch"
+ )
+ )
+
+ # fetch() without a method → GET, skipping URLs already matched above.
+ method_urls = {m.group(1) for m in _FETCH_METHOD_RE.finditer(content)}
+ for m in _FETCH_RE.finditer(content):
+ url = m.group(1)
+ if url in method_urls:
+ continue
+ out.append(build_consumer_contract(ctx, method="GET", url=url, client="fetch"))
+
+ # axios.<method>()
+ for m in _AXIOS_RE.finditer(content):
+ out.append(
+ build_consumer_contract(
+ ctx, method=m.group(1).upper(), url=m.group(2), client="axios"
+ )
+ )
+
+ return out
diff --git a/packages/core/src/repowise/core/workspace/extractors/http/laravel.py b/packages/core/src/repowise/core/workspace/extractors/http/laravel.py
new file mode 100644
index 000000000..f4a40a2da
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/http/laravel.py
@@ -0,0 +1,35 @@
+"""Laravel (PHP) HTTP provider dialect — ``Route::get('/path', ...)``."""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING
+
+from ..langs import PHP
+from .dialect import METHODS, build_provider_contract
+
+if TYPE_CHECKING:
+ from repowise.core.workspace.contracts import Contract
+
+ from ..base import ScanContext
+
+# Route::get('/path', ...)
+_LARAVEL_RE = re.compile(
+ rf"""Route::({METHODS})\s*\(\s*['"]([^'"]+)['"]""",
+ re.IGNORECASE,
+)
+
+
+class LaravelDialect:
+ name = "laravel"
+ extensions = PHP
+
+ def extract(self, ctx: ScanContext) -> list[Contract]:
+ out: list[Contract] = []
+ for m in _LARAVEL_RE.finditer(ctx.content):
+ c = build_provider_contract(
+ ctx, method=m.group(1).upper(), path_raw=m.group(2), framework="laravel"
+ )
+ if c is not None:
+ out.append(c)
+ return out
diff --git a/packages/core/src/repowise/core/workspace/extractors/http/paths.py b/packages/core/src/repowise/core/workspace/extractors/http/paths.py
new file mode 100644
index 000000000..b24535b3c
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/http/paths.py
@@ -0,0 +1,91 @@
+"""HTTP path normalization and URL helpers shared by every HTTP dialect.
+
+A contract's identity is its normalized ``method::path`` pair, so all dialects
+funnel their raw matches through :func:`normalize_http_path` to compare on equal
+footing regardless of the framework's parameter syntax.
+"""
+
+from __future__ import annotations
+
+import re
+
+
+def normalize_http_path(path: str) -> str:
+ """Normalize an HTTP path for matching.
+
+ Steps:
+ 1. Strip whitespace
+ 2. Remove query string
+ 3. Lowercase
+ 4. Strip trailing slash (but keep root ``/``)
+ 5. Unify param styles: ``:param``, ``{param}``, ``[param]`` → ``{param}``
+ """
+ s = path.strip().split("?")[0].lower()
+ if s != "/":
+ s = s.rstrip("/")
+ # ASP.NET routes commonly omit the leading slash; add one so all
+ # frameworks compare on equal footing.
+ if s and not s.startswith("/") and not s.startswith("http"):
+ s = "/" + s
+ # ASP.NET route constraints: `{id:int}` / `{slug:regex(\d+)}` — strip the
+ # ``:type`` portion so the next normalisation step doesn't double-wrap it.
+ s = re.sub(r"(\{[a-z_][\w]*):[^}]+(\})", r"\1\2", s)
+ # Unify Express :param (must run before {…} so it doesn't eat braces).
+ s = re.sub(r":(\w+)", "{param}", s)
+ # Unify Spring/FastAPI {name} → {param}
+ s = re.sub(r"\{[^}]+\}", "{param}", s)
+ # Unify Next.js [name] → {param}
+ s = re.sub(r"\[[^\]]+\]", "{param}", s)
+ # Unify JS template literal ${expr} → {param}
+ s = re.sub(r"\$\{[^}]+\}", "{param}", s)
+ return s or "/"
+
+
+def extract_path_from_url(url: str) -> str:
+ """Extract just the path portion from a URL, stripping scheme and host."""
+ # If it starts with http:// or https://, strip scheme + authority
+ if "://" in url:
+ after_scheme = url.split("://", 1)[1]
+ slash_idx = after_scheme.find("/")
+ if slash_idx >= 0:
+ return after_scheme[slash_idx:]
+ return "/"
+ return url
+
+
+# A leading base/host placeholder in a consumer URL, e.g. ``${API_BASE}/users``
+# or ``${apiUrl}/v1/users``. The value is unresolved at extraction time, so the
+# only thing we can match on is the concrete suffix. Anchored at the start so
+# interior expressions (real path params like ``/users/${id}``) are untouched.
+_LEADING_BASE_EXPR_RE = re.compile(r"^\s*\$\{[^}]+\}")
+
+
+def strip_leading_base_expr(path: str) -> tuple[str, bool]:
+ """Strip a leading base/host placeholder from a consumer URL path.
+
+ Returns ``(path, stripped)``. ``${API_BASE}/users`` becomes ``/users`` with
+ ``stripped=True``. Treating the placeholder as an ordinary ``{param}`` path
+ segment (which is what :func:`normalize_http_path` would otherwise do)
+ prevents the route from ever lining up with a concrete provider path, so we
+ drop it and let the matcher link on the suffix as a lower-confidence
+ candidate instead.
+ """
+ new_path = _LEADING_BASE_EXPR_RE.sub("", path, count=1)
+ if new_path == path:
+ return path, False
+ if not new_path.startswith("/"):
+ new_path = "/" + new_path
+ return new_path, True
+
+
+def consumer_meta(method: str, norm_path: str, client: str, base_stripped: bool) -> dict:
+ """Build a consumer contract's ``meta`` dict.
+
+ ``base_stripped`` is recorded only when True so the matcher knows the path
+ had an unresolved base prefix removed and should be linked as a candidate
+ rather than an exact match.
+ """
+ meta = {"method": method, "path": norm_path, "client": client}
+ if base_stripped:
+ meta["base_stripped"] = True
+ return meta
diff --git a/packages/core/src/repowise/core/workspace/extractors/http/python_clients.py b/packages/core/src/repowise/core/workspace/extractors/http/python_clients.py
new file mode 100644
index 000000000..196c33d6f
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/http/python_clients.py
@@ -0,0 +1,35 @@
+"""Python HTTP consumer dialect — ``requests`` and ``httpx``."""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING
+
+from ..langs import PYTHON
+from .dialect import METHODS, build_consumer_contract
+
+if TYPE_CHECKING:
+ from repowise.core.workspace.contracts import Contract
+
+ from ..base import ScanContext
+
+# requests.get('http://host/api/users') or httpx.post(...)
+_REQUESTS_RE = re.compile(
+ rf"""(?:requests|httpx)\.({METHODS})\s*\(\s*['"]([^'"]+)['"]""",
+ re.IGNORECASE,
+)
+
+
+class PythonClientsDialect:
+ name = "python-clients"
+ extensions = PYTHON
+
+ def extract(self, ctx: ScanContext) -> list[Contract]:
+ out: list[Contract] = []
+ for m in _REQUESTS_RE.finditer(ctx.content):
+ out.append(
+ build_consumer_contract(
+ ctx, method=m.group(1).upper(), url=m.group(2), client="requests"
+ )
+ )
+ return out
diff --git a/packages/core/src/repowise/core/workspace/extractors/http/spring.py b/packages/core/src/repowise/core/workspace/extractors/http/spring.py
new file mode 100644
index 000000000..71547b8f3
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/http/spring.py
@@ -0,0 +1,55 @@
+"""Spring (Java) HTTP provider dialect.
+
+Handles method-level ``@GetMapping("/users")`` annotations and stitches on the
+nearest preceding class-level ``@RequestMapping("/api/v1")`` prefix.
+"""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING
+
+from ..langs import JAVA
+from .dialect import build_provider_contract, nearest_prefix
+
+if TYPE_CHECKING:
+ from repowise.core.workspace.contracts import Contract
+
+ from ..base import ScanContext
+
+# @GetMapping("/path"), @PostMapping(value="/path"), etc.
+_SPRING_METHOD_RE = re.compile(
+ r"""@(Get|Post|Put|Delete|Patch)Mapping\s*\(\s*(?:value\s*=\s*)?['"]([^'"]+)['"]""",
+ re.IGNORECASE,
+)
+
+# Class-level prefix: @RequestMapping("/api/v1")
+_SPRING_CLASS_RE = re.compile(
+ r"""@RequestMapping\s*\(\s*(?:value\s*=\s*)?['"]([^'"]+)['"]""",
+)
+
+
+class SpringDialect:
+ name = "spring"
+ extensions = JAVA
+
+ def extract(self, ctx: ScanContext) -> list[Contract]:
+ content = ctx.content
+ # Collect every class-level @RequestMapping so each method annotation
+ # gets the prefix from its nearest preceding class declaration rather
+ # than always the first one in the file.
+ class_mappings: list[tuple[int, str]] = [
+ (cm.start(), cm.group(1).rstrip("/")) for cm in _SPRING_CLASS_RE.finditer(content)
+ ]
+
+ out: list[Contract] = []
+ for m in _SPRING_METHOD_RE.finditer(content):
+ method = m.group(1).upper()
+ path_raw = m.group(2)
+ prefix = nearest_prefix(class_mappings, m.start())
+ if prefix:
+ path_raw = prefix + "/" + path_raw.lstrip("/")
+ c = build_provider_contract(ctx, method=method, path_raw=path_raw, framework="spring")
+ if c is not None:
+ out.append(c)
+ return out
diff --git a/packages/core/src/repowise/core/workspace/extractors/http_extractor.py b/packages/core/src/repowise/core/workspace/extractors/http_extractor.py
index f309a775b..4e2ae81ed 100644
--- a/packages/core/src/repowise/core/workspace/extractors/http_extractor.py
+++ b/packages/core/src/repowise/core/workspace/extractors/http_extractor.py
@@ -1,533 +1,12 @@
-"""HTTP route contract extraction.
+"""Backwards-compatible re-exports for the HTTP contract extractor.
-Scans source files for route handler declarations (providers) and HTTP client
-calls (consumers). Patterns cover Express, FastAPI, Spring, Laravel, Go,
-fetch, axios, requests, and httpx.
+The implementation moved into the :mod:`.http` dialect package. This shim keeps
+``from ...extractors.http_extractor import HttpExtractor, normalize_http_path``
+working for existing imports.
"""
from __future__ import annotations
-import logging
-import os
-import re
-from pathlib import Path
-from typing import TYPE_CHECKING
+from .http import HttpExtractor, normalize_http_path
-from repowise.core.ingestion.languages.registry import REGISTRY as _LANG_REGISTRY
-
-if TYPE_CHECKING:
- from repowise.core.workspace.contracts import Contract
-
-_log = logging.getLogger("repowise.workspace.extractors.http")
-
-# ---------------------------------------------------------------------------
-# Constants
-# ---------------------------------------------------------------------------
-
-_BLOCKED_DIRS = frozenset(
- {
- ".git",
- "node_modules",
- "__pycache__",
- ".venv",
- "venv",
- "dist",
- "build",
- "target",
- "vendor",
- ".next",
- ".nuxt",
- ".tox",
- ".mypy_cache",
- ".gradle",
- ".mvn",
- "out",
- "bin",
- }
-)
-
-_MAX_FILE_SIZE = 512 * 1024 # 512 KB
-
-_PROVIDER_EXTENSIONS = _LANG_REGISTRY.extensions_for(
- ["python", "typescript", "javascript", "java", "php", "go", "csharp"]
-)
-
-_CONSUMER_EXTENSIONS = _LANG_REGISTRY.extensions_for(
- ["python", "typescript", "javascript", "csharp"]
-)
-
-_ALL_EXTENSIONS = _PROVIDER_EXTENSIONS | _CONSUMER_EXTENSIONS
-
-
-# ---------------------------------------------------------------------------
-# Path normalization
-# ---------------------------------------------------------------------------
-
-
-def normalize_http_path(path: str) -> str:
- """Normalize an HTTP path for matching.
-
- Steps:
- 1. Strip whitespace
- 2. Remove query string
- 3. Lowercase
- 4. Strip trailing slash (but keep root ``/``)
- 5. Unify param styles: ``:param``, ``{param}``, ``[param]`` → ``{param}``
- """
- s = path.strip().split("?")[0].lower()
- if s != "/":
- s = s.rstrip("/")
- # ASP.NET routes commonly omit the leading slash; add one so all
- # frameworks compare on equal footing.
- if s and not s.startswith("/") and not s.startswith("http"):
- s = "/" + s
- # ASP.NET route constraints: `{id:int}` / `{slug:regex(\d+)}` — strip the
- # ``:type`` portion so the next normalisation step doesn't double-wrap it.
- s = re.sub(r"(\{[a-z_][\w]*):[^}]+(\})", r"\1\2", s)
- # Unify Express :param (must run before {…} so it doesn't eat braces).
- s = re.sub(r":(\w+)", "{param}", s)
- # Unify Spring/FastAPI {name} → {param}
- s = re.sub(r"\{[^}]+\}", "{param}", s)
- # Unify Next.js [name] → {param}
- s = re.sub(r"\[[^\]]+\]", "{param}", s)
- # Unify JS template literal ${expr} → {param}
- s = re.sub(r"\$\{[^}]+\}", "{param}", s)
- return s or "/"
-
-
-# ---------------------------------------------------------------------------
-# Provider patterns
-# ---------------------------------------------------------------------------
-
-# Each pattern: (compiled_regex, method_group_or_none, path_group, framework)
-# method_group is the capture group index for the HTTP method (1-based), or 0
-# if the method is embedded in the regex match differently.
-
-_METHODS = r"get|post|put|delete|patch"
-_METHODS_UPPER = r"GET|POST|PUT|DELETE|PATCH"
-
-# Express / Node.js: router.get('/path', ...) or app.post('/path', ...)
-# Negative lookbehind for @ to avoid matching FastAPI decorators
-_EXPRESS_RE = re.compile(
- rf"""(?<!@)(?:router|app)\.({_METHODS})\s*\(\s*['"]([^'"]+)['"]""",
- re.IGNORECASE,
-)
-
-# FastAPI / Python: @app.get('/path') or @router.post('/path')
-_FASTAPI_RE = re.compile(
- rf"""@(?:app|router)\.({_METHODS})\s*\(\s*['"]([^'"]+)['"]""",
- re.IGNORECASE,
-)
-
-# Spring: @GetMapping("/path"), @PostMapping(value="/path"), etc.
-_SPRING_METHOD_RE = re.compile(
- r"""@(Get|Post|Put|Delete|Patch)Mapping\s*\(\s*(?:value\s*=\s*)?['"]([^'"]+)['"]""",
- re.IGNORECASE,
-)
-
-# Spring class-level prefix: @RequestMapping("/api/v1")
-_SPRING_CLASS_RE = re.compile(
- r"""@RequestMapping\s*\(\s*(?:value\s*=\s*)?['"]([^'"]+)['"]""",
-)
-
-# Laravel: Route::get('/path', ...)
-_LARAVEL_RE = re.compile(
- rf"""Route::({_METHODS})\s*\(\s*['"]([^'"]+)['"]""",
- re.IGNORECASE,
-)
-
-# Go (gin, echo, chi, net/http): r.GET("/path", ...) or .HandleFunc("/path", ...)
-_GO_ROUTE_RE = re.compile(
- rf"""\.({_METHODS_UPPER}|Handle|HandleFunc)\s*\(\s*['"]([^'"]+)['"]""",
-)
-
-# ASP.NET attribute routing: [HttpGet("path")], [HttpPost("path")], etc.
-# The leading bracket may be on its own line, so we anchor on the attribute name.
-_ASPNET_METHOD_RE = re.compile(
- r"""\[\s*Http(Get|Post|Put|Delete|Patch)\s*\(\s*['"]([^'"]+)['"]""",
- re.IGNORECASE,
-)
-
-# Parameterless attribute: [HttpPost] / [HttpGet] — the route is the class
-# prefix only. We capture an empty path that the prefix-stitcher will fill in.
-_ASPNET_BARE_METHOD_RE = re.compile(
- r"""\[\s*Http(Get|Post|Put|Delete|Patch)\s*\]""",
- re.IGNORECASE,
-)
-
-# ASP.NET class-level prefix: [Route("api/users")] above an [ApiController] class.
-_ASPNET_CLASS_ROUTE_RE = re.compile(
- r"""\[\s*Route\s*\(\s*['"]([^'"]+)['"]""",
-)
-
-# ASP.NET minimal API: app.MapGet("/users", ...) — same shape, different method names.
-_ASPNET_MINIMAL_RE = re.compile(
- rf"""\.\s*Map({_METHODS})\s*\(\s*['"]([^'"]+)['"]""",
- re.IGNORECASE,
-)
-
-_PROVIDER_PATTERNS = [
- (_EXPRESS_RE, "express"),
- (_FASTAPI_RE, "fastapi"),
- (_SPRING_METHOD_RE, "spring"),
- (_LARAVEL_RE, "laravel"),
- (_GO_ROUTE_RE, "go"),
- (_ASPNET_METHOD_RE, "aspnet"),
- (_ASPNET_MINIMAL_RE, "aspnet-minimal"),
-]
-
-# ---------------------------------------------------------------------------
-# Consumer patterns
-# ---------------------------------------------------------------------------
-
-# fetch('/api/users') or fetch('/api/users', { method: 'POST' })
-_FETCH_RE = re.compile(
- r"""fetch\s*\(\s*['"`]([^'"`]+)['"`]""",
-)
-_FETCH_METHOD_RE = re.compile(
- r"""fetch\s*\(\s*['"`]([^'"`]+)['"`]\s*,\s*\{[^}]*method\s*:\s*['"](\w+)['"]""",
- re.DOTALL,
-)
-
-# axios.get('/api/users')
-_AXIOS_RE = re.compile(
- rf"""axios\.({_METHODS})\s*\(\s*['"]([^'"]+)['"]""",
- re.IGNORECASE,
-)
-
-# requests.get('http://host/api/users') or httpx.post(...)
-_REQUESTS_RE = re.compile(
- rf"""(?:requests|httpx)\.({_METHODS})\s*\(\s*['"]([^'"]+)['"]""",
- re.IGNORECASE,
-)
-
-# C# HttpClient: client.GetAsync("/api/users") / PostAsync / PutAsync / DeleteAsync
-_HTTPCLIENT_RE = re.compile(
- rf"""\.\s*({_METHODS})Async\s*\(\s*['"]([^'"]+)['"]""",
- re.IGNORECASE,
-)
-
-
-# ---------------------------------------------------------------------------
-# Extractor
-# ---------------------------------------------------------------------------
-
-
-def _extract_path_from_url(url: str) -> str:
- """Extract just the path portion from a URL, stripping scheme and host."""
- # If it starts with http:// or https://, strip scheme + authority
- if "://" in url:
- after_scheme = url.split("://", 1)[1]
- slash_idx = after_scheme.find("/")
- if slash_idx >= 0:
- return after_scheme[slash_idx:]
- return "/"
- return url
-
-
-# A leading base/host placeholder in a consumer URL, e.g. ``${API_BASE}/users``
-# or ``${apiUrl}/v1/users``. The value is unresolved at extraction time, so the
-# only thing we can match on is the concrete suffix. Anchored at the start so
-# interior expressions (real path params like ``/users/${id}``) are untouched.
-_LEADING_BASE_EXPR_RE = re.compile(r"^\s*\$\{[^}]+\}")
-
-
-def _strip_leading_base_expr(path: str) -> tuple[str, bool]:
- """Strip a leading base/host placeholder from a consumer URL path.
-
- Returns ``(path, stripped)``. ``${API_BASE}/users`` becomes ``/users`` with
- ``stripped=True``. Treating the placeholder as an ordinary ``{param}`` path
- segment (which is what :func:`normalize_http_path` would otherwise do)
- prevents the route from ever lining up with a concrete provider path, so we
- drop it and let the matcher link on the suffix as a lower-confidence
- candidate instead.
- """
- new_path = _LEADING_BASE_EXPR_RE.sub("", path, count=1)
- if new_path == path:
- return path, False
- if not new_path.startswith("/"):
- new_path = "/" + new_path
- return new_path, True
-
-
-def _consumer_meta(method: str, norm_path: str, client: str, base_stripped: bool) -> dict:
- """Build a consumer contract's ``meta`` dict.
-
- ``base_stripped`` is recorded only when True so the matcher knows the path
- had an unresolved base prefix removed and should be linked as a candidate
- rather than an exact match.
- """
- meta = {"method": method, "path": norm_path, "client": client}
- if base_stripped:
- meta["base_stripped"] = True
- return meta
-
-
-class HttpExtractor:
- """Extract HTTP route contracts from source files."""
-
- def extract(self, repo_path: Path, repo_alias: str = "") -> list[Contract]:
- """Scan all source files in *repo_path* and return Contract instances."""
- from repowise.core.workspace.contracts import Contract
-
- contracts: list[Contract] = []
- repo_root = repo_path.resolve()
-
- for dirpath, dirnames, filenames in os.walk(repo_root):
- dirnames[:] = [d for d in dirnames if d not in _BLOCKED_DIRS and not d.startswith(".")]
- for fname in filenames:
- fpath = Path(dirpath) / fname
- suffix = fpath.suffix.lower()
- if suffix not in _ALL_EXTENSIONS:
- continue
- try:
- if fpath.stat().st_size > _MAX_FILE_SIZE:
- continue
- except OSError:
- continue
-
- try:
- content = fpath.read_text(encoding="utf-8", errors="replace")
- except OSError:
- continue
-
- rel_path = fpath.relative_to(repo_root).as_posix()
-
- # --- Providers ---
- if suffix in _PROVIDER_EXTENSIONS:
- # Spring: collect all class-level @RequestMapping positions and prefixes
- # so each method-level annotation gets the prefix from the nearest
- # preceding class declaration rather than always the first one in the file.
- spring_class_mappings: list[tuple[int, str]] = []
- if suffix == ".java":
- for cm in _SPRING_CLASS_RE.finditer(content):
- spring_class_mappings.append((cm.start(), cm.group(1).rstrip("/")))
-
- # ASP.NET: same prefix-stitching logic as Spring — [Route("api/users")]
- # above an [ApiController] class anchors the per-method prefixes.
- aspnet_class_mappings: list[tuple[int, str]] = []
- if suffix == ".cs":
- for cm in _ASPNET_CLASS_ROUTE_RE.finditer(content):
- aspnet_class_mappings.append((cm.start(), cm.group(1).rstrip("/")))
-
- for pattern, framework in _PROVIDER_PATTERNS:
- for match in pattern.finditer(content):
- method_raw = match.group(1)
- path_raw = match.group(2)
-
- # Go Handle/HandleFunc don't carry a method
- if method_raw in ("Handle", "HandleFunc"):
- method = "*"
- else:
- method = method_raw.upper()
-
- # Apply Spring class-level prefix: pick the nearest preceding
- # @RequestMapping (highest start position that is still before
- # this match).
- if framework == "spring" and spring_class_mappings:
- match_pos = match.start()
- spring_prefix = ""
- for cls_pos, cls_prefix in spring_class_mappings:
- if cls_pos < match_pos:
- spring_prefix = cls_prefix
- else:
- break
- if spring_prefix:
- path_raw = spring_prefix + "/" + path_raw.lstrip("/")
-
- # Apply ASP.NET class-level prefix using the same nearest-
- # preceding rule. Skipped for the minimal-API pattern since
- # those are not inside controller classes.
- if framework == "aspnet" and aspnet_class_mappings:
- match_pos = match.start()
- cls_prefix = ""
- for pos, prefix in aspnet_class_mappings:
- if pos < match_pos:
- cls_prefix = prefix
- else:
- break
- if cls_prefix:
- path_raw = cls_prefix + "/" + path_raw.lstrip("/")
-
- norm_path = normalize_http_path(path_raw)
-
- # Skip paths that look like template variables or empty
- if not norm_path or norm_path == "/":
- if not path_raw.strip("/"):
- continue
-
- contract_id = f"http::{method}::{norm_path}"
-
- contracts.append(
- Contract(
- repo=repo_alias,
- contract_id=contract_id,
- contract_type="http",
- role="provider",
- file_path=rel_path,
- symbol_name=f"{framework}:{method} {path_raw}",
- confidence=0.85,
- service=None,
- meta={
- "method": method,
- "path": norm_path,
- "framework": framework,
- },
- )
- )
-
- # Bare ASP.NET attributes — `[HttpPost]` with no route arg.
- # The path is whichever class-level [Route("...")] precedes
- # the attribute. If no class route exists, we skip the
- # match — there's no useful path to record.
- if suffix == ".cs" and aspnet_class_mappings:
- for match in _ASPNET_BARE_METHOD_RE.finditer(content):
- method = match.group(1).upper()
- match_pos = match.start()
- cls_prefix = ""
- for pos, prefix in aspnet_class_mappings:
- if pos < match_pos:
- cls_prefix = prefix
- else:
- break
- if not cls_prefix:
- continue
- norm_path = normalize_http_path(cls_prefix)
- contract_id = f"http::{method}::{norm_path}"
- contracts.append(
- Contract(
- repo=repo_alias,
- contract_id=contract_id,
- contract_type="http",
- role="provider",
- file_path=rel_path,
- symbol_name=f"aspnet:{method} {cls_prefix}",
- confidence=0.85,
- service=None,
- meta={
- "method": method,
- "path": norm_path,
- "framework": "aspnet",
- },
- )
- )
-
- # --- Consumers ---
- if suffix in _CONSUMER_EXTENSIONS:
- # fetch() with method
- for match in _FETCH_METHOD_RE.finditer(content):
- url = match.group(1)
- method = match.group(2).upper()
- path = _extract_path_from_url(url)
- path, base_stripped = _strip_leading_base_expr(path)
- norm_path = normalize_http_path(path)
- contract_id = f"http::{method}::{norm_path}"
- contracts.append(
- Contract(
- repo=repo_alias,
- contract_id=contract_id,
- contract_type="http",
- role="consumer",
- file_path=rel_path,
- symbol_name=f"fetch:{method} {url}",
- confidence=0.75,
- service=None,
- meta=_consumer_meta(method, norm_path, "fetch", base_stripped),
- )
- )
-
- # fetch() without explicit method → GET (but skip if already matched with method)
- fetch_method_urls = {m.group(1) for m in _FETCH_METHOD_RE.finditer(content)}
- for match in _FETCH_RE.finditer(content):
- url = match.group(1)
- if url in fetch_method_urls:
- continue
- path = _extract_path_from_url(url)
- path, base_stripped = _strip_leading_base_expr(path)
- norm_path = normalize_http_path(path)
- contract_id = f"http::GET::{norm_path}"
- contracts.append(
- Contract(
- repo=repo_alias,
- contract_id=contract_id,
- contract_type="http",
- role="consumer",
- file_path=rel_path,
- symbol_name=f"fetch:GET {url}",
- confidence=0.75,
- service=None,
- meta=_consumer_meta("GET", norm_path, "fetch", base_stripped),
- )
- )
-
- # axios
- for match in _AXIOS_RE.finditer(content):
- method = match.group(1).upper()
- url = match.group(2)
- path = _extract_path_from_url(url)
- path, base_stripped = _strip_leading_base_expr(path)
- norm_path = normalize_http_path(path)
- contract_id = f"http::{method}::{norm_path}"
- contracts.append(
- Contract(
- repo=repo_alias,
- contract_id=contract_id,
- contract_type="http",
- role="consumer",
- file_path=rel_path,
- symbol_name=f"axios:{method} {url}",
- confidence=0.75,
- service=None,
- meta=_consumer_meta(method, norm_path, "axios", base_stripped),
- )
- )
-
- # C# HttpClient (only run on .cs files to avoid false matches
- # against non-HTTP `*Async` methods like `WriteAsync`).
- if suffix == ".cs":
- for match in _HTTPCLIENT_RE.finditer(content):
- method = match.group(1).upper()
- url = match.group(2)
- if "/" not in url:
- continue # Avoid matching non-URL strings.
- path = _extract_path_from_url(url)
- path, base_stripped = _strip_leading_base_expr(path)
- norm_path = normalize_http_path(path)
- contract_id = f"http::{method}::{norm_path}"
- contracts.append(
- Contract(
- repo=repo_alias,
- contract_id=contract_id,
- contract_type="http",
- role="consumer",
- file_path=rel_path,
- symbol_name=f"httpclient:{method} {url}",
- confidence=0.70,
- service=None,
- meta=_consumer_meta(method, norm_path, "httpclient", base_stripped),
- )
- )
-
- # requests / httpx
- for match in _REQUESTS_RE.finditer(content):
- method = match.group(1).upper()
- url = match.group(2)
- path = _extract_path_from_url(url)
- path, base_stripped = _strip_leading_base_expr(path)
- norm_path = normalize_http_path(path)
- contract_id = f"http::{method}::{norm_path}"
- contracts.append(
- Contract(
- repo=repo_alias,
- contract_id=contract_id,
- contract_type="http",
- role="consumer",
- file_path=rel_path,
- symbol_name=f"requests:{method} {url}",
- confidence=0.75,
- service=None,
- meta=_consumer_meta(method, norm_path, "requests", base_stripped),
- )
- )
-
- return contracts
+__all__ = ["HttpExtractor", "normalize_http_path"]
diff --git a/packages/core/src/repowise/core/workspace/extractors/langs.py b/packages/core/src/repowise/core/workspace/extractors/langs.py
new file mode 100644
index 000000000..fb42851e3
--- /dev/null
+++ b/packages/core/src/repowise/core/workspace/extractors/langs.py
@@ -0,0 +1,19 @@
+"""Named file-extension sets, resolved once from the language registry.
+
+Dialects declare the languages they target by importing these constants instead
+of re-deriving extension lists, so the language → extension mapping stays in the
+registry and a dialect file reads as "this recogniser is for Rust" at a glance.
+"""
+
+from __future__ import annotations
+
+from repowise.core.ingestion.languages.registry import REGISTRY as _REGISTRY
+
+JS_TS = _REGISTRY.extensions_for(["javascript", "typescript"])
+PYTHON = _REGISTRY.extensions_for(["python"])
+JAVA = _REGISTRY.extensions_for(["java"])
+PHP = _REGISTRY.extensions_for(["php"])
+GO = _REGISTRY.extensions_for(["go"])
+CSHARP = _REGISTRY.extensions_for(["csharp"])
+RUST = _REGISTRY.extensions_for(["rust"])
+PROTO = _REGISTRY.extensions_for(["proto"])