This document describes the process of generating runtime/depgraph.md (or runtime/project_codemap.md) from source code. The codemap is the input that drives the depgraph visualizer.
Source Code → AST Parse → Extract Nodes → Cluster Assignment → depgraph.md
The goal is to turn raw source files into a structured codemap where every function and variable is a node in a hypergraph, grouped into conceptual clusters.
Identify all source files in the project. For depgraph itself:
prototypes/index.html — main application (JS embedded in HTML)depgraph-server.mjs — Node.js servercodegen/codemap.py — Python code analysis toolParse each source file into an Abstract Syntax Tree to extract structured information.
For JavaScript (in index.html):
<script> tagsextractJS() pulls the JS block and computes a lineOffset so line numbers map back to the HTML fileanalyzeCode() walks the AST in two passes:
globals mapanalyzeFunction() which walks the function body to find:
reads — global variables readwrites — global variables writtenrw — globals both read and writtencalls — other top-level functions calledFor Python (codemap.py):
extract_functions() uses regex to find function name( patternsextract_constants() finds const/let ALL_CAPS_NAME = patternsFor Node.js (depgraph-server.mjs):
function name() become nodesAfter AST analysis, every named entity becomes a node:
function name() declarationconst/let/var that is used by 2+ functionsEach node carries metadata:
function or global)This is the human/AI step. Claude (or a human) reads through all extracted functions and groups them into conceptual clusters — high-level systems or feature areas.
Clustering criteria:
startAttractor, attractorLoop, lockAttractor)For depgraph, the clusters are:
| Cluster | What it covers |
|---|---|
| AST Analysis | Parsing source code into structured data |
| Codemap Parsing | Reading the markdown codemap format |
| Clustering & Affinities | Assigning functions to systems, computing affinity scores |
| Graph Building | Converting analysis results into nodes + edges |
| Layout Engine | Force-directed positioning, cluster packing |
| Animation | Smooth transitions between positions |
| SVG Rendering | D3-based drawing of nodes, edges, hulls, labels |
| Cluster Labels & Meta-edges | Inter-cluster visualization layer |
| Spatial Memory | Persisting user arrangements in localStorage |
| Arrangement Navigation | Time-travel through layout history |
| Node Interaction | Selection, highlighting, info panel |
| Attractor / Gravity Well | Force-touch pull mechanic |
| Gather & Pull | Space-pull, neighbor-gather, cluster-gather |
| Spread & Dismiss | X-key spread, right-click repulse, dismiss to T0 |
| Time Travel | Z-key hold to scrub backwards |
| Lock / Selection | Pin/unpin nodes |
| User Clusters | Create/delete custom groupings via Enter key |
| Main Loop | Load, parse, rebuild cycle + SSE focus events |
| Server | HTTP static serving + SSE broadcast |
| Code Analysis Tool | Python codemap generator |
The output is written to runtime/depgraph.md in this format:
---
name: Code Map
description: ...
type: reference
---
## Cluster Name
- `functionName`: ~lineNumber importance:N
- `anotherFunc`: ~lineNumber importance:N
## Another Cluster
- `func`: ~lineNumber importance:N
Format rules:
## H2 heading- `name`: ~line importance:N~) since they may shift between edits<!-- user-cluster --> marker after the headingThe depgraph visualizer (prototypes/index.html) reads the codemap and uses it as the primary clustering signal:
parseCodemap() reads the markdown, extracts sections and function listsclusterFunctions() assigns each function to its codemap section (weight 5.0 — strongest signal)computeAffinities() adds 4 secondary signals:
| Step | Automated | Manual/AI |
|---|---|---|
| AST parsing | codemap.py or Acorn |
— |
| Node extraction | codemap.py or analyzeCode() |
— |
| Cluster creation | — | Claude reads functions, creates conceptual groups |
| Cluster naming | — | Claude names each group |
| Importance scoring | Default 3 | Human tunes 1-10 per function |
| Codemap writing | codemap.py --update (Equinox) |
Claude writes markdown (depgraph) |
| Affinity scoring | computeAffinities() |
— |
| Layout & rendering | computeLayout() + D3 |
— |
The codemap is the bridge between automated AST analysis and human/AI understanding. It encodes the “why” (conceptual grouping) that pure syntax analysis cannot infer.