A semantic code graph visualization platform for understanding large codebases.
Semantic Lens processes codebase data from external chunkers/analyzers, stores it in a graph database, detects design patterns using declarative rules, and renders interactive architectural diagrams.
- Schema-validated ingestion of SemanticGraphBundle payloads
- Graph storage with in-memory or Memgraph backends
- Pattern detection via YAML DSL with Cypher compilation
- Interactive visualization with lenses, filters, and pattern overlays
- Deterministic layout using ELK for reproducible diagrams
npm install semantic-lens
# Or install globally for CLI access
npm install -g semantic-lenssemantic-lens validate bundle.json# Load bundle and detect patterns
semantic-lens load bundle.json
semantic-lens patterns --bundle bundle.json --output patterns.jsonsemantic-lens serve --bundle bundle.jsonThen open http://localhost:3001 in your browser.
Port Configuration:
The server uses port 3001 by default and automatically finds the next available port if needed:
# Use default port (3001, auto-fallback to 3002+ if unavailable)
semantic-lens serve
# Specify port explicitly
semantic-lens serve --port 8080
# Use environment variable
VIEW_SERVICE_PORT=8080 semantic-lens serveValidate a SemanticGraphBundle JSON file against the schema.
semantic-lens validate <bundle.json>Exit codes:
- 0: Valid bundle
- 1: Invalid bundle or error
Load a bundle into the graph store and display statistics.
semantic-lens load <bundle.json> [options]
Options:
--db <uri> Database URI (default: in-memory)
--clear Clear store before loadingRun pattern detection on a loaded graph.
semantic-lens patterns [options]
Options:
--bundle <file> Bundle file to load
--output <file> Output file (default: stdout)
--pattern <id> Filter by pattern IDBuilt-in patterns:
observer- Observer/Publisher-Subscriber patternfactory- Factory/Builder patternsingleton- Singleton patternstrategy- Strategy/Policy pattern
Start the HTTP API server for visualization.
semantic-lens serve [options]
Options:
--port <port> Server port (default: 3000)
--bundle <file> Pre-load a bundle fileExport a view to a static format.
semantic-lens export <config.json> [options]
Options:
--format <fmt> Output format: json (default)
--output <file> Output file (default: stdout)Semantic Lens accepts SemanticGraphBundle JSON files:
{
"version": "v1.0",
"generated_at": "2026-01-01T00:00:00Z",
"repo": {
"name": "my-project",
"commit": "abc123",
"root": "/path/to/project"
},
"nodes": [
{
"node_id": "class-user",
"kind": "class",
"name": "User",
"file": "src/models/user.ts",
"route": "app::models::User",
"span": {
"start": { "line": 1, "col": 1 },
"end": { "line": 50, "col": 1 }
},
"visibility": "public",
"language": "typescript"
}
],
"edges": [
{
"edge_id": "e1",
"kind": "uses",
"src": "class-user-service",
"dst": "class-user",
"confidence": 0.95,
"evidence": ["static_analysis"]
}
],
"annotations": [],
"patterns": []
}module- File or packageclass- Class definitioninterface- Interface/protocoltrait- Trait/mixinfunction- Standalone functionmethod- Class methodfield- Class field/propertyproperty- Property accessor
defines- Parent defines childimports- Module imports anothercalls- Function/method calls anotherinherits- Class extends anotherimplements- Class implements interfaceuses- General usage relationshipreads- Reads a fieldwrites- Writes a fieldthrows- Throws an exception
See docs/api.md for complete API documentation.
| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Health check |
/views |
GET | List available view types |
/view |
POST | Generate a view |
/layout/elk |
POST | Compute layout only |
/patterns/run |
POST | Run pattern detection |
Define custom patterns in YAML:
id: observer
description: Observer pattern - subject notifies observers
roles:
subject:
kind: class
name: /Subject|Observable/
observer:
kind: interface
name: /Observer|Listener/
constraints:
- type: edge
from: subject
to: observer
kind: uses
- type: group
role: observer
min_size: 1
scoring:
base: 0.6
weights:
subject_uses_observer: 0.2
group_observer: 0.2# Install dependencies
npm install
# Build
npm run build
# Run tests
npm test
# Run E2E tests
npm run test:e2e
# Run with coverage
npm run test:coverageMIT