diff --git a/CLAUDE.md b/CLAUDE.md index efef122f..512162b0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -42,21 +42,28 @@ JS source is plain JavaScript (ES modules) in `src/`. No transpilation step. The |------|------| | `cli.js` | Commander CLI entry point (`bin.codegraph`) | | `index.js` | Programmatic API exports | -| `parser.js` | tree-sitter WASM wrapper; `LANGUAGE_REGISTRY` + per-language extractors for functions, classes, methods, imports, exports, call sites | -| `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 | -| `paginate.js` | Pagination helpers for bounded query results | -| `logger.js` | Structured logging (`warn`, `debug`, `info`, `error`) | +| **`shared/`** | **Cross-cutting constants and utilities** | +| `shared/constants.js` | `EXTENSIONS` (derived from parser registry) and `IGNORE_DIRS` constants | +| `shared/errors.js` | Domain error hierarchy (`CodegraphError`, `ConfigError`, `ParseError`, etc.) | +| `shared/kinds.js` | Symbol and edge kind constants (`CORE_SYMBOL_KINDS`, `EVERY_SYMBOL_KIND`, `VALID_ROLES`) | +| `shared/paginate.js` | Pagination helpers for bounded query results | +| **`infrastructure/`** | **Platform and I/O plumbing** | +| `infrastructure/config.js` | `.codegraphrc.json` loading, env overrides, `apiKeyCommand` secret resolution | +| `infrastructure/logger.js` | Structured logging (`warn`, `debug`, `info`, `error`) | +| `infrastructure/native.js` | Native napi-rs addon loader with WASM fallback | +| `infrastructure/registry.js` | Global repo registry (`~/.codegraph/registry.json`) for multi-repo MCP | +| `infrastructure/update-check.js` | npm update availability check | | **`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/parser.js` | tree-sitter WASM wrapper; `LANGUAGE_REGISTRY` + per-language extractors for functions, classes, methods, imports, exports, call sites | +| `domain/queries.js` | Query functions: symbol search, file deps, impact analysis, diff-impact | | `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/graph/journal.js` | Change journal for incremental builds | +| `domain/graph/change-journal.js` | Change event tracking (NDJSON) | | `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** | @@ -87,7 +94,7 @@ JS source is plain JavaScript (ES modules) in `src/`. No transpilation step. The - **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 +- **Language parser registry:** `LANGUAGE_REGISTRY` in `domain/parser.js` is the single source of truth for all supported languages — maps each language to `{ id, extensions, grammarFile, extractor, required }`. `EXTENSIONS` in `shared/constants.js` is derived from the registry. Adding a new language requires one registry entry + extractor function - **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 diff --git a/src/ast-analysis/engine.js b/src/ast-analysis/engine.js index 3998e313..6775a7f0 100644 --- a/src/ast-analysis/engine.js +++ b/src/ast-analysis/engine.js @@ -18,7 +18,7 @@ import path from 'node:path'; import { performance } from 'node:perf_hooks'; import { bulkNodeIdsByFile } from '../db/index.js'; -import { debug } from '../logger.js'; +import { debug } from '../infrastructure/logger.js'; import { computeLOCMetrics, computeMaintainabilityIndex } from './metrics.js'; import { AST_TYPE_MAPS, @@ -45,7 +45,7 @@ const WALK_EXTENSIONS = buildExtensionSet(AST_TYPE_MAPS); let _parserModule = null; async function getParserModule() { - if (!_parserModule) _parserModule = await import('../parser.js'); + if (!_parserModule) _parserModule = await import('../domain/parser.js'); return _parserModule; } diff --git a/src/ast-analysis/shared.js b/src/ast-analysis/shared.js index f5d8e0be..964f9a06 100644 --- a/src/ast-analysis/shared.js +++ b/src/ast-analysis/shared.js @@ -2,8 +2,8 @@ * Shared utilities for AST analysis modules (complexity, CFG, dataflow, AST nodes). */ -import { ConfigError } from '../errors.js'; -import { LANGUAGE_REGISTRY } from '../parser.js'; +import { LANGUAGE_REGISTRY } from '../domain/parser.js'; +import { ConfigError } from '../shared/errors.js'; // ─── Generic Rule Factory ───────────────────────────────────────────────── diff --git a/src/cli.js b/src/cli.js index 6318f0e4..449bd25f 100644 --- a/src/cli.js +++ b/src/cli.js @@ -1,7 +1,7 @@ #!/usr/bin/env node import { run } from './cli/index.js'; -import { CodegraphError } from './errors.js'; +import { CodegraphError } from './shared/errors.js'; run().catch((err) => { if (err instanceof CodegraphError) { diff --git a/src/cli/commands/ast.js b/src/cli/commands/ast.js index cc9124b0..1588804a 100644 --- a/src/cli/commands/ast.js +++ b/src/cli/commands/ast.js @@ -1,4 +1,4 @@ -import { ConfigError } from '../../errors.js'; +import { ConfigError } from '../../shared/errors.js'; export const command = { name: 'ast [pattern]', diff --git a/src/cli/commands/batch.js b/src/cli/commands/batch.js index 8ba4f99c..5d740ad1 100644 --- a/src/cli/commands/batch.js +++ b/src/cli/commands/batch.js @@ -1,8 +1,8 @@ import fs from 'node:fs'; import { batch } from '../../commands/batch.js'; import { EVERY_SYMBOL_KIND } from '../../domain/queries.js'; -import { ConfigError } from '../../errors.js'; import { BATCH_COMMANDS, multiBatchData, splitTargets } from '../../features/batch.js'; +import { ConfigError } from '../../shared/errors.js'; export const command = { name: 'batch [targets...]', diff --git a/src/cli/commands/check.js b/src/cli/commands/check.js index 43d98a3a..8c5f29ca 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 { ConfigError } from '../../shared/errors.js'; export const command = { name: 'check [ref]', diff --git a/src/cli/commands/co-change.js b/src/cli/commands/co-change.js index ef4885b5..83b29e75 100644 --- a/src/cli/commands/co-change.js +++ b/src/cli/commands/co-change.js @@ -1,4 +1,4 @@ -import { AnalysisError } from '../../errors.js'; +import { AnalysisError } from '../../shared/errors.js'; export const command = { name: 'co-change [file]', diff --git a/src/cli/commands/info.js b/src/cli/commands/info.js index a0fd2d6c..b4c0a28a 100644 --- a/src/cli/commands/info.js +++ b/src/cli/commands/info.js @@ -3,9 +3,9 @@ export const command = { description: 'Show codegraph engine info and diagnostics', async execute(_args, _opts, ctx) { const { getNativePackageVersion, isNativeAvailable, loadNative } = await import( - '../../native.js' + '../../infrastructure/native.js' ); - const { getActiveEngine } = await import('../../parser.js'); + const { getActiveEngine } = await import('../../domain/parser.js'); const engine = ctx.program.opts().engine; const { name: activeName, version: activeVersion } = getActiveEngine({ engine }); diff --git a/src/cli/commands/registry.js b/src/cli/commands/registry.js index 9e516d9a..f2803116 100644 --- a/src/cli/commands/registry.js +++ b/src/cli/commands/registry.js @@ -1,13 +1,13 @@ import fs from 'node:fs'; import path from 'node:path'; -import { ConfigError } from '../../errors.js'; import { listRepos, pruneRegistry, REGISTRY_PATH, registerRepo, unregisterRepo, -} from '../../registry.js'; +} from '../../infrastructure/registry.js'; +import { ConfigError } from '../../shared/errors.js'; export const command = { name: 'registry', diff --git a/src/cli/commands/triage.js b/src/cli/commands/triage.js index 851df8e9..23e07183 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 { ConfigError } from '../../shared/errors.js'; export const command = { name: 'triage', diff --git a/src/cli/index.js b/src/cli/index.js index 02d36a77..057bae31 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -2,9 +2,9 @@ import fs from 'node:fs'; import path from 'node:path'; import { pathToFileURL } from 'node:url'; import { Command } from 'commander'; -import { ConfigError } from '../errors.js'; -import { setVerbose } from '../logger.js'; -import { checkForUpdates, printUpdateNotification } from '../update-check.js'; +import { setVerbose } from '../infrastructure/logger.js'; +import { checkForUpdates, printUpdateNotification } from '../infrastructure/update-check.js'; +import { ConfigError } from '../shared/errors.js'; import { applyQueryOpts, config, formatSize, resolveNoTests } from './shared/options.js'; import { outputResult } from './shared/output.js'; diff --git a/src/cli/shared/options.js b/src/cli/shared/options.js index 9f596076..7f7552c3 100644 --- a/src/cli/shared/options.js +++ b/src/cli/shared/options.js @@ -1,4 +1,4 @@ -import { loadConfig } from '../../config.js'; +import { loadConfig } from '../../infrastructure/config.js'; const config = loadConfig(process.cwd()); diff --git a/src/commands/check.js b/src/commands/check.js index eb592fe0..1dc0c4fc 100644 --- a/src/commands/check.js +++ b/src/commands/check.js @@ -1,6 +1,6 @@ -import { AnalysisError } from '../errors.js'; import { checkData } from '../features/check.js'; import { outputResult } from '../infrastructure/result-formatter.js'; +import { AnalysisError } from '../shared/errors.js'; /** * CLI formatter — prints check results and sets exitCode 1 on failure. diff --git a/src/db/connection.js b/src/db/connection.js index d8b34c21..acf87547 100644 --- a/src/db/connection.js +++ b/src/db/connection.js @@ -1,8 +1,8 @@ import fs from 'node:fs'; import path from 'node:path'; import Database from 'better-sqlite3'; -import { DbError } from '../errors.js'; -import { warn } from '../logger.js'; +import { warn } from '../infrastructure/logger.js'; +import { DbError } from '../shared/errors.js'; function isProcessAlive(pid) { try { diff --git a/src/db/migrations.js b/src/db/migrations.js index e3925cdf..3b38feff 100644 --- a/src/db/migrations.js +++ b/src/db/migrations.js @@ -1,4 +1,4 @@ -import { debug } from '../logger.js'; +import { debug } from '../infrastructure/logger.js'; // ─── Schema Migrations ───────────────────────────────────────────────── export const MIGRATIONS = [ diff --git a/src/db/query-builder.js b/src/db/query-builder.js index 12a15ecc..10dd1fca 100644 --- a/src/db/query-builder.js +++ b/src/db/query-builder.js @@ -1,5 +1,5 @@ -import { DbError } from '../errors.js'; -import { EVERY_EDGE_KIND } from '../kinds.js'; +import { DbError } from '../shared/errors.js'; +import { EVERY_EDGE_KIND } from '../shared/kinds.js'; // ─── Validation Helpers ───────────────────────────────────────────── diff --git a/src/db/repository/graph-read.js b/src/db/repository/graph-read.js index b514e9bc..8fd284ad 100644 --- a/src/db/repository/graph-read.js +++ b/src/db/repository/graph-read.js @@ -1,4 +1,4 @@ -import { CORE_SYMBOL_KINDS } from '../../kinds.js'; +import { CORE_SYMBOL_KINDS } from '../../shared/kinds.js'; import { cachedStmt } from './cached-stmt.js'; // ─── Statement caches (one prepared statement per db instance) ──────────── diff --git a/src/db/repository/in-memory-repository.js b/src/db/repository/in-memory-repository.js index 91205c3c..9d228ca1 100644 --- a/src/db/repository/in-memory-repository.js +++ b/src/db/repository/in-memory-repository.js @@ -1,5 +1,5 @@ -import { ConfigError } from '../../errors.js'; -import { CORE_SYMBOL_KINDS, EVERY_SYMBOL_KIND, VALID_ROLES } from '../../kinds.js'; +import { ConfigError } from '../../shared/errors.js'; +import { CORE_SYMBOL_KINDS, EVERY_SYMBOL_KIND, VALID_ROLES } from '../../shared/kinds.js'; import { escapeLike } from '../query-builder.js'; import { Repository } from './base.js'; diff --git a/src/db/repository/nodes.js b/src/db/repository/nodes.js index cabc2ce3..fbe2ddf0 100644 --- a/src/db/repository/nodes.js +++ b/src/db/repository/nodes.js @@ -1,5 +1,5 @@ -import { ConfigError } from '../../errors.js'; -import { EVERY_SYMBOL_KIND, VALID_ROLES } from '../../kinds.js'; +import { ConfigError } from '../../shared/errors.js'; +import { EVERY_SYMBOL_KIND, VALID_ROLES } from '../../shared/kinds.js'; import { escapeLike, NodeQuery } from '../query-builder.js'; import { cachedStmt } from './cached-stmt.js'; diff --git a/src/domain/analysis/context.js b/src/domain/analysis/context.js index 803fcc99..e3409208 100644 --- a/src/domain/analysis/context.js +++ b/src/domain/analysis/context.js @@ -14,7 +14,6 @@ import { openReadonlyOrFail, } from '../../db/index.js'; import { isTestFile } from '../../infrastructure/test-filter.js'; -import { paginateResult } from '../../paginate.js'; import { createFileLinesReader, extractSignature, @@ -24,6 +23,7 @@ import { } from '../../shared/file-utils.js'; import { resolveMethodViaHierarchy } from '../../shared/hierarchy.js'; import { normalizeSymbol } from '../../shared/normalize.js'; +import { paginateResult } from '../../shared/paginate.js'; import { findMatchingNodes } from './symbol-lookup.js'; function explainFileImpl(db, target, getFileLines) { diff --git a/src/domain/analysis/dependencies.js b/src/domain/analysis/dependencies.js index 63778733..e632470f 100644 --- a/src/domain/analysis/dependencies.js +++ b/src/domain/analysis/dependencies.js @@ -8,9 +8,9 @@ import { openReadonlyOrFail, } 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 { paginateResult } from '../../shared/paginate.js'; import { findMatchingNodes } from './symbol-lookup.js'; export function fileDepsData(file, customDbPath, opts = {}) { diff --git a/src/domain/analysis/exports.js b/src/domain/analysis/exports.js index 6088656f..9af6b807 100644 --- a/src/domain/analysis/exports.js +++ b/src/domain/analysis/exports.js @@ -7,12 +7,12 @@ import { openReadonlyOrFail, } 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'; +import { paginateResult } from '../../shared/paginate.js'; export function exportsData(file, customDbPath, opts = {}) { const db = openReadonlyOrFail(customDbPath); diff --git a/src/domain/analysis/impact.js b/src/domain/analysis/impact.js index 282e9c64..01b5cef6 100644 --- a/src/domain/analysis/impact.js +++ b/src/domain/analysis/impact.js @@ -1,7 +1,6 @@ import { execFileSync } from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; -import { loadConfig } from '../../config.js'; import { findDbPath, findDistinctCallers, @@ -13,9 +12,10 @@ import { import { evaluateBoundaries } from '../../features/boundaries.js'; import { coChangeForFiles } from '../../features/cochange.js'; import { ownersForFiles } from '../../features/owners.js'; +import { loadConfig } from '../../infrastructure/config.js'; import { isTestFile } from '../../infrastructure/test-filter.js'; -import { paginateResult } from '../../paginate.js'; import { normalizeSymbol } from '../../shared/normalize.js'; +import { paginateResult } from '../../shared/paginate.js'; import { findMatchingNodes } from './symbol-lookup.js'; export function impactAnalysisData(file, customDbPath, opts = {}) { diff --git a/src/domain/analysis/module-map.js b/src/domain/analysis/module-map.js index fedef93e..e6aa0936 100644 --- a/src/domain/analysis/module-map.js +++ b/src/domain/analysis/module-map.js @@ -1,8 +1,8 @@ import path from 'node:path'; 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'; +import { LANGUAGE_REGISTRY } from '../parser.js'; export const FALSE_POSITIVE_NAMES = new Set([ 'run', diff --git a/src/domain/analysis/roles.js b/src/domain/analysis/roles.js index d295515f..a54362fd 100644 --- a/src/domain/analysis/roles.js +++ b/src/domain/analysis/roles.js @@ -1,7 +1,7 @@ import { openReadonlyOrFail } from '../../db/index.js'; import { isTestFile } from '../../infrastructure/test-filter.js'; -import { paginateResult } from '../../paginate.js'; import { normalizeSymbol } from '../../shared/normalize.js'; +import { paginateResult } from '../../shared/paginate.js'; export function rolesData(customDbPath, opts = {}) { const db = openReadonlyOrFail(customDbPath); diff --git a/src/domain/analysis/symbol-lookup.js b/src/domain/analysis/symbol-lookup.js index e269a42d..47a7d403 100644 --- a/src/domain/analysis/symbol-lookup.js +++ b/src/domain/analysis/symbol-lookup.js @@ -14,9 +14,9 @@ import { openReadonlyOrFail, } from '../../db/index.js'; import { isTestFile } from '../../infrastructure/test-filter.js'; -import { ALL_SYMBOL_KINDS } from '../../kinds.js'; -import { paginateResult } from '../../paginate.js'; +import { ALL_SYMBOL_KINDS } from '../../shared/kinds.js'; import { getFileHash, normalizeSymbol } from '../../shared/normalize.js'; +import { paginateResult } from '../../shared/paginate.js'; const FUNCTION_KINDS = ['function', 'method', 'class']; diff --git a/src/domain/graph/builder/helpers.js b/src/domain/graph/builder/helpers.js index a333f456..038de4c2 100644 --- a/src/domain/graph/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/index.js'; -import { warn } from '../../../logger.js'; +import { warn } from '../../../infrastructure/logger.js'; +import { EXTENSIONS, IGNORE_DIRS } from '../../../shared/constants.js'; export const BUILTIN_RECEIVERS = new Set([ 'console', diff --git a/src/domain/graph/builder/incremental.js b/src/domain/graph/builder/incremental.js index 7183d4b7..f04a136e 100644 --- a/src/domain/graph/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 { warn } from '../../../infrastructure/logger.js'; +import { normalizePath } from '../../../shared/constants.js'; +import { parseFileIncremental } from '../../parser.js'; import { computeConfidence, resolveImportPath } from '../resolve.js'; import { BUILTIN_RECEIVERS, readFileSafe } from './helpers.js'; diff --git a/src/domain/graph/builder/pipeline.js b/src/domain/graph/builder/pipeline.js index d1be7ebb..ea9848c5 100644 --- a/src/domain/graph/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/index.js'; -import { info } from '../../../logger.js'; -import { getActiveEngine } from '../../../parser.js'; +import { loadConfig } from '../../../infrastructure/config.js'; +import { info } from '../../../infrastructure/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/domain/graph/builder/stages/build-edges.js b/src/domain/graph/builder/stages/build-edges.js index 33aa66ca..a8879b62 100644 --- a/src/domain/graph/builder/stages/build-edges.js +++ b/src/domain/graph/builder/stages/build-edges.js @@ -7,7 +7,7 @@ import path from 'node:path'; import { performance } from 'node:perf_hooks'; import { getNodeId } from '../../../../db/index.js'; -import { loadNative } from '../../../../native.js'; +import { loadNative } from '../../../../infrastructure/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/domain/graph/builder/stages/build-structure.js b/src/domain/graph/builder/stages/build-structure.js index ec235be2..f4737df9 100644 --- a/src/domain/graph/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 { debug } from '../../../../infrastructure/logger.js'; +import { normalizePath } from '../../../../shared/constants.js'; import { readFileSafe } from '../helpers.js'; /** diff --git a/src/domain/graph/builder/stages/collect-files.js b/src/domain/graph/builder/stages/collect-files.js index 97d183ce..9f3eb636 100644 --- a/src/domain/graph/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 { info } from '../../../../infrastructure/logger.js'; +import { normalizePath } from '../../../../shared/constants.js'; import { collectFiles as collectFilesUtil } from '../helpers.js'; /** diff --git a/src/domain/graph/builder/stages/detect-changes.js b/src/domain/graph/builder/stages/detect-changes.js index 29d25a8a..50ffbd1d 100644 --- a/src/domain/graph/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/index.js'; -import { readJournal, writeJournalHeader } from '../../../../journal.js'; -import { debug, info } from '../../../../logger.js'; -import { parseFilesAuto } from '../../../../parser.js'; +import { debug, info } from '../../../../infrastructure/logger.js'; +import { normalizePath } from '../../../../shared/constants.js'; +import { parseFilesAuto } from '../../../parser.js'; +import { readJournal, writeJournalHeader } from '../../journal.js'; import { fileHash, fileStat, purgeFilesFromGraph, readFileSafe } from '../helpers.js'; /** diff --git a/src/domain/graph/builder/stages/finalize.js b/src/domain/graph/builder/stages/finalize.js index e82411d7..6b493785 100644 --- a/src/domain/graph/builder/stages/finalize.js +++ b/src/domain/graph/builder/stages/finalize.js @@ -7,8 +7,8 @@ import fs from 'node:fs'; import path from 'node:path'; import { performance } from 'node:perf_hooks'; import { closeDb, getBuildMeta, setBuildMeta } from '../../../../db/index.js'; -import { writeJournalHeader } from '../../../../journal.js'; -import { debug, info, warn } from '../../../../logger.js'; +import { debug, info, warn } from '../../../../infrastructure/logger.js'; +import { writeJournalHeader } from '../../journal.js'; const __builderDir = path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Z]:)/i, '$1')); const CODEGRAPH_VERSION = JSON.parse( @@ -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('../../../../infrastructure/registry.js'); registerRepo(rootDir); } catch (err) { debug(`Auto-registration failed: ${err.message}`); diff --git a/src/domain/graph/builder/stages/parse-files.js b/src/domain/graph/builder/stages/parse-files.js index 0d3e1167..6690bb5f 100644 --- a/src/domain/graph/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 '../../../../infrastructure/logger.js'; +import { parseFilesAuto } from '../../../parser.js'; /** * @param {import('../context.js').PipelineContext} ctx diff --git a/src/domain/graph/builder/stages/resolve-imports.js b/src/domain/graph/builder/stages/resolve-imports.js index d2a39861..7d9bbe40 100644 --- a/src/domain/graph/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/domain/graph/builder/stages/run-analyses.js b/src/domain/graph/builder/stages/run-analyses.js index f6dbbdb9..53384613 100644 --- a/src/domain/graph/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 '../../../../infrastructure/logger.js'; /** * @param {import('../context.js').PipelineContext} ctx diff --git a/src/change-journal.js b/src/domain/graph/change-journal.js similarity index 98% rename from src/change-journal.js rename to src/domain/graph/change-journal.js index bbba73ec..7589b5a6 100644 --- a/src/change-journal.js +++ b/src/domain/graph/change-journal.js @@ -1,6 +1,6 @@ import fs from 'node:fs'; import path from 'node:path'; -import { debug, warn } from './logger.js'; +import { debug, warn } from '../../infrastructure/logger.js'; export const CHANGE_EVENTS_FILENAME = 'change-events.ndjson'; export const DEFAULT_MAX_BYTES = 1024 * 1024; // 1 MB diff --git a/src/domain/graph/cycles.js b/src/domain/graph/cycles.js index bed9fc03..c7872a61 100644 --- a/src/domain/graph/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 { loadNative } from '../../infrastructure/native.js'; /** * Detect circular dependencies in the codebase using Tarjan's SCC algorithm. diff --git a/src/journal.js b/src/domain/graph/journal.js similarity index 97% rename from src/journal.js rename to src/domain/graph/journal.js index a072df50..714889f2 100644 --- a/src/journal.js +++ b/src/domain/graph/journal.js @@ -1,6 +1,6 @@ import fs from 'node:fs'; import path from 'node:path'; -import { debug, warn } from './logger.js'; +import { debug, warn } from '../../infrastructure/logger.js'; export const JOURNAL_FILENAME = 'changes.journal'; const HEADER_PREFIX = '# codegraph-journal v1 '; diff --git a/src/domain/graph/resolve.js b/src/domain/graph/resolve.js index 73179b67..5e0ab1d3 100644 --- a/src/domain/graph/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 { loadNative } from '../../infrastructure/native.js'; +import { normalizePath } from '../../shared/constants.js'; // ── Alias format conversion ───────────────────────────────────────── diff --git a/src/domain/graph/watcher.js b/src/domain/graph/watcher.js index 58b56eeb..15b4b4a6 100644 --- a/src/domain/graph/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 { info } from '../../infrastructure/logger.js'; +import { EXTENSIONS, IGNORE_DIRS, normalizePath } from '../../shared/constants.js'; +import { DbError } from '../../shared/errors.js'; +import { createParseTreeCache, getActiveEngine } from '../parser.js'; import { rebuildFile } from './builder/incremental.js'; +import { appendChangeEvents, buildChangeEvent, diffSymbols } from './change-journal.js'; +import { appendJournalEntries } from './journal.js'; function shouldIgnore(filePath) { const parts = filePath.split(path.sep); diff --git a/src/parser.js b/src/domain/parser.js similarity index 98% rename from src/parser.js rename to src/domain/parser.js index d7393bb3..fb41d473 100644 --- a/src/parser.js +++ b/src/domain/parser.js @@ -2,8 +2,8 @@ import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { Language, Parser, Query } from 'web-tree-sitter'; -import { warn } from './logger.js'; -import { getNative, getNativePackageVersion, loadNative } from './native.js'; +import { warn } from '../infrastructure/logger.js'; +import { getNative, getNativePackageVersion, loadNative } from '../infrastructure/native.js'; // Re-export all extractors for backward compatibility export { @@ -16,7 +16,7 @@ export { extractRubySymbols, extractRustSymbols, extractSymbols, -} from './extractors/index.js'; +} from '../extractors/index.js'; import { extractCSharpSymbols, @@ -28,12 +28,12 @@ import { extractRubySymbols, extractRustSymbols, extractSymbols, -} from './extractors/index.js'; +} from '../extractors/index.js'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); function grammarPath(name) { - return path.join(__dirname, '..', 'grammars', name); + return path.join(__dirname, '..', '..', 'grammars', name); } let _initialized = false; diff --git a/src/domain/queries.js b/src/domain/queries.js index 4b853d79..57a7cac7 100644 --- a/src/domain/queries.js +++ b/src/domain/queries.js @@ -8,6 +8,7 @@ // ── Re-export from dedicated module for backward compat ─────────────────── export { isTestFile, TEST_PATTERN } from '../infrastructure/test-filter.js'; +export { iterListFunctions, iterRoles, iterWhere } from '../shared/generators.js'; // ── Kind/edge constants (canonical source: kinds.js) ───────────────────── export { ALL_SYMBOL_KINDS, @@ -18,8 +19,7 @@ export { EXTENDED_SYMBOL_KINDS, STRUCTURAL_EDGE_KINDS, VALID_ROLES, -} from '../kinds.js'; -export { iterListFunctions, iterRoles, iterWhere } from '../shared/generators.js'; +} from '../shared/kinds.js'; // ── Shared utilities ───────────────────────────────────────────────────── export { kindIcon, normalizeSymbol } from '../shared/normalize.js'; export { contextData, explainData } from './analysis/context.js'; diff --git a/src/domain/search/generator.js b/src/domain/search/generator.js index 6936dd84..dcdfd36c 100644 --- a/src/domain/search/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/index.js'; -import { DbError } from '../../errors.js'; -import { warn } from '../../logger.js'; +import { warn } from '../../infrastructure/logger.js'; +import { DbError } from '../../shared/errors.js'; import { embed, getModelConfig } from './models.js'; import { buildSourceText } from './strategies/source.js'; import { buildStructuredText } from './strategies/structured.js'; diff --git a/src/domain/search/models.js b/src/domain/search/models.js index 355dd381..404952cc 100644 --- a/src/domain/search/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 { info } from '../../infrastructure/logger.js'; +import { ConfigError, EngineError } from '../../shared/errors.js'; // Lazy-load transformers (heavy, optional module) let pipeline = null; diff --git a/src/domain/search/search/cli-formatter.js b/src/domain/search/search/cli-formatter.js index 013333af..a0b45a80 100644 --- a/src/domain/search/search/cli-formatter.js +++ b/src/domain/search/search/cli-formatter.js @@ -1,4 +1,4 @@ -import { warn } from '../../../logger.js'; +import { warn } from '../../../infrastructure/logger.js'; import { hybridSearchData } from './hybrid.js'; import { ftsSearchData } from './keyword.js'; import { multiSearchData, searchData } from './semantic.js'; diff --git a/src/domain/search/search/semantic.js b/src/domain/search/search/semantic.js index aa624ab6..dc7b301a 100644 --- a/src/domain/search/search/semantic.js +++ b/src/domain/search/search/semantic.js @@ -1,4 +1,4 @@ -import { warn } from '../../../logger.js'; +import { warn } from '../../../infrastructure/logger.js'; import { normalizeSymbol } from '../../queries.js'; import { embed } from '../models.js'; import { cosineSim } from '../stores/sqlite-blob.js'; diff --git a/src/extractors/javascript.js b/src/extractors/javascript.js index 06f9468b..a2d9e7b1 100644 --- a/src/extractors/javascript.js +++ b/src/extractors/javascript.js @@ -1,4 +1,4 @@ -import { debug } from '../logger.js'; +import { debug } from '../infrastructure/logger.js'; import { findChild, nodeEndLine } from './helpers.js'; /** diff --git a/src/features/ast.js b/src/features/ast.js index 6935efe7..6bc3a371 100644 --- a/src/features/ast.js +++ b/src/features/ast.js @@ -12,9 +12,9 @@ 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 { debug } from '../infrastructure/logger.js'; import { outputResult } from '../infrastructure/result-formatter.js'; -import { debug } from '../logger.js'; -import { paginateResult } from '../paginate.js'; +import { paginateResult } from '../shared/paginate.js'; // ─── Constants ──────────────────────────────────────────────────────── diff --git a/src/features/audit.js b/src/features/audit.js index c267b04a..ef71ca93 100644 --- a/src/features/audit.js +++ b/src/features/audit.js @@ -7,9 +7,9 @@ */ import path from 'node:path'; -import { loadConfig } from '../config.js'; import { openReadonlyOrFail } from '../db/index.js'; import { explainData } from '../domain/queries.js'; +import { loadConfig } from '../infrastructure/config.js'; import { isTestFile } from '../infrastructure/test-filter.js'; import { RULE_DEFS } from './manifesto.js'; diff --git a/src/features/batch.js b/src/features/batch.js index 4d1225bd..f5f386a7 100644 --- a/src/features/batch.js +++ b/src/features/batch.js @@ -15,7 +15,7 @@ import { impactAnalysisData, whereData, } from '../domain/queries.js'; -import { ConfigError } from '../errors.js'; +import { ConfigError } from '../shared/errors.js'; import { complexityData } from './complexity.js'; import { dataflowData } from './dataflow.js'; import { flowData } from './flow.js'; diff --git a/src/features/boundaries.js b/src/features/boundaries.js index 8da92b92..7a357ebd 100644 --- a/src/features/boundaries.js +++ b/src/features/boundaries.js @@ -1,5 +1,5 @@ +import { debug } from '../infrastructure/logger.js'; import { isTestFile } from '../infrastructure/test-filter.js'; -import { debug } from '../logger.js'; // ─── Glob-to-Regex ─────────────────────────────────────────────────── diff --git a/src/features/cfg.js b/src/features/cfg.js index 6f1dcdfc..e8728cab 100644 --- a/src/features/cfg.js +++ b/src/features/cfg.js @@ -23,9 +23,9 @@ import { hasCfgTables, openReadonlyOrFail, } from '../db/index.js'; +import { info } from '../infrastructure/logger.js'; import { isTestFile } from '../infrastructure/test-filter.js'; -import { info } from '../logger.js'; -import { paginateResult } from '../paginate.js'; +import { paginateResult } from '../shared/paginate.js'; // Re-export for backward compatibility export { _makeCfgRules as makeCfgRules, CFG_RULES }; @@ -104,13 +104,13 @@ export async function buildCFGData(db, fileSymbols, rootDir, _engineOpts) { } if (needsFallback) { - const { createParsers } = await import('./parser.js'); + const { createParsers } = await import('../domain/parser.js'); parsers = await createParsers(); } let getParserFn = null; if (parsers) { - const mod = await import('./parser.js'); + const mod = await import('../domain/parser.js'); getParserFn = mod.getParser; } diff --git a/src/features/check.js b/src/features/check.js index b8e3c75f..f3de3b78 100644 --- a/src/features/check.js +++ b/src/features/check.js @@ -1,9 +1,9 @@ import { execFileSync } from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; -import { loadConfig } from '../config.js'; import { findDbPath, openReadonlyOrFail } from '../db/index.js'; import { findCycles } from '../domain/graph/cycles.js'; +import { loadConfig } from '../infrastructure/config.js'; import { isTestFile } from '../infrastructure/test-filter.js'; import { matchOwners, parseCodeowners } from './owners.js'; diff --git a/src/features/cochange.js b/src/features/cochange.js index 134519ed..4c531dfe 100644 --- a/src/features/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/index.js'; +import { warn } from '../infrastructure/logger.js'; import { isTestFile } from '../infrastructure/test-filter.js'; -import { warn } from '../logger.js'; -import { paginateResult } from '../paginate.js'; +import { normalizePath } from '../shared/constants.js'; +import { paginateResult } from '../shared/paginate.js'; /** * Scan git history and return parsed commit data. diff --git a/src/features/communities.js b/src/features/communities.js index 51970558..cf46fa39 100644 --- a/src/features/communities.js +++ b/src/features/communities.js @@ -2,7 +2,7 @@ import path from 'node:path'; 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'; +import { paginateResult } from '../shared/paginate.js'; // ─── Directory Helpers ──────────────────────────────────────────────── diff --git a/src/features/complexity.js b/src/features/complexity.js index b319c945..4e4cf35d 100644 --- a/src/features/complexity.js +++ b/src/features/complexity.js @@ -12,11 +12,11 @@ import { } 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 { loadConfig } from '../infrastructure/config.js'; +import { info } from '../infrastructure/logger.js'; import { isTestFile } from '../infrastructure/test-filter.js'; -import { info } from '../logger.js'; -import { paginateResult } from '../paginate.js'; +import { paginateResult } from '../shared/paginate.js'; // Re-export rules for backward compatibility export { COMPLEXITY_RULES, HALSTEAD_RULES }; @@ -360,12 +360,12 @@ export async function buildComplexityMetrics(db, fileSymbols, rootDir, _engineOp } } if (needsFallback) { - const { createParsers } = await import('./parser.js'); + const { createParsers } = await import('../domain/parser.js'); parsers = await createParsers(); extToLang = buildExtToLangMap(); } - const { getParser } = await import('./parser.js'); + const { getParser } = await import('../domain/parser.js'); const upsert = db.prepare( `INSERT OR REPLACE INTO function_complexity diff --git a/src/features/dataflow.js b/src/features/dataflow.js index dbff4cda..9d0c8bcc 100644 --- a/src/features/dataflow.js +++ b/src/features/dataflow.js @@ -21,9 +21,9 @@ 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 { info } from '../infrastructure/logger.js'; import { isTestFile } from '../infrastructure/test-filter.js'; -import { info } from '../logger.js'; -import { paginateResult } from '../paginate.js'; +import { paginateResult } from '../shared/paginate.js'; // Re-export for backward compatibility export { _makeDataflowRules as makeDataflowRules, DATAFLOW_RULES }; @@ -88,13 +88,13 @@ export async function buildDataflowEdges(db, fileSymbols, rootDir, _engineOpts) } if (needsFallback) { - const { createParsers } = await import('./parser.js'); + const { createParsers } = await import('../domain/parser.js'); parsers = await createParsers(); } let getParserFn = null; if (parsers) { - const mod = await import('./parser.js'); + const mod = await import('../domain/parser.js'); getParserFn = mod.getParser; } diff --git a/src/features/export.js b/src/features/export.js index 61ed15ba..6f93faae 100644 --- a/src/features/export.js +++ b/src/features/export.js @@ -1,6 +1,5 @@ import path from 'node:path'; import { isTestFile } from '../infrastructure/test-filter.js'; -import { paginateResult } from '../paginate.js'; import { renderFileLevelDOT, renderFileLevelGraphML, @@ -11,6 +10,7 @@ import { renderFunctionLevelMermaid, renderFunctionLevelNeo4jCSV, } from '../presentation/export.js'; +import { paginateResult } from '../shared/paginate.js'; const DEFAULT_MIN_CONFIDENCE = 0.5; diff --git a/src/features/flow.js b/src/features/flow.js index 8f42af3a..e91e00b8 100644 --- a/src/features/flow.js +++ b/src/features/flow.js @@ -8,7 +8,7 @@ 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 { paginateResult } from '../shared/paginate.js'; import { FRAMEWORK_ENTRY_PREFIXES } from './structure.js'; /** diff --git a/src/features/manifesto.js b/src/features/manifesto.js index c77ae21d..3113122a 100644 --- a/src/features/manifesto.js +++ b/src/features/manifesto.js @@ -1,8 +1,8 @@ -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 { loadConfig } from '../infrastructure/config.js'; +import { debug } from '../infrastructure/logger.js'; +import { paginateResult } from '../shared/paginate.js'; import { evaluateBoundaries } from './boundaries.js'; // ─── Rule Definitions ───────────────────────────────────────────────── diff --git a/src/features/sequence.js b/src/features/sequence.js index 78a3d68a..0edeba87 100644 --- a/src/features/sequence.js +++ b/src/features/sequence.js @@ -9,7 +9,7 @@ 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 { paginateResult } from '../shared/paginate.js'; import { FRAMEWORK_ENTRY_PREFIXES } from './structure.js'; // ─── Alias generation ──────────────────────────────────────────────── diff --git a/src/features/snapshot.js b/src/features/snapshot.js index 007549aa..71baf8d2 100644 --- a/src/features/snapshot.js +++ b/src/features/snapshot.js @@ -2,8 +2,8 @@ import fs from 'node:fs'; import path from 'node:path'; import Database from 'better-sqlite3'; import { findDbPath } from '../db/index.js'; -import { ConfigError, DbError } from '../errors.js'; -import { debug } from '../logger.js'; +import { debug } from '../infrastructure/logger.js'; +import { ConfigError, DbError } from '../shared/errors.js'; const NAME_RE = /^[a-zA-Z0-9_-]+$/; diff --git a/src/features/structure.js b/src/features/structure.js index 7fcd5628..4ba9ee0a 100644 --- a/src/features/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/index.js'; +import { debug } from '../infrastructure/logger.js'; import { isTestFile } from '../infrastructure/test-filter.js'; -import { debug } from '../logger.js'; -import { paginateResult } from '../paginate.js'; +import { normalizePath } from '../shared/constants.js'; +import { paginateResult } from '../shared/paginate.js'; // ─── Build-time: insert directory nodes, contains edges, and metrics ──── diff --git a/src/features/triage.js b/src/features/triage.js index 5cd9d7a1..32257f3f 100644 --- a/src/features/triage.js +++ b/src/features/triage.js @@ -1,8 +1,8 @@ import { findNodesForTriage, openReadonlyOrFail } from '../db/index.js'; import { DEFAULT_WEIGHTS, scoreRisk } from '../graph/classifiers/risk.js'; +import { warn } from '../infrastructure/logger.js'; import { isTestFile } from '../infrastructure/test-filter.js'; -import { warn } from '../logger.js'; -import { paginateResult } from '../paginate.js'; +import { paginateResult } from '../shared/paginate.js'; // ─── Data Function ──────────────────────────────────────────────────── diff --git a/src/index.js b/src/index.js index a50e9017..448cbed0 100644 --- a/src/index.js +++ b/src/index.js @@ -9,8 +9,6 @@ * import { buildGraph, queryNameData, findCycles, exportDOT } from '@optave/codegraph'; */ -export { loadConfig } from './config.js'; -export { EXTENSIONS, IGNORE_DIRS } from './constants.js'; export { buildGraph } from './domain/graph/builder.js'; export { findCycles } from './domain/graph/cycles.js'; export { @@ -36,16 +34,6 @@ export { 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'; @@ -63,4 +51,16 @@ 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'; +export { loadConfig } from './infrastructure/config.js'; +export { EXTENSIONS, IGNORE_DIRS } from './shared/constants.js'; +export { + AnalysisError, + BoundaryError, + CodegraphError, + ConfigError, + DbError, + EngineError, + ParseError, + ResolutionError, +} from './shared/errors.js'; +export { EVERY_EDGE_KIND, EVERY_SYMBOL_KIND } from './shared/kinds.js'; diff --git a/src/config.js b/src/infrastructure/config.js similarity index 100% rename from src/config.js rename to src/infrastructure/config.js diff --git a/src/logger.js b/src/infrastructure/logger.js similarity index 100% rename from src/logger.js rename to src/infrastructure/logger.js diff --git a/src/native.js b/src/infrastructure/native.js similarity index 98% rename from src/native.js rename to src/infrastructure/native.js index 7de86d9a..a1481621 100644 --- a/src/native.js +++ b/src/infrastructure/native.js @@ -8,7 +8,7 @@ import { createRequire } from 'node:module'; import os from 'node:os'; -import { EngineError } from './errors.js'; +import { EngineError } from '../shared/errors.js'; let _cached; // undefined = not yet tried, null = failed, object = module let _loadError = null; diff --git a/src/registry.js b/src/infrastructure/registry.js similarity index 100% rename from src/registry.js rename to src/infrastructure/registry.js diff --git a/src/update-check.js b/src/infrastructure/update-check.js similarity index 100% rename from src/update-check.js rename to src/infrastructure/update-check.js diff --git a/src/mcp/middleware.js b/src/mcp/middleware.js index 7f261cad..96dc26af 100644 --- a/src/mcp/middleware.js +++ b/src/mcp/middleware.js @@ -2,7 +2,7 @@ * MCP middleware helpers — pagination defaults and limits. */ -import { MCP_DEFAULTS, MCP_MAX_LIMIT } from '../paginate.js'; +import { MCP_DEFAULTS, MCP_MAX_LIMIT } from '../shared/paginate.js'; export { MCP_DEFAULTS, MCP_MAX_LIMIT }; diff --git a/src/mcp/server.js b/src/mcp/server.js index b5c1ea92..464fafaf 100644 --- a/src/mcp/server.js +++ b/src/mcp/server.js @@ -7,8 +7,8 @@ import { createRequire } from 'node:module'; import { findDbPath } from '../db/index.js'; -import { CodegraphError, ConfigError } from '../errors.js'; -import { MCP_MAX_LIMIT } from '../paginate.js'; +import { CodegraphError, ConfigError } from '../shared/errors.js'; +import { MCP_MAX_LIMIT } from '../shared/paginate.js'; import { buildToolList } from './tool-registry.js'; import { TOOL_HANDLERS } from './tools/index.js'; @@ -89,7 +89,7 @@ export async function startMCPServer(customDbPath, options = {}) { if (allowedRepos && !allowedRepos.includes(args.repo)) { throw new ConfigError(`Repository "${args.repo}" is not in the allowed repos list.`); } - const { resolveRepoDbPath } = await import('../registry.js'); + const { resolveRepoDbPath } = await import('../infrastructure/registry.js'); const resolved = resolveRepoDbPath(args.repo); if (!resolved) throw new ConfigError( diff --git a/src/mcp/tools/list-repos.js b/src/mcp/tools/list-repos.js index 743fa959..1cd18d3d 100644 --- a/src/mcp/tools/list-repos.js +++ b/src/mcp/tools/list-repos.js @@ -1,7 +1,7 @@ export const name = 'list_repos'; export async function handler(_args, ctx) { - const { listRepos, pruneRegistry } = await import('../../registry.js'); + const { listRepos, pruneRegistry } = await import('../../infrastructure/registry.js'); pruneRegistry(); let repos = listRepos(); if (ctx.allowedRepos) { diff --git a/src/presentation/result-formatter.js b/src/presentation/result-formatter.js index 98aa8ea1..389df681 100644 --- a/src/presentation/result-formatter.js +++ b/src/presentation/result-formatter.js @@ -1,4 +1,4 @@ -import { printNdjson } from '../paginate.js'; +import { printNdjson } from '../shared/paginate.js'; /** * Shared JSON / NDJSON output dispatch for CLI wrappers. diff --git a/src/constants.js b/src/shared/constants.js similarity index 92% rename from src/constants.js rename to src/shared/constants.js index 2bcbb1af..db06b4c5 100644 --- a/src/constants.js +++ b/src/shared/constants.js @@ -1,5 +1,5 @@ import path from 'node:path'; -import { SUPPORTED_EXTENSIONS } from './parser.js'; +import { SUPPORTED_EXTENSIONS } from '../domain/parser.js'; export const IGNORE_DIRS = new Set([ 'node_modules', diff --git a/src/errors.js b/src/shared/errors.js similarity index 100% rename from src/errors.js rename to src/shared/errors.js diff --git a/src/shared/file-utils.js b/src/shared/file-utils.js index bd52719d..814f54de 100644 --- a/src/shared/file-utils.js +++ b/src/shared/file-utils.js @@ -1,7 +1,7 @@ import fs from 'node:fs'; import path from 'node:path'; -import { debug } from '../logger.js'; -import { LANGUAGE_REGISTRY } from '../parser.js'; +import { LANGUAGE_REGISTRY } from '../domain/parser.js'; +import { debug } from '../infrastructure/logger.js'; /** * Resolve a file path relative to repoRoot, rejecting traversal outside the repo. diff --git a/src/shared/generators.js b/src/shared/generators.js index 93753dbd..3d121f81 100644 --- a/src/shared/generators.js +++ b/src/shared/generators.js @@ -1,6 +1,6 @@ import { iterateFunctionNodes, openReadonlyOrFail } from '../db/index.js'; import { isTestFile } from '../infrastructure/test-filter.js'; -import { ALL_SYMBOL_KINDS } from '../kinds.js'; +import { ALL_SYMBOL_KINDS } from './kinds.js'; /** * Generator: stream functions one-by-one using .iterate() for memory efficiency. diff --git a/src/kinds.js b/src/shared/kinds.js similarity index 100% rename from src/kinds.js rename to src/shared/kinds.js diff --git a/src/paginate.js b/src/shared/paginate.js similarity index 100% rename from src/paginate.js rename to src/shared/paginate.js diff --git a/tests/builder/detect-changes.test.js b/tests/builder/detect-changes.test.js index f6a671e3..2555b097 100644 --- a/tests/builder/detect-changes.test.js +++ b/tests/builder/detect-changes.test.js @@ -8,7 +8,7 @@ import { afterAll, beforeAll, describe, expect, it } from 'vitest'; 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'; +import { writeJournalHeader } from '../../src/domain/graph/journal.js'; let tmpDir; diff --git a/tests/engines/dataflow-parity.test.js b/tests/engines/dataflow-parity.test.js index 1559243a..0ed2d996 100644 --- a/tests/engines/dataflow-parity.test.js +++ b/tests/engines/dataflow-parity.test.js @@ -12,9 +12,9 @@ */ import { beforeAll, describe, expect, it } from 'vitest'; +import { createParsers, getParser } from '../../src/domain/parser.js'; import { extractDataflow } from '../../src/features/dataflow.js'; -import { isNativeAvailable } from '../../src/native.js'; -import { createParsers, getParser } from '../../src/parser.js'; +import { isNativeAvailable } from '../../src/infrastructure/native.js'; let native; let parsers; @@ -136,7 +136,7 @@ const describeOrSkip = hasNative ? describe : describe.skip; describeOrSkip('Cross-engine dataflow parity', () => { beforeAll(async () => { if (!hasNative) return; - const { getNative } = await import('../../src/native.js'); + const { getNative } = await import('../../src/infrastructure/native.js'); native = getNative(); nativeHasDataflow = detectNativeDataflow(); parsers = await createParsers(); diff --git a/tests/engines/parity.test.js b/tests/engines/parity.test.js index 184d2e06..fc11c2e1 100644 --- a/tests/engines/parity.test.js +++ b/tests/engines/parity.test.js @@ -8,7 +8,6 @@ */ import { beforeAll, describe, expect, it } from 'vitest'; -import { isNativeAvailable } from '../../src/native.js'; import { createParsers, extractCSharpSymbols, @@ -21,7 +20,8 @@ import { extractRustSymbols, extractSymbols, getParser, -} from '../../src/parser.js'; +} from '../../src/domain/parser.js'; +import { isNativeAvailable } from '../../src/infrastructure/native.js'; let native; let parsers; @@ -110,7 +110,7 @@ const describeOrSkip = hasNative ? describe : describe.skip; describeOrSkip('Cross-engine parity', () => { beforeAll(async () => { if (!hasNative) return; - const { getNative } = await import('../../src/native.js'); + const { getNative } = await import('../../src/infrastructure/native.js'); native = getNative(); parsers = await createParsers(); }); diff --git a/tests/engines/query-walk-parity.test.js b/tests/engines/query-walk-parity.test.js index 2556af08..05335c5c 100644 --- a/tests/engines/query-walk-parity.test.js +++ b/tests/engines/query-walk-parity.test.js @@ -9,8 +9,8 @@ */ import { beforeAll, describe, expect, it } from 'vitest'; +import { createParsers, getParser, parseFileAuto } from '../../src/domain/parser.js'; import { extractSymbols } from '../../src/extractors/javascript.js'; -import { createParsers, getParser, parseFileAuto } from '../../src/parser.js'; let parsers; diff --git a/tests/graph/cycles.test.js b/tests/graph/cycles.test.js index 8f6946e3..2dd8a2ea 100644 --- a/tests/graph/cycles.test.js +++ b/tests/graph/cycles.test.js @@ -6,7 +6,7 @@ import Database from 'better-sqlite3'; import { describe, expect, it } from 'vitest'; import { initSchema } from '../../src/db/index.js'; import { findCycles, findCyclesJS } from '../../src/domain/graph/cycles.js'; -import { isNativeAvailable, loadNative } from '../../src/native.js'; +import { isNativeAvailable, loadNative } from '../../src/infrastructure/native.js'; const hasNative = isNativeAvailable(); diff --git a/tests/incremental/cache.test.js b/tests/incremental/cache.test.js index f930ce64..46ee6290 100644 --- a/tests/incremental/cache.test.js +++ b/tests/incremental/cache.test.js @@ -5,7 +5,7 @@ */ import { beforeEach, describe, expect, it } from 'vitest'; -import { isNativeAvailable, loadNative } from '../../src/native.js'; +import { isNativeAvailable, loadNative } from '../../src/infrastructure/native.js'; const hasNative = isNativeAvailable(); diff --git a/tests/incremental/watcher-incremental.test.js b/tests/incremental/watcher-incremental.test.js index d2619894..8c273203 100644 --- a/tests/incremental/watcher-incremental.test.js +++ b/tests/incremental/watcher-incremental.test.js @@ -11,8 +11,8 @@ import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { isNativeAvailable } from '../../src/native.js'; -import { createParseTreeCache, parseFileIncremental } from '../../src/parser.js'; +import { createParseTreeCache, parseFileIncremental } from '../../src/domain/parser.js'; +import { isNativeAvailable } from '../../src/infrastructure/native.js'; const hasNative = isNativeAvailable(); diff --git a/tests/integration/build-parity.test.js b/tests/integration/build-parity.test.js index 18c710e2..86ef5043 100644 --- a/tests/integration/build-parity.test.js +++ b/tests/integration/build-parity.test.js @@ -13,7 +13,7 @@ import path from 'node:path'; import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, it } from 'vitest'; import { buildGraph } from '../../src/domain/graph/builder.js'; -import { isNativeAvailable } from '../../src/native.js'; +import { isNativeAvailable } from '../../src/infrastructure/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 8af7600d..d7bee6bc 100644 --- a/tests/integration/build.test.js +++ b/tests/integration/build.test.js @@ -10,7 +10,7 @@ import Database from 'better-sqlite3'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; 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'; +import { JOURNAL_FILENAME, writeJournalHeader } from '../../src/domain/graph/journal.js'; // ES-module versions of the sample-project fixture so the parser // generates import edges (the originals use CommonJS require()). diff --git a/tests/integration/complexity.test.js b/tests/integration/complexity.test.js index 52454bd9..8d7ea175 100644 --- a/tests/integration/complexity.test.js +++ b/tests/integration/complexity.test.js @@ -10,11 +10,11 @@ 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 { loadConfig } from '../../src/config.js'; import { initSchema } from '../../src/db/index.js'; import { complexityData } from '../../src/features/complexity.js'; +import { loadConfig } from '../../src/infrastructure/config.js'; -vi.mock('../../src/config.js', () => ({ +vi.mock('../../src/infrastructure/config.js', () => ({ loadConfig: vi.fn(() => ({})), })); diff --git a/tests/integration/pagination.test.js b/tests/integration/pagination.test.js index e57f9c19..ecf31c5d 100644 --- a/tests/integration/pagination.test.js +++ b/tests/integration/pagination.test.js @@ -41,7 +41,7 @@ import { paginate, paginateResult, printNdjson, -} from '../../src/paginate.js'; +} from '../../src/shared/paginate.js'; // ─── Helpers ─────────────────────────────────────────────────────────── diff --git a/tests/parsers/ast-all-langs.test.js b/tests/parsers/ast-all-langs.test.js index 615c9304..b4130a18 100644 --- a/tests/parsers/ast-all-langs.test.js +++ b/tests/parsers/ast-all-langs.test.js @@ -13,9 +13,9 @@ 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 { parseFilesAuto } from '../../src/domain/parser.js'; import { buildAstNodes } from '../../src/features/ast.js'; -import { loadNative } from '../../src/native.js'; -import { parseFilesAuto } from '../../src/parser.js'; +import { loadNative } from '../../src/infrastructure/native.js'; // ─── Helpers ────────────────────────────────────────────────────────── diff --git a/tests/parsers/ast-nodes.test.js b/tests/parsers/ast-nodes.test.js index 894d9d1a..3d3c3de7 100644 --- a/tests/parsers/ast-nodes.test.js +++ b/tests/parsers/ast-nodes.test.js @@ -11,9 +11,9 @@ 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 { parseFilesAuto } from '../../src/domain/parser.js'; import { buildAstNodes } from '../../src/features/ast.js'; -import { loadNative } from '../../src/native.js'; -import { parseFilesAuto } from '../../src/parser.js'; +import { loadNative } from '../../src/infrastructure/native.js'; // ─── Fixture ────────────────────────────────────────────────────────── diff --git a/tests/parsers/cfg-all-langs.test.js b/tests/parsers/cfg-all-langs.test.js index f19ab8ec..f37c9a95 100644 --- a/tests/parsers/cfg-all-langs.test.js +++ b/tests/parsers/cfg-all-langs.test.js @@ -14,10 +14,10 @@ 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 { createParsers, getParser, parseFilesAuto } from '../../src/domain/parser.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'; +import { loadNative } from '../../src/infrastructure/native.js'; // ─── Helpers ────────────────────────────────────────────────────────── diff --git a/tests/parsers/csharp.test.js b/tests/parsers/csharp.test.js index e8031262..01d3725a 100644 --- a/tests/parsers/csharp.test.js +++ b/tests/parsers/csharp.test.js @@ -1,5 +1,5 @@ import { beforeAll, describe, expect, it } from 'vitest'; -import { createParsers, extractCSharpSymbols } from '../../src/parser.js'; +import { createParsers, extractCSharpSymbols } from '../../src/domain/parser.js'; describe('C# parser', () => { let parsers; diff --git a/tests/parsers/dataflow-csharp.test.js b/tests/parsers/dataflow-csharp.test.js index 6744d1c9..30f91a2d 100644 --- a/tests/parsers/dataflow-csharp.test.js +++ b/tests/parsers/dataflow-csharp.test.js @@ -2,8 +2,8 @@ * Unit tests for extractDataflow() against parsed C# ASTs. */ import { beforeAll, describe, expect, it } from 'vitest'; +import { createParsers } from '../../src/domain/parser.js'; import { extractDataflow } from '../../src/features/dataflow.js'; -import { createParsers } from '../../src/parser.js'; describe('extractDataflow — C#', () => { let parsers; diff --git a/tests/parsers/dataflow-go.test.js b/tests/parsers/dataflow-go.test.js index 674b8b3c..2f73d294 100644 --- a/tests/parsers/dataflow-go.test.js +++ b/tests/parsers/dataflow-go.test.js @@ -2,8 +2,8 @@ * Unit tests for extractDataflow() against parsed Go ASTs. */ import { beforeAll, describe, expect, it } from 'vitest'; +import { createParsers } from '../../src/domain/parser.js'; import { extractDataflow } from '../../src/features/dataflow.js'; -import { createParsers } from '../../src/parser.js'; describe('extractDataflow — Go', () => { let parsers; diff --git a/tests/parsers/dataflow-java.test.js b/tests/parsers/dataflow-java.test.js index 24175ea0..44481a4e 100644 --- a/tests/parsers/dataflow-java.test.js +++ b/tests/parsers/dataflow-java.test.js @@ -2,8 +2,8 @@ * Unit tests for extractDataflow() against parsed Java ASTs. */ import { beforeAll, describe, expect, it } from 'vitest'; +import { createParsers } from '../../src/domain/parser.js'; import { extractDataflow } from '../../src/features/dataflow.js'; -import { createParsers } from '../../src/parser.js'; describe('extractDataflow — Java', () => { let parsers; diff --git a/tests/parsers/dataflow-javascript.test.js b/tests/parsers/dataflow-javascript.test.js index df9d1dfb..bcbdf0c9 100644 --- a/tests/parsers/dataflow-javascript.test.js +++ b/tests/parsers/dataflow-javascript.test.js @@ -2,8 +2,8 @@ * Unit tests for extractDataflow() against parsed JS/TS ASTs. */ import { beforeAll, describe, expect, it } from 'vitest'; +import { createParsers } from '../../src/domain/parser.js'; import { extractDataflow } from '../../src/features/dataflow.js'; -import { createParsers } from '../../src/parser.js'; describe('extractDataflow — JavaScript', () => { let parsers; diff --git a/tests/parsers/dataflow-php.test.js b/tests/parsers/dataflow-php.test.js index ae337942..ef5ddcc9 100644 --- a/tests/parsers/dataflow-php.test.js +++ b/tests/parsers/dataflow-php.test.js @@ -2,8 +2,8 @@ * Unit tests for extractDataflow() against parsed PHP ASTs. */ import { beforeAll, describe, expect, it } from 'vitest'; +import { createParsers } from '../../src/domain/parser.js'; import { extractDataflow } from '../../src/features/dataflow.js'; -import { createParsers } from '../../src/parser.js'; describe('extractDataflow — PHP', () => { let parsers; diff --git a/tests/parsers/dataflow-python.test.js b/tests/parsers/dataflow-python.test.js index 4a83874e..e97aeea9 100644 --- a/tests/parsers/dataflow-python.test.js +++ b/tests/parsers/dataflow-python.test.js @@ -2,8 +2,8 @@ * Unit tests for extractDataflow() against parsed Python ASTs. */ import { beforeAll, describe, expect, it } from 'vitest'; +import { createParsers } from '../../src/domain/parser.js'; import { extractDataflow } from '../../src/features/dataflow.js'; -import { createParsers } from '../../src/parser.js'; describe('extractDataflow — Python', () => { let parsers; diff --git a/tests/parsers/dataflow-ruby.test.js b/tests/parsers/dataflow-ruby.test.js index 69aa67db..973c6bee 100644 --- a/tests/parsers/dataflow-ruby.test.js +++ b/tests/parsers/dataflow-ruby.test.js @@ -2,8 +2,8 @@ * Unit tests for extractDataflow() against parsed Ruby ASTs. */ import { beforeAll, describe, expect, it } from 'vitest'; +import { createParsers } from '../../src/domain/parser.js'; import { extractDataflow } from '../../src/features/dataflow.js'; -import { createParsers } from '../../src/parser.js'; describe('extractDataflow — Ruby', () => { let parsers; diff --git a/tests/parsers/dataflow-rust.test.js b/tests/parsers/dataflow-rust.test.js index 5d771740..f7200487 100644 --- a/tests/parsers/dataflow-rust.test.js +++ b/tests/parsers/dataflow-rust.test.js @@ -2,8 +2,8 @@ * Unit tests for extractDataflow() against parsed Rust ASTs. */ import { beforeAll, describe, expect, it } from 'vitest'; +import { createParsers } from '../../src/domain/parser.js'; import { extractDataflow } from '../../src/features/dataflow.js'; -import { createParsers } from '../../src/parser.js'; describe('extractDataflow — Rust', () => { let parsers; diff --git a/tests/parsers/extended-kinds.test.js b/tests/parsers/extended-kinds.test.js index 266ac44a..ab1a8ccf 100644 --- a/tests/parsers/extended-kinds.test.js +++ b/tests/parsers/extended-kinds.test.js @@ -15,7 +15,7 @@ import { extractRubySymbols, extractRustSymbols, extractSymbols, -} from '../../src/parser.js'; +} from '../../src/domain/parser.js'; // ── JavaScript ────────────────────────────────────────────────────────────── diff --git a/tests/parsers/go.test.js b/tests/parsers/go.test.js index 6d6c23a0..e8c29581 100644 --- a/tests/parsers/go.test.js +++ b/tests/parsers/go.test.js @@ -1,5 +1,5 @@ import { beforeAll, describe, expect, it } from 'vitest'; -import { createParsers, extractGoSymbols } from '../../src/parser.js'; +import { createParsers, extractGoSymbols } from '../../src/domain/parser.js'; describe('Go parser', () => { let parsers; diff --git a/tests/parsers/java.test.js b/tests/parsers/java.test.js index cc458dbd..79486a04 100644 --- a/tests/parsers/java.test.js +++ b/tests/parsers/java.test.js @@ -1,5 +1,5 @@ import { beforeAll, describe, expect, it } from 'vitest'; -import { createParsers, extractJavaSymbols } from '../../src/parser.js'; +import { createParsers, extractJavaSymbols } from '../../src/domain/parser.js'; describe('Java parser', () => { let parsers; diff --git a/tests/parsers/javascript.test.js b/tests/parsers/javascript.test.js index 539929c0..63875fc8 100644 --- a/tests/parsers/javascript.test.js +++ b/tests/parsers/javascript.test.js @@ -6,7 +6,7 @@ * Then: npm test */ import { beforeAll, describe, expect, it } from 'vitest'; -import { createParsers, extractSymbols } from '../../src/parser.js'; +import { createParsers, extractSymbols } from '../../src/domain/parser.js'; describe('JavaScript parser', () => { let parsers; diff --git a/tests/parsers/php.test.js b/tests/parsers/php.test.js index 8f32dbad..106ba306 100644 --- a/tests/parsers/php.test.js +++ b/tests/parsers/php.test.js @@ -1,5 +1,5 @@ import { beforeAll, describe, expect, it } from 'vitest'; -import { createParsers, extractPHPSymbols } from '../../src/parser.js'; +import { createParsers, extractPHPSymbols } from '../../src/domain/parser.js'; describe('PHP parser', () => { let parsers; diff --git a/tests/parsers/ruby.test.js b/tests/parsers/ruby.test.js index 64d0d45a..eff4a403 100644 --- a/tests/parsers/ruby.test.js +++ b/tests/parsers/ruby.test.js @@ -1,5 +1,5 @@ import { beforeAll, describe, expect, it } from 'vitest'; -import { createParsers, extractRubySymbols } from '../../src/parser.js'; +import { createParsers, extractRubySymbols } from '../../src/domain/parser.js'; describe('Ruby parser', () => { let parsers; diff --git a/tests/parsers/rust.test.js b/tests/parsers/rust.test.js index e58ea256..e6ee7dae 100644 --- a/tests/parsers/rust.test.js +++ b/tests/parsers/rust.test.js @@ -1,5 +1,5 @@ import { beforeAll, describe, expect, it } from 'vitest'; -import { createParsers, extractRustSymbols } from '../../src/parser.js'; +import { createParsers, extractRustSymbols } from '../../src/domain/parser.js'; describe('Rust parser', () => { let parsers; diff --git a/tests/parsers/unified.test.js b/tests/parsers/unified.test.js index d5c59d66..b05c1919 100644 --- a/tests/parsers/unified.test.js +++ b/tests/parsers/unified.test.js @@ -6,7 +6,7 @@ import path from 'node:path'; import { describe, expect, it } from 'vitest'; -import { getActiveEngine, parseFileAuto, parseFilesAuto } from '../../src/parser.js'; +import { getActiveEngine, parseFileAuto, parseFilesAuto } from '../../src/domain/parser.js'; describe('Unified parser API', () => { describe('getActiveEngine', () => { diff --git a/tests/resolution/parity.test.js b/tests/resolution/parity.test.js index 444c4040..6c036ee0 100644 --- a/tests/resolution/parity.test.js +++ b/tests/resolution/parity.test.js @@ -14,7 +14,7 @@ import { resolveImportPathJS, resolveImportsBatch, } from '../../src/domain/graph/resolve.js'; -import { isNativeAvailable, loadNative } from '../../src/native.js'; +import { isNativeAvailable, loadNative } from '../../src/infrastructure/native.js'; const hasNative = isNativeAvailable(); diff --git a/tests/unit/cfg.test.js b/tests/unit/cfg.test.js index adf8aa49..50dc06dd 100644 --- a/tests/unit/cfg.test.js +++ b/tests/unit/cfg.test.js @@ -9,9 +9,9 @@ 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 { createParsers } from '../../src/domain/parser.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/change-journal.test.js b/tests/unit/change-journal.test.js index 5fcc787b..3595c674 100644 --- a/tests/unit/change-journal.test.js +++ b/tests/unit/change-journal.test.js @@ -14,7 +14,7 @@ import { DEFAULT_MAX_BYTES, diffSymbols, rotateIfNeeded, -} from '../../src/change-journal.js'; +} from '../../src/domain/graph/change-journal.js'; let tmpDir; diff --git a/tests/unit/complexity.test.js b/tests/unit/complexity.test.js index b458ead1..776df84c 100644 --- a/tests/unit/complexity.test.js +++ b/tests/unit/complexity.test.js @@ -6,6 +6,7 @@ */ import { beforeAll, describe, expect, it } from 'vitest'; +import { createParsers } from '../../src/domain/parser.js'; import { COMPLEXITY_RULES, computeFunctionComplexity, @@ -14,7 +15,6 @@ import { computeMaintainabilityIndex, HALSTEAD_RULES, } from '../../src/features/complexity.js'; -import { createParsers } from '../../src/parser.js'; let jsParser; diff --git a/tests/unit/config.test.js b/tests/unit/config.test.js index 77af17aa..56685830 100644 --- a/tests/unit/config.test.js +++ b/tests/unit/config.test.js @@ -12,7 +12,7 @@ import { DEFAULTS, loadConfig, resolveSecrets, -} from '../../src/config.js'; +} from '../../src/infrastructure/config.js'; vi.mock('node:child_process', async (importOriginal) => { const actual = await importOriginal(); diff --git a/tests/unit/constants.test.js b/tests/unit/constants.test.js index e192c056..81ed4dba 100644 --- a/tests/unit/constants.test.js +++ b/tests/unit/constants.test.js @@ -10,7 +10,7 @@ import { isSupportedFile, normalizePath, shouldIgnore, -} from '../../src/constants.js'; +} from '../../src/shared/constants.js'; describe('EXTENSIONS', () => { it('contains known supported extensions', () => { diff --git a/tests/unit/errors.test.js b/tests/unit/errors.test.js index 3714df5b..db4736e0 100644 --- a/tests/unit/errors.test.js +++ b/tests/unit/errors.test.js @@ -12,7 +12,7 @@ import { EngineError, ParseError, ResolutionError, -} from '../../src/errors.js'; +} from '../../src/shared/errors.js'; describe('CodegraphError', () => { it('sets defaults', () => { diff --git a/tests/unit/journal.test.js b/tests/unit/journal.test.js index a4ef3dd2..27769f2a 100644 --- a/tests/unit/journal.test.js +++ b/tests/unit/journal.test.js @@ -11,7 +11,7 @@ import { JOURNAL_FILENAME, readJournal, writeJournalHeader, -} from '../../src/journal.js'; +} from '../../src/domain/graph/journal.js'; let tmpDir; diff --git a/tests/unit/logger.test.js b/tests/unit/logger.test.js index a95ee42f..fb54863d 100644 --- a/tests/unit/logger.test.js +++ b/tests/unit/logger.test.js @@ -3,7 +3,14 @@ */ import { afterEach, describe, expect, it, vi } from 'vitest'; -import { debug, error, info, isVerbose, setVerbose, warn } from '../../src/logger.js'; +import { + debug, + error, + info, + isVerbose, + setVerbose, + warn, +} from '../../src/infrastructure/logger.js'; describe('logger', () => { let stderrSpy; diff --git a/tests/unit/mcp.test.js b/tests/unit/mcp.test.js index cb9f490e..352ea092 100644 --- a/tests/unit/mcp.test.js +++ b/tests/unit/mcp.test.js @@ -587,7 +587,7 @@ describe('startMCPServer handler dispatch', () => { ListToolsRequestSchema: 'tools/list', CallToolRequestSchema: 'tools/call', })); - vi.doMock('../../src/registry.js', () => ({ + vi.doMock('../../src/infrastructure/registry.js', () => ({ resolveRepoDbPath: vi.fn((name) => name === 'my-project' ? '/resolved/path/.codegraph/graph.db' : undefined, ), @@ -650,7 +650,7 @@ describe('startMCPServer handler dispatch', () => { ListToolsRequestSchema: 'tools/list', CallToolRequestSchema: 'tools/call', })); - vi.doMock('../../src/registry.js', () => ({ + vi.doMock('../../src/infrastructure/registry.js', () => ({ resolveRepoDbPath: vi.fn(() => undefined), })); vi.doMock('../../src/domain/queries.js', () => ({ @@ -703,7 +703,7 @@ describe('startMCPServer handler dispatch', () => { ListToolsRequestSchema: 'tools/list', CallToolRequestSchema: 'tools/call', })); - vi.doMock('../../src/registry.js', () => ({ + vi.doMock('../../src/infrastructure/registry.js', () => ({ resolveRepoDbPath: vi.fn(() => '/some/path'), })); vi.doMock('../../src/domain/queries.js', () => ({ @@ -756,7 +756,7 @@ describe('startMCPServer handler dispatch', () => { ListToolsRequestSchema: 'tools/list', CallToolRequestSchema: 'tools/call', })); - vi.doMock('../../src/registry.js', () => ({ + vi.doMock('../../src/infrastructure/registry.js', () => ({ resolveRepoDbPath: vi.fn(() => '/resolved/db'), })); @@ -817,7 +817,7 @@ describe('startMCPServer handler dispatch', () => { ListToolsRequestSchema: 'tools/list', CallToolRequestSchema: 'tools/call', })); - vi.doMock('../../src/registry.js', () => ({ + vi.doMock('../../src/infrastructure/registry.js', () => ({ resolveRepoDbPath: vi.fn(), listRepos: vi.fn(() => [ { name: 'alpha', path: '/alpha' }, @@ -876,7 +876,7 @@ describe('startMCPServer handler dispatch', () => { ListToolsRequestSchema: 'tools/list', CallToolRequestSchema: 'tools/call', })); - vi.doMock('../../src/registry.js', () => ({ + vi.doMock('../../src/infrastructure/registry.js', () => ({ resolveRepoDbPath: vi.fn(), listRepos: vi.fn(() => [ { name: 'alpha', path: '/alpha' }, diff --git a/tests/unit/parser.test.js b/tests/unit/parser.test.js index 495b2a96..7995ba77 100644 --- a/tests/unit/parser.test.js +++ b/tests/unit/parser.test.js @@ -4,7 +4,7 @@ import fs from 'node:fs'; import { afterEach, describe, expect, it, vi } from 'vitest'; -import { isWasmAvailable, LANGUAGE_REGISTRY } from '../../src/parser.js'; +import { isWasmAvailable, LANGUAGE_REGISTRY } from '../../src/domain/parser.js'; describe('isWasmAvailable', () => { afterEach(() => { diff --git a/tests/unit/registry.test.js b/tests/unit/registry.test.js index 3d166d62..9cc0d1aa 100644 --- a/tests/unit/registry.test.js +++ b/tests/unit/registry.test.js @@ -13,7 +13,7 @@ import { resolveRepoDbPath, saveRegistry, unregisterRepo, -} from '../../src/registry.js'; +} from '../../src/infrastructure/registry.js'; let tmpDir; let registryPath; @@ -41,7 +41,7 @@ describe('REGISTRY_PATH', () => { [ '--input-type=module', '-e', - `import { REGISTRY_PATH } from './src/registry.js'; process.stdout.write(REGISTRY_PATH);`, + `import { REGISTRY_PATH } from './src/infrastructure/registry.js'; process.stdout.write(REGISTRY_PATH);`, ], { cwd: path.resolve(import.meta.dirname, '..', '..'), diff --git a/tests/unit/update-check.test.js b/tests/unit/update-check.test.js index 1bd41cff..78bc204f 100644 --- a/tests/unit/update-check.test.js +++ b/tests/unit/update-check.test.js @@ -2,7 +2,11 @@ import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import { checkForUpdates, printUpdateNotification, semverCompare } from '../../src/update-check.js'; +import { + checkForUpdates, + printUpdateNotification, + semverCompare, +} from '../../src/infrastructure/update-check.js'; let tmpDir; let cachePath; diff --git a/tests/unit/visitor.test.js b/tests/unit/visitor.test.js index e8f4d437..e15571ec 100644 --- a/tests/unit/visitor.test.js +++ b/tests/unit/visitor.test.js @@ -8,7 +8,7 @@ let parse; async function ensureParser() { if (parse) return; - const { createParsers, getParser } = await import('../../src/parser.js'); + const { createParsers, getParser } = await import('../../src/domain/parser.js'); const parsers = await createParsers(); parse = (code) => { // getParser needs a path to determine language