22
33## Project Overview
44
5- npm package that generates 3D interactive maps of TypeScript codebases. Two modes: browser (3D visualization) and MCP stdio ( LLM integration) .
5+ npm package that analyzes TypeScript codebases — parses source, builds dependency graphs, computes architectural metrics, and exposes everything via MCP stdio for LLM-assisted code understanding .
66
77## Architecture
88
1212 parser/index.ts <- TS Compiler API parser (files, functions, imports)
1313 graph/index.ts <- graphology graph builder + circular dep detection
1414 analyzer/index.ts <- Metrics engine (PageRank, betweenness, cohesion, tension, churn, complexity, blast radius, dead exports)
15- mcp/index.ts <- MCP stdio server (7 tools)
16- server/index.ts <- Express web server
17- server/api.ts <- REST API routes
15+ mcp/index.ts <- MCP stdio server (15 tools, 2 prompts, 3 resources)
16+ mcp/hints.ts <- Next-step hints for MCP tool responses
17+ server/graph-store.ts <- Global graph state (shared by CLI + MCP)
18+ impact/index.ts <- Symbol-level impact analysis + rename planning
19+ search/index.ts <- BM25 search engine
20+ process/index.ts <- Entry point detection + call chain tracing
21+ community/index.ts <- Louvain clustering
22+ persistence/index.ts <- Graph export/import to .code-visualizer/
1823 cli.ts <- CLI entry point (commander)
19- public/
20- index.html <- Client-side 3D renderer (8 views, uses 3d-force-graph from CDN)
2124docs/
2225 architecture.md <- Pipeline, module map, data flow, design decisions
2326 data-model.md <- All TypeScript interfaces with field descriptions
2427 metrics.md <- Per-file + module metrics, force analysis, complexity scoring
25- mcp-tools.md <- 7 MCP tools: inputs, outputs, use cases, selection guide
28+ mcp-tools.md <- 15 MCP tools: inputs, outputs, use cases, selection guide
2629specs/
2730 active/ <- Current spec
2831```
2932
3033## Pipeline
3134
3235```
33- CLI args -> Parser (TS AST) -> Graph Builder (graphology) -> Analyzer (metrics) -> Server (Express | MCP stdio)
36+ CLI args -> Parser (TS AST) -> Graph Builder (graphology) -> Analyzer (metrics) -> MCP stdio
3437```
3538
3639## Key Conventions
@@ -47,9 +50,9 @@ CLI args -> Parser (TS AST) -> Graph Builder (graphology) -> Analyzer (metrics)
4750- ** graphology** — graph data structure. Import as ` import Graph from "graphology" ` . Use as both constructor and type.
4851- ** graphology-metrics** — PageRank, betweenness. Default imports from subpaths.
4952- ** @modelcontextprotocol/sdk ** — MCP server. Uses ` McpServer ` class with ` server.tool() ` registration.
50- - ** express** — web server. Routes in ` server/api.ts ` , static files from ` public/ ` .
5153- ** typescript** — used as a library (Compiler API), not just a dev tool.
5254- ** zod** — MCP tool input validation.
55+ - ** commander** — CLI argument parsing.
5356
5457### Quality Gates
5558
@@ -68,7 +71,7 @@ All four must pass before shipping. Run in order: lint -> typecheck -> build ->
6871
6972| Change Type | Bump | Example |
7073| -------------| ------| ---------|
71- | New MCP tools, new views, new metrics | minor | 1.0.1 → 1.1.0 |
74+ | New MCP tools, new metrics | minor | 1.0.1 → 1.1.0 |
7275| Bug fixes, description changes, doc sync | patch | 1.1.0 → 1.1.1 |
7376| Breaking: removed tool, changed tool params | major | 1.1.0 → 2.0.0 |
7477
@@ -117,23 +120,13 @@ pnpm publish:npm
117120
118121## Security Rules
119122
120- ### Client-side (public/index.html)
121- - ** NEVER use innerHTML with dynamic data** — use DOM API (` createElement ` + ` textContent ` )
122- - ** NEVER use inline onclick attributes** — use ` addEventListener `
123- - All node data from the API must be treated as untrusted (file paths can contain HTML metacharacters)
124- - Use the ` el() ` helper for safe DOM construction
125-
126- ### Server-side
127- - Validate and clamp all query parameters (especially ` limit ` )
128- - API routes should return JSON 404s, not HTML
123+ - Validate and clamp all MCP tool input parameters
129124- No filesystem access beyond the parsed graph data
130125
131126## File Conventions
132127
133128- New analysis metrics go in ` src/analyzer/index.ts `
134129- New MCP tools go in ` src/mcp/index.ts ` (register with ` server.tool() ` )
135- - New REST endpoints go in ` src/server/api.ts `
136- - New browser views go in ` public/index.html ` (add render function + view tab)
137130- Types always in ` src/types/index.ts `
138131
139132## Common Pitfalls
@@ -153,12 +146,12 @@ LLM knowledge base for building this tool. Single source of truth per topic:
153146| ` docs/architecture.md ` | Pipeline, module map, data flow, design decisions | New module or pipeline change |
154147| ` docs/data-model.md ` | All TypeScript interfaces (mirrors ` src/types/index.ts ` ) | Type changes |
155148| ` docs/metrics.md ` | Per-file + module metrics, force analysis, complexity scoring | New metric added |
156- | ` docs/mcp-tools.md ` | 7 MCP tools with inputs/outputs/use cases | New tool or param change |
149+ | ` docs/mcp-tools.md ` | 15 MCP tools with inputs/outputs/use cases | New tool or param change |
157150
158151## Testing (BLOCKING)
159152
160153- Test runner: vitest
161- - Test files: ` src/**/*.test.ts `
154+ - Test files: ` src/**/*.test.ts ` , ` tests/**/*.test.ts `
162155- Run: ` npm test ` or ` npx vitest run `
163156
164157### Coverage Policy (ENFORCE)
@@ -171,7 +164,6 @@ LLM knowledge base for building this tool. Single source of truth per topic:
171164### Real Environment Tests (MANDATORY)
172165
173166- ** NEVER mock internal modules** — use real parser, real graph, real analyzer
174- - ** NEVER mock Express** — use ` supertest ` against the real app
175167- ** NEVER mock graphology** — build real graphs with real data
176168- ** NEVER mock filesystem for parser tests** — use real fixture directories with real ` .ts ` files
177169- ** Only mock external third-party APIs** that require network/auth (none currently)
@@ -184,23 +176,12 @@ LLM knowledge base for building this tool. Single source of truth per topic:
184176| Parser | Real ` .ts ` fixture files on disk, assert parsed output |
185177| Graph | Real parsed files -> real graph builder, assert nodes/edges |
186178| Analyzer | Real graph -> real metrics, assert values |
187- | API | ` supertest ` against real Express app with real graph data |
188179| MCP | Real MCP server instance, assert tool responses |
189180| CLI | Real process execution where feasible |
190181
191- ### Visual Verification (MANDATORY for UI changes)
192-
193- - After ANY UI change (HTML/CSS/client JS), start the server and verify in a browser
194- - Start server: ` node dist/cli.js ./src --port 3333 `
195- - Verify: page loads, graph renders, changed feature works visually
196- - Check browser console for JavaScript errors
197- - Kill server after verification
198- - If browser agent is available, use it for automated visual verification
199-
200182### Anti-Patterns (NEVER)
201183
202184- NEVER use ` jest.mock() ` or ` vi.mock() ` for internal modules
203185- NEVER create fake/stub graph objects — build them through the real pipeline
204- - NEVER skip tests because "it's just UI" or "it's just config"
186+ - NEVER skip tests because "it's just config"
205187- NEVER write tests that pass regardless of implementation (test behavior, not existence)
206- - NEVER ship UI changes without visual verification in a real browser
0 commit comments