CodeGraph/docs
Section 3.1

Graph Data Structure

The canonical 5-map in-memory data structure that represents files, declarations, npm packages, and system modules as an indexed directed graph.

Source: server/src/graph/models/Graph.ts

The 5 Synchronized In-Memory Maps

The canonical Graph interface is designed for instantaneous $O(1)$ lookups and high-performance traversals:

server/src/graph/models/Graph.ts
1
2
3
4
5
6
7
export interface Graph { nodes: Map<string, GraphNode>; // nodeId -> Node object (O(1) lookup) edges: Map<string, GraphEdge>; // edgeId -> Edge object (O(1) lookup) nodesByKind: Map<GraphNodeKind, Set<string>>; // kind -> Set of nodeIds (O(1) kind iteration) outgoingEdges: Map<string, Set<string>>; // nodeId -> Set of outgoing edgeIds incomingEdges: Map<string, Set<string>>; // nodeId -> Set of incoming edgeIds }
Map FieldTypeOperational Purpose
nodesMap<string, GraphNode>Primary node registry storing full payloads (name, location, kind).
edgesMap<string, GraphEdge>Primary edge registry storing directional relationship types.
nodesByKindMap<GraphNodeKind, Set<string>>Pre-indexes node IDs by kind ('file', 'symbol', 'dependency', 'module').
outgoingEdgesMap<string, Set<string>>Forward adjacency index for forward reachability, DFS, and Kahn's sort.
incomingEdgesMap<string, Set<string>>Backward adjacency index for impact analysis and Tarjan's SCC.

Node Kinds & Prefixed ID Convention

All node IDs are strictly prefixed with their discriminant kind via getGraphNodeId(kind, rawId):

Prefixed Node ID Examples
1
2
3
4
file: file:/abs/path/to/src/auth/service.ts symbol: symbol:/abs/path/to/src/auth/service.ts:14:4:validateToken dependency: dependency:express module: module:fs

This prefix prevents collisions between file paths, symbols, and npm dependencies sharing similar names.