diff --git a/CLAUDE.md b/CLAUDE.md index bafb0d8b..efef122f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -38,47 +38,57 @@ npm run release:dry-run # Preview what release would do without writing JS source is plain JavaScript (ES modules) in `src/`. No transpilation step. The Rust native engine lives in `crates/codegraph-core/`. -| File | Role | +| Path | Role | |------|------| | `cli.js` | Commander CLI entry point (`bin.codegraph`) | | `index.js` | Programmatic API exports | -| `builder.js` | Graph building: file collection, parsing, import resolution, incremental hashing | | `parser.js` | tree-sitter WASM wrapper; `LANGUAGE_REGISTRY` + per-language extractors for functions, classes, methods, imports, exports, call sites | -| `queries.js` | Query functions: symbol search, file deps, impact analysis, diff-impact; `SYMBOL_KINDS` constant defines all node kinds | -| `embeddings/` | Embedding subsystem: model management, vector generation, semantic/keyword/hybrid search, CLI formatting | -| `db.js` | SQLite schema and operations (`better-sqlite3`) | -| `mcp.js` | MCP server exposing graph queries to AI agents; single-repo by default, `--multi-repo` to enable cross-repo access | -| `graph/` | Unified graph model: `CodeGraph` class (`model.js`), algorithms (Tarjan SCC, Louvain, BFS, shortest path, centrality), classifiers (role, risk), builders (dependency, structure, temporal) | -| `cycles.js` | Circular dependency detection (delegates to `graph/` subsystem) | -| `export.js` | Graph export orchestration: loads data from DB, delegates to `presentation/export.js` serializers | -| `presentation/` | Pure output formatting: `viewer.js` (HTML renderer), `export.js` (DOT/Mermaid/GraphML/Neo4j serializers), `sequence-renderer.js` (Mermaid sequence diagrams), `table.js` (CLI table formatting), `result-formatter.js` (JSON/NDJSON output) | -| `watcher.js` | Watch mode for incremental rebuilds | | `config.js` | `.codegraphrc.json` loading, env overrides, `apiKeyCommand` secret resolution | | `constants.js` | `EXTENSIONS` (derived from parser registry) and `IGNORE_DIRS` constants | | `native.js` | Native napi-rs addon loader with WASM fallback | | `registry.js` | Global repo registry (`~/.codegraph/registry.json`) for multi-repo MCP | -| `resolve.js` | Import resolution (supports native batch mode) | -| `ast-analysis/` | Unified AST analysis framework: shared DFS walker (`visitor.js`), engine orchestrator (`engine.js`), extracted metrics (`metrics.js`), and pluggable visitors for complexity, dataflow, and AST-store | -| `complexity.js` | Cognitive, cyclomatic, Halstead, MI computation from AST; `complexity` CLI command | -| `communities.js` | Louvain community detection, drift analysis (delegates to `graph/` subsystem) | -| `manifesto.js` | Configurable rule engine with warn/fail thresholds; CI gate | -| `audit.js` | Composite audit command: explain + impact + health in one call | -| `batch.js` | Batch querying for multi-agent dispatch | -| `triage.js` | Risk-ranked audit priority queue (delegates scoring to `graph/classifiers/`) | -| `check.js` | CI validation predicates (cycles, complexity, blast radius, boundaries) | -| `boundaries.js` | Architecture boundary rules with onion architecture preset | -| `owners.js` | CODEOWNERS integration for ownership queries | -| `snapshot.js` | SQLite DB backup and restore | -| `sequence.js` | Sequence diagram data generation (BFS traversal); Mermaid rendering delegated to `presentation/sequence-renderer.js` | | `paginate.js` | Pagination helpers for bounded query results | | `logger.js` | Structured logging (`warn`, `debug`, `info`, `error`) | +| **`db/`** | **Database layer** | +| `db/index.js` | SQLite schema and operations (`better-sqlite3`) | +| **`domain/`** | **Core domain logic** | +| `domain/queries.js` | Query functions: symbol search, file deps, impact analysis, diff-impact; `SYMBOL_KINDS` constant defines all node kinds | +| `domain/graph/builder.js` | Graph building: file collection, parsing, import resolution, incremental hashing | +| `domain/graph/cycles.js` | Circular dependency detection (delegates to `graph/` subsystem) | +| `domain/graph/resolve.js` | Import resolution (supports native batch mode) | +| `domain/graph/watcher.js` | Watch mode for incremental rebuilds | +| `domain/analysis/` | Query-layer analysis: context, dependencies, exports, impact, module-map, roles, symbol-lookup | +| `domain/search/` | Embedding subsystem: model management, vector generation, semantic/keyword/hybrid search, CLI formatting | +| **`features/`** | **Composable feature modules** | +| `features/audit.js` | Composite audit command: explain + impact + health in one call | +| `features/batch.js` | Batch querying for multi-agent dispatch | +| `features/boundaries.js` | Architecture boundary rules with onion architecture preset | +| `features/cfg.js` | Control-flow graph generation | +| `features/check.js` | CI validation predicates (cycles, complexity, blast radius, boundaries) | +| `features/communities.js` | Louvain community detection, drift analysis (delegates to `graph/` subsystem) | +| `features/complexity.js` | Cognitive, cyclomatic, Halstead, MI computation from AST | +| `features/dataflow.js` | Dataflow analysis | +| `features/export.js` | Graph export orchestration: loads data from DB, delegates to `presentation/` serializers | +| `features/manifesto.js` | Configurable rule engine with warn/fail thresholds; CI gate | +| `features/owners.js` | CODEOWNERS integration for ownership queries | +| `features/sequence.js` | Sequence diagram data generation (BFS traversal) | +| `features/snapshot.js` | SQLite DB backup and restore | +| `features/structure.js` | Codebase structure analysis | +| `features/triage.js` | Risk-ranked audit priority queue (delegates scoring to `graph/classifiers/`) | +| **`presentation/`** | **Pure output formatting** | +| `presentation/` | `viewer.js` (HTML renderer), `export.js` (DOT/Mermaid/GraphML/Neo4j serializers), `sequence-renderer.js` (Mermaid sequence diagrams), `table.js` (CLI table formatting), `result-formatter.js` (JSON/NDJSON output) | +| **`graph/`** | **Unified graph model** | +| `graph/` | `CodeGraph` class (`model.js`), algorithms (Tarjan SCC, Louvain, BFS, shortest path, centrality), classifiers (role, risk), builders (dependency, structure, temporal) | +| **`mcp/`** | **MCP server** | +| `mcp/` | MCP server exposing graph queries to AI agents; single-repo by default, `--multi-repo` to enable cross-repo access | +| `ast-analysis/` | Unified AST analysis framework: shared DFS walker (`visitor.js`), engine orchestrator (`engine.js`), extracted metrics (`metrics.js`), and pluggable visitors for complexity, dataflow, and AST-store | **Key design decisions:** - **Dual-engine architecture:** Native Rust parsing via napi-rs (`crates/codegraph-core/`) with automatic fallback to WASM. Controlled by `--engine native|wasm|auto` (default: `auto`) - Platform-specific prebuilt binaries published as optional npm packages (`@optave/codegraph-{platform}-{arch}`) - WASM grammars are built from devDeps on `npm install` (via `prepare` script) and not committed to git — used as fallback when native addon is unavailable - **Language parser registry:** `LANGUAGE_REGISTRY` in `parser.js` is the single source of truth for all supported languages — maps each language to `{ id, extensions, grammarFile, extractor, required }`. `EXTENSIONS` in `constants.js` is derived from the registry. Adding a new language requires one registry entry + extractor function -- **Node kinds:** `SYMBOL_KINDS` in `queries.js` lists all valid kinds: `function`, `method`, `class`, `interface`, `type`, `struct`, `enum`, `trait`, `record`, `module`. Language-specific types use their native kind (e.g. Go structs → `struct`, Rust traits → `trait`, Ruby modules → `module`) rather than mapping everything to `class`/`interface` +- **Node kinds:** `SYMBOL_KINDS` in `domain/queries.js` lists all valid kinds: `function`, `method`, `class`, `interface`, `type`, `struct`, `enum`, `trait`, `record`, `module`. Language-specific types use their native kind (e.g. Go structs → `struct`, Rust traits → `trait`, Ruby modules → `module`) rather than mapping everything to `class`/`interface` - `@huggingface/transformers` and `@modelcontextprotocol/sdk` are optional dependencies, lazy-loaded - Non-required parsers (all except JS/TS/TSX) fail gracefully if their WASM grammar is unavailable - Import resolution uses a 6-level priority system with confidence scoring (import-aware → same-file → directory → parent → global → method hierarchy) diff --git a/src/ast-analysis/engine.js b/src/ast-analysis/engine.js index e45e1eb8..3998e313 100644 --- a/src/ast-analysis/engine.js +++ b/src/ast-analysis/engine.js @@ -17,7 +17,7 @@ import path from 'node:path'; import { performance } from 'node:perf_hooks'; -import { bulkNodeIdsByFile } from '../db.js'; +import { bulkNodeIdsByFile } from '../db/index.js'; import { debug } from '../logger.js'; import { computeLOCMetrics, computeMaintainabilityIndex } from './metrics.js'; import { diff --git a/src/cli/commands/audit.js b/src/cli/commands/audit.js index 8a3de7cf..caa0b747 100644 --- a/src/cli/commands/audit.js +++ b/src/cli/commands/audit.js @@ -1,6 +1,6 @@ import { audit } from '../../commands/audit.js'; -import { EVERY_SYMBOL_KIND } from '../../queries.js'; -import { explain } from '../../queries-cli.js'; +import { EVERY_SYMBOL_KIND } from '../../domain/queries.js'; +import { explain } from '../../presentation/queries-cli.js'; export const command = { name: 'audit ', diff --git a/src/cli/commands/batch.js b/src/cli/commands/batch.js index 7637b5fb..8ba4f99c 100644 --- a/src/cli/commands/batch.js +++ b/src/cli/commands/batch.js @@ -1,8 +1,8 @@ import fs from 'node:fs'; -import { BATCH_COMMANDS, multiBatchData, splitTargets } from '../../batch.js'; import { batch } from '../../commands/batch.js'; +import { EVERY_SYMBOL_KIND } from '../../domain/queries.js'; import { ConfigError } from '../../errors.js'; -import { EVERY_SYMBOL_KIND } from '../../queries.js'; +import { BATCH_COMMANDS, multiBatchData, splitTargets } from '../../features/batch.js'; export const command = { name: 'batch [targets...]', diff --git a/src/cli/commands/build.js b/src/cli/commands/build.js index 614d7098..f913945d 100644 --- a/src/cli/commands/build.js +++ b/src/cli/commands/build.js @@ -1,5 +1,5 @@ import path from 'node:path'; -import { buildGraph } from '../../builder.js'; +import { buildGraph } from '../../domain/graph/builder.js'; export const command = { name: 'build [dir]', diff --git a/src/cli/commands/cfg.js b/src/cli/commands/cfg.js index a6034e2e..20ef05bb 100644 --- a/src/cli/commands/cfg.js +++ b/src/cli/commands/cfg.js @@ -1,4 +1,4 @@ -import { EVERY_SYMBOL_KIND } from '../../queries.js'; +import { EVERY_SYMBOL_KIND } from '../../domain/queries.js'; export const command = { name: 'cfg ', diff --git a/src/cli/commands/check.js b/src/cli/commands/check.js index 78edb0b9..43d98a3a 100644 --- a/src/cli/commands/check.js +++ b/src/cli/commands/check.js @@ -1,5 +1,5 @@ +import { EVERY_SYMBOL_KIND } from '../../domain/queries.js'; import { ConfigError } from '../../errors.js'; -import { EVERY_SYMBOL_KIND } from '../../queries.js'; export const command = { name: 'check [ref]', diff --git a/src/cli/commands/children.js b/src/cli/commands/children.js index 909c13d4..3412dcf4 100644 --- a/src/cli/commands/children.js +++ b/src/cli/commands/children.js @@ -1,5 +1,5 @@ -import { EVERY_SYMBOL_KIND } from '../../queries.js'; -import { children } from '../../queries-cli.js'; +import { EVERY_SYMBOL_KIND } from '../../domain/queries.js'; +import { children } from '../../presentation/queries-cli.js'; export const command = { name: 'children ', diff --git a/src/cli/commands/complexity.js b/src/cli/commands/complexity.js index 5211b197..193271d3 100644 --- a/src/cli/commands/complexity.js +++ b/src/cli/commands/complexity.js @@ -1,4 +1,4 @@ -import { EVERY_SYMBOL_KIND } from '../../queries.js'; +import { EVERY_SYMBOL_KIND } from '../../domain/queries.js'; export const command = { name: 'complexity [target]', diff --git a/src/cli/commands/context.js b/src/cli/commands/context.js index d2bbec9e..7a4e53da 100644 --- a/src/cli/commands/context.js +++ b/src/cli/commands/context.js @@ -1,5 +1,5 @@ -import { EVERY_SYMBOL_KIND } from '../../queries.js'; -import { context } from '../../queries-cli.js'; +import { EVERY_SYMBOL_KIND } from '../../domain/queries.js'; +import { context } from '../../presentation/queries-cli.js'; export const command = { name: 'context ', diff --git a/src/cli/commands/cycles.js b/src/cli/commands/cycles.js index e5f09dc4..614473af 100644 --- a/src/cli/commands/cycles.js +++ b/src/cli/commands/cycles.js @@ -1,5 +1,5 @@ -import { findCycles, formatCycles } from '../../cycles.js'; -import { openReadonlyOrFail } from '../../db.js'; +import { openReadonlyOrFail } from '../../db/index.js'; +import { findCycles, formatCycles } from '../../domain/graph/cycles.js'; export const command = { name: 'cycles', diff --git a/src/cli/commands/dataflow.js b/src/cli/commands/dataflow.js index 2c6b57a9..4118b5b3 100644 --- a/src/cli/commands/dataflow.js +++ b/src/cli/commands/dataflow.js @@ -1,4 +1,4 @@ -import { EVERY_SYMBOL_KIND } from '../../queries.js'; +import { EVERY_SYMBOL_KIND } from '../../domain/queries.js'; export const command = { name: 'dataflow ', diff --git a/src/cli/commands/deps.js b/src/cli/commands/deps.js index 872f2888..a7644eff 100644 --- a/src/cli/commands/deps.js +++ b/src/cli/commands/deps.js @@ -1,4 +1,4 @@ -import { fileDeps } from '../../queries-cli.js'; +import { fileDeps } from '../../presentation/queries-cli.js'; export const command = { name: 'deps ', diff --git a/src/cli/commands/diff-impact.js b/src/cli/commands/diff-impact.js index cf15f599..15fd67c9 100644 --- a/src/cli/commands/diff-impact.js +++ b/src/cli/commands/diff-impact.js @@ -1,4 +1,4 @@ -import { diffImpact } from '../../queries-cli.js'; +import { diffImpact } from '../../presentation/queries-cli.js'; export const command = { name: 'diff-impact [ref]', diff --git a/src/cli/commands/embed.js b/src/cli/commands/embed.js index 075520cd..c6bfb363 100644 --- a/src/cli/commands/embed.js +++ b/src/cli/commands/embed.js @@ -1,5 +1,5 @@ import path from 'node:path'; -import { buildEmbeddings, DEFAULT_MODEL, EMBEDDING_STRATEGIES } from '../../embeddings/index.js'; +import { buildEmbeddings, DEFAULT_MODEL, EMBEDDING_STRATEGIES } from '../../domain/search/index.js'; export const command = { name: 'embed [dir]', diff --git a/src/cli/commands/export.js b/src/cli/commands/export.js index 7bca538c..fd69c51a 100644 --- a/src/cli/commands/export.js +++ b/src/cli/commands/export.js @@ -1,5 +1,5 @@ import fs from 'node:fs'; -import { openReadonlyOrFail } from '../../db.js'; +import { openReadonlyOrFail } from '../../db/index.js'; import { exportDOT, exportGraphML, @@ -7,7 +7,7 @@ import { exportJSON, exportMermaid, exportNeo4jCSV, -} from '../../export.js'; +} from '../../features/export.js'; export const command = { name: 'export', diff --git a/src/cli/commands/exports.js b/src/cli/commands/exports.js index a94c1c9f..2334f1ba 100644 --- a/src/cli/commands/exports.js +++ b/src/cli/commands/exports.js @@ -1,4 +1,4 @@ -import { fileExports } from '../../queries-cli.js'; +import { fileExports } from '../../presentation/queries-cli.js'; export const command = { name: 'exports ', diff --git a/src/cli/commands/flow.js b/src/cli/commands/flow.js index 13332c23..20814a3c 100644 --- a/src/cli/commands/flow.js +++ b/src/cli/commands/flow.js @@ -1,4 +1,4 @@ -import { EVERY_SYMBOL_KIND } from '../../queries.js'; +import { EVERY_SYMBOL_KIND } from '../../domain/queries.js'; export const command = { name: 'flow [name]', diff --git a/src/cli/commands/fn-impact.js b/src/cli/commands/fn-impact.js index 50a8fbbe..5c64831f 100644 --- a/src/cli/commands/fn-impact.js +++ b/src/cli/commands/fn-impact.js @@ -1,5 +1,5 @@ -import { EVERY_SYMBOL_KIND } from '../../queries.js'; -import { fnImpact } from '../../queries-cli.js'; +import { EVERY_SYMBOL_KIND } from '../../domain/queries.js'; +import { fnImpact } from '../../presentation/queries-cli.js'; export const command = { name: 'fn-impact ', diff --git a/src/cli/commands/impact.js b/src/cli/commands/impact.js index a20e199e..fa4c5585 100644 --- a/src/cli/commands/impact.js +++ b/src/cli/commands/impact.js @@ -1,4 +1,4 @@ -import { impactAnalysis } from '../../queries-cli.js'; +import { impactAnalysis } from '../../presentation/queries-cli.js'; export const command = { name: 'impact ', diff --git a/src/cli/commands/map.js b/src/cli/commands/map.js index ae5d8bff..370d2c25 100644 --- a/src/cli/commands/map.js +++ b/src/cli/commands/map.js @@ -1,4 +1,4 @@ -import { moduleMap } from '../../queries-cli.js'; +import { moduleMap } from '../../presentation/queries-cli.js'; export const command = { name: 'map', diff --git a/src/cli/commands/models.js b/src/cli/commands/models.js index 0763650a..3ae9fc0f 100644 --- a/src/cli/commands/models.js +++ b/src/cli/commands/models.js @@ -1,4 +1,4 @@ -import { DEFAULT_MODEL, MODELS } from '../../embeddings/index.js'; +import { DEFAULT_MODEL, MODELS } from '../../domain/search/index.js'; export const command = { name: 'models', diff --git a/src/cli/commands/path.js b/src/cli/commands/path.js index 44a20d14..34f53248 100644 --- a/src/cli/commands/path.js +++ b/src/cli/commands/path.js @@ -1,5 +1,5 @@ -import { EVERY_SYMBOL_KIND } from '../../queries.js'; -import { symbolPath } from '../../queries-cli.js'; +import { EVERY_SYMBOL_KIND } from '../../domain/queries.js'; +import { symbolPath } from '../../presentation/queries-cli.js'; export const command = { name: 'path ', diff --git a/src/cli/commands/plot.js b/src/cli/commands/plot.js index 9bc5925b..8dafe532 100644 --- a/src/cli/commands/plot.js +++ b/src/cli/commands/plot.js @@ -1,6 +1,6 @@ import fs from 'node:fs'; import path from 'node:path'; -import { openReadonlyOrFail } from '../../db.js'; +import { openReadonlyOrFail } from '../../db/index.js'; export const command = { name: 'plot', diff --git a/src/cli/commands/query.js b/src/cli/commands/query.js index 2c4ee642..ac758116 100644 --- a/src/cli/commands/query.js +++ b/src/cli/commands/query.js @@ -1,5 +1,5 @@ -import { EVERY_SYMBOL_KIND } from '../../queries.js'; -import { fnDeps, symbolPath } from '../../queries-cli.js'; +import { EVERY_SYMBOL_KIND } from '../../domain/queries.js'; +import { fnDeps, symbolPath } from '../../presentation/queries-cli.js'; export const command = { name: 'query ', diff --git a/src/cli/commands/roles.js b/src/cli/commands/roles.js index 225c17bf..0380bee4 100644 --- a/src/cli/commands/roles.js +++ b/src/cli/commands/roles.js @@ -1,5 +1,5 @@ -import { VALID_ROLES } from '../../queries.js'; -import { roles } from '../../queries-cli.js'; +import { VALID_ROLES } from '../../domain/queries.js'; +import { roles } from '../../presentation/queries-cli.js'; export const command = { name: 'roles', diff --git a/src/cli/commands/search.js b/src/cli/commands/search.js index 238b59a0..e8670691 100644 --- a/src/cli/commands/search.js +++ b/src/cli/commands/search.js @@ -1,4 +1,4 @@ -import { search } from '../../embeddings/index.js'; +import { search } from '../../domain/search/index.js'; export const command = { name: 'search ', diff --git a/src/cli/commands/sequence.js b/src/cli/commands/sequence.js index a07f784b..343a9fac 100644 --- a/src/cli/commands/sequence.js +++ b/src/cli/commands/sequence.js @@ -1,4 +1,4 @@ -import { EVERY_SYMBOL_KIND } from '../../queries.js'; +import { EVERY_SYMBOL_KIND } from '../../domain/queries.js'; export const command = { name: 'sequence ', diff --git a/src/cli/commands/snapshot.js b/src/cli/commands/snapshot.js index 8dd0093e..666f0f47 100644 --- a/src/cli/commands/snapshot.js +++ b/src/cli/commands/snapshot.js @@ -1,4 +1,9 @@ -import { snapshotDelete, snapshotList, snapshotRestore, snapshotSave } from '../../snapshot.js'; +import { + snapshotDelete, + snapshotList, + snapshotRestore, + snapshotSave, +} from '../../features/snapshot.js'; export const command = { name: 'snapshot', diff --git a/src/cli/commands/stats.js b/src/cli/commands/stats.js index c0f6e2de..e9b4e9fa 100644 --- a/src/cli/commands/stats.js +++ b/src/cli/commands/stats.js @@ -1,4 +1,4 @@ -import { stats } from '../../queries-cli.js'; +import { stats } from '../../presentation/queries-cli.js'; export const command = { name: 'stats', diff --git a/src/cli/commands/triage.js b/src/cli/commands/triage.js index a334475f..851df8e9 100644 --- a/src/cli/commands/triage.js +++ b/src/cli/commands/triage.js @@ -1,5 +1,5 @@ +import { EVERY_SYMBOL_KIND, VALID_ROLES } from '../../domain/queries.js'; import { ConfigError } from '../../errors.js'; -import { EVERY_SYMBOL_KIND, VALID_ROLES } from '../../queries.js'; export const command = { name: 'triage', diff --git a/src/cli/commands/watch.js b/src/cli/commands/watch.js index 78858158..8e55e2fc 100644 --- a/src/cli/commands/watch.js +++ b/src/cli/commands/watch.js @@ -1,5 +1,5 @@ import path from 'node:path'; -import { watchProject } from '../../watcher.js'; +import { watchProject } from '../../domain/graph/watcher.js'; export const command = { name: 'watch [dir]', diff --git a/src/cli/commands/where.js b/src/cli/commands/where.js index 382c1f21..9f0d37a9 100644 --- a/src/cli/commands/where.js +++ b/src/cli/commands/where.js @@ -1,4 +1,4 @@ -import { where } from '../../queries-cli.js'; +import { where } from '../../presentation/queries-cli.js'; export const command = { name: 'where [name]', diff --git a/src/commands/audit.js b/src/commands/audit.js index 6cfeb3d7..13e4d488 100644 --- a/src/commands/audit.js +++ b/src/commands/audit.js @@ -1,6 +1,6 @@ -import { auditData } from '../audit.js'; +import { kindIcon } from '../domain/queries.js'; +import { auditData } from '../features/audit.js'; import { outputResult } from '../infrastructure/result-formatter.js'; -import { kindIcon } from '../queries.js'; /** * CLI formatter for the audit command. diff --git a/src/commands/batch.js b/src/commands/batch.js index 60fdd3c1..bec40cf9 100644 --- a/src/commands/batch.js +++ b/src/commands/batch.js @@ -1,4 +1,4 @@ -import { batchData, multiBatchData } from '../batch.js'; +import { batchData, multiBatchData } from '../features/batch.js'; /** * CLI wrapper — calls batchData and prints JSON to stdout. diff --git a/src/commands/branch-compare.js b/src/commands/branch-compare.js index aa1f2ef7..c90394fb 100644 --- a/src/commands/branch-compare.js +++ b/src/commands/branch-compare.js @@ -1,6 +1,6 @@ -import { branchCompareData, branchCompareMermaid } from '../branch-compare.js'; +import { kindIcon } from '../domain/queries.js'; +import { branchCompareData, branchCompareMermaid } from '../features/branch-compare.js'; import { outputResult } from '../infrastructure/result-formatter.js'; -import { kindIcon } from '../queries.js'; // ─── Text Formatting ──────────────────────────────────────────────────── diff --git a/src/commands/cfg.js b/src/commands/cfg.js index c0f6c13b..97b1e414 100644 --- a/src/commands/cfg.js +++ b/src/commands/cfg.js @@ -1,4 +1,4 @@ -import { cfgData, cfgToDOT, cfgToMermaid } from '../cfg.js'; +import { cfgData, cfgToDOT, cfgToMermaid } from '../features/cfg.js'; import { outputResult } from '../infrastructure/result-formatter.js'; /** diff --git a/src/commands/check.js b/src/commands/check.js index 114b09f6..eb592fe0 100644 --- a/src/commands/check.js +++ b/src/commands/check.js @@ -1,5 +1,5 @@ -import { checkData } from '../check.js'; import { AnalysisError } from '../errors.js'; +import { checkData } from '../features/check.js'; import { outputResult } from '../infrastructure/result-formatter.js'; /** diff --git a/src/commands/communities.js b/src/commands/communities.js index db21afba..ae1e8fb7 100644 --- a/src/commands/communities.js +++ b/src/commands/communities.js @@ -1,4 +1,4 @@ -import { communitiesData } from '../communities.js'; +import { communitiesData } from '../features/communities.js'; import { outputResult } from '../infrastructure/result-formatter.js'; /** diff --git a/src/commands/complexity.js b/src/commands/complexity.js index 419064c2..f2de7f6a 100644 --- a/src/commands/complexity.js +++ b/src/commands/complexity.js @@ -1,4 +1,4 @@ -import { complexityData } from '../complexity.js'; +import { complexityData } from '../features/complexity.js'; import { outputResult } from '../infrastructure/result-formatter.js'; /** diff --git a/src/commands/dataflow.js b/src/commands/dataflow.js index 258f0d9c..fafcfb21 100644 --- a/src/commands/dataflow.js +++ b/src/commands/dataflow.js @@ -1,4 +1,4 @@ -import { dataflowData, dataflowImpactData } from '../dataflow.js'; +import { dataflowData, dataflowImpactData } from '../features/dataflow.js'; import { outputResult } from '../infrastructure/result-formatter.js'; /** diff --git a/src/commands/flow.js b/src/commands/flow.js index 630bcff4..e86f2de9 100644 --- a/src/commands/flow.js +++ b/src/commands/flow.js @@ -1,6 +1,6 @@ -import { flowData, listEntryPointsData } from '../flow.js'; +import { kindIcon } from '../domain/queries.js'; +import { flowData, listEntryPointsData } from '../features/flow.js'; import { outputResult } from '../infrastructure/result-formatter.js'; -import { kindIcon } from '../queries.js'; /** * CLI formatter — text or JSON output. diff --git a/src/commands/manifesto.js b/src/commands/manifesto.js index 0ccf1d1e..f491e0bf 100644 --- a/src/commands/manifesto.js +++ b/src/commands/manifesto.js @@ -1,5 +1,5 @@ +import { manifestoData } from '../features/manifesto.js'; import { outputResult } from '../infrastructure/result-formatter.js'; -import { manifestoData } from '../manifesto.js'; /** * CLI formatter — prints manifesto results and sets exitCode 1 on failure. diff --git a/src/commands/owners.js b/src/commands/owners.js index 3923cce0..2ec0f5c3 100644 --- a/src/commands/owners.js +++ b/src/commands/owners.js @@ -1,5 +1,5 @@ +import { ownersData } from '../features/owners.js'; import { outputResult } from '../infrastructure/result-formatter.js'; -import { ownersData } from '../owners.js'; /** * CLI display function for the `owners` command. diff --git a/src/commands/query.js b/src/commands/query.js index 63c4db64..471e45c0 100644 --- a/src/commands/query.js +++ b/src/commands/query.js @@ -18,4 +18,4 @@ export { stats, symbolPath, where, -} from '../queries-cli.js'; +} from '../presentation/queries-cli.js'; diff --git a/src/commands/sequence.js b/src/commands/sequence.js index 3b0a2a9e..ff8946c0 100644 --- a/src/commands/sequence.js +++ b/src/commands/sequence.js @@ -1,6 +1,6 @@ +import { kindIcon } from '../domain/queries.js'; +import { sequenceData, sequenceToMermaid } from '../features/sequence.js'; import { outputResult } from '../infrastructure/result-formatter.js'; -import { kindIcon } from '../queries.js'; -import { sequenceData, sequenceToMermaid } from '../sequence.js'; /** * CLI entry point — format sequence data as mermaid, JSON, or ndjson. diff --git a/src/commands/structure.js b/src/commands/structure.js index b76df909..a2679a4f 100644 --- a/src/commands/structure.js +++ b/src/commands/structure.js @@ -1,5 +1,5 @@ import path from 'node:path'; -import { hotspotsData, moduleBoundariesData, structureData } from '../structure.js'; +import { hotspotsData, moduleBoundariesData, structureData } from '../features/structure.js'; export { hotspotsData, moduleBoundariesData, structureData }; diff --git a/src/commands/triage.js b/src/commands/triage.js index 2ca8d136..8c10cb03 100644 --- a/src/commands/triage.js +++ b/src/commands/triage.js @@ -1,5 +1,5 @@ +import { triageData } from '../features/triage.js'; import { outputResult } from '../infrastructure/result-formatter.js'; -import { triageData } from '../triage.js'; /** * Print triage results to console. diff --git a/src/db.js b/src/db/index.js similarity index 90% rename from src/db.js rename to src/db/index.js index 7b67a9cf..fc947b23 100644 --- a/src/db.js +++ b/src/db/index.js @@ -1,13 +1,13 @@ -// Barrel re-export — keeps all existing `import { ... } from './db.js'` working. -export { closeDb, findDbPath, openDb, openReadonlyOrFail } from './db/connection.js'; -export { getBuildMeta, initSchema, MIGRATIONS, setBuildMeta } from './db/migrations.js'; +// Barrel re-export — keeps all existing `import { ... } from '…/db/index.js'` working. +export { closeDb, findDbPath, openDb, openReadonlyOrFail } from './connection.js'; +export { getBuildMeta, initSchema, MIGRATIONS, setBuildMeta } from './migrations.js'; export { fanInJoinSQL, fanOutJoinSQL, kindInClause, NodeQuery, testFilterSQL, -} from './db/query-builder.js'; +} from './query-builder.js'; export { bulkNodeIdsByFile, countCrossFileCallers, @@ -60,4 +60,4 @@ export { Repository, SqliteRepository, upsertCoChangeMeta, -} from './db/repository/index.js'; +} from './repository/index.js'; diff --git a/src/analysis/context.js b/src/domain/analysis/context.js similarity index 97% rename from src/analysis/context.js rename to src/domain/analysis/context.js index 8710ac90..803fcc99 100644 --- a/src/analysis/context.js +++ b/src/domain/analysis/context.js @@ -12,18 +12,18 @@ import { findNodesByFile, getComplexityForNode, openReadonlyOrFail, -} from '../db.js'; -import { isTestFile } from '../infrastructure/test-filter.js'; -import { paginateResult } from '../paginate.js'; +} from '../../db/index.js'; +import { isTestFile } from '../../infrastructure/test-filter.js'; +import { paginateResult } from '../../paginate.js'; import { createFileLinesReader, extractSignature, extractSummary, isFileLikeTarget, readSourceRange, -} from '../shared/file-utils.js'; -import { resolveMethodViaHierarchy } from '../shared/hierarchy.js'; -import { normalizeSymbol } from '../shared/normalize.js'; +} from '../../shared/file-utils.js'; +import { resolveMethodViaHierarchy } from '../../shared/hierarchy.js'; +import { normalizeSymbol } from '../../shared/normalize.js'; import { findMatchingNodes } from './symbol-lookup.js'; function explainFileImpl(db, target, getFileLines) { diff --git a/src/analysis/dependencies.js b/src/domain/analysis/dependencies.js similarity index 97% rename from src/analysis/dependencies.js rename to src/domain/analysis/dependencies.js index 5503570c..63778733 100644 --- a/src/analysis/dependencies.js +++ b/src/domain/analysis/dependencies.js @@ -6,11 +6,11 @@ import { findImportTargets, findNodesByFile, openReadonlyOrFail, -} from '../db.js'; -import { isTestFile } from '../infrastructure/test-filter.js'; -import { paginateResult } from '../paginate.js'; -import { resolveMethodViaHierarchy } from '../shared/hierarchy.js'; -import { normalizeSymbol } from '../shared/normalize.js'; +} from '../../db/index.js'; +import { isTestFile } from '../../infrastructure/test-filter.js'; +import { paginateResult } from '../../paginate.js'; +import { resolveMethodViaHierarchy } from '../../shared/hierarchy.js'; +import { normalizeSymbol } from '../../shared/normalize.js'; import { findMatchingNodes } from './symbol-lookup.js'; export function fileDepsData(file, customDbPath, opts = {}) { diff --git a/src/analysis/exports.js b/src/domain/analysis/exports.js similarity index 93% rename from src/analysis/exports.js rename to src/domain/analysis/exports.js index 2d2de439..6088656f 100644 --- a/src/analysis/exports.js +++ b/src/domain/analysis/exports.js @@ -5,10 +5,14 @@ import { findFileNodes, findNodesByFile, openReadonlyOrFail, -} from '../db.js'; -import { isTestFile } from '../infrastructure/test-filter.js'; -import { paginateResult } from '../paginate.js'; -import { createFileLinesReader, extractSignature, extractSummary } from '../shared/file-utils.js'; +} from '../../db/index.js'; +import { isTestFile } from '../../infrastructure/test-filter.js'; +import { paginateResult } from '../../paginate.js'; +import { + createFileLinesReader, + extractSignature, + extractSummary, +} from '../../shared/file-utils.js'; export function exportsData(file, customDbPath, opts = {}) { const db = openReadonlyOrFail(customDbPath); diff --git a/src/analysis/impact.js b/src/domain/analysis/impact.js similarity index 96% rename from src/analysis/impact.js rename to src/domain/analysis/impact.js index b4e18979..282e9c64 100644 --- a/src/analysis/impact.js +++ b/src/domain/analysis/impact.js @@ -1,9 +1,7 @@ import { execFileSync } from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; -import { evaluateBoundaries } from '../boundaries.js'; -import { coChangeForFiles } from '../cochange.js'; -import { loadConfig } from '../config.js'; +import { loadConfig } from '../../config.js'; import { findDbPath, findDistinctCallers, @@ -11,11 +9,13 @@ import { findImportDependents, findNodeById, openReadonlyOrFail, -} from '../db.js'; -import { isTestFile } from '../infrastructure/test-filter.js'; -import { ownersForFiles } from '../owners.js'; -import { paginateResult } from '../paginate.js'; -import { normalizeSymbol } from '../shared/normalize.js'; +} from '../../db/index.js'; +import { evaluateBoundaries } from '../../features/boundaries.js'; +import { coChangeForFiles } from '../../features/cochange.js'; +import { ownersForFiles } from '../../features/owners.js'; +import { isTestFile } from '../../infrastructure/test-filter.js'; +import { paginateResult } from '../../paginate.js'; +import { normalizeSymbol } from '../../shared/normalize.js'; import { findMatchingNodes } from './symbol-lookup.js'; export function impactAnalysisData(file, customDbPath, opts = {}) { diff --git a/src/analysis/module-map.js b/src/domain/analysis/module-map.js similarity index 97% rename from src/analysis/module-map.js rename to src/domain/analysis/module-map.js index 7c0bbcdb..fedef93e 100644 --- a/src/analysis/module-map.js +++ b/src/domain/analysis/module-map.js @@ -1,8 +1,8 @@ import path from 'node:path'; -import { findCycles } from '../cycles.js'; -import { openReadonlyOrFail, testFilterSQL } from '../db.js'; -import { isTestFile } from '../infrastructure/test-filter.js'; -import { LANGUAGE_REGISTRY } from '../parser.js'; +import { openReadonlyOrFail, testFilterSQL } from '../../db/index.js'; +import { isTestFile } from '../../infrastructure/test-filter.js'; +import { LANGUAGE_REGISTRY } from '../../parser.js'; +import { findCycles } from '../graph/cycles.js'; export const FALSE_POSITIVE_NAMES = new Set([ 'run', diff --git a/src/analysis/roles.js b/src/domain/analysis/roles.js similarity index 83% rename from src/analysis/roles.js rename to src/domain/analysis/roles.js index 5d76af95..d295515f 100644 --- a/src/analysis/roles.js +++ b/src/domain/analysis/roles.js @@ -1,7 +1,7 @@ -import { openReadonlyOrFail } from '../db.js'; -import { isTestFile } from '../infrastructure/test-filter.js'; -import { paginateResult } from '../paginate.js'; -import { normalizeSymbol } from '../shared/normalize.js'; +import { openReadonlyOrFail } from '../../db/index.js'; +import { isTestFile } from '../../infrastructure/test-filter.js'; +import { paginateResult } from '../../paginate.js'; +import { normalizeSymbol } from '../../shared/normalize.js'; export function rolesData(customDbPath, opts = {}) { const db = openReadonlyOrFail(customDbPath); diff --git a/src/analysis/symbol-lookup.js b/src/domain/analysis/symbol-lookup.js similarity index 96% rename from src/analysis/symbol-lookup.js rename to src/domain/analysis/symbol-lookup.js index 78ea24f6..e269a42d 100644 --- a/src/analysis/symbol-lookup.js +++ b/src/domain/analysis/symbol-lookup.js @@ -12,11 +12,11 @@ import { findNodesWithFanIn, listFunctionNodes, openReadonlyOrFail, -} from '../db.js'; -import { isTestFile } from '../infrastructure/test-filter.js'; -import { ALL_SYMBOL_KINDS } from '../kinds.js'; -import { paginateResult } from '../paginate.js'; -import { getFileHash, normalizeSymbol } from '../shared/normalize.js'; +} from '../../db/index.js'; +import { isTestFile } from '../../infrastructure/test-filter.js'; +import { ALL_SYMBOL_KINDS } from '../../kinds.js'; +import { paginateResult } from '../../paginate.js'; +import { getFileHash, normalizeSymbol } from '../../shared/normalize.js'; const FUNCTION_KINDS = ['function', 'method', 'class']; diff --git a/src/builder.js b/src/domain/graph/builder.js similarity index 100% rename from src/builder.js rename to src/domain/graph/builder.js diff --git a/src/builder/context.js b/src/domain/graph/builder/context.js similarity index 100% rename from src/builder/context.js rename to src/domain/graph/builder/context.js diff --git a/src/builder/helpers.js b/src/domain/graph/builder/helpers.js similarity index 97% rename from src/builder/helpers.js rename to src/domain/graph/builder/helpers.js index 0ad89def..a333f456 100644 --- a/src/builder/helpers.js +++ b/src/domain/graph/builder/helpers.js @@ -6,9 +6,9 @@ import { createHash } from 'node:crypto'; import fs from 'node:fs'; import path from 'node:path'; -import { EXTENSIONS, IGNORE_DIRS } from '../constants.js'; -import { purgeFilesData } from '../db.js'; -import { warn } from '../logger.js'; +import { EXTENSIONS, IGNORE_DIRS } from '../../../constants.js'; +import { purgeFilesData } from '../../../db/index.js'; +import { warn } from '../../../logger.js'; export const BUILTIN_RECEIVERS = new Set([ 'console', diff --git a/src/builder/incremental.js b/src/domain/graph/builder/incremental.js similarity index 97% rename from src/builder/incremental.js rename to src/domain/graph/builder/incremental.js index d30c89df..7183d4b7 100644 --- a/src/builder/incremental.js +++ b/src/domain/graph/builder/incremental.js @@ -6,9 +6,9 @@ */ import fs from 'node:fs'; import path from 'node:path'; -import { normalizePath } from '../constants.js'; -import { warn } from '../logger.js'; -import { parseFileIncremental } from '../parser.js'; +import { normalizePath } from '../../../constants.js'; +import { warn } from '../../../logger.js'; +import { parseFileIncremental } from '../../../parser.js'; import { computeConfidence, resolveImportPath } from '../resolve.js'; import { BUILTIN_RECEIVERS, readFileSafe } from './helpers.js'; diff --git a/src/builder/pipeline.js b/src/domain/graph/builder/pipeline.js similarity index 96% rename from src/builder/pipeline.js rename to src/domain/graph/builder/pipeline.js index 09a97a5c..d1be7ebb 100644 --- a/src/builder/pipeline.js +++ b/src/domain/graph/builder/pipeline.js @@ -6,10 +6,10 @@ */ import path from 'node:path'; import { performance } from 'node:perf_hooks'; -import { loadConfig } from '../config.js'; -import { closeDb, getBuildMeta, initSchema, MIGRATIONS, openDb } from '../db.js'; -import { info } from '../logger.js'; -import { getActiveEngine } from '../parser.js'; +import { loadConfig } from '../../../config.js'; +import { closeDb, getBuildMeta, initSchema, MIGRATIONS, openDb } from '../../../db/index.js'; +import { info } from '../../../logger.js'; +import { getActiveEngine } from '../../../parser.js'; import { PipelineContext } from './context.js'; import { loadPathAliases } from './helpers.js'; import { buildEdges } from './stages/build-edges.js'; diff --git a/src/builder/stages/build-edges.js b/src/domain/graph/builder/stages/build-edges.js similarity index 99% rename from src/builder/stages/build-edges.js rename to src/domain/graph/builder/stages/build-edges.js index 545aa9bf..33aa66ca 100644 --- a/src/builder/stages/build-edges.js +++ b/src/domain/graph/builder/stages/build-edges.js @@ -6,8 +6,8 @@ */ import path from 'node:path'; import { performance } from 'node:perf_hooks'; -import { getNodeId } from '../../db.js'; -import { loadNative } from '../../native.js'; +import { getNodeId } from '../../../../db/index.js'; +import { loadNative } from '../../../../native.js'; import { computeConfidence } from '../../resolve.js'; import { BUILTIN_RECEIVERS, batchInsertEdges } from '../helpers.js'; import { getResolved, isBarrelFile, resolveBarrelExport } from './resolve-imports.js'; diff --git a/src/builder/stages/build-structure.js b/src/domain/graph/builder/stages/build-structure.js similarity index 94% rename from src/builder/stages/build-structure.js rename to src/domain/graph/builder/stages/build-structure.js index 9f69e455..ec235be2 100644 --- a/src/builder/stages/build-structure.js +++ b/src/domain/graph/builder/stages/build-structure.js @@ -5,8 +5,8 @@ */ import path from 'node:path'; import { performance } from 'node:perf_hooks'; -import { normalizePath } from '../../constants.js'; -import { debug } from '../../logger.js'; +import { normalizePath } from '../../../../constants.js'; +import { debug } from '../../../../logger.js'; import { readFileSafe } from '../helpers.js'; /** @@ -88,7 +88,7 @@ export async function buildStructure(ctx) { relDirs.add(normalizePath(path.relative(rootDir, absDir))); } try { - const { buildStructure: buildStructureFn } = await import('../../structure.js'); + const { buildStructure: buildStructureFn } = await import('../../../../features/structure.js'); const changedFilePaths = isFullBuild ? null : [...allSymbols.keys()]; buildStructureFn(db, fileSymbols, rootDir, ctx.lineCountMap, relDirs, changedFilePaths); } catch (err) { @@ -99,7 +99,7 @@ export async function buildStructure(ctx) { // Classify node roles const t1 = performance.now(); try { - const { classifyNodeRoles } = await import('../../structure.js'); + const { classifyNodeRoles } = await import('../../../../features/structure.js'); const roleSummary = classifyNodeRoles(db); debug( `Roles: ${Object.entries(roleSummary) diff --git a/src/builder/stages/collect-files.js b/src/domain/graph/builder/stages/collect-files.js similarity index 92% rename from src/builder/stages/collect-files.js rename to src/domain/graph/builder/stages/collect-files.js index 29511d21..97d183ce 100644 --- a/src/builder/stages/collect-files.js +++ b/src/domain/graph/builder/stages/collect-files.js @@ -5,8 +5,8 @@ */ import fs from 'node:fs'; import path from 'node:path'; -import { normalizePath } from '../../constants.js'; -import { info } from '../../logger.js'; +import { normalizePath } from '../../../../constants.js'; +import { info } from '../../../../logger.js'; import { collectFiles as collectFilesUtil } from '../helpers.js'; /** diff --git a/src/builder/stages/detect-changes.js b/src/domain/graph/builder/stages/detect-changes.js similarity index 96% rename from src/builder/stages/detect-changes.js rename to src/domain/graph/builder/stages/detect-changes.js index ce902a71..29d25a8a 100644 --- a/src/builder/stages/detect-changes.js +++ b/src/domain/graph/builder/stages/detect-changes.js @@ -6,11 +6,11 @@ */ import fs from 'node:fs'; import path from 'node:path'; -import { normalizePath } from '../../constants.js'; -import { closeDb } from '../../db.js'; -import { readJournal, writeJournalHeader } from '../../journal.js'; -import { debug, info } from '../../logger.js'; -import { parseFilesAuto } from '../../parser.js'; +import { normalizePath } from '../../../../constants.js'; +import { closeDb } from '../../../../db/index.js'; +import { readJournal, writeJournalHeader } from '../../../../journal.js'; +import { debug, info } from '../../../../logger.js'; +import { parseFilesAuto } from '../../../../parser.js'; import { fileHash, fileStat, purgeFilesFromGraph, readFileSafe } from '../helpers.js'; /** @@ -203,11 +203,11 @@ async function runPendingAnalysis(ctx) { }; const analysisSymbols = await parseFilesAuto(allFiles, rootDir, analysisOpts); if (needsCfg) { - const { buildCFGData } = await import('../../cfg.js'); + const { buildCFGData } = await import('../../../../features/cfg.js'); await buildCFGData(db, analysisSymbols, rootDir, engineOpts); } if (needsDataflow) { - const { buildDataflowEdges } = await import('../../dataflow.js'); + const { buildDataflowEdges } = await import('../../../../features/dataflow.js'); await buildDataflowEdges(db, analysisSymbols, rootDir, engineOpts); } return true; diff --git a/src/builder/stages/finalize.js b/src/domain/graph/builder/stages/finalize.js similarity index 92% rename from src/builder/stages/finalize.js rename to src/domain/graph/builder/stages/finalize.js index 1b59cebc..e82411d7 100644 --- a/src/builder/stages/finalize.js +++ b/src/domain/graph/builder/stages/finalize.js @@ -6,13 +6,13 @@ import fs from 'node:fs'; import path from 'node:path'; import { performance } from 'node:perf_hooks'; -import { closeDb, getBuildMeta, setBuildMeta } from '../../db.js'; -import { writeJournalHeader } from '../../journal.js'; -import { debug, info, warn } from '../../logger.js'; +import { closeDb, getBuildMeta, setBuildMeta } from '../../../../db/index.js'; +import { writeJournalHeader } from '../../../../journal.js'; +import { debug, info, warn } from '../../../../logger.js'; const __builderDir = path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Z]:)/i, '$1')); const CODEGRAPH_VERSION = JSON.parse( - fs.readFileSync(path.join(__builderDir, '..', '..', '..', 'package.json'), 'utf-8'), + fs.readFileSync(path.join(__builderDir, '..', '..', '..', '..', '..', 'package.json'), 'utf-8'), ).version; /** @@ -127,7 +127,7 @@ export async function finalize(ctx) { debug(`Skipping auto-registration for temp directory: ${resolvedRoot}`); } else { try { - const { registerRepo } = await import('../../registry.js'); + const { registerRepo } = await import('../../../../registry.js'); registerRepo(rootDir); } catch (err) { debug(`Auto-registration failed: ${err.message}`); diff --git a/src/builder/stages/insert-nodes.js b/src/domain/graph/builder/stages/insert-nodes.js similarity index 99% rename from src/builder/stages/insert-nodes.js rename to src/domain/graph/builder/stages/insert-nodes.js index d0244268..2eaf6a73 100644 --- a/src/builder/stages/insert-nodes.js +++ b/src/domain/graph/builder/stages/insert-nodes.js @@ -6,7 +6,7 @@ */ import path from 'node:path'; import { performance } from 'node:perf_hooks'; -import { bulkNodeIdsByFile } from '../../db.js'; +import { bulkNodeIdsByFile } from '../../../../db/index.js'; import { batchInsertEdges, batchInsertNodes, diff --git a/src/builder/stages/parse-files.js b/src/domain/graph/builder/stages/parse-files.js similarity index 89% rename from src/builder/stages/parse-files.js rename to src/domain/graph/builder/stages/parse-files.js index 3cdae46e..0d3e1167 100644 --- a/src/builder/stages/parse-files.js +++ b/src/domain/graph/builder/stages/parse-files.js @@ -5,8 +5,8 @@ * Populates ctx.allSymbols, ctx.fileSymbols, ctx.filesToParse. */ import { performance } from 'node:perf_hooks'; -import { info } from '../../logger.js'; -import { parseFilesAuto } from '../../parser.js'; +import { info } from '../../../../logger.js'; +import { parseFilesAuto } from '../../../../parser.js'; /** * @param {import('../context.js').PipelineContext} ctx diff --git a/src/builder/stages/resolve-imports.js b/src/domain/graph/builder/stages/resolve-imports.js similarity index 98% rename from src/builder/stages/resolve-imports.js rename to src/domain/graph/builder/stages/resolve-imports.js index 1fba3f53..d2a39861 100644 --- a/src/builder/stages/resolve-imports.js +++ b/src/domain/graph/builder/stages/resolve-imports.js @@ -6,7 +6,7 @@ */ import path from 'node:path'; import { performance } from 'node:perf_hooks'; -import { parseFilesAuto } from '../../parser.js'; +import { parseFilesAuto } from '../../../../parser.js'; import { resolveImportPath, resolveImportsBatch } from '../../resolve.js'; /** diff --git a/src/builder/stages/run-analyses.js b/src/domain/graph/builder/stages/run-analyses.js similarity index 91% rename from src/builder/stages/run-analyses.js rename to src/domain/graph/builder/stages/run-analyses.js index bc8db8a3..f6dbbdb9 100644 --- a/src/builder/stages/run-analyses.js +++ b/src/domain/graph/builder/stages/run-analyses.js @@ -4,7 +4,7 @@ * Dispatches to the unified AST analysis engine (AST nodes, complexity, CFG, dataflow). * Filters out reverse-dep files for incremental builds. */ -import { debug, warn } from '../../logger.js'; +import { debug, warn } from '../../../../logger.js'; /** * @param {import('../context.js').PipelineContext} ctx @@ -31,7 +31,7 @@ export async function runAnalyses(ctx) { } } - const { runAnalyses: runAnalysesFn } = await import('../../ast-analysis/engine.js'); + const { runAnalyses: runAnalysesFn } = await import('../../../../ast-analysis/engine.js'); try { const analysisTiming = await runAnalysesFn(db, astComplexitySymbols, rootDir, opts, engineOpts); ctx.timing.astMs = analysisTiming.astMs; diff --git a/src/cycles.js b/src/domain/graph/cycles.js similarity index 91% rename from src/cycles.js rename to src/domain/graph/cycles.js index a66b6ff0..bed9fc03 100644 --- a/src/cycles.js +++ b/src/domain/graph/cycles.js @@ -1,7 +1,7 @@ -import { tarjan } from './graph/algorithms/tarjan.js'; -import { buildDependencyGraph } from './graph/builders/dependency.js'; -import { CodeGraph } from './graph/model.js'; -import { loadNative } from './native.js'; +import { tarjan } from '../../graph/algorithms/tarjan.js'; +import { buildDependencyGraph } from '../../graph/builders/dependency.js'; +import { CodeGraph } from '../../graph/model.js'; +import { loadNative } from '../../native.js'; /** * Detect circular dependencies in the codebase using Tarjan's SCC algorithm. diff --git a/src/resolve.js b/src/domain/graph/resolve.js similarity index 98% rename from src/resolve.js rename to src/domain/graph/resolve.js index 8581b58c..73179b67 100644 --- a/src/resolve.js +++ b/src/domain/graph/resolve.js @@ -1,7 +1,7 @@ import fs from 'node:fs'; import path from 'node:path'; -import { normalizePath } from './constants.js'; -import { loadNative } from './native.js'; +import { normalizePath } from '../../constants.js'; +import { loadNative } from '../../native.js'; // ── Alias format conversion ───────────────────────────────────────── diff --git a/src/watcher.js b/src/domain/graph/watcher.js similarity index 93% rename from src/watcher.js rename to src/domain/graph/watcher.js index 8c5ed85b..58b56eeb 100644 --- a/src/watcher.js +++ b/src/domain/graph/watcher.js @@ -1,13 +1,13 @@ import fs from 'node:fs'; import path from 'node:path'; +import { appendChangeEvents, buildChangeEvent, diffSymbols } from '../../change-journal.js'; +import { EXTENSIONS, IGNORE_DIRS, normalizePath } from '../../constants.js'; +import { closeDb, getNodeId as getNodeIdQuery, initSchema, openDb } from '../../db/index.js'; +import { DbError } from '../../errors.js'; +import { appendJournalEntries } from '../../journal.js'; +import { info } from '../../logger.js'; +import { createParseTreeCache, getActiveEngine } from '../../parser.js'; import { rebuildFile } from './builder/incremental.js'; -import { appendChangeEvents, buildChangeEvent, diffSymbols } from './change-journal.js'; -import { EXTENSIONS, IGNORE_DIRS, normalizePath } from './constants.js'; -import { closeDb, getNodeId as getNodeIdQuery, initSchema, openDb } from './db.js'; -import { DbError } from './errors.js'; -import { appendJournalEntries } from './journal.js'; -import { info } from './logger.js'; -import { createParseTreeCache, getActiveEngine } from './parser.js'; function shouldIgnore(filePath) { const parts = filePath.split(path.sep); diff --git a/src/queries.js b/src/domain/queries.js similarity index 87% rename from src/queries.js rename to src/domain/queries.js index 68121023..4b853d79 100644 --- a/src/queries.js +++ b/src/domain/queries.js @@ -6,6 +6,22 @@ * importers continue to work without changes. */ +// ── Re-export from dedicated module for backward compat ─────────────────── +export { isTestFile, TEST_PATTERN } from '../infrastructure/test-filter.js'; +// ── Kind/edge constants (canonical source: kinds.js) ───────────────────── +export { + ALL_SYMBOL_KINDS, + CORE_EDGE_KINDS, + CORE_SYMBOL_KINDS, + EVERY_EDGE_KIND, + EVERY_SYMBOL_KIND, + EXTENDED_SYMBOL_KINDS, + STRUCTURAL_EDGE_KINDS, + VALID_ROLES, +} from '../kinds.js'; +export { iterListFunctions, iterRoles, iterWhere } from '../shared/generators.js'; +// ── Shared utilities ───────────────────────────────────────────────────── +export { kindIcon, normalizeSymbol } from '../shared/normalize.js'; export { contextData, explainData } from './analysis/context.js'; export { fileDepsData, fnDepsData, pathData } from './analysis/dependencies.js'; export { exportsData } from './analysis/exports.js'; @@ -30,19 +46,3 @@ export { queryNameData, whereData, } from './analysis/symbol-lookup.js'; -// ── Re-export from dedicated module for backward compat ─────────────────── -export { isTestFile, TEST_PATTERN } from './infrastructure/test-filter.js'; -// ── Kind/edge constants (canonical source: kinds.js) ───────────────────── -export { - ALL_SYMBOL_KINDS, - CORE_EDGE_KINDS, - CORE_SYMBOL_KINDS, - EVERY_EDGE_KIND, - EVERY_SYMBOL_KIND, - EXTENDED_SYMBOL_KINDS, - STRUCTURAL_EDGE_KINDS, - VALID_ROLES, -} from './kinds.js'; -export { iterListFunctions, iterRoles, iterWhere } from './shared/generators.js'; -// ── Shared utilities ───────────────────────────────────────────────────── -export { kindIcon, normalizeSymbol } from './shared/normalize.js'; diff --git a/src/embeddings/generator.js b/src/domain/search/generator.js similarity index 97% rename from src/embeddings/generator.js rename to src/domain/search/generator.js index b34f5934..6936dd84 100644 --- a/src/embeddings/generator.js +++ b/src/domain/search/generator.js @@ -1,8 +1,8 @@ import fs from 'node:fs'; import path from 'node:path'; -import { closeDb, findDbPath, openDb } from '../db.js'; -import { DbError } from '../errors.js'; -import { warn } from '../logger.js'; +import { closeDb, findDbPath, openDb } from '../../db/index.js'; +import { DbError } from '../../errors.js'; +import { warn } from '../../logger.js'; import { embed, getModelConfig } from './models.js'; import { buildSourceText } from './strategies/source.js'; import { buildStructuredText } from './strategies/structured.js'; diff --git a/src/embeddings/index.js b/src/domain/search/index.js similarity index 100% rename from src/embeddings/index.js rename to src/domain/search/index.js diff --git a/src/embeddings/models.js b/src/domain/search/models.js similarity index 98% rename from src/embeddings/models.js rename to src/domain/search/models.js index 1202dd28..355dd381 100644 --- a/src/embeddings/models.js +++ b/src/domain/search/models.js @@ -1,7 +1,7 @@ import { execFileSync } from 'node:child_process'; import { createInterface } from 'node:readline'; -import { ConfigError, EngineError } from '../errors.js'; -import { info } from '../logger.js'; +import { ConfigError, EngineError } from '../../errors.js'; +import { info } from '../../logger.js'; // Lazy-load transformers (heavy, optional module) let pipeline = null; diff --git a/src/embeddings/search/cli-formatter.js b/src/domain/search/search/cli-formatter.js similarity index 99% rename from src/embeddings/search/cli-formatter.js rename to src/domain/search/search/cli-formatter.js index f79a9e27..013333af 100644 --- a/src/embeddings/search/cli-formatter.js +++ b/src/domain/search/search/cli-formatter.js @@ -1,4 +1,4 @@ -import { warn } from '../../logger.js'; +import { warn } from '../../../logger.js'; import { hybridSearchData } from './hybrid.js'; import { ftsSearchData } from './keyword.js'; import { multiSearchData, searchData } from './semantic.js'; diff --git a/src/embeddings/search/filters.js b/src/domain/search/search/filters.js similarity index 100% rename from src/embeddings/search/filters.js rename to src/domain/search/search/filters.js diff --git a/src/embeddings/search/hybrid.js b/src/domain/search/search/hybrid.js similarity index 98% rename from src/embeddings/search/hybrid.js rename to src/domain/search/search/hybrid.js index 759e91c7..6d236568 100644 --- a/src/embeddings/search/hybrid.js +++ b/src/domain/search/search/hybrid.js @@ -1,4 +1,4 @@ -import { openReadonlyOrFail } from '../../db.js'; +import { openReadonlyOrFail } from '../../../db/index.js'; import { hasFtsIndex } from '../stores/fts5.js'; import { ftsSearchData } from './keyword.js'; import { searchData } from './semantic.js'; diff --git a/src/embeddings/search/keyword.js b/src/domain/search/search/keyword.js similarity index 96% rename from src/embeddings/search/keyword.js rename to src/domain/search/search/keyword.js index cc8975d3..e43c5212 100644 --- a/src/embeddings/search/keyword.js +++ b/src/domain/search/search/keyword.js @@ -1,4 +1,4 @@ -import { openReadonlyOrFail } from '../../db.js'; +import { openReadonlyOrFail } from '../../../db/index.js'; import { normalizeSymbol } from '../../queries.js'; import { hasFtsIndex, sanitizeFtsQuery } from '../stores/fts5.js'; import { applyFilters } from './filters.js'; diff --git a/src/embeddings/search/prepare.js b/src/domain/search/search/prepare.js similarity index 93% rename from src/embeddings/search/prepare.js rename to src/domain/search/search/prepare.js index 864bfbe9..484584c5 100644 --- a/src/embeddings/search/prepare.js +++ b/src/domain/search/search/prepare.js @@ -1,5 +1,5 @@ -import { getEmbeddingCount, getEmbeddingMeta } from '../../db/repository/embeddings.js'; -import { openReadonlyOrFail } from '../../db.js'; +import { openReadonlyOrFail } from '../../../db/index.js'; +import { getEmbeddingCount, getEmbeddingMeta } from '../../../db/repository/embeddings.js'; import { MODELS } from '../models.js'; import { applyFilters } from './filters.js'; diff --git a/src/embeddings/search/semantic.js b/src/domain/search/search/semantic.js similarity index 99% rename from src/embeddings/search/semantic.js rename to src/domain/search/search/semantic.js index 62263ac3..aa624ab6 100644 --- a/src/embeddings/search/semantic.js +++ b/src/domain/search/search/semantic.js @@ -1,4 +1,4 @@ -import { warn } from '../../logger.js'; +import { warn } from '../../../logger.js'; import { normalizeSymbol } from '../../queries.js'; import { embed } from '../models.js'; import { cosineSim } from '../stores/sqlite-blob.js'; diff --git a/src/embeddings/stores/fts5.js b/src/domain/search/stores/fts5.js similarity index 100% rename from src/embeddings/stores/fts5.js rename to src/domain/search/stores/fts5.js diff --git a/src/embeddings/stores/sqlite-blob.js b/src/domain/search/stores/sqlite-blob.js similarity index 100% rename from src/embeddings/stores/sqlite-blob.js rename to src/domain/search/stores/sqlite-blob.js diff --git a/src/embeddings/strategies/source.js b/src/domain/search/strategies/source.js similarity index 100% rename from src/embeddings/strategies/source.js rename to src/domain/search/strategies/source.js diff --git a/src/embeddings/strategies/structured.js b/src/domain/search/strategies/structured.js similarity index 95% rename from src/embeddings/strategies/structured.js rename to src/domain/search/strategies/structured.js index c488d1c6..83f5ff0a 100644 --- a/src/embeddings/strategies/structured.js +++ b/src/domain/search/strategies/structured.js @@ -1,4 +1,4 @@ -import { findCalleeNames, findCallerNames } from '../../db.js'; +import { findCalleeNames, findCallerNames } from '../../../db/index.js'; import { extractLeadingComment, splitIdentifier } from './text-utils.js'; /** diff --git a/src/embeddings/strategies/text-utils.js b/src/domain/search/strategies/text-utils.js similarity index 100% rename from src/embeddings/strategies/text-utils.js rename to src/domain/search/strategies/text-utils.js diff --git a/src/ast.js b/src/features/ast.js similarity index 94% rename from src/ast.js rename to src/features/ast.js index b0ad6d72..6935efe7 100644 --- a/src/ast.js +++ b/src/features/ast.js @@ -7,14 +7,14 @@ */ import path from 'node:path'; -import { AST_TYPE_MAPS } from './ast-analysis/rules/index.js'; -import { buildExtensionSet } from './ast-analysis/shared.js'; -import { walkWithVisitors } from './ast-analysis/visitor.js'; -import { createAstStoreVisitor } from './ast-analysis/visitors/ast-store-visitor.js'; -import { bulkNodeIdsByFile, openReadonlyOrFail } from './db.js'; -import { outputResult } from './infrastructure/result-formatter.js'; -import { debug } from './logger.js'; -import { paginateResult } from './paginate.js'; +import { AST_TYPE_MAPS } from '../ast-analysis/rules/index.js'; +import { buildExtensionSet } from '../ast-analysis/shared.js'; +import { walkWithVisitors } from '../ast-analysis/visitor.js'; +import { createAstStoreVisitor } from '../ast-analysis/visitors/ast-store-visitor.js'; +import { bulkNodeIdsByFile, openReadonlyOrFail } from '../db/index.js'; +import { outputResult } from '../infrastructure/result-formatter.js'; +import { debug } from '../logger.js'; +import { paginateResult } from '../paginate.js'; // ─── Constants ──────────────────────────────────────────────────────── diff --git a/src/audit.js b/src/features/audit.js similarity index 98% rename from src/audit.js rename to src/features/audit.js index 63e5c08b..c267b04a 100644 --- a/src/audit.js +++ b/src/features/audit.js @@ -7,11 +7,11 @@ */ import path from 'node:path'; -import { loadConfig } from './config.js'; -import { openReadonlyOrFail } from './db.js'; -import { isTestFile } from './infrastructure/test-filter.js'; +import { loadConfig } from '../config.js'; +import { openReadonlyOrFail } from '../db/index.js'; +import { explainData } from '../domain/queries.js'; +import { isTestFile } from '../infrastructure/test-filter.js'; import { RULE_DEFS } from './manifesto.js'; -import { explainData } from './queries.js'; // ─── Threshold resolution ─────────────────────────────────────────── diff --git a/src/batch.js b/src/features/batch.js similarity index 98% rename from src/batch.js rename to src/features/batch.js index fb4ce88d..4d1225bd 100644 --- a/src/batch.js +++ b/src/features/batch.js @@ -5,10 +5,6 @@ * Designed for multi-agent swarms that need to dispatch 20+ queries in one call. */ -import { complexityData } from './complexity.js'; -import { dataflowData } from './dataflow.js'; -import { ConfigError } from './errors.js'; -import { flowData } from './flow.js'; import { contextData, explainData, @@ -18,7 +14,11 @@ import { fnImpactData, impactAnalysisData, whereData, -} from './queries.js'; +} from '../domain/queries.js'; +import { ConfigError } from '../errors.js'; +import { complexityData } from './complexity.js'; +import { dataflowData } from './dataflow.js'; +import { flowData } from './flow.js'; /** * Map of supported batch commands → their data function + first-arg semantics. diff --git a/src/boundaries.js b/src/features/boundaries.js similarity index 99% rename from src/boundaries.js rename to src/features/boundaries.js index 6bf92fd4..8da92b92 100644 --- a/src/boundaries.js +++ b/src/features/boundaries.js @@ -1,5 +1,5 @@ -import { isTestFile } from './infrastructure/test-filter.js'; -import { debug } from './logger.js'; +import { isTestFile } from '../infrastructure/test-filter.js'; +import { debug } from '../logger.js'; // ─── Glob-to-Regex ─────────────────────────────────────────────────── diff --git a/src/branch-compare.js b/src/features/branch-compare.js similarity index 98% rename from src/branch-compare.js rename to src/features/branch-compare.js index 29172c7e..474e162e 100644 --- a/src/branch-compare.js +++ b/src/features/branch-compare.js @@ -11,9 +11,9 @@ import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; -import { buildGraph } from './builder.js'; -import { isTestFile } from './infrastructure/test-filter.js'; -import { kindIcon } from './queries.js'; +import { buildGraph } from '../domain/graph/builder.js'; +import { kindIcon } from '../domain/queries.js'; +import { isTestFile } from '../infrastructure/test-filter.js'; // ─── Git Helpers ──────────────────────────────────────────────────────── diff --git a/src/cfg.js b/src/features/cfg.js similarity index 97% rename from src/cfg.js rename to src/features/cfg.js index cf023f3b..6f1dcdfc 100644 --- a/src/cfg.js +++ b/src/features/cfg.js @@ -7,14 +7,14 @@ import fs from 'node:fs'; import path from 'node:path'; -import { CFG_RULES } from './ast-analysis/rules/index.js'; +import { CFG_RULES } from '../ast-analysis/rules/index.js'; import { makeCfgRules as _makeCfgRules, buildExtensionSet, buildExtToLangMap, -} from './ast-analysis/shared.js'; -import { walkWithVisitors } from './ast-analysis/visitor.js'; -import { createCfgVisitor } from './ast-analysis/visitors/cfg-visitor.js'; +} from '../ast-analysis/shared.js'; +import { walkWithVisitors } from '../ast-analysis/visitor.js'; +import { createCfgVisitor } from '../ast-analysis/visitors/cfg-visitor.js'; import { deleteCfgForNode, getCfgBlocks, @@ -22,10 +22,10 @@ import { getFunctionNodeId, hasCfgTables, openReadonlyOrFail, -} from './db.js'; -import { isTestFile } from './infrastructure/test-filter.js'; -import { info } from './logger.js'; -import { paginateResult } from './paginate.js'; +} from '../db/index.js'; +import { isTestFile } from '../infrastructure/test-filter.js'; +import { info } from '../logger.js'; +import { paginateResult } from '../paginate.js'; // Re-export for backward compatibility export { _makeCfgRules as makeCfgRules, CFG_RULES }; diff --git a/src/check.js b/src/features/check.js similarity index 98% rename from src/check.js rename to src/features/check.js index dd53de50..b8e3c75f 100644 --- a/src/check.js +++ b/src/features/check.js @@ -1,10 +1,10 @@ import { execFileSync } from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; -import { loadConfig } from './config.js'; -import { findCycles } from './cycles.js'; -import { findDbPath, openReadonlyOrFail } from './db.js'; -import { isTestFile } from './infrastructure/test-filter.js'; +import { loadConfig } from '../config.js'; +import { findDbPath, openReadonlyOrFail } from '../db/index.js'; +import { findCycles } from '../domain/graph/cycles.js'; +import { isTestFile } from '../infrastructure/test-filter.js'; import { matchOwners, parseCodeowners } from './owners.js'; // ─── Diff Parser ────────────────────────────────────────────────────── diff --git a/src/cochange.js b/src/features/cochange.js similarity index 98% rename from src/cochange.js rename to src/features/cochange.js index 182e4d9e..134519ed 100644 --- a/src/cochange.js +++ b/src/features/cochange.js @@ -8,11 +8,11 @@ import { execFileSync } from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; -import { normalizePath } from './constants.js'; -import { closeDb, findDbPath, initSchema, openDb, openReadonlyOrFail } from './db.js'; -import { isTestFile } from './infrastructure/test-filter.js'; -import { warn } from './logger.js'; -import { paginateResult } from './paginate.js'; +import { normalizePath } from '../constants.js'; +import { closeDb, findDbPath, initSchema, openDb, openReadonlyOrFail } from '../db/index.js'; +import { isTestFile } from '../infrastructure/test-filter.js'; +import { warn } from '../logger.js'; +import { paginateResult } from '../paginate.js'; /** * Scan git history and return parsed commit data. diff --git a/src/communities.js b/src/features/communities.js similarity index 95% rename from src/communities.js rename to src/features/communities.js index e0d51ae2..51970558 100644 --- a/src/communities.js +++ b/src/features/communities.js @@ -1,8 +1,8 @@ import path from 'node:path'; -import { openReadonlyOrFail } from './db.js'; -import { louvainCommunities } from './graph/algorithms/louvain.js'; -import { buildDependencyGraph } from './graph/builders/dependency.js'; -import { paginateResult } from './paginate.js'; +import { openReadonlyOrFail } from '../db/index.js'; +import { louvainCommunities } from '../graph/algorithms/louvain.js'; +import { buildDependencyGraph } from '../graph/builders/dependency.js'; +import { paginateResult } from '../paginate.js'; // ─── Directory Helpers ──────────────────────────────────────────────── diff --git a/src/complexity.js b/src/features/complexity.js similarity index 97% rename from src/complexity.js rename to src/features/complexity.js index fce3d89b..b319c945 100644 --- a/src/complexity.js +++ b/src/features/complexity.js @@ -3,20 +3,20 @@ import path from 'node:path'; import { computeLOCMetrics as _computeLOCMetrics, computeMaintainabilityIndex as _computeMaintainabilityIndex, -} from './ast-analysis/metrics.js'; -import { COMPLEXITY_RULES, HALSTEAD_RULES } from './ast-analysis/rules/index.js'; +} from '../ast-analysis/metrics.js'; +import { COMPLEXITY_RULES, HALSTEAD_RULES } from '../ast-analysis/rules/index.js'; import { findFunctionNode as _findFunctionNode, buildExtensionSet, buildExtToLangMap, -} from './ast-analysis/shared.js'; -import { walkWithVisitors } from './ast-analysis/visitor.js'; -import { createComplexityVisitor } from './ast-analysis/visitors/complexity-visitor.js'; -import { loadConfig } from './config.js'; -import { getFunctionNodeId, openReadonlyOrFail } from './db.js'; -import { isTestFile } from './infrastructure/test-filter.js'; -import { info } from './logger.js'; -import { paginateResult } from './paginate.js'; +} from '../ast-analysis/shared.js'; +import { walkWithVisitors } from '../ast-analysis/visitor.js'; +import { createComplexityVisitor } from '../ast-analysis/visitors/complexity-visitor.js'; +import { loadConfig } from '../config.js'; +import { getFunctionNodeId, openReadonlyOrFail } from '../db/index.js'; +import { isTestFile } from '../infrastructure/test-filter.js'; +import { info } from '../logger.js'; +import { paginateResult } from '../paginate.js'; // Re-export rules for backward compatibility export { COMPLEXITY_RULES, HALSTEAD_RULES }; diff --git a/src/dataflow.js b/src/features/dataflow.js similarity index 97% rename from src/dataflow.js rename to src/features/dataflow.js index 5ed355e1..dbff4cda 100644 --- a/src/dataflow.js +++ b/src/features/dataflow.js @@ -11,19 +11,19 @@ import fs from 'node:fs'; import path from 'node:path'; -import { DATAFLOW_RULES } from './ast-analysis/rules/index.js'; +import { DATAFLOW_RULES } from '../ast-analysis/rules/index.js'; import { makeDataflowRules as _makeDataflowRules, buildExtensionSet, buildExtToLangMap, -} from './ast-analysis/shared.js'; -import { walkWithVisitors } from './ast-analysis/visitor.js'; -import { createDataflowVisitor } from './ast-analysis/visitors/dataflow-visitor.js'; -import { hasDataflowTable, openReadonlyOrFail } from './db.js'; -import { isTestFile } from './infrastructure/test-filter.js'; -import { info } from './logger.js'; -import { paginateResult } from './paginate.js'; -import { ALL_SYMBOL_KINDS, normalizeSymbol } from './queries.js'; +} from '../ast-analysis/shared.js'; +import { walkWithVisitors } from '../ast-analysis/visitor.js'; +import { createDataflowVisitor } from '../ast-analysis/visitors/dataflow-visitor.js'; +import { hasDataflowTable, openReadonlyOrFail } from '../db/index.js'; +import { ALL_SYMBOL_KINDS, normalizeSymbol } from '../domain/queries.js'; +import { isTestFile } from '../infrastructure/test-filter.js'; +import { info } from '../logger.js'; +import { paginateResult } from '../paginate.js'; // Re-export for backward compatibility export { _makeDataflowRules as makeDataflowRules, DATAFLOW_RULES }; diff --git a/src/export.js b/src/features/export.js similarity index 98% rename from src/export.js rename to src/features/export.js index 8dfa768b..61ed15ba 100644 --- a/src/export.js +++ b/src/features/export.js @@ -1,6 +1,6 @@ import path from 'node:path'; -import { isTestFile } from './infrastructure/test-filter.js'; -import { paginateResult } from './paginate.js'; +import { isTestFile } from '../infrastructure/test-filter.js'; +import { paginateResult } from '../paginate.js'; import { renderFileLevelDOT, renderFileLevelGraphML, @@ -10,7 +10,7 @@ import { renderFunctionLevelGraphML, renderFunctionLevelMermaid, renderFunctionLevelNeo4jCSV, -} from './presentation/export.js'; +} from '../presentation/export.js'; const DEFAULT_MIN_CONFIDENCE = 0.5; diff --git a/src/flow.js b/src/features/flow.js similarity index 96% rename from src/flow.js rename to src/features/flow.js index e3af32bd..8f42af3a 100644 --- a/src/flow.js +++ b/src/features/flow.js @@ -5,10 +5,10 @@ * framework entry points (routes, commands, events) through their call chains. */ -import { openReadonlyOrFail } from './db.js'; -import { isTestFile } from './infrastructure/test-filter.js'; -import { paginateResult } from './paginate.js'; -import { CORE_SYMBOL_KINDS, findMatchingNodes } from './queries.js'; +import { openReadonlyOrFail } from '../db/index.js'; +import { CORE_SYMBOL_KINDS, findMatchingNodes } from '../domain/queries.js'; +import { isTestFile } from '../infrastructure/test-filter.js'; +import { paginateResult } from '../paginate.js'; import { FRAMEWORK_ENTRY_PREFIXES } from './structure.js'; /** diff --git a/src/manifesto.js b/src/features/manifesto.js similarity index 98% rename from src/manifesto.js rename to src/features/manifesto.js index 234391fd..c77ae21d 100644 --- a/src/manifesto.js +++ b/src/features/manifesto.js @@ -1,9 +1,9 @@ +import { loadConfig } from '../config.js'; +import { openReadonlyOrFail } from '../db/index.js'; +import { findCycles } from '../domain/graph/cycles.js'; +import { debug } from '../logger.js'; +import { paginateResult } from '../paginate.js'; import { evaluateBoundaries } from './boundaries.js'; -import { loadConfig } from './config.js'; -import { findCycles } from './cycles.js'; -import { openReadonlyOrFail } from './db.js'; -import { debug } from './logger.js'; -import { paginateResult } from './paginate.js'; // ─── Rule Definitions ───────────────────────────────────────────────── diff --git a/src/owners.js b/src/features/owners.js similarity index 98% rename from src/owners.js rename to src/features/owners.js index e0fef2e3..58509ff9 100644 --- a/src/owners.js +++ b/src/features/owners.js @@ -1,7 +1,7 @@ import fs from 'node:fs'; import path from 'node:path'; -import { findDbPath, openReadonlyOrFail } from './db.js'; -import { isTestFile } from './infrastructure/test-filter.js'; +import { findDbPath, openReadonlyOrFail } from '../db/index.js'; +import { isTestFile } from '../infrastructure/test-filter.js'; // ─── CODEOWNERS Parsing ────────────────────────────────────────────── diff --git a/src/sequence.js b/src/features/sequence.js similarity index 96% rename from src/sequence.js rename to src/features/sequence.js index 5d87a1f0..78a3d68a 100644 --- a/src/sequence.js +++ b/src/features/sequence.js @@ -6,10 +6,10 @@ * sequence-diagram conventions. */ -import { findCallees, openReadonlyOrFail } from './db.js'; -import { isTestFile } from './infrastructure/test-filter.js'; -import { paginateResult } from './paginate.js'; -import { findMatchingNodes } from './queries.js'; +import { findCallees, openReadonlyOrFail } from '../db/index.js'; +import { findMatchingNodes } from '../domain/queries.js'; +import { isTestFile } from '../infrastructure/test-filter.js'; +import { paginateResult } from '../paginate.js'; import { FRAMEWORK_ENTRY_PREFIXES } from './structure.js'; // ─── Alias generation ──────────────────────────────────────────────── @@ -286,4 +286,4 @@ export function sequenceData(name, dbPath, opts = {}) { } // Re-export Mermaid renderer from presentation layer -export { sequenceToMermaid } from './presentation/sequence-renderer.js'; +export { sequenceToMermaid } from '../presentation/sequence-renderer.js'; diff --git a/src/snapshot.js b/src/features/snapshot.js similarity index 96% rename from src/snapshot.js rename to src/features/snapshot.js index 0ce12bf5..007549aa 100644 --- a/src/snapshot.js +++ b/src/features/snapshot.js @@ -1,9 +1,9 @@ import fs from 'node:fs'; import path from 'node:path'; import Database from 'better-sqlite3'; -import { findDbPath } from './db.js'; -import { ConfigError, DbError } from './errors.js'; -import { debug } from './logger.js'; +import { findDbPath } from '../db/index.js'; +import { ConfigError, DbError } from '../errors.js'; +import { debug } from '../logger.js'; const NAME_RE = /^[a-zA-Z0-9_-]+$/; diff --git a/src/structure.js b/src/features/structure.js similarity index 98% rename from src/structure.js rename to src/features/structure.js index 8a65125e..7fcd5628 100644 --- a/src/structure.js +++ b/src/features/structure.js @@ -1,9 +1,9 @@ import path from 'node:path'; -import { normalizePath } from './constants.js'; -import { getNodeId, openReadonlyOrFail, testFilterSQL } from './db.js'; -import { isTestFile } from './infrastructure/test-filter.js'; -import { debug } from './logger.js'; -import { paginateResult } from './paginate.js'; +import { normalizePath } from '../constants.js'; +import { getNodeId, openReadonlyOrFail, testFilterSQL } from '../db/index.js'; +import { isTestFile } from '../infrastructure/test-filter.js'; +import { debug } from '../logger.js'; +import { paginateResult } from '../paginate.js'; // ─── Build-time: insert directory nodes, contains edges, and metrics ──── @@ -313,9 +313,9 @@ export function buildStructure(db, fileSymbols, _rootDir, lineCountMap, director // ─── Node role classification ───────────────────────────────────────── // Re-export from classifier for backward compatibility -export { FRAMEWORK_ENTRY_PREFIXES } from './graph/classifiers/roles.js'; +export { FRAMEWORK_ENTRY_PREFIXES } from '../graph/classifiers/roles.js'; -import { classifyRoles } from './graph/classifiers/roles.js'; +import { classifyRoles } from '../graph/classifiers/roles.js'; export function classifyNodeRoles(db) { const rows = db diff --git a/src/triage.js b/src/features/triage.js similarity index 93% rename from src/triage.js rename to src/features/triage.js index 5f02aa9e..5cd9d7a1 100644 --- a/src/triage.js +++ b/src/features/triage.js @@ -1,8 +1,8 @@ -import { findNodesForTriage, openReadonlyOrFail } from './db.js'; -import { DEFAULT_WEIGHTS, scoreRisk } from './graph/classifiers/risk.js'; -import { isTestFile } from './infrastructure/test-filter.js'; -import { warn } from './logger.js'; -import { paginateResult } from './paginate.js'; +import { findNodesForTriage, openReadonlyOrFail } from '../db/index.js'; +import { DEFAULT_WEIGHTS, scoreRisk } from '../graph/classifiers/risk.js'; +import { isTestFile } from '../infrastructure/test-filter.js'; +import { warn } from '../logger.js'; +import { paginateResult } from '../paginate.js'; // ─── Data Function ──────────────────────────────────────────────────── diff --git a/src/viewer.js b/src/features/viewer.js similarity index 96% rename from src/viewer.js rename to src/features/viewer.js index fb438823..96e47e2c 100644 --- a/src/viewer.js +++ b/src/features/viewer.js @@ -1,16 +1,16 @@ import path from 'node:path'; -import { louvainCommunities } from './graph/algorithms/louvain.js'; -import { CodeGraph } from './graph/model.js'; -import { isTestFile } from './infrastructure/test-filter.js'; +import { louvainCommunities } from '../graph/algorithms/louvain.js'; +import { CodeGraph } from '../graph/model.js'; +import { isTestFile } from '../infrastructure/test-filter.js'; import { COMMUNITY_COLORS, DEFAULT_NODE_COLORS, DEFAULT_ROLE_COLORS, -} from './presentation/colors.js'; -import { DEFAULT_CONFIG, renderPlotHTML } from './presentation/viewer.js'; +} from '../presentation/colors.js'; +import { DEFAULT_CONFIG, renderPlotHTML } from '../presentation/viewer.js'; // Re-export presentation utilities for backward compatibility -export { loadPlotConfig } from './presentation/viewer.js'; +export { loadPlotConfig } from '../presentation/viewer.js'; const DEFAULT_MIN_CONFIDENCE = 0.5; diff --git a/src/graph/builders/dependency.js b/src/graph/builders/dependency.js index b0e24f78..a494ef11 100644 --- a/src/graph/builders/dependency.js +++ b/src/graph/builders/dependency.js @@ -3,7 +3,7 @@ * Replaces inline graph construction in cycles.js, communities.js, viewer.js, export.js. */ -import { getCallableNodes, getCallEdges, getFileNodesAll, getImportEdges } from '../../db.js'; +import { getCallableNodes, getCallEdges, getFileNodesAll, getImportEdges } from '../../db/index.js'; import { isTestFile } from '../../infrastructure/test-filter.js'; import { CodeGraph } from '../model.js'; diff --git a/src/index.js b/src/index.js index 576efac6..a50e9017 100644 --- a/src/index.js +++ b/src/index.js @@ -9,41 +9,10 @@ * import { buildGraph, queryNameData, findCycles, exportDOT } from '@optave/codegraph'; */ -export { astQueryData } from './ast.js'; -export { auditData } from './audit.js'; -export { batchData } from './batch.js'; -export { branchCompareData } from './branch-compare.js'; -export { buildGraph } from './builder.js'; -export { cfgData } from './cfg.js'; -export { checkData } from './check.js'; -export { coChangeData } from './cochange.js'; -export { communitiesData } from './communities.js'; -export { complexityData } from './complexity.js'; export { loadConfig } from './config.js'; export { EXTENSIONS, IGNORE_DIRS } from './constants.js'; -export { findCycles } from './cycles.js'; -export { dataflowData } from './dataflow.js'; -export { - buildEmbeddings, - hybridSearchData, - multiSearchData, - searchData, -} from './embeddings/index.js'; -export { - AnalysisError, - BoundaryError, - CodegraphError, - ConfigError, - DbError, - EngineError, - ParseError, - ResolutionError, -} from './errors.js'; -export { exportDOT, exportJSON, exportMermaid } from './export.js'; -export { flowData, listEntryPointsData } from './flow.js'; -export { EVERY_EDGE_KIND, EVERY_SYMBOL_KIND } from './kinds.js'; -export { manifestoData } from './manifesto.js'; -export { ownersData } from './owners.js'; +export { buildGraph } from './domain/graph/builder.js'; +export { findCycles } from './domain/graph/cycles.js'; export { childrenData, contextData, @@ -60,7 +29,38 @@ export { rolesData, statsData, whereData, -} from './queries.js'; -export { sequenceData } from './sequence.js'; -export { hotspotsData, moduleBoundariesData, structureData } from './structure.js'; -export { triageData } from './triage.js'; +} from './domain/queries.js'; +export { + buildEmbeddings, + hybridSearchData, + multiSearchData, + searchData, +} from './domain/search/index.js'; +export { + AnalysisError, + BoundaryError, + CodegraphError, + ConfigError, + DbError, + EngineError, + ParseError, + ResolutionError, +} from './errors.js'; +export { astQueryData } from './features/ast.js'; +export { auditData } from './features/audit.js'; +export { batchData } from './features/batch.js'; +export { branchCompareData } from './features/branch-compare.js'; +export { cfgData } from './features/cfg.js'; +export { checkData } from './features/check.js'; +export { coChangeData } from './features/cochange.js'; +export { communitiesData } from './features/communities.js'; +export { complexityData } from './features/complexity.js'; +export { dataflowData } from './features/dataflow.js'; +export { exportDOT, exportJSON, exportMermaid } from './features/export.js'; +export { flowData, listEntryPointsData } from './features/flow.js'; +export { manifestoData } from './features/manifesto.js'; +export { ownersData } from './features/owners.js'; +export { sequenceData } from './features/sequence.js'; +export { hotspotsData, moduleBoundariesData, structureData } from './features/structure.js'; +export { triageData } from './features/triage.js'; +export { EVERY_EDGE_KIND, EVERY_SYMBOL_KIND } from './kinds.js'; diff --git a/src/mcp.js b/src/mcp.js deleted file mode 100644 index 51d59cd9..00000000 --- a/src/mcp.js +++ /dev/null @@ -1,2 +0,0 @@ -export { startMCPServer } from './mcp/server.js'; -export { buildToolList, TOOLS } from './mcp/tool-registry.js'; diff --git a/src/mcp/server.js b/src/mcp/server.js index 3a39aed8..b5c1ea92 100644 --- a/src/mcp/server.js +++ b/src/mcp/server.js @@ -6,7 +6,7 @@ */ import { createRequire } from 'node:module'; -import { findDbPath } from '../db.js'; +import { findDbPath } from '../db/index.js'; import { CodegraphError, ConfigError } from '../errors.js'; import { MCP_MAX_LIMIT } from '../paginate.js'; import { buildToolList } from './tool-registry.js'; @@ -48,7 +48,7 @@ export async function startMCPServer(customDbPath, options = {}) { async function getQueries() { if (!_queries) { - _queries = await import('../queries.js'); + _queries = await import('../domain/queries.js'); } return _queries; } diff --git a/src/mcp/tool-registry.js b/src/mcp/tool-registry.js index 7247b271..a09beea1 100644 --- a/src/mcp/tool-registry.js +++ b/src/mcp/tool-registry.js @@ -4,8 +4,8 @@ * Owns BASE_TOOLS, LIST_REPOS_TOOL, buildToolList(), and the backward-compatible TOOLS export. */ -import { AST_NODE_KINDS } from '../ast.js'; -import { EVERY_EDGE_KIND, EVERY_SYMBOL_KIND, VALID_ROLES } from '../queries.js'; +import { EVERY_EDGE_KIND, EVERY_SYMBOL_KIND, VALID_ROLES } from '../domain/queries.js'; +import { AST_NODE_KINDS } from '../features/ast.js'; const REPO_PROP = { repo: { diff --git a/src/mcp/tools/ast-query.js b/src/mcp/tools/ast-query.js index 97a5b124..a353e7ea 100644 --- a/src/mcp/tools/ast-query.js +++ b/src/mcp/tools/ast-query.js @@ -3,7 +3,7 @@ import { effectiveLimit, effectiveOffset } from '../middleware.js'; export const name = 'ast_query'; export async function handler(args, ctx) { - const { astQueryData } = await import('../../ast.js'); + const { astQueryData } = await import('../../features/ast.js'); return astQueryData(args.pattern, ctx.dbPath, { kind: args.kind, file: args.file, diff --git a/src/mcp/tools/audit.js b/src/mcp/tools/audit.js index 7dd47b43..c4438ba1 100644 --- a/src/mcp/tools/audit.js +++ b/src/mcp/tools/audit.js @@ -11,7 +11,7 @@ export async function handler(args, ctx) { offset: effectiveOffset(args), }); } - const { auditData } = await import('../../audit.js'); + const { auditData } = await import('../../features/audit.js'); return auditData(args.target, ctx.dbPath, { depth: args.depth, file: args.file, diff --git a/src/mcp/tools/batch-query.js b/src/mcp/tools/batch-query.js index f93f979b..01dc19ba 100644 --- a/src/mcp/tools/batch-query.js +++ b/src/mcp/tools/batch-query.js @@ -1,7 +1,7 @@ export const name = 'batch_query'; export async function handler(args, ctx) { - const { batchData } = await import('../../batch.js'); + const { batchData } = await import('../../features/batch.js'); return batchData(args.command, args.targets, ctx.dbPath, { depth: args.depth, file: args.file, diff --git a/src/mcp/tools/branch-compare.js b/src/mcp/tools/branch-compare.js index 21e363c8..a01022dd 100644 --- a/src/mcp/tools/branch-compare.js +++ b/src/mcp/tools/branch-compare.js @@ -1,7 +1,9 @@ export const name = 'branch_compare'; export async function handler(args, _ctx) { - const { branchCompareData, branchCompareMermaid } = await import('../../branch-compare.js'); + const { branchCompareData, branchCompareMermaid } = await import( + '../../features/branch-compare.js' + ); const bcData = await branchCompareData(args.base, args.target, { depth: args.depth, noTests: args.no_tests, diff --git a/src/mcp/tools/cfg.js b/src/mcp/tools/cfg.js index 07524cf7..bb77c455 100644 --- a/src/mcp/tools/cfg.js +++ b/src/mcp/tools/cfg.js @@ -3,7 +3,7 @@ import { effectiveOffset, MCP_DEFAULTS } from '../middleware.js'; export const name = 'cfg'; export async function handler(args, ctx) { - const { cfgData, cfgToDOT, cfgToMermaid } = await import('../../cfg.js'); + const { cfgData, cfgToDOT, cfgToMermaid } = await import('../../features/cfg.js'); const cfgResult = cfgData(args.name, ctx.dbPath, { file: args.file, kind: args.kind, diff --git a/src/mcp/tools/check.js b/src/mcp/tools/check.js index 48c57e7a..e1e587c6 100644 --- a/src/mcp/tools/check.js +++ b/src/mcp/tools/check.js @@ -6,7 +6,7 @@ export async function handler(args, ctx) { const isDiffMode = args.ref || args.staged; if (!isDiffMode && !args.rules) { - const { manifestoData } = await import('../../manifesto.js'); + const { manifestoData } = await import('../../features/manifesto.js'); return manifestoData(ctx.dbPath, { file: args.file, noTests: args.no_tests, @@ -16,7 +16,7 @@ export async function handler(args, ctx) { }); } - const { checkData } = await import('../../check.js'); + const { checkData } = await import('../../features/check.js'); const checkResult = checkData(ctx.dbPath, { ref: args.ref, staged: args.staged, @@ -29,7 +29,7 @@ export async function handler(args, ctx) { }); if (args.rules) { - const { manifestoData } = await import('../../manifesto.js'); + const { manifestoData } = await import('../../features/manifesto.js'); const manifestoResult = manifestoData(ctx.dbPath, { file: args.file, noTests: args.no_tests, diff --git a/src/mcp/tools/co-changes.js b/src/mcp/tools/co-changes.js index 5e6fcab0..32efa4ac 100644 --- a/src/mcp/tools/co-changes.js +++ b/src/mcp/tools/co-changes.js @@ -3,7 +3,7 @@ import { effectiveLimit, effectiveOffset } from '../middleware.js'; export const name = 'co_changes'; export async function handler(args, ctx) { - const { coChangeData, coChangeTopData } = await import('../../cochange.js'); + const { coChangeData, coChangeTopData } = await import('../../features/cochange.js'); return args.file ? coChangeData(args.file, ctx.dbPath, { limit: effectiveLimit(args, name), diff --git a/src/mcp/tools/code-owners.js b/src/mcp/tools/code-owners.js index 633cc58c..7fe97d7d 100644 --- a/src/mcp/tools/code-owners.js +++ b/src/mcp/tools/code-owners.js @@ -1,7 +1,7 @@ export const name = 'code_owners'; export async function handler(args, ctx) { - const { ownersData } = await import('../../owners.js'); + const { ownersData } = await import('../../features/owners.js'); return ownersData(ctx.dbPath, { file: args.file, owner: args.owner, diff --git a/src/mcp/tools/communities.js b/src/mcp/tools/communities.js index 0c491976..1ec66a0b 100644 --- a/src/mcp/tools/communities.js +++ b/src/mcp/tools/communities.js @@ -3,7 +3,7 @@ import { effectiveLimit, effectiveOffset } from '../middleware.js'; export const name = 'communities'; export async function handler(args, ctx) { - const { communitiesData } = await import('../../communities.js'); + const { communitiesData } = await import('../../features/communities.js'); return communitiesData(ctx.dbPath, { functions: args.functions, resolution: args.resolution, diff --git a/src/mcp/tools/complexity.js b/src/mcp/tools/complexity.js index c5639cb1..3c999773 100644 --- a/src/mcp/tools/complexity.js +++ b/src/mcp/tools/complexity.js @@ -3,7 +3,7 @@ import { effectiveLimit, effectiveOffset } from '../middleware.js'; export const name = 'complexity'; export async function handler(args, ctx) { - const { complexityData } = await import('../../complexity.js'); + const { complexityData } = await import('../../features/complexity.js'); return complexityData(ctx.dbPath, { target: args.name, file: args.file, diff --git a/src/mcp/tools/dataflow.js b/src/mcp/tools/dataflow.js index a3e19198..39d84db9 100644 --- a/src/mcp/tools/dataflow.js +++ b/src/mcp/tools/dataflow.js @@ -5,7 +5,7 @@ export const name = 'dataflow'; export async function handler(args, ctx) { const dfMode = args.mode || 'edges'; if (dfMode === 'impact') { - const { dataflowImpactData } = await import('../../dataflow.js'); + const { dataflowImpactData } = await import('../../features/dataflow.js'); return dataflowImpactData(args.name, ctx.dbPath, { depth: args.depth, file: args.file, @@ -15,7 +15,7 @@ export async function handler(args, ctx) { offset: effectiveOffset(args), }); } - const { dataflowData } = await import('../../dataflow.js'); + const { dataflowData } = await import('../../features/dataflow.js'); return dataflowData(args.name, ctx.dbPath, { file: args.file, kind: args.kind, diff --git a/src/mcp/tools/execution-flow.js b/src/mcp/tools/execution-flow.js index e2932000..d8fefb1c 100644 --- a/src/mcp/tools/execution-flow.js +++ b/src/mcp/tools/execution-flow.js @@ -4,7 +4,7 @@ export const name = 'execution_flow'; export async function handler(args, ctx) { if (args.list) { - const { listEntryPointsData } = await import('../../flow.js'); + const { listEntryPointsData } = await import('../../features/flow.js'); return listEntryPointsData(ctx.dbPath, { noTests: args.no_tests, limit: effectiveLimit(args, name), @@ -14,7 +14,7 @@ export async function handler(args, ctx) { if (!args.name) { return { error: 'Provide a name or set list=true' }; } - const { flowData } = await import('../../flow.js'); + const { flowData } = await import('../../features/flow.js'); return flowData(args.name, ctx.dbPath, { depth: args.depth, file: args.file, diff --git a/src/mcp/tools/export-graph.js b/src/mcp/tools/export-graph.js index 900abb36..e632086f 100644 --- a/src/mcp/tools/export-graph.js +++ b/src/mcp/tools/export-graph.js @@ -1,11 +1,11 @@ -import { findDbPath } from '../../db.js'; +import { findDbPath } from '../../db/index.js'; import { effectiveOffset, MCP_DEFAULTS, MCP_MAX_LIMIT } from '../middleware.js'; export const name = 'export_graph'; export async function handler(args, ctx) { const { exportDOT, exportGraphML, exportGraphSON, exportJSON, exportMermaid, exportNeo4jCSV } = - await import('../../export.js'); + await import('../../features/export.js'); const Database = ctx.getDatabase(); const db = new Database(findDbPath(ctx.dbPath), { readonly: true }); const fileLevel = args.file_level !== false; diff --git a/src/mcp/tools/find-cycles.js b/src/mcp/tools/find-cycles.js index df366101..6a24f581 100644 --- a/src/mcp/tools/find-cycles.js +++ b/src/mcp/tools/find-cycles.js @@ -1,5 +1,5 @@ -import { findCycles } from '../../cycles.js'; -import { findDbPath } from '../../db.js'; +import { findDbPath } from '../../db/index.js'; +import { findCycles } from '../../domain/graph/cycles.js'; export const name = 'find_cycles'; diff --git a/src/mcp/tools/sequence.js b/src/mcp/tools/sequence.js index 4712e015..8209cb36 100644 --- a/src/mcp/tools/sequence.js +++ b/src/mcp/tools/sequence.js @@ -3,7 +3,7 @@ import { effectiveOffset, MCP_DEFAULTS } from '../middleware.js'; export const name = 'sequence'; export async function handler(args, ctx) { - const { sequenceData, sequenceToMermaid } = await import('../../sequence.js'); + const { sequenceData, sequenceToMermaid } = await import('../../features/sequence.js'); const seqResult = sequenceData(args.name, ctx.dbPath, { depth: args.depth, file: args.file, diff --git a/src/mcp/tools/structure.js b/src/mcp/tools/structure.js index 27aba582..51dc453f 100644 --- a/src/mcp/tools/structure.js +++ b/src/mcp/tools/structure.js @@ -3,7 +3,7 @@ import { effectiveLimit, effectiveOffset } from '../middleware.js'; export const name = 'structure'; export async function handler(args, ctx) { - const { structureData } = await import('../../structure.js'); + const { structureData } = await import('../../features/structure.js'); return structureData(ctx.dbPath, { directory: args.directory, depth: args.depth, diff --git a/src/mcp/tools/triage.js b/src/mcp/tools/triage.js index 2d84efa6..b153a76b 100644 --- a/src/mcp/tools/triage.js +++ b/src/mcp/tools/triage.js @@ -4,7 +4,7 @@ export const name = 'triage'; export async function handler(args, ctx) { if (args.level === 'file' || args.level === 'directory') { - const { hotspotsData } = await import('../../structure.js'); + const { hotspotsData } = await import('../../features/structure.js'); const TRIAGE_TO_HOTSPOT = { risk: 'fan-in', complexity: 'density', @@ -20,7 +20,7 @@ export async function handler(args, ctx) { noTests: args.no_tests, }); } - const { triageData } = await import('../../triage.js'); + const { triageData } = await import('../../features/triage.js'); return triageData(ctx.dbPath, { sort: args.sort, minScore: args.min_score, diff --git a/src/queries-cli.js b/src/presentation/queries-cli.js similarity index 99% rename from src/queries-cli.js rename to src/presentation/queries-cli.js index f4981a31..8eab363e 100644 --- a/src/queries-cli.js +++ b/src/presentation/queries-cli.js @@ -7,7 +7,6 @@ */ import path from 'node:path'; -import { outputResult } from './infrastructure/result-formatter.js'; import { childrenData, contextData, @@ -26,7 +25,8 @@ import { rolesData, statsData, whereData, -} from './queries.js'; +} from '../domain/queries.js'; +import { outputResult } from '../infrastructure/result-formatter.js'; // ─── symbolPath ───────────────────────────────────────────────────────── diff --git a/src/shared/generators.js b/src/shared/generators.js index 56c58b0d..93753dbd 100644 --- a/src/shared/generators.js +++ b/src/shared/generators.js @@ -1,4 +1,4 @@ -import { iterateFunctionNodes, openReadonlyOrFail } from '../db.js'; +import { iterateFunctionNodes, openReadonlyOrFail } from '../db/index.js'; import { isTestFile } from '../infrastructure/test-filter.js'; import { ALL_SYMBOL_KINDS } from '../kinds.js'; diff --git a/src/shared/hierarchy.js b/src/shared/hierarchy.js index 7be0eaf3..d2d511fc 100644 --- a/src/shared/hierarchy.js +++ b/src/shared/hierarchy.js @@ -1,4 +1,4 @@ -import { getClassHierarchy } from '../db.js'; +import { getClassHierarchy } from '../db/index.js'; export function resolveMethodViaHierarchy(db, methodName) { const methods = db diff --git a/tests/builder/collect-files.test.js b/tests/builder/collect-files.test.js index 709ef352..4d4955c5 100644 --- a/tests/builder/collect-files.test.js +++ b/tests/builder/collect-files.test.js @@ -5,8 +5,8 @@ import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { afterAll, beforeAll, describe, expect, it } from 'vitest'; -import { PipelineContext } from '../../src/builder/context.js'; -import { collectFiles } from '../../src/builder/stages/collect-files.js'; +import { PipelineContext } from '../../src/domain/graph/builder/context.js'; +import { collectFiles } from '../../src/domain/graph/builder/stages/collect-files.js'; let tmpDir; diff --git a/tests/builder/context.test.js b/tests/builder/context.test.js index d691ab5a..360d287d 100644 --- a/tests/builder/context.test.js +++ b/tests/builder/context.test.js @@ -2,7 +2,7 @@ * Unit tests for PipelineContext. */ import { describe, expect, it } from 'vitest'; -import { PipelineContext } from '../../src/builder/context.js'; +import { PipelineContext } from '../../src/domain/graph/builder/context.js'; describe('PipelineContext', () => { it('creates an instance with default values', () => { diff --git a/tests/builder/detect-changes.test.js b/tests/builder/detect-changes.test.js index ec0734d3..f6a671e3 100644 --- a/tests/builder/detect-changes.test.js +++ b/tests/builder/detect-changes.test.js @@ -5,9 +5,9 @@ import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { afterAll, beforeAll, describe, expect, it } from 'vitest'; -import { PipelineContext } from '../../src/builder/context.js'; -import { detectChanges } from '../../src/builder/stages/detect-changes.js'; -import { closeDb, initSchema, openDb } from '../../src/db.js'; +import { closeDb, initSchema, openDb } from '../../src/db/index.js'; +import { PipelineContext } from '../../src/domain/graph/builder/context.js'; +import { detectChanges } from '../../src/domain/graph/builder/stages/detect-changes.js'; import { writeJournalHeader } from '../../src/journal.js'; let tmpDir; diff --git a/tests/builder/pipeline.test.js b/tests/builder/pipeline.test.js index d6b8b76b..2fe0c283 100644 --- a/tests/builder/pipeline.test.js +++ b/tests/builder/pipeline.test.js @@ -8,7 +8,7 @@ import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { afterAll, beforeAll, describe, expect, it } from 'vitest'; -import { buildGraph } from '../../src/builder/pipeline.js'; +import { buildGraph } from '../../src/domain/graph/builder/pipeline.js'; const FIXTURE_DIR = path.join(import.meta.dirname, '..', 'fixtures', 'sample-project'); let tmpDir; @@ -73,7 +73,7 @@ describe('buildGraph pipeline', () => { it('exports from barrel are identical to direct import', async () => { // Verify the barrel re-export works - const { buildGraph: fromBarrel } = await import('../../src/builder.js'); + const { buildGraph: fromBarrel } = await import('../../src/domain/graph/builder.js'); expect(fromBarrel).toBe(buildGraph); }); }); diff --git a/tests/engines/dataflow-parity.test.js b/tests/engines/dataflow-parity.test.js index ae08b92a..1559243a 100644 --- a/tests/engines/dataflow-parity.test.js +++ b/tests/engines/dataflow-parity.test.js @@ -12,7 +12,7 @@ */ import { beforeAll, describe, expect, it } from 'vitest'; -import { extractDataflow } from '../../src/dataflow.js'; +import { extractDataflow } from '../../src/features/dataflow.js'; import { isNativeAvailable } from '../../src/native.js'; import { createParsers, getParser } from '../../src/parser.js'; diff --git a/tests/graph/builders/dependency.test.js b/tests/graph/builders/dependency.test.js index 18d46a77..6afb68de 100644 --- a/tests/graph/builders/dependency.test.js +++ b/tests/graph/builders/dependency.test.js @@ -1,6 +1,6 @@ import Database from 'better-sqlite3'; import { describe, expect, it } from 'vitest'; -import { initSchema } from '../../../src/db.js'; +import { initSchema } from '../../../src/db/index.js'; import { buildDependencyGraph } from '../../../src/graph/builders/dependency.js'; function createTestDb() { diff --git a/tests/graph/builders/structure.test.js b/tests/graph/builders/structure.test.js index 6d700b8a..dee6395f 100644 --- a/tests/graph/builders/structure.test.js +++ b/tests/graph/builders/structure.test.js @@ -1,6 +1,6 @@ import Database from 'better-sqlite3'; import { describe, expect, it } from 'vitest'; -import { initSchema } from '../../../src/db.js'; +import { initSchema } from '../../../src/db/index.js'; import { buildStructureGraph } from '../../../src/graph/builders/structure.js'; function createTestDb() { diff --git a/tests/graph/builders/temporal.test.js b/tests/graph/builders/temporal.test.js index be650681..cd602b0a 100644 --- a/tests/graph/builders/temporal.test.js +++ b/tests/graph/builders/temporal.test.js @@ -1,6 +1,6 @@ import Database from 'better-sqlite3'; import { describe, expect, it } from 'vitest'; -import { initSchema } from '../../../src/db.js'; +import { initSchema } from '../../../src/db/index.js'; import { buildTemporalGraph } from '../../../src/graph/builders/temporal.js'; function createTestDb() { diff --git a/tests/graph/cycles.test.js b/tests/graph/cycles.test.js index 915baf39..8f6946e3 100644 --- a/tests/graph/cycles.test.js +++ b/tests/graph/cycles.test.js @@ -4,8 +4,8 @@ import Database from 'better-sqlite3'; import { describe, expect, it } from 'vitest'; -import { findCycles, findCyclesJS } from '../../src/cycles.js'; -import { initSchema } from '../../src/db.js'; +import { initSchema } from '../../src/db/index.js'; +import { findCycles, findCyclesJS } from '../../src/domain/graph/cycles.js'; import { isNativeAvailable, loadNative } from '../../src/native.js'; const hasNative = isNativeAvailable(); @@ -123,13 +123,13 @@ describe('findCycles — function-level', () => { describe('formatCycles', () => { it('returns no-cycles message for empty array', () => { - const { formatCycles } = require('../../src/cycles.js'); + const { formatCycles } = require('../../src/domain/graph/cycles.js'); const output = formatCycles([]); expect(output.toLowerCase()).toMatch(/no.*circular/); }); it('formats a single cycle with all member files', () => { - const { formatCycles } = require('../../src/cycles.js'); + const { formatCycles } = require('../../src/domain/graph/cycles.js'); const output = formatCycles([['a.js', 'b.js']]); expect(output).toContain('a.js'); expect(output).toContain('b.js'); @@ -137,7 +137,7 @@ describe('formatCycles', () => { }); it('formats multiple cycles with distinct labels', () => { - const { formatCycles } = require('../../src/cycles.js'); + const { formatCycles } = require('../../src/domain/graph/cycles.js'); const output = formatCycles([ ['a.js', 'b.js'], ['x.js', 'y.js', 'z.js'], diff --git a/tests/graph/export.test.js b/tests/graph/export.test.js index 3a12970e..fa3d4e11 100644 --- a/tests/graph/export.test.js +++ b/tests/graph/export.test.js @@ -4,7 +4,7 @@ import Database from 'better-sqlite3'; import { describe, expect, it } from 'vitest'; -import { initSchema } from '../../src/db.js'; +import { initSchema } from '../../src/db/index.js'; import { exportDOT, exportGraphML, @@ -12,7 +12,7 @@ import { exportJSON, exportMermaid, exportNeo4jCSV, -} from '../../src/export.js'; +} from '../../src/features/export.js'; function createTestDb() { const db = new Database(':memory:'); diff --git a/tests/graph/viewer.test.js b/tests/graph/viewer.test.js index 0ace2b01..95a67190 100644 --- a/tests/graph/viewer.test.js +++ b/tests/graph/viewer.test.js @@ -4,8 +4,8 @@ import Database from 'better-sqlite3'; import { describe, expect, it } from 'vitest'; -import { initSchema } from '../../src/db.js'; -import { generatePlotHTML, loadPlotConfig, prepareGraphData } from '../../src/viewer.js'; +import { initSchema } from '../../src/db/index.js'; +import { generatePlotHTML, loadPlotConfig, prepareGraphData } from '../../src/features/viewer.js'; function createTestDb() { const db = new Database(':memory:'); diff --git a/tests/integration/ast.test.js b/tests/integration/ast.test.js index 60cee696..706684d9 100644 --- a/tests/integration/ast.test.js +++ b/tests/integration/ast.test.js @@ -9,8 +9,8 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { AST_NODE_KINDS, astQueryData } from '../../src/ast.js'; -import { initSchema } from '../../src/db.js'; +import { initSchema } from '../../src/db/index.js'; +import { AST_NODE_KINDS, astQueryData } from '../../src/features/ast.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/integration/audit.test.js b/tests/integration/audit.test.js index 1664f7df..f6d00768 100644 --- a/tests/integration/audit.test.js +++ b/tests/integration/audit.test.js @@ -4,8 +4,8 @@ import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { auditData } from '../../src/audit.js'; -import { initSchema } from '../../src/db.js'; +import { initSchema } from '../../src/db/index.js'; +import { auditData } from '../../src/features/audit.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/integration/batch.test.js b/tests/integration/batch.test.js index a4c5e6db..e903645c 100644 --- a/tests/integration/batch.test.js +++ b/tests/integration/batch.test.js @@ -17,8 +17,13 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { BATCH_COMMANDS, batchData, multiBatchData, splitTargets } from '../../src/batch.js'; -import { initSchema } from '../../src/db.js'; +import { initSchema } from '../../src/db/index.js'; +import { + BATCH_COMMANDS, + batchData, + multiBatchData, + splitTargets, +} from '../../src/features/batch.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/integration/branch-compare.test.js b/tests/integration/branch-compare.test.js index 46c56c3c..0a276117 100644 --- a/tests/integration/branch-compare.test.js +++ b/tests/integration/branch-compare.test.js @@ -10,7 +10,7 @@ import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { branchCompareData, branchCompareMermaid } from '../../src/branch-compare.js'; +import { branchCompareData, branchCompareMermaid } from '../../src/features/branch-compare.js'; let tmpDir; diff --git a/tests/integration/build-parity.test.js b/tests/integration/build-parity.test.js index d2f2e8a8..18c710e2 100644 --- a/tests/integration/build-parity.test.js +++ b/tests/integration/build-parity.test.js @@ -12,7 +12,7 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, it } from 'vitest'; -import { buildGraph } from '../../src/builder.js'; +import { buildGraph } from '../../src/domain/graph/builder.js'; import { isNativeAvailable } from '../../src/native.js'; const FIXTURE_DIR = path.join(import.meta.dirname, '..', 'fixtures', 'sample-project'); diff --git a/tests/integration/build.test.js b/tests/integration/build.test.js index 3669cdb3..8af7600d 100644 --- a/tests/integration/build.test.js +++ b/tests/integration/build.test.js @@ -8,8 +8,8 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { buildGraph } from '../../src/builder.js'; -import { closeDb, openDb, setBuildMeta } from '../../src/db.js'; +import { closeDb, openDb, setBuildMeta } from '../../src/db/index.js'; +import { buildGraph } from '../../src/domain/graph/builder.js'; import { JOURNAL_FILENAME, writeJournalHeader } from '../../src/journal.js'; // ES-module versions of the sample-project fixture so the parser diff --git a/tests/integration/cfg.test.js b/tests/integration/cfg.test.js index 3fdbeab0..548042ea 100644 --- a/tests/integration/cfg.test.js +++ b/tests/integration/cfg.test.js @@ -9,8 +9,8 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { cfgData, cfgToDOT, cfgToMermaid } from '../../src/cfg.js'; -import { initSchema } from '../../src/db.js'; +import { initSchema } from '../../src/db/index.js'; +import { cfgData, cfgToDOT, cfgToMermaid } from '../../src/features/cfg.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/integration/check.test.js b/tests/integration/check.test.js index feb5921b..1e339188 100644 --- a/tests/integration/check.test.js +++ b/tests/integration/check.test.js @@ -10,6 +10,7 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; +import { initSchema } from '../../src/db/index.js'; import { checkData, checkMaxBlastRadius, @@ -17,8 +18,7 @@ import { checkNoNewCycles, checkNoSignatureChanges, parseDiffOutput, -} from '../../src/check.js'; -import { initSchema } from '../../src/db.js'; +} from '../../src/features/check.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/integration/cochange.test.js b/tests/integration/cochange.test.js index e1a9ad51..4b60e893 100644 --- a/tests/integration/cochange.test.js +++ b/tests/integration/cochange.test.js @@ -12,13 +12,13 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; +import { initSchema } from '../../src/db/index.js'; import { coChangeData, coChangeTopData, computeCoChanges, scanGitHistory, -} from '../../src/cochange.js'; -import { initSchema } from '../../src/db.js'; +} from '../../src/features/cochange.js'; // ─── A. computeCoChanges (pure logic) ──────────────────────────────── diff --git a/tests/integration/communities.test.js b/tests/integration/communities.test.js index cdd1224e..3981beb2 100644 --- a/tests/integration/communities.test.js +++ b/tests/integration/communities.test.js @@ -14,8 +14,8 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { communitiesData, communitySummaryForStats } from '../../src/communities.js'; -import { initSchema } from '../../src/db.js'; +import { initSchema } from '../../src/db/index.js'; +import { communitiesData, communitySummaryForStats } from '../../src/features/communities.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/integration/complexity.test.js b/tests/integration/complexity.test.js index 5ec66107..52454bd9 100644 --- a/tests/integration/complexity.test.js +++ b/tests/integration/complexity.test.js @@ -10,9 +10,9 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest'; -import { complexityData } from '../../src/complexity.js'; import { loadConfig } from '../../src/config.js'; -import { initSchema } from '../../src/db.js'; +import { initSchema } from '../../src/db/index.js'; +import { complexityData } from '../../src/features/complexity.js'; vi.mock('../../src/config.js', () => ({ loadConfig: vi.fn(() => ({})), diff --git a/tests/integration/context.test.js b/tests/integration/context.test.js index fd2779a7..e9b1afc0 100644 --- a/tests/integration/context.test.js +++ b/tests/integration/context.test.js @@ -10,8 +10,8 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { initSchema } from '../../src/db.js'; -import { contextData } from '../../src/queries.js'; +import { initSchema } from '../../src/db/index.js'; +import { contextData } from '../../src/domain/queries.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/integration/dataflow.test.js b/tests/integration/dataflow.test.js index 910dca76..1659fdce 100644 --- a/tests/integration/dataflow.test.js +++ b/tests/integration/dataflow.test.js @@ -16,8 +16,8 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { dataflowData, dataflowImpactData, dataflowPathData } from '../../src/dataflow.js'; -import { initSchema } from '../../src/db.js'; +import { initSchema } from '../../src/db/index.js'; +import { dataflowData, dataflowImpactData, dataflowPathData } from '../../src/features/dataflow.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/integration/exports.test.js b/tests/integration/exports.test.js index b7793c86..623f19b6 100644 --- a/tests/integration/exports.test.js +++ b/tests/integration/exports.test.js @@ -28,8 +28,8 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { initSchema } from '../../src/db.js'; -import { exportsData } from '../../src/queries.js'; +import { initSchema } from '../../src/db/index.js'; +import { exportsData } from '../../src/domain/queries.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/integration/flow.test.js b/tests/integration/flow.test.js index 0ff8e5f2..97d83515 100644 --- a/tests/integration/flow.test.js +++ b/tests/integration/flow.test.js @@ -17,9 +17,9 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { initSchema } from '../../src/db.js'; -import { entryPointType, flowData, listEntryPointsData } from '../../src/flow.js'; -import { classifyNodeRoles, FRAMEWORK_ENTRY_PREFIXES } from '../../src/structure.js'; +import { initSchema } from '../../src/db/index.js'; +import { entryPointType, flowData, listEntryPointsData } from '../../src/features/flow.js'; +import { classifyNodeRoles, FRAMEWORK_ENTRY_PREFIXES } from '../../src/features/structure.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/integration/incremental-parity.test.js b/tests/integration/incremental-parity.test.js index a109471f..555975b8 100644 --- a/tests/integration/incremental-parity.test.js +++ b/tests/integration/incremental-parity.test.js @@ -11,7 +11,7 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, it } from 'vitest'; -import { buildGraph } from '../../src/builder.js'; +import { buildGraph } from '../../src/domain/graph/builder.js'; const FIXTURE_DIR = path.join(import.meta.dirname, '..', 'fixtures', 'barrel-project'); diff --git a/tests/integration/manifesto.test.js b/tests/integration/manifesto.test.js index 755f240d..d9b5d93f 100644 --- a/tests/integration/manifesto.test.js +++ b/tests/integration/manifesto.test.js @@ -10,8 +10,8 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { initSchema } from '../../src/db.js'; -import { manifestoData, RULE_DEFS } from '../../src/manifesto.js'; +import { initSchema } from '../../src/db/index.js'; +import { manifestoData, RULE_DEFS } from '../../src/features/manifesto.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/integration/owners.test.js b/tests/integration/owners.test.js index 35ad147c..7d26f958 100644 --- a/tests/integration/owners.test.js +++ b/tests/integration/owners.test.js @@ -3,8 +3,8 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { initSchema } from '../../src/db.js'; -import { ownersData, ownersForFiles } from '../../src/owners.js'; +import { initSchema } from '../../src/db/index.js'; +import { ownersData, ownersForFiles } from '../../src/features/owners.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/integration/pagination.test.js b/tests/integration/pagination.test.js index f938ee1c..e57f9c19 100644 --- a/tests/integration/pagination.test.js +++ b/tests/integration/pagination.test.js @@ -18,16 +18,7 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { initSchema } from '../../src/db.js'; -import { exportDOT, exportJSON, exportMermaid } from '../../src/export.js'; -import { listEntryPointsData } from '../../src/flow.js'; -import { - MCP_DEFAULTS, - MCP_MAX_LIMIT, - paginate, - paginateResult, - printNdjson, -} from '../../src/paginate.js'; +import { initSchema } from '../../src/db/index.js'; import { contextData, explainData, @@ -41,7 +32,16 @@ import { queryNameData, rolesData, whereData, -} from '../../src/queries.js'; +} from '../../src/domain/queries.js'; +import { exportDOT, exportJSON, exportMermaid } from '../../src/features/export.js'; +import { listEntryPointsData } from '../../src/features/flow.js'; +import { + MCP_DEFAULTS, + MCP_MAX_LIMIT, + paginate, + paginateResult, + printNdjson, +} from '../../src/paginate.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/integration/qualified-names.test.js b/tests/integration/qualified-names.test.js index 0ea987a2..3fc1beae 100644 --- a/tests/integration/qualified-names.test.js +++ b/tests/integration/qualified-names.test.js @@ -2,10 +2,14 @@ import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { afterAll, beforeAll, describe, expect, it } from 'vitest'; -import { buildGraph } from '../../src/builder.js'; -import { findNodeByQualifiedName, findNodesByScope, openReadonlyOrFail } from '../../src/db.js'; +import { + findNodeByQualifiedName, + findNodesByScope, + openReadonlyOrFail, +} from '../../src/db/index.js'; +import { buildGraph } from '../../src/domain/graph/builder.js'; +import { childrenData } from '../../src/domain/queries.js'; import { pythonVisibility } from '../../src/extractors/helpers.js'; -import { childrenData } from '../../src/queries.js'; // Fixture: a small project with classes, methods, and visibility modifiers const FIXTURE_FILES = { diff --git a/tests/integration/queries.test.js b/tests/integration/queries.test.js index 788bb117..282ee84e 100644 --- a/tests/integration/queries.test.js +++ b/tests/integration/queries.test.js @@ -24,7 +24,7 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { initSchema } from '../../src/db.js'; +import { initSchema } from '../../src/db/index.js'; import { diffImpactData, explainData, @@ -39,7 +39,7 @@ import { queryNameData, statsData, whereData, -} from '../../src/queries.js'; +} from '../../src/domain/queries.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/integration/roles.test.js b/tests/integration/roles.test.js index c76b5719..2a92b16a 100644 --- a/tests/integration/roles.test.js +++ b/tests/integration/roles.test.js @@ -12,15 +12,15 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { initSchema } from '../../src/db.js'; +import { initSchema } from '../../src/db/index.js'; import { explainData, listFunctionsData, rolesData, statsData, whereData, -} from '../../src/queries.js'; -import { classifyNodeRoles } from '../../src/structure.js'; +} from '../../src/domain/queries.js'; +import { classifyNodeRoles } from '../../src/features/structure.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/integration/scoped-rebuild.test.js b/tests/integration/scoped-rebuild.test.js index fd4d8a12..9b6d699b 100644 --- a/tests/integration/scoped-rebuild.test.js +++ b/tests/integration/scoped-rebuild.test.js @@ -10,7 +10,7 @@ import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { buildGraph } from '../../src/builder.js'; +import { buildGraph } from '../../src/domain/graph/builder.js'; const FIXTURE_DIR = path.join(import.meta.dirname, '..', 'fixtures', 'sample-project'); diff --git a/tests/integration/sequence.test.js b/tests/integration/sequence.test.js index 6d3367e4..fade9cca 100644 --- a/tests/integration/sequence.test.js +++ b/tests/integration/sequence.test.js @@ -19,8 +19,8 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { initSchema } from '../../src/db.js'; -import { sequenceData, sequenceToMermaid } from '../../src/sequence.js'; +import { initSchema } from '../../src/db/index.js'; +import { sequenceData, sequenceToMermaid } from '../../src/features/sequence.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/integration/structure.test.js b/tests/integration/structure.test.js index 5dae68f6..fe97a118 100644 --- a/tests/integration/structure.test.js +++ b/tests/integration/structure.test.js @@ -8,8 +8,8 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { buildGraph } from '../../src/builder.js'; -import { hotspotsData, moduleBoundariesData, structureData } from '../../src/structure.js'; +import { buildGraph } from '../../src/domain/graph/builder.js'; +import { hotspotsData, moduleBoundariesData, structureData } from '../../src/features/structure.js'; // Multi-directory fixture with cross-directory imports const FIXTURE_FILES = { diff --git a/tests/integration/triage.test.js b/tests/integration/triage.test.js index f9727d5b..47192cf3 100644 --- a/tests/integration/triage.test.js +++ b/tests/integration/triage.test.js @@ -10,7 +10,7 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { triageData } from '../../src/triage.js'; +import { triageData } from '../../src/features/triage.js'; // ─── Helpers ─────────────────────────────────────────────────────────── @@ -57,7 +57,7 @@ let tmpDir, dbPath; let fnHigh, fnMed, fnLow, fnTest, fnClass; beforeAll(async () => { - const { initSchema } = await import('../../src/db.js'); + const { initSchema } = await import('../../src/db/index.js'); tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegraph-triage-')); fs.mkdirSync(path.join(tmpDir, '.codegraph')); @@ -286,7 +286,7 @@ describe('triage', () => { fs.mkdirSync(path.join(sparseDir, '.codegraph')); const sparseDbPath = path.join(sparseDir, '.codegraph', 'graph.db'); - const { initSchema } = await import('../../src/db.js'); + const { initSchema } = await import('../../src/db/index.js'); const db = new Database(sparseDbPath); db.pragma('journal_mode = WAL'); initSchema(db); diff --git a/tests/parsers/ast-all-langs.test.js b/tests/parsers/ast-all-langs.test.js index 8021aeb0..615c9304 100644 --- a/tests/parsers/ast-all-langs.test.js +++ b/tests/parsers/ast-all-langs.test.js @@ -12,8 +12,8 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { buildAstNodes } from '../../src/ast.js'; -import { initSchema } from '../../src/db.js'; +import { initSchema } from '../../src/db/index.js'; +import { buildAstNodes } from '../../src/features/ast.js'; import { loadNative } from '../../src/native.js'; import { parseFilesAuto } from '../../src/parser.js'; diff --git a/tests/parsers/ast-nodes.test.js b/tests/parsers/ast-nodes.test.js index 93b1e1be..894d9d1a 100644 --- a/tests/parsers/ast-nodes.test.js +++ b/tests/parsers/ast-nodes.test.js @@ -10,8 +10,8 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { buildAstNodes } from '../../src/ast.js'; -import { initSchema } from '../../src/db.js'; +import { initSchema } from '../../src/db/index.js'; +import { buildAstNodes } from '../../src/features/ast.js'; import { loadNative } from '../../src/native.js'; import { parseFilesAuto } from '../../src/parser.js'; diff --git a/tests/parsers/cfg-all-langs.test.js b/tests/parsers/cfg-all-langs.test.js index d8dd1de7..f19ab8ec 100644 --- a/tests/parsers/cfg-all-langs.test.js +++ b/tests/parsers/cfg-all-langs.test.js @@ -13,9 +13,9 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { buildCFGData, buildFunctionCFG } from '../../src/cfg.js'; -import { COMPLEXITY_RULES, findFunctionNode } from '../../src/complexity.js'; -import { initSchema } from '../../src/db.js'; +import { initSchema } from '../../src/db/index.js'; +import { buildCFGData, buildFunctionCFG } from '../../src/features/cfg.js'; +import { COMPLEXITY_RULES, findFunctionNode } from '../../src/features/complexity.js'; import { loadNative } from '../../src/native.js'; import { createParsers, getParser, parseFilesAuto } from '../../src/parser.js'; diff --git a/tests/parsers/dataflow-csharp.test.js b/tests/parsers/dataflow-csharp.test.js index 2e3249ad..6744d1c9 100644 --- a/tests/parsers/dataflow-csharp.test.js +++ b/tests/parsers/dataflow-csharp.test.js @@ -2,7 +2,7 @@ * Unit tests for extractDataflow() against parsed C# ASTs. */ import { beforeAll, describe, expect, it } from 'vitest'; -import { extractDataflow } from '../../src/dataflow.js'; +import { extractDataflow } from '../../src/features/dataflow.js'; import { createParsers } from '../../src/parser.js'; describe('extractDataflow — C#', () => { diff --git a/tests/parsers/dataflow-go.test.js b/tests/parsers/dataflow-go.test.js index 040f671a..674b8b3c 100644 --- a/tests/parsers/dataflow-go.test.js +++ b/tests/parsers/dataflow-go.test.js @@ -2,7 +2,7 @@ * Unit tests for extractDataflow() against parsed Go ASTs. */ import { beforeAll, describe, expect, it } from 'vitest'; -import { extractDataflow } from '../../src/dataflow.js'; +import { extractDataflow } from '../../src/features/dataflow.js'; import { createParsers } from '../../src/parser.js'; describe('extractDataflow — Go', () => { diff --git a/tests/parsers/dataflow-java.test.js b/tests/parsers/dataflow-java.test.js index b62c999f..24175ea0 100644 --- a/tests/parsers/dataflow-java.test.js +++ b/tests/parsers/dataflow-java.test.js @@ -2,7 +2,7 @@ * Unit tests for extractDataflow() against parsed Java ASTs. */ import { beforeAll, describe, expect, it } from 'vitest'; -import { extractDataflow } from '../../src/dataflow.js'; +import { extractDataflow } from '../../src/features/dataflow.js'; import { createParsers } from '../../src/parser.js'; describe('extractDataflow — Java', () => { diff --git a/tests/parsers/dataflow-javascript.test.js b/tests/parsers/dataflow-javascript.test.js index e4c2d58d..df9d1dfb 100644 --- a/tests/parsers/dataflow-javascript.test.js +++ b/tests/parsers/dataflow-javascript.test.js @@ -2,7 +2,7 @@ * Unit tests for extractDataflow() against parsed JS/TS ASTs. */ import { beforeAll, describe, expect, it } from 'vitest'; -import { extractDataflow } from '../../src/dataflow.js'; +import { extractDataflow } from '../../src/features/dataflow.js'; import { createParsers } from '../../src/parser.js'; describe('extractDataflow — JavaScript', () => { diff --git a/tests/parsers/dataflow-php.test.js b/tests/parsers/dataflow-php.test.js index 8d1d4cb3..ae337942 100644 --- a/tests/parsers/dataflow-php.test.js +++ b/tests/parsers/dataflow-php.test.js @@ -2,7 +2,7 @@ * Unit tests for extractDataflow() against parsed PHP ASTs. */ import { beforeAll, describe, expect, it } from 'vitest'; -import { extractDataflow } from '../../src/dataflow.js'; +import { extractDataflow } from '../../src/features/dataflow.js'; import { createParsers } from '../../src/parser.js'; describe('extractDataflow — PHP', () => { diff --git a/tests/parsers/dataflow-python.test.js b/tests/parsers/dataflow-python.test.js index 0fdf1c74..4a83874e 100644 --- a/tests/parsers/dataflow-python.test.js +++ b/tests/parsers/dataflow-python.test.js @@ -2,7 +2,7 @@ * Unit tests for extractDataflow() against parsed Python ASTs. */ import { beforeAll, describe, expect, it } from 'vitest'; -import { extractDataflow } from '../../src/dataflow.js'; +import { extractDataflow } from '../../src/features/dataflow.js'; import { createParsers } from '../../src/parser.js'; describe('extractDataflow — Python', () => { diff --git a/tests/parsers/dataflow-ruby.test.js b/tests/parsers/dataflow-ruby.test.js index 110bf2ab..69aa67db 100644 --- a/tests/parsers/dataflow-ruby.test.js +++ b/tests/parsers/dataflow-ruby.test.js @@ -2,7 +2,7 @@ * Unit tests for extractDataflow() against parsed Ruby ASTs. */ import { beforeAll, describe, expect, it } from 'vitest'; -import { extractDataflow } from '../../src/dataflow.js'; +import { extractDataflow } from '../../src/features/dataflow.js'; import { createParsers } from '../../src/parser.js'; describe('extractDataflow — Ruby', () => { diff --git a/tests/parsers/dataflow-rust.test.js b/tests/parsers/dataflow-rust.test.js index c1437146..5d771740 100644 --- a/tests/parsers/dataflow-rust.test.js +++ b/tests/parsers/dataflow-rust.test.js @@ -2,7 +2,7 @@ * Unit tests for extractDataflow() against parsed Rust ASTs. */ import { beforeAll, describe, expect, it } from 'vitest'; -import { extractDataflow } from '../../src/dataflow.js'; +import { extractDataflow } from '../../src/features/dataflow.js'; import { createParsers } from '../../src/parser.js'; describe('extractDataflow — Rust', () => { diff --git a/tests/resolution/parity.test.js b/tests/resolution/parity.test.js index 08adc839..444c4040 100644 --- a/tests/resolution/parity.test.js +++ b/tests/resolution/parity.test.js @@ -6,7 +6,6 @@ import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { describe, expect, it } from 'vitest'; -import { isNativeAvailable, loadNative } from '../../src/native.js'; import { computeConfidence, computeConfidenceJS, @@ -14,7 +13,8 @@ import { resolveImportPath, resolveImportPathJS, resolveImportsBatch, -} from '../../src/resolve.js'; +} from '../../src/domain/graph/resolve.js'; +import { isNativeAvailable, loadNative } from '../../src/native.js'; const hasNative = isNativeAvailable(); diff --git a/tests/search/embedder-search.test.js b/tests/search/embedder-search.test.js index 86fe5543..f873a33b 100644 --- a/tests/search/embedder-search.test.js +++ b/tests/search/embedder-search.test.js @@ -3,7 +3,7 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest'; -import { initSchema } from '../../src/db.js'; +import { initSchema } from '../../src/db/index.js'; // ─── Mock setup ──────────────────────────────────────────────────────── @@ -38,7 +38,7 @@ import { multiSearchData, search, searchData, -} from '../../src/embeddings/index.js'; +} from '../../src/domain/search/index.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/search/embedding-regression.test.js b/tests/search/embedding-regression.test.js index 56222875..8e618185 100644 --- a/tests/search/embedding-regression.test.js +++ b/tests/search/embedding-regression.test.js @@ -22,8 +22,8 @@ try { } // Lazy-import to avoid top-level errors when transformers is missing -const { buildGraph } = await import('../../src/builder.js'); -const { buildEmbeddings, searchData } = await import('../../src/embeddings/index.js'); +const { buildGraph } = await import('../../src/domain/graph/builder.js'); +const { buildEmbeddings, searchData } = await import('../../src/domain/search/index.js'); // Same ES-module fixture files used by build.test.js const FIXTURE_FILES = { diff --git a/tests/search/embedding-strategy.test.js b/tests/search/embedding-strategy.test.js index 70215559..a8a50a2c 100644 --- a/tests/search/embedding-strategy.test.js +++ b/tests/search/embedding-strategy.test.js @@ -3,7 +3,7 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest'; -import { initSchema } from '../../src/db.js'; +import { initSchema } from '../../src/db/index.js'; // ─── Mock setup ──────────────────────────────────────────────────────── @@ -31,7 +31,7 @@ import { EMBEDDING_STRATEGIES, estimateTokens, MODELS, -} from '../../src/embeddings/index.js'; +} from '../../src/domain/search/index.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/unit/boundaries.test.js b/tests/unit/boundaries.test.js index 6dfe1e12..0f2642e7 100644 --- a/tests/unit/boundaries.test.js +++ b/tests/unit/boundaries.test.js @@ -3,14 +3,14 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; +import { initSchema } from '../../src/db/index.js'; import { evaluateBoundaries, globToRegex, PRESETS, resolveModules, validateBoundaryConfig, -} from '../../src/boundaries.js'; -import { initSchema } from '../../src/db.js'; +} from '../../src/features/boundaries.js'; // ─── globToRegex ───────────────────────────────────────────────────── diff --git a/tests/unit/builder.test.js b/tests/unit/builder.test.js index 63c60a4c..7dc7d958 100644 --- a/tests/unit/builder.test.js +++ b/tests/unit/builder.test.js @@ -9,7 +9,7 @@ import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'; -import { collectFiles, loadPathAliases, readFileSafe } from '../../src/builder.js'; +import { collectFiles, loadPathAliases, readFileSafe } from '../../src/domain/graph/builder.js'; let tmpDir; diff --git a/tests/unit/cfg.test.js b/tests/unit/cfg.test.js index 7a19a457..adf8aa49 100644 --- a/tests/unit/cfg.test.js +++ b/tests/unit/cfg.test.js @@ -9,8 +9,8 @@ import { beforeAll, describe, expect, it } from 'vitest'; import { CFG_RULES } from '../../src/ast-analysis/rules/index.js'; import { walkWithVisitors } from '../../src/ast-analysis/visitor.js'; import { createCfgVisitor } from '../../src/ast-analysis/visitors/cfg-visitor.js'; -import { buildFunctionCFG, makeCfgRules } from '../../src/cfg.js'; -import { COMPLEXITY_RULES } from '../../src/complexity.js'; +import { buildFunctionCFG, makeCfgRules } from '../../src/features/cfg.js'; +import { COMPLEXITY_RULES } from '../../src/features/complexity.js'; import { createParsers } from '../../src/parser.js'; let jsParser; diff --git a/tests/unit/complexity.test.js b/tests/unit/complexity.test.js index d3b4b73f..b458ead1 100644 --- a/tests/unit/complexity.test.js +++ b/tests/unit/complexity.test.js @@ -13,7 +13,7 @@ import { computeLOCMetrics, computeMaintainabilityIndex, HALSTEAD_RULES, -} from '../../src/complexity.js'; +} from '../../src/features/complexity.js'; import { createParsers } from '../../src/parser.js'; let jsParser; diff --git a/tests/unit/db.test.js b/tests/unit/db.test.js index 47dc393d..7d338971 100644 --- a/tests/unit/db.test.js +++ b/tests/unit/db.test.js @@ -16,7 +16,7 @@ import { openDb, openReadonlyOrFail, setBuildMeta, -} from '../../src/db.js'; +} from '../../src/db/index.js'; let tmpDir; diff --git a/tests/unit/mcp.test.js b/tests/unit/mcp.test.js index 94149c0a..cb9f490e 100644 --- a/tests/unit/mcp.test.js +++ b/tests/unit/mcp.test.js @@ -6,7 +6,7 @@ */ import { beforeEach, describe, expect, it, vi } from 'vitest'; -import { buildToolList, TOOLS } from '../../src/mcp.js'; +import { buildToolList, TOOLS } from '../../src/mcp/index.js'; const ALL_TOOL_NAMES = [ 'query', @@ -281,7 +281,7 @@ describe('startMCPServer handler dispatch', () => { })); // Mock query functions - vi.doMock('../../src/queries.js', () => ({ + vi.doMock('../../src/domain/queries.js', () => ({ EVERY_SYMBOL_KIND: [], EVERY_EDGE_KIND: [], VALID_ROLES: [], @@ -309,7 +309,7 @@ describe('startMCPServer handler dispatch', () => { })); // Clear module cache and reimport - const { startMCPServer } = await import('../../src/mcp.js'); + const { startMCPServer } = await import('../../src/mcp/index.js'); await startMCPServer('/tmp/test.db'); // Test tools/list — single-repo mode by default (no list_repos) @@ -352,7 +352,7 @@ describe('startMCPServer handler dispatch', () => { })); const fnDepsMock = vi.fn(() => ({ name: 'myFn', results: [{ callers: [] }] })); - vi.doMock('../../src/queries.js', () => ({ + vi.doMock('../../src/domain/queries.js', () => ({ EVERY_SYMBOL_KIND: [], EVERY_EDGE_KIND: [], VALID_ROLES: [], @@ -373,7 +373,7 @@ describe('startMCPServer handler dispatch', () => { pathData: vi.fn(() => ({ from: 'a', to: 'b', found: false })), })); - const { startMCPServer } = await import('../../src/mcp.js'); + const { startMCPServer } = await import('../../src/mcp/index.js'); await startMCPServer('/tmp/test.db'); const result = await handlers['tools/call']({ @@ -413,7 +413,7 @@ describe('startMCPServer handler dispatch', () => { })); const fnImpactMock = vi.fn(() => ({ name: 'test', results: [] })); - vi.doMock('../../src/queries.js', () => ({ + vi.doMock('../../src/domain/queries.js', () => ({ EVERY_SYMBOL_KIND: [], EVERY_EDGE_KIND: [], VALID_ROLES: [], @@ -434,7 +434,7 @@ describe('startMCPServer handler dispatch', () => { pathData: vi.fn(() => ({ from: 'a', to: 'b', found: false })), })); - const { startMCPServer } = await import('../../src/mcp.js'); + const { startMCPServer } = await import('../../src/mcp/index.js'); await startMCPServer('/tmp/test.db'); const result = await handlers['tools/call']({ @@ -471,7 +471,7 @@ describe('startMCPServer handler dispatch', () => { })); const diffImpactMock = vi.fn(() => ({ changedFiles: 2, affectedFunctions: [] })); - vi.doMock('../../src/queries.js', () => ({ + vi.doMock('../../src/domain/queries.js', () => ({ EVERY_SYMBOL_KIND: [], EVERY_EDGE_KIND: [], VALID_ROLES: [], @@ -492,7 +492,7 @@ describe('startMCPServer handler dispatch', () => { pathData: vi.fn(() => ({ from: 'a', to: 'b', found: false })), })); - const { startMCPServer } = await import('../../src/mcp.js'); + const { startMCPServer } = await import('../../src/mcp/index.js'); await startMCPServer('/tmp/test.db'); const result = await handlers['tools/call']({ @@ -532,7 +532,7 @@ describe('startMCPServer handler dispatch', () => { count: 3, functions: [{ name: 'a' }, { name: 'b' }, { name: 'c' }], })); - vi.doMock('../../src/queries.js', () => ({ + vi.doMock('../../src/domain/queries.js', () => ({ EVERY_SYMBOL_KIND: [], EVERY_EDGE_KIND: [], VALID_ROLES: [], @@ -553,7 +553,7 @@ describe('startMCPServer handler dispatch', () => { pathData: vi.fn(() => ({ from: 'a', to: 'b', found: false })), })); - const { startMCPServer } = await import('../../src/mcp.js'); + const { startMCPServer } = await import('../../src/mcp/index.js'); await startMCPServer('/tmp/test.db'); const result = await handlers['tools/call']({ @@ -594,7 +594,7 @@ describe('startMCPServer handler dispatch', () => { })); const fnDepsMock = vi.fn(() => ({ name: 'test', results: [] })); - vi.doMock('../../src/queries.js', () => ({ + vi.doMock('../../src/domain/queries.js', () => ({ EVERY_SYMBOL_KIND: [], EVERY_EDGE_KIND: [], VALID_ROLES: [], @@ -615,7 +615,7 @@ describe('startMCPServer handler dispatch', () => { pathData: vi.fn(() => ({ from: 'a', to: 'b', found: false })), })); - const { startMCPServer } = await import('../../src/mcp.js'); + const { startMCPServer } = await import('../../src/mcp/index.js'); await startMCPServer(undefined, { multiRepo: true }); const result = await handlers['tools/call']({ @@ -653,7 +653,7 @@ describe('startMCPServer handler dispatch', () => { vi.doMock('../../src/registry.js', () => ({ resolveRepoDbPath: vi.fn(() => undefined), })); - vi.doMock('../../src/queries.js', () => ({ + vi.doMock('../../src/domain/queries.js', () => ({ EVERY_SYMBOL_KIND: [], EVERY_EDGE_KIND: [], VALID_ROLES: [], @@ -674,7 +674,7 @@ describe('startMCPServer handler dispatch', () => { pathData: vi.fn(() => ({ from: 'a', to: 'b', found: false })), })); - const { startMCPServer } = await import('../../src/mcp.js'); + const { startMCPServer } = await import('../../src/mcp/index.js'); await startMCPServer(undefined, { multiRepo: true }); const result = await handlers['tools/call']({ @@ -706,7 +706,7 @@ describe('startMCPServer handler dispatch', () => { vi.doMock('../../src/registry.js', () => ({ resolveRepoDbPath: vi.fn(() => '/some/path'), })); - vi.doMock('../../src/queries.js', () => ({ + vi.doMock('../../src/domain/queries.js', () => ({ EVERY_SYMBOL_KIND: [], EVERY_EDGE_KIND: [], VALID_ROLES: [], @@ -727,7 +727,7 @@ describe('startMCPServer handler dispatch', () => { pathData: vi.fn(() => ({ from: 'a', to: 'b', found: false })), })); - const { startMCPServer } = await import('../../src/mcp.js'); + const { startMCPServer } = await import('../../src/mcp/index.js'); await startMCPServer(undefined, { allowedRepos: ['allowed-repo'] }); const result = await handlers['tools/call']({ @@ -761,7 +761,7 @@ describe('startMCPServer handler dispatch', () => { })); const fnDepsMock = vi.fn(() => ({ name: 'test', results: [] })); - vi.doMock('../../src/queries.js', () => ({ + vi.doMock('../../src/domain/queries.js', () => ({ EVERY_SYMBOL_KIND: [], EVERY_EDGE_KIND: [], VALID_ROLES: [], @@ -782,7 +782,7 @@ describe('startMCPServer handler dispatch', () => { pathData: vi.fn(() => ({ from: 'a', to: 'b', found: false })), })); - const { startMCPServer } = await import('../../src/mcp.js'); + const { startMCPServer } = await import('../../src/mcp/index.js'); await startMCPServer(undefined, { allowedRepos: ['my-repo'] }); const result = await handlers['tools/call']({ @@ -826,7 +826,7 @@ describe('startMCPServer handler dispatch', () => { ]), pruneRegistry: vi.fn(), })); - vi.doMock('../../src/queries.js', () => ({ + vi.doMock('../../src/domain/queries.js', () => ({ EVERY_SYMBOL_KIND: [], EVERY_EDGE_KIND: [], VALID_ROLES: [], @@ -847,7 +847,7 @@ describe('startMCPServer handler dispatch', () => { pathData: vi.fn(() => ({ from: 'a', to: 'b', found: false })), })); - const { startMCPServer } = await import('../../src/mcp.js'); + const { startMCPServer } = await import('../../src/mcp/index.js'); await startMCPServer(undefined, { allowedRepos: ['alpha', 'gamma'] }); const result = await handlers['tools/call']({ @@ -884,7 +884,7 @@ describe('startMCPServer handler dispatch', () => { ]), pruneRegistry: vi.fn(), })); - vi.doMock('../../src/queries.js', () => ({ + vi.doMock('../../src/domain/queries.js', () => ({ EVERY_SYMBOL_KIND: [], EVERY_EDGE_KIND: [], VALID_ROLES: [], @@ -905,7 +905,7 @@ describe('startMCPServer handler dispatch', () => { pathData: vi.fn(() => ({ from: 'a', to: 'b', found: false })), })); - const { startMCPServer } = await import('../../src/mcp.js'); + const { startMCPServer } = await import('../../src/mcp/index.js'); await startMCPServer(undefined, { multiRepo: true }); const result = await handlers['tools/call']({ @@ -933,7 +933,7 @@ describe('startMCPServer handler dispatch', () => { ListToolsRequestSchema: 'tools/list', CallToolRequestSchema: 'tools/call', })); - vi.doMock('../../src/queries.js', () => ({ + vi.doMock('../../src/domain/queries.js', () => ({ EVERY_SYMBOL_KIND: [], EVERY_EDGE_KIND: [], VALID_ROLES: [], @@ -954,7 +954,7 @@ describe('startMCPServer handler dispatch', () => { pathData: vi.fn(() => ({ from: 'a', to: 'b', found: false })), })); - const { startMCPServer } = await import('../../src/mcp.js'); + const { startMCPServer } = await import('../../src/mcp/index.js'); await startMCPServer('/tmp/test.db'); const result = await handlers['tools/call']({ @@ -983,7 +983,7 @@ describe('startMCPServer handler dispatch', () => { ListToolsRequestSchema: 'tools/list', CallToolRequestSchema: 'tools/call', })); - vi.doMock('../../src/queries.js', () => ({ + vi.doMock('../../src/domain/queries.js', () => ({ EVERY_SYMBOL_KIND: [], EVERY_EDGE_KIND: [], VALID_ROLES: [], @@ -1004,7 +1004,7 @@ describe('startMCPServer handler dispatch', () => { pathData: vi.fn(() => ({ from: 'a', to: 'b', found: false })), })); - const { startMCPServer } = await import('../../src/mcp.js'); + const { startMCPServer } = await import('../../src/mcp/index.js'); await startMCPServer('/tmp/test.db'); const result = await handlers['tools/call']({ @@ -1033,7 +1033,7 @@ describe('startMCPServer handler dispatch', () => { ListToolsRequestSchema: 'tools/list', CallToolRequestSchema: 'tools/call', })); - vi.doMock('../../src/queries.js', () => ({ + vi.doMock('../../src/domain/queries.js', () => ({ EVERY_SYMBOL_KIND: [], EVERY_EDGE_KIND: [], VALID_ROLES: [], @@ -1054,7 +1054,7 @@ describe('startMCPServer handler dispatch', () => { pathData: vi.fn(() => ({ from: 'a', to: 'b', found: false })), })); - const { startMCPServer } = await import('../../src/mcp.js'); + const { startMCPServer } = await import('../../src/mcp/index.js'); await startMCPServer('/tmp/test.db'); const toolsList = await handlers['tools/list'](); @@ -1084,7 +1084,7 @@ describe('startMCPServer handler dispatch', () => { CallToolRequestSchema: 'tools/call', })); - vi.doMock('../../src/queries.js', () => ({ + vi.doMock('../../src/domain/queries.js', () => ({ EVERY_SYMBOL_KIND: [], EVERY_EDGE_KIND: [], VALID_ROLES: [], @@ -1110,11 +1110,11 @@ describe('startMCPServer handler dispatch', () => { summary: { analyzed: 1, avgCognitive: 50, avgCyclomatic: 20 }, thresholds: { cognitive: { warn: 15 }, cyclomatic: { warn: 10 }, maxNesting: { warn: 4 } }, })); - vi.doMock('../../src/complexity.js', () => ({ + vi.doMock('../../src/features/complexity.js', () => ({ complexityData: complexityMock, })); - const { startMCPServer } = await import('../../src/mcp.js'); + const { startMCPServer } = await import('../../src/mcp/index.js'); await startMCPServer('/tmp/test.db'); const result = await handlers['tools/call']({ diff --git a/tests/unit/normalize-symbol.test.js b/tests/unit/normalize-symbol.test.js index 8a27b344..e6ec00cf 100644 --- a/tests/unit/normalize-symbol.test.js +++ b/tests/unit/normalize-symbol.test.js @@ -1,5 +1,5 @@ import { describe, expect, test, vi } from 'vitest'; -import { normalizeSymbol } from '../../src/queries.js'; +import { normalizeSymbol } from '../../src/domain/queries.js'; describe('normalizeSymbol', () => { test('full row with all fields', () => { diff --git a/tests/unit/owners.test.js b/tests/unit/owners.test.js index 40d4b361..52ed123c 100644 --- a/tests/unit/owners.test.js +++ b/tests/unit/owners.test.js @@ -8,7 +8,7 @@ import { parseCodeowners, parseCodeownersContent, patternToRegex, -} from '../../src/owners.js'; +} from '../../src/features/owners.js'; // ─── parseCodeownersContent ────────────────────────────────────────── diff --git a/tests/unit/prompt-install.test.js b/tests/unit/prompt-install.test.js index f23a73f8..d7e09981 100644 --- a/tests/unit/prompt-install.test.js +++ b/tests/unit/prompt-install.test.js @@ -44,7 +44,7 @@ describe('loadTransformers install prompt', () => { throw new Error('Cannot find package'); }); - const { embed } = await import('../../src/embeddings/index.js'); + const { embed } = await import('../../src/domain/search/index.js'); await expect(embed(['test'], 'minilm')).rejects.toThrow( 'Semantic search requires @huggingface/transformers', @@ -71,7 +71,7 @@ describe('loadTransformers install prompt', () => { throw new Error('Cannot find package'); }); - const { embed } = await import('../../src/embeddings/index.js'); + const { embed } = await import('../../src/domain/search/index.js'); await expect(embed(['test'], 'minilm')).rejects.toThrow( 'Semantic search requires @huggingface/transformers', @@ -99,7 +99,7 @@ describe('loadTransformers install prompt', () => { throw new Error('Cannot find package'); }); - const { embed } = await import('../../src/embeddings/index.js'); + const { embed } = await import('../../src/domain/search/index.js'); await expect(embed(['test'], 'minilm')).rejects.toThrow( 'Semantic search requires @huggingface/transformers', @@ -137,7 +137,7 @@ describe('loadTransformers install prompt', () => { }; }); - const { embed } = await import('../../src/embeddings/index.js'); + const { embed } = await import('../../src/domain/search/index.js'); const result = await embed(['test text'], 'minilm'); expect(result.vectors).toHaveLength(1); diff --git a/tests/unit/purge-files.test.js b/tests/unit/purge-files.test.js index 9702899a..3e7ca8b5 100644 --- a/tests/unit/purge-files.test.js +++ b/tests/unit/purge-files.test.js @@ -7,8 +7,8 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterEach, describe, expect, test } from 'vitest'; -import { purgeFilesFromGraph } from '../../src/builder.js'; -import { initSchema } from '../../src/db.js'; +import { initSchema } from '../../src/db/index.js'; +import { purgeFilesFromGraph } from '../../src/domain/graph/builder.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/unit/queries-unit.test.js b/tests/unit/queries-unit.test.js index db188420..19a6b2aa 100644 --- a/tests/unit/queries-unit.test.js +++ b/tests/unit/queries-unit.test.js @@ -14,8 +14,13 @@ import os from 'node:os'; import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'; -import { initSchema } from '../../src/db.js'; -import { diffImpactData, diffImpactMermaid, fnDepsData, fnImpactData } from '../../src/queries.js'; +import { initSchema } from '../../src/db/index.js'; +import { + diffImpactData, + diffImpactMermaid, + fnDepsData, + fnImpactData, +} from '../../src/domain/queries.js'; import { diffImpact, fileDeps, @@ -23,7 +28,7 @@ import { fnImpact, impactAnalysis, moduleMap, -} from '../../src/queries-cli.js'; +} from '../../src/presentation/queries-cli.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/unit/resolve.test.js b/tests/unit/resolve.test.js index 151322f4..d5e487b6 100644 --- a/tests/unit/resolve.test.js +++ b/tests/unit/resolve.test.js @@ -14,7 +14,7 @@ import { convertAliasesForNative, resolveImportPathJS, resolveImportsBatch, -} from '../../src/resolve.js'; +} from '../../src/domain/graph/resolve.js'; // ─── Temp project setup ────────────────────────────────────────────── diff --git a/tests/unit/roles.test.js b/tests/unit/roles.test.js index 5f8c0e1a..b703f899 100644 --- a/tests/unit/roles.test.js +++ b/tests/unit/roles.test.js @@ -15,8 +15,8 @@ import Database from 'better-sqlite3'; import { beforeEach, describe, expect, it } from 'vitest'; -import { initSchema } from '../../src/db.js'; -import { classifyNodeRoles } from '../../src/structure.js'; +import { initSchema } from '../../src/db/index.js'; +import { classifyNodeRoles } from '../../src/features/structure.js'; let db; diff --git a/tests/unit/snapshot.test.js b/tests/unit/snapshot.test.js index 950028f1..b12b912a 100644 --- a/tests/unit/snapshot.test.js +++ b/tests/unit/snapshot.test.js @@ -10,7 +10,7 @@ import { snapshotSave, snapshotsDir, validateSnapshotName, -} from '../../src/snapshot.js'; +} from '../../src/features/snapshot.js'; let tmpDir; let dbPath; diff --git a/tests/unit/structure.test.js b/tests/unit/structure.test.js index 003a879d..fd57e487 100644 --- a/tests/unit/structure.test.js +++ b/tests/unit/structure.test.js @@ -7,8 +7,8 @@ import Database from 'better-sqlite3'; import { beforeEach, describe, expect, it } from 'vitest'; -import { initSchema } from '../../src/db.js'; -import { buildStructure } from '../../src/structure.js'; +import { initSchema } from '../../src/db/index.js'; +import { buildStructure } from '../../src/features/structure.js'; let db;