The Three Layers
Analyzer
Parses source code and extracts structure (classes, methods, dependencies)
Graph Database
Stores the code structure as nodes and relationships
Visualization
Renders the graph as an interactive 3D experience
Hexagonal Architecture
CodeGraph follows hexagonal architecture (ports and adapters). The core business logic sits in the center and knows nothing about the outside world.The Core
The core contains pure business logic—no frameworks, no databases, no HTTP. It defines ports (interfaces) for everything it needs.Driving Adapters (Input)
Driving adapters call into the core. They handle incoming requests:CLI
.NET ConsoleCommand-line interface for analysis
REST API
ASP.NET CoreHTTP endpoints for the frontend
React Frontend
React + Three.js3D visualization and interaction
Driven Adapters (Output)
Driven adapters are called by the core through ports:Roslyn Analyzer
Microsoft.CodeAnalysisImplements
IStructuralAnalyzerNeo4j Storage
Neo4j.DriverImplements
IGraphStorageGraphPU Layout
Rust + Metal/VulkanImplements
ILayoutComputePorts
The core defines interfaces (ports) that adapters implement. This allows swapping implementations without changing business logic.IStructuralAnalyzer
IStructuralAnalyzer
Analyzes source code and extracts structure.Implementations: Roslyn (C#), Tree-sitter (future)
IGraphStorage
IGraphStorage
Persists and queries the code graph.Implementations: Neo4j, Memgraph, In-Memory
ILayoutCompute
ILayoutCompute
Computes node positions using force-directed algorithms.Implementations: GraphPU (Metal), GraphPU (Vulkan), CPU Fallback
Data Flow
1
User triggers analysis
Through CLI command or React UI button click
2
Driving adapter calls core
The REST API receives the request and calls core business logic
3
Core orchestrates through ports
Core calls
IStructuralAnalyzer.AnalyzeAsync() — doesn’t know it’s Roslyn4
Driven adapter does the work
Roslyn adapter parses the code and returns nodes/edges
5
Core stores results
Core calls
IGraphStorage.SaveAsync() — doesn’t know it’s Neo4j6
Response flows back
Results return through the driving adapter to the user
Why This Separation?
Each layer and adapter can evolve independently:| Component | Can be replaced with |
|---|---|
| Roslyn | Tree-sitter for other languages |
| Neo4j | Memgraph, PostgreSQL, or in-memory |
| GraphPU | CPU-based layout, different algorithms |
| React Frontend | Desktop app, VR client, VS Code extension |
Plugin System
Plugins are just adapters that implement the same ports:| Plugin Type | Examples |
|---|---|
| Overlay plugins | Git activity, test coverage, complexity metrics |
| Analyzer plugins | TypeScript parser, Python parser |
| Export plugins | JSON, GraphML, DOT format |
Benefits
Testability
Mock any external dependency. Test business logic in isolation without databases or APIs.
Swappability
Replace any component without touching core. Switch databases, add languages, change providers.