Section 3.2Source:
server/src/graph/GraphBuilder.tsGraph Construction & Validation
How GraphBuilder transforms raw parser models into an indexed, referentially valid graph with two validation phases.
Source:
server/src/graph/GraphBuilder.ts5 Sequential Build Phases
GraphBuilder.build(parsedRepository) is a pure construction engine that executes in 5 strict phases:
server/src/graph/GraphBuilder.ts
123456789101112131415161718192021222324build(repository: ParsedRepository): Graph { const graph: Graph = { nodes: new Map(), edges: new Map(), nodesByKind: new Map(), outgoingEdges: new Map(), incomingEdges: new Map(), }; // Phase 1: Construct Nodes this.addFileNodes(graph, repository); this.addSymbolNodes(graph, repository); this.addDependencyNodes(graph, repository); this.addModuleNodes(graph, repository); // Phase 2: Construct & Index Edges this.addRelationshipEdges(graph, repository.relationships); // Phase 3 & 4: Dual Validation this.validateGraph(graph); // Referential integrity (no dangling edges) this.validateIndexes(graph); // Index consistency verification return graph; }
Dual Validation Invariants
1. Referential Integrity (`validateGraph`)
Verifies that every edge references source and target nodes that actually exist in the nodes map. Throws GraphValidationError if any dangling edge is found.
2. Index Consistency (`validateIndexes`)
Verifies that every node is indexed in nodesByKind and every edge is present in bothoutgoingEdges and incomingEdges.