Skip to content

Commit 62d87f5

Browse files
authored
refactor: move remaining flat src/ files into subdirectories (#458)
* refactor: reorganize src/ into domain/, features/, presentation/ layers Move source files into a domain-driven directory structure: - src/domain/ — core graph building, queries, analysis, search (embeddings) - src/features/ — composable feature modules (audit, check, complexity, etc.) - src/presentation/ — CLI formatting and output rendering - src/db/ — database layer (db.js → db/index.js) All 199 files updated with corrected import paths. 1858 tests pass, 0 cycles, all manifesto rules green. Impact: 22 functions changed, 5 affected * docs: update CLAUDE.md architecture table for new directory structure Update file paths in the architecture table to reflect the domain/, features/, presentation/, db/ reorganization. Addresses Greptile review. * refactor: move remaining flat src/ files into subdirectories Move 12 remaining files out of flat src/ so only cli.js and index.js remain as entry points: - config, logger, native, registry, update-check → infrastructure/ - constants, errors, kinds, paginate → shared/ - parser → domain/ - journal, change-journal → domain/graph/ Update all import paths across src/ and tests/. Update CLAUDE.md architecture table to match. Impact: 9 functions changed, 17 affected * style: fix import ordering after file moves
1 parent 68bd052 commit 62d87f5

128 files changed

Lines changed: 234 additions & 216 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CLAUDE.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,28 @@ JS source is plain JavaScript (ES modules) in `src/`. No transpilation step. The
4242
|------|------|
4343
| `cli.js` | Commander CLI entry point (`bin.codegraph`) |
4444
| `index.js` | Programmatic API exports |
45-
| `parser.js` | tree-sitter WASM wrapper; `LANGUAGE_REGISTRY` + per-language extractors for functions, classes, methods, imports, exports, call sites |
46-
| `config.js` | `.codegraphrc.json` loading, env overrides, `apiKeyCommand` secret resolution |
47-
| `constants.js` | `EXTENSIONS` (derived from parser registry) and `IGNORE_DIRS` constants |
48-
| `native.js` | Native napi-rs addon loader with WASM fallback |
49-
| `registry.js` | Global repo registry (`~/.codegraph/registry.json`) for multi-repo MCP |
50-
| `paginate.js` | Pagination helpers for bounded query results |
51-
| `logger.js` | Structured logging (`warn`, `debug`, `info`, `error`) |
45+
| **`shared/`** | **Cross-cutting constants and utilities** |
46+
| `shared/constants.js` | `EXTENSIONS` (derived from parser registry) and `IGNORE_DIRS` constants |
47+
| `shared/errors.js` | Domain error hierarchy (`CodegraphError`, `ConfigError`, `ParseError`, etc.) |
48+
| `shared/kinds.js` | Symbol and edge kind constants (`CORE_SYMBOL_KINDS`, `EVERY_SYMBOL_KIND`, `VALID_ROLES`) |
49+
| `shared/paginate.js` | Pagination helpers for bounded query results |
50+
| **`infrastructure/`** | **Platform and I/O plumbing** |
51+
| `infrastructure/config.js` | `.codegraphrc.json` loading, env overrides, `apiKeyCommand` secret resolution |
52+
| `infrastructure/logger.js` | Structured logging (`warn`, `debug`, `info`, `error`) |
53+
| `infrastructure/native.js` | Native napi-rs addon loader with WASM fallback |
54+
| `infrastructure/registry.js` | Global repo registry (`~/.codegraph/registry.json`) for multi-repo MCP |
55+
| `infrastructure/update-check.js` | npm update availability check |
5256
| **`db/`** | **Database layer** |
5357
| `db/index.js` | SQLite schema and operations (`better-sqlite3`) |
5458
| **`domain/`** | **Core domain logic** |
55-
| `domain/queries.js` | Query functions: symbol search, file deps, impact analysis, diff-impact; `SYMBOL_KINDS` constant defines all node kinds |
59+
| `domain/parser.js` | tree-sitter WASM wrapper; `LANGUAGE_REGISTRY` + per-language extractors for functions, classes, methods, imports, exports, call sites |
60+
| `domain/queries.js` | Query functions: symbol search, file deps, impact analysis, diff-impact |
5661
| `domain/graph/builder.js` | Graph building: file collection, parsing, import resolution, incremental hashing |
5762
| `domain/graph/cycles.js` | Circular dependency detection (delegates to `graph/` subsystem) |
5863
| `domain/graph/resolve.js` | Import resolution (supports native batch mode) |
5964
| `domain/graph/watcher.js` | Watch mode for incremental rebuilds |
65+
| `domain/graph/journal.js` | Change journal for incremental builds |
66+
| `domain/graph/change-journal.js` | Change event tracking (NDJSON) |
6067
| `domain/analysis/` | Query-layer analysis: context, dependencies, exports, impact, module-map, roles, symbol-lookup |
6168
| `domain/search/` | Embedding subsystem: model management, vector generation, semantic/keyword/hybrid search, CLI formatting |
6269
| **`features/`** | **Composable feature modules** |
@@ -87,7 +94,7 @@ JS source is plain JavaScript (ES modules) in `src/`. No transpilation step. The
8794
- **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`)
8895
- Platform-specific prebuilt binaries published as optional npm packages (`@optave/codegraph-{platform}-{arch}`)
8996
- 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
90-
- **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
97+
- **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
9198
- **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`
9299
- `@huggingface/transformers` and `@modelcontextprotocol/sdk` are optional dependencies, lazy-loaded
93100
- Non-required parsers (all except JS/TS/TSX) fail gracefully if their WASM grammar is unavailable

src/ast-analysis/engine.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import path from 'node:path';
1919
import { performance } from 'node:perf_hooks';
2020
import { bulkNodeIdsByFile } from '../db/index.js';
21-
import { debug } from '../logger.js';
21+
import { debug } from '../infrastructure/logger.js';
2222
import { computeLOCMetrics, computeMaintainabilityIndex } from './metrics.js';
2323
import {
2424
AST_TYPE_MAPS,
@@ -45,7 +45,7 @@ const WALK_EXTENSIONS = buildExtensionSet(AST_TYPE_MAPS);
4545

4646
let _parserModule = null;
4747
async function getParserModule() {
48-
if (!_parserModule) _parserModule = await import('../parser.js');
48+
if (!_parserModule) _parserModule = await import('../domain/parser.js');
4949
return _parserModule;
5050
}
5151

src/ast-analysis/shared.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* Shared utilities for AST analysis modules (complexity, CFG, dataflow, AST nodes).
33
*/
44

5-
import { ConfigError } from '../errors.js';
6-
import { LANGUAGE_REGISTRY } from '../parser.js';
5+
import { LANGUAGE_REGISTRY } from '../domain/parser.js';
6+
import { ConfigError } from '../shared/errors.js';
77

88
// ─── Generic Rule Factory ─────────────────────────────────────────────────
99

src/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

33
import { run } from './cli/index.js';
4-
import { CodegraphError } from './errors.js';
4+
import { CodegraphError } from './shared/errors.js';
55

66
run().catch((err) => {
77
if (err instanceof CodegraphError) {

src/cli/commands/ast.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ConfigError } from '../../errors.js';
1+
import { ConfigError } from '../../shared/errors.js';
22

33
export const command = {
44
name: 'ast [pattern]',

src/cli/commands/batch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import fs from 'node:fs';
22
import { batch } from '../../commands/batch.js';
33
import { EVERY_SYMBOL_KIND } from '../../domain/queries.js';
4-
import { ConfigError } from '../../errors.js';
54
import { BATCH_COMMANDS, multiBatchData, splitTargets } from '../../features/batch.js';
5+
import { ConfigError } from '../../shared/errors.js';
66

77
export const command = {
88
name: 'batch <command> [targets...]',

src/cli/commands/check.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { EVERY_SYMBOL_KIND } from '../../domain/queries.js';
2-
import { ConfigError } from '../../errors.js';
2+
import { ConfigError } from '../../shared/errors.js';
33

44
export const command = {
55
name: 'check [ref]',

src/cli/commands/co-change.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AnalysisError } from '../../errors.js';
1+
import { AnalysisError } from '../../shared/errors.js';
22

33
export const command = {
44
name: 'co-change [file]',

src/cli/commands/info.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ export const command = {
33
description: 'Show codegraph engine info and diagnostics',
44
async execute(_args, _opts, ctx) {
55
const { getNativePackageVersion, isNativeAvailable, loadNative } = await import(
6-
'../../native.js'
6+
'../../infrastructure/native.js'
77
);
8-
const { getActiveEngine } = await import('../../parser.js');
8+
const { getActiveEngine } = await import('../../domain/parser.js');
99

1010
const engine = ctx.program.opts().engine;
1111
const { name: activeName, version: activeVersion } = getActiveEngine({ engine });

src/cli/commands/registry.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
3-
import { ConfigError } from '../../errors.js';
43
import {
54
listRepos,
65
pruneRegistry,
76
REGISTRY_PATH,
87
registerRepo,
98
unregisterRepo,
10-
} from '../../registry.js';
9+
} from '../../infrastructure/registry.js';
10+
import { ConfigError } from '../../shared/errors.js';
1111

1212
export const command = {
1313
name: 'registry',

0 commit comments

Comments
 (0)