Skip to content

refactor: move remaining flat src/ files into subdirectories#458

Merged
carlos-alm merged 6 commits intomainfrom
refactor/domain-grouping
Mar 16, 2026
Merged

refactor: move remaining flat src/ files into subdirectories#458
carlos-alm merged 6 commits intomainfrom
refactor/domain-grouping

Conversation

@carlos-alm
Copy link
Contributor

Summary

  • Moves 12 remaining files out of flat src/ so only cli.js and index.js remain as entry points:
    • config, logger, native, registry, update-checkinfrastructure/
    • constants, errors, kinds, paginateshared/
    • parserdomain/
    • journal, change-journaldomain/graph/
  • Updates all import paths across src/ and tests/ (128 files)
  • Fixes import ordering (biome organizeImports) in affected files
  • Updates CLAUDE.md architecture table to match new layout

Follows up on #456 which moved the first batch of files into domain/, features/, presentation/.

Test plan

  • All 1862 tests pass across 104 test files
  • npx biome check src/ tests/ — 0 issues
  • Only cli.js and index.js remain in flat src/

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
Update file paths in the architecture table to reflect the domain/,
features/, presentation/, db/ reorganization. Addresses Greptile review.
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
@claude
Copy link

claude bot commented Mar 16, 2026

Claude finished @carlos-alm's task —— View job


Reviewing PR: refactor: move remaining flat src/ files into subdirectories

Todo List:

  • Read key files to understand the refactoring scope and approach
  • Analyze the changes for root cause and justification
  • Check for configuration changes or test integrity issues
  • Evaluate code quality and architecture decisions
  • Rate against backlog compliance criteria
  • Provide structured final assessment

Root Cause Analysis

Problem Being Solved: Completing the domain-driven architecture refactoring started in PR #456. The PR moves the final 12 files out of flat src/ directory structure into organized domain subdirectories (infrastructure/, shared/, domain/graph/), leaving only cli.js and index.js as intended entry points.

Why This Approach: This follows the established layered architecture pattern documented in CLAUDE.md. The moves are logical:

  • Cross-cutting utilities → shared/ (constants, errors, kinds, paginate)
  • Platform/I/O concerns → infrastructure/ (config, logger, native, registry, update-check)
  • Core domain logic → domain/ (parser) and domain/graph/ (journal, change-journal)

Risk Assessment: LOW RISK. This is a pure refactoring with no behavioral changes - only import path updates across 128 files. The CLAUDE.md architecture table was properly updated to match the new structure.

Configuration Analysis

No suspicious configuration changes detected:

  • No biome.json, package.json, or test configuration modifications
  • No linting rules disabled or relaxed
  • No test timeouts increased or coverage thresholds lowered
  • No TypeScript config changes (project uses plain JS)

Test Integrity

Test changes are purely mechanical:

  • All 128 test file modifications are import path updates only (e.g., '../../src/config.js''../../src/infrastructure/config.js')
  • No test assertions weakened, removed, or made conditional
  • No test files skipped or modified beyond import updates
  • No eslint-disable comments added
  • PR claims "All 1862 tests pass" - tests validate the refactoring didn't break functionality

Code Quality Assessment

Excellent execution:

  • Mechanical precision: All 213 additions/206 deletions are import path updates with zero logic changes
  • Import organization: biome's organizeImports was properly applied for consistent formatting
  • Backward compatibility: src/index.js programmatic API exports updated correctly
  • Documentation sync: CLAUDE.md architecture table reflects new structure accurately
  • Dependency integrity: LANGUAGE_REGISTRY and constants remain properly connected despite moves
  • Entry points preserved: Only cli.js and index.js remain in root src/ as intended

Backlog Compliance

  • Zero-dep: ✓ No new runtime dependencies added
  • Foundation-aligned: ✓ Fully compliant - improves codebase organization without violating any core principles
  • Problem-fit: 3/5 - Useful refactoring that improves maintainability but doesn't directly address AI navigation challenges. Better organization helps but is tangential to core "lost AI" problem
  • Breaking: No - Pure internal refactoring; all public API contracts preserved in src/index.js
  • Tier: 1 (zero-dep ✓ + foundation-aligned ✓)

Final Assessment

This is a textbook example of careful refactoring executed with surgical precision. The author:

The scope is appropriately narrow (addressing one concern), execution is flawless, and risk is minimal. While the organizational improvement doesn't directly solve codegraph's core problem of helping AI agents navigate codebases, it establishes good architectural foundations for future development.

Rating: ⭐⭐⭐⭐☆ (4/5)
Action: APPROVE
Reasoning: High-quality refactoring with zero behavioral risk, proper documentation updates, and excellent execution. The only reason this isn't 5 stars is that it's primarily organizational maintenance rather than feature advancement.

@carlos-alm
Copy link
Contributor Author

@greptileai

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 16, 2026

Greptile Summary

Completes the directory reorganization started in #456 by moving the remaining 12 flat src/ files into layered subdirectories: infrastructure/ (config, logger, native, registry, update-check), shared/ (constants, errors, kinds, paginate), domain/ (parser), and domain/graph/ (journal, change-journal). Only cli.js and index.js remain as entry points in flat src/.

  • All 128 files updated with correct relative import paths across src/ and tests/
  • Import ordering fixed to satisfy biome organizeImports
  • CLAUDE.md architecture table updated to reflect new layout
  • grammarPath() in domain/parser.js correctly adds an extra .. to compensate for the deeper nesting
  • Dynamic imports in features/complexity.js, features/cfg.js, and features/dataflow.js updated from ./parser.js to ../domain/parser.js
  • vi.mock and vi.doMock paths in test files updated alongside static imports
  • No stale import paths remain in the codebase — verified via exhaustive search

Confidence Score: 5/5

  • This PR is safe to merge — it is a mechanical file reorganization with no behavioral changes.
  • All 128 files contain only import path updates and file moves. No logic, APIs, or behavior changed. All relative paths were verified correct. Exhaustive search confirmed no stale import paths remain. The PR description confirms all 1862 tests pass and biome reports 0 issues. CLAUDE.md documentation is updated accurately.
  • No files require special attention. The most complex path updates are in src/domain/graph/builder/stages/detect-changes.js (4 levels of ../) and src/domain/parser.js (grammarPath adjustment), both verified correct.

Important Files Changed

Filename Overview
src/domain/parser.js Moved from src/parser.js; import paths and grammarPath __dirname traversal correctly updated for new depth.
src/infrastructure/native.js Moved from src/native.js; errors import correctly updated to ../shared/errors.js.
src/shared/constants.js Moved from src/constants.js; parser import correctly updated to ../domain/parser.js.
src/index.js Entry point updated with correct import paths to new infrastructure/, shared/ locations; export reordering matches biome organize imports.
src/domain/graph/watcher.js 6 import paths updated for infrastructure/, shared/, and local graph/ modules; all relative paths verified correct.
src/domain/graph/builder/stages/detect-changes.js 4 import paths updated with deep relative paths (4 levels); all paths verified correct.
src/features/complexity.js Static and dynamic imports updated to infrastructure/, shared/, and domain/parser.js; all paths correct.
CLAUDE.md Architecture table and narrative references updated to match new shared/, infrastructure/, domain/ layout; accurate.
tests/unit/mcp.test.js 6 vi.doMock paths updated from ../../src/registry.js to ../../src/infrastructure/registry.js; consistent.
tests/integration/complexity.test.js Both import and vi.mock path updated from config.js to infrastructure/config.js; correct.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    subgraph "src/ (entry points)"
        CLI[cli.js]
        IDX[index.js]
    end

    subgraph "shared/"
        CONST[constants.js]
        ERR[errors.js]
        KINDS[kinds.js]
        PAG[paginate.js]
    end

    subgraph "infrastructure/"
        CFG[config.js]
        LOG[logger.js]
        NAT[native.js]
        REG[registry.js]
        UPD[update-check.js]
    end

    subgraph "domain/"
        PARSER[parser.js]
        QUERIES[queries.js]
        subgraph "domain/graph/"
            JOURNAL[journal.js]
            CHJOURNAL[change-journal.js]
            WATCHER[watcher.js]
            BUILDER[builder/]
        end
    end

    subgraph "features/"
        FEAT[complexity / cfg / dataflow / ...]
    end

    CLI --> ERR
    IDX --> CFG
    IDX --> CONST
    IDX --> ERR
    IDX --> KINDS
    PARSER --> LOG
    PARSER --> NAT
    CONST --> PARSER
    WATCHER --> LOG
    WATCHER --> CONST
    WATCHER --> ERR
    WATCHER --> PARSER
    WATCHER --> JOURNAL
    WATCHER --> CHJOURNAL
    BUILDER --> LOG
    BUILDER --> CONST
    BUILDER --> PARSER
    BUILDER --> JOURNAL
    FEAT --> CFG
    FEAT --> LOG
    FEAT --> PAG
    FEAT --> PARSER
Loading

Last reviewed commit: 6b24119

@carlos-alm carlos-alm merged commit 62d87f5 into main Mar 16, 2026
14 checks passed
@carlos-alm carlos-alm deleted the refactor/domain-grouping branch March 16, 2026 09:09
@github-actions github-actions bot locked and limited conversation to collaborators Mar 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant