Deterministic architecture & change intelligence for codebases — fuses dependency graphs, coupling/instability metrics, and Git churn into a single hotspot ranking, then runs one grounded LLM synthesis pass over the result that rejects findings whose cited module, metric or number does not match the computed model before they reach a human (free-text wording is not verified).
Status: working prototype. TypeScript/JavaScript repositories only. The engine, the validator and the dashboard are covered by 108 tests that run in CI. The Docker Compose files and the Dockerfile are reviewed but not yet run end to end.
Self-analysis of this repo: hotspot ranking, dependency graph (amber-bordered nodes and animated edges mark the two detected cycles), and the narrative panel with both an accepted and a rejected LLM finding.
CodeAtlas analyzes a TypeScript/JavaScript codebase's structure (import graph, coupling, instability, cycles, blast radius) and its history (Git churn, change concentration), fuses both into a deterministic hotspot score per module, and applies explicit rule-based risk flags — no LLM involved in any of that. A single LLM call then reads only that structured JSON (never raw source) and writes a short narrative with per-finding citations; every citation is mechanically checked against the same JSON before it's shown as "accepted."
This isn't a claim of novelty — tools like ArchMind, CodeMap, DevLens, and CodeAutopsy already do parts of this. What's different here:
- Coupling/instability is fused with churn into one deterministic hotspot score, not shown as two disconnected metrics.
- A grounding/hallucination-rejection validator sits between the LLM and the user: schema validation, referential integrity against real module IDs, and numeric-tolerance checks against the real computed values. Rejections are logged and shown, not hidden.
- CodeAtlas analyzes itself in CI as a quality gate, not just as a demo target — see the
self-analysisjob.
Add a step to any TypeScript/JavaScript repo's workflow. It runs the deterministic engine only (no LLM, no API key), writes a hotspot table, cycles and high-severity risks to the job summary, saves the full JSON model, and can fail the build past a threshold:
jobs:
codeatlas:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # churn needs real history; a shallow clone reads as zero churn
- uses: basartuncay/CodeAtlas@v1.0.1
with:
path: . # or a package folder in a monorepo
max-hotspot: "0.9" # optional quality gate (0-1); omit to report only
top: "10"Locally, the same analysis is one command:
npm ci --workspace=@codeatlas/engine
npm run analyze --workspace=@codeatlas/engine -- /path/to/repo --summary report.md --out analysis.jsonThis repo's own CI runs the action on itself (uses: ./), so the published action is tested on every push.
flowchart LR
subgraph ENGINE["packages/engine — deterministic, no LLM"]
direction TB
G["buildDependencyGraph<br/>(dependency-cruiser)"] --> C1["coupling: fan-in / fan-out / instability"]
G --> C2["Tarjan SCC: cycle detection"]
G --> C3["BFS: blast radius"]
CX["ts-morph: cyclomatic complexity + LOC"]
CH["git log: churn (windowed)"]
C1 & C2 & C3 & CX & CH --> H["hotspot_score<br/>(percentile-rank fusion)"]
H --> R["rule-based risk flags"]
R --> M[("JSON model<br/>schema_version 1.0")]
end
subgraph SYNTH["packages/llm-synthesis"]
direction TB
M --> L["Claude (Sonnet): structured-output synthesis"]
L --> V{"validateFindings"}
V -->|"schema OK, module_id real,<br/>value within ±0.01"| OK["accepted findings"]
V -->|"fails any check"| NO["rejected findings (logged)"]
end
subgraph OUT["consumers of the same model"]
M --> DASH["packages/web — dashboard<br/>(ranking + graph + narrative)"]
OK --> DASH
NO --> DASH
M --> CI["GitHub Action:<br/>analyze.ts + quality gate"]
end
packages/engine is pure and independently testable (graph, metrics, cycles, blast radius, complexity, LOC, churn, hotspot fusion, risk rules — each its own small module with its own unit tests). packages/llm-synthesis depends on it only for types and never sees raw source. packages/web is a thin Next.js layer over both.
- Hotspot fusion:
hotspot_score = percentile-rank(complexity) × percentile-rank(churn), wherepercentile-rank(x) = |{v in population : v < x}| / (n-1)— chosen specifically because min-max normalization lets a single outlier compress every other module's score toward zero (see ADR 0004). - Grounding validator: three checks in order — schema (Zod), referential integrity (does the cited
module_idexist in the model?), numeric tolerance (isvalue_citedwithin ±0.01 of the real value?). A finding failing any check is dropped and logged, never silently kept. - Self-analysis as a CI quality gate: every push runs
analyzeRepository(deterministic only, no LLM, no API key) against the repo itself, publishes the JSON model as a build artifact, and fails the build if the maxhotspot_scoreexceeds a defined threshold. - Cycle detection with a visual payoff: Tarjan's SCC algorithm feeds directly into the dashboard's dependency graph — modules in a cycle get a distinct amber border and animated connecting edges, not just a boolean in a table.
A few things this deliberately does not do, straight from the project's own scope discipline:
- Auth, billing, multi-tenancy — this is a single-user analysis tool, not a SaaS product; none of it has any demo value.
- Universal multi-language support — one language done correctly beats shallow coverage of many in a time-boxed build.
- Security pattern detection — a scope trap: either too shallow to be credible or too deep to fit the time available.
- Auto-fix / code-rewriting agent — a fundamentally different project (an agent that edits code), not an analysis-and-reporting tool.
Requires Node.js ≥ 20. An ANTHROPIC_API_KEY is required for the "Run analysis" flow specifically — it calls Claude for narrative synthesis as part of the same request as the deterministic analysis. Without a key, the deterministic engine (tests, the CI self-analysis job) still works fully; only the dashboard's analyze button needs one.
cp .env.example .env
# edit .env, set ANTHROPIC_API_KEY=sk-ant-...
docker compose up --build
# open http://localhost:3000npm install
cp .env.example .env
# edit .env, set ANTHROPIC_API_KEY=sk-ant-...
npm run typecheck --workspaces --if-present
npm test --workspaces --if-present
npm run dev --workspace=@codeatlas/web
# open http://localhost:3000The dashboard analyzes one server-chosen repo (CODEATLAS_REPO_PATH, default: this monorepo) —
the API never takes a path from the request. Each "Run analysis" makes a paid Claude call, so runs
are limited to one per CODEATLAS_ANALYZE_COOLDOWN_SECONDS (default 600) and concurrent clicks share
one in-flight run; inside the cooldown the latest result is returned with HTTP 429.
Set CODEATLAS_ANALYZE_TOKEN to require a shared secret: POST and GET /api/analyze then answer 401 unless
the request carries a matching x-codeatlas-token header (e.g. curl -X POST -H "x-codeatlas-token: $TOKEN" …).
The "Run analysis" button does not send it, so on a token-protected deployment runs are started from the
command line and the page shows the cached result. The dashboard pages themselves are server-rendered and
public, so for a private repository put the app behind authentication or a private network.
The Docker image contains the repository's .git directory (full history and .git/config): do not push
it to a public registry. Docker Compose binds the port to 127.0.0.1 only.
This project was built test-first throughout, and that discipline is what actually caught the three most interesting bugs below — none of them were hypothetical, all three were found by running real code against real (or precisely reproduced) conditions, not by inspection.
While building a fixture that needed a real (not static) git history, buildDependencyGraph started getting pointed at mkdtemp-created directories for the first time — and on macOS, os.tmpdir() sits behind a symlink (/var → /private/var). The same file started showing up twice, under two different path spellings, whenever it was part of a circular import.
Root cause: dependency-cruiser resolves a circular import's target via realpath internally, but does its initial file-system scan against the given (non-realpath'd) baseDir — the two disagree across a symlink boundary, and the same file gets treated as two different modules.
Fix: fs.realpathSync(projectRoot) before handing the path to dependency-cruiser. Caught with a regression test that reproduces a two-file cycle under a real mkdtemp'd directory, confirmed to fail before the fix and pass after.
While wiring up the dashboard's dependency graph view, a self-analysis run from inside packages/web (exactly what next dev does) suddenly returned only ~20 fixture modules instead of the expected ~68 — packages/engine, packages/web, and packages/llm-synthesis had vanished entirely, even though every glob pattern passed to ts-morph was already absolute.
Root cause (best understanding — not documented behavior): ts-morph's glob-based file discovery appears to treat directories along process.cwd()'s own ancestor chain as already-visited and prunes them, taking any sibling reached only through that pruned ancestor down with it.
Fix: computeComplexity and computeLoc now chdir into the target root for the duration of the scan and restore the original cwd afterward. Reproducing this precisely required a synthetic directory shaped exactly like the monorepo (cwd = target/packages/web, target file under the sibling target/packages/engine) — and, notably, realpathSync-normalizing the temp directory first, since macOS's un-realpath'd os.tmpdir() accidentally defeated the very first version of the repro.
While writing the Dockerfile for the one-command setup, a real next build run (no Docker needed to catch this) showed the home page marked ○ (Static) in Next's own route table. The dashboard's home page reads an in-memory analysis cache via a plain function call — not one of Next's recognized dynamic data sources (cookies(), headers(), etc.) — so App Router had no way to know the page needed to be rendered fresh per request. In production, the page would have been baked in at build time (always showing "no analysis yet") and never updated again, no matter how many times POST /api/analyze succeeded afterward.
Fix: export const dynamic = "force-dynamic" on the page. Verified by rebuilding (confirmed the route now shows ƒ), then running the actual production server locally end-to-end: empty state before triggering an analysis, real module count and narrative after — proving the fix changes runtime behavior, not just the build log.
- Run CodeAtlas on itself, live. The self-analysis CI job does this on every push; the dashboard's "Run analysis" button does it interactively.
- Run it on a recognizable repo, land on the hotspot ranking, click into the top hotspot, show the real underlying numbers on its drill-down page — every claim on screen traces back to a raw metric.
- Trigger a rejected LLM claim, live. Ask something ungroundable, or replay a corrupted response through
validateFindings(seepackages/llm-synthesis/tests/validate-findings.test.tsfor pre-recorded good/bad examples), and show the validator catch it in the narrative panel — the rejected claim renders struck through in red, next to the exact reason it didn't pass.
- 0001 — Instability is
NaN(not defaulted) for isolated modules - 0002 — Type-only imports are excluded from the dependency graph
- 0003 — File-level cyclomatic complexity is the sum of its functions
- 0004 — Percentile-rank normalization for hotspot fusion (not min-max, not z-score)
The Docker Compose files have been statically reviewed (multi-stage build, git CLI included, env flow) but not yet tested end-to-end with a real docker compose up — the dashboard was instead run and verified manually via npm run dev --workspace=@codeatlas/web.
If this was useful to you, a ⭐ on GitHub helps others find it. Bug reports, questions and results that disagree with mine are welcome as issues.
