/** * Architecture Intelligence — P4-T4 (D4) * * Pure functions that derive architectural signal from the file-import graph * and symbol definitions: packages, entry points, routes, hotspots, and layers. * Pairs with `communities.ts` (community detection) and is consumed by * `getProjectMap` to enrich the project-map response (additive — never mutates * existing fields). * * Heuristics ported (rewritten fresh) from codebase-memory-mcp's * `get_architecture` aspects, adapted to th0th's symbol_imports / symbol_references * model instead of a labeled property graph. */ import type { Community } from "./communities.js"; export interface PackageInfo { /** Common root directory or package marker label. */ name: string; /** File paths belonging to this package. */ files: string[]; fileCount: number; /** Distinct packages this one imports (fan-out). */ fanOut: number; /** Distinct packages importing this one (fan-in). */ fanIn: number; } export interface EntryPoint { file: string; /** In-degree (number of distinct internal importers). */ inDegree: number; /** Out-degree (number of distinct internal imports this file makes). */ outDegree: number; /** Why this file was flagged as an entry-point candidate. */ reason: string; } export interface RouteInfo { /** Route path string (from http_call edge metadata or definition name). */ path: string; /** HTTP method when known. */ method?: string; /** File where the route/HTTP call originates. */ file?: string; /** Symbol name or target FQN bound to the route. */ handler?: string; } export interface HotspotInfo { file: string; /** Centrality (PageRank) score when available, else undefined. */ centrality?: number; /** In-degree (number of distinct internal importers). */ inDegree: number; /** Symbol count in the file when available. */ symbolCount?: number; } export interface LayerInfo { /** Layer label: entry | api | core | service | leaf | unknown. */ layer: "entry" | "api" | "core" | "service" | "leaf" | "unknown"; /** Common-path-prefix or community label identifying the layer. */ name: string; fileCount: number; /** One-line rationale. */ reason: string; } export interface CommunityInfo { /** Stable community id. */ id: number; /** Representative label (common path prefix or most-central file). */ label: string; /** Number of files in the community. */ size: number; /** Internal / (internal + boundary) edge-weight ratio (0..1). */ cohesion: number; /** Top files by degree within the community (≤5). */ topFiles: string[]; } export interface ArchitectureMap { packages: PackageInfo[]; entryPoints: EntryPoint[]; routes: RouteInfo[]; hotspots: HotspotInfo[]; communities: CommunityInfo[]; layers: LayerInfo[]; } /** Internal import edge between two files (both endpoints known, non-external). */ export interface InternalImport { fromFile: string; toFile: string; } export interface SymbolDefLite { filePath: string; name: string; kind: string; exported?: boolean; } export interface HttpEdgeLite { fromFile?: string; symbolName?: string; targetFqn?: string; method?: string; route?: string; } interface GraphView { /** All files (nodes). */ files: string[]; /** Internal import edges (non-external, both endpoints known). */ edges: InternalImport[]; /** File index for O(1) lookup. */ fileIndex: Map; /** In-degree per file (distinct importers). */ inDegree: Int32Array; /** Out-degree per file (distinct imports). */ outDegree: Int32Array; /** File → set of distinct imported files. */ outAdj: Map>; /** File → set of distinct importers. */ inAdj: Map>; } export declare function detectPackages(files: string[], gv: GraphView, opts?: { maxPackages?: number; minFiles?: number; }): PackageInfo[]; export declare function detectEntryPoints(gv: GraphView, opts?: { maxResults?: number; minInDegree?: number; }): EntryPoint[]; export declare function detectRoutes(httpEdges: HttpEdgeLite[], defs: SymbolDefLite[], opts?: { maxResults?: number; }): RouteInfo[]; /** * Most-depended-on files. Combines PageRank centrality (when available) with * in-degree (number of distinct importers) and per-file symbol counts. */ export declare function detectHotspots(gv: GraphView, opts?: { centrality?: Map; symbolCounts?: Map; maxResults?: number; }): HotspotInfo[]; /** * Convert raw community memberships (node indices) into labeled clusters over * file paths. Each community gets a representative label (common path prefix * when one exists, else the most-central/most-connected file), a size, a * cohesion metric, and its top files. */ export declare function labelCommunities(files: string[], gv: GraphView, communities: Community[], opts?: { maxResults?: number; minSize?: number; maxTopFiles?: number; }): CommunityInfo[]; /** * Classify communities/files into de-facto layers using fan-in/fan-out signals: * - entry: imported by others, imports little (bootstrap / public surface) * - api: contains routes / http_call edges * - core: high fan-in, moderate fan-out (foundation modules) * - leaf: high fan-out, low fan-in (terminals: handlers, scripts) * - service: default for mid-coupling groups */ export declare function classifyLayers(communities: CommunityInfo[], gv: GraphView, routes: RouteInfo[]): LayerInfo[]; export interface ArchitectureInput { files: string[]; internalEdges: InternalImport[]; definitions: SymbolDefLite[]; httpEdges: HttpEdgeLite[]; centrality?: Map; symbolCounts?: Map; communities?: Community[]; } export interface ArchitectureOptions { /** Whether to compute communities (skip to save cost when undesired). */ withCommunities?: boolean; } /** * Compute the full architecture map. Pure: no DB, no I/O. */ export declare function computeArchitectureMap(input: ArchitectureInput, _opts?: ArchitectureOptions): ArchitectureMap; export {}; //# sourceMappingURL=architecture.d.ts.map