codegraph Workspace
A fast, reliable, and flexible graph database optimized for storing and querying code relationships, with production-ready language parsers.
Mission
The codegraph ecosystem provides:
- codegraph: Fast graph database for storing code relationships
- codegraph-parser-api: Unified parser interface and types
- Language parsers: Production-ready parsers for Python, Rust, TypeScript, and Go
- A complete solution for building code analysis tools
Workspace Crates
| Crate | Version | Description | Status |
|---|---|---|---|
codegraph |
0.1.1 | Graph database core | ✅ Stable |
codegraph-parser-api |
0.1.0 | Parser trait and types | ✅ Stable |
codegraph-python |
0.2.0 | Python parser | ✅ Stable |
codegraph-rust |
0.1.0 | Rust parser | ✅ Stable |
codegraph-typescript |
0.1.0 | TypeScript/JavaScript parser | ✅ Stable |
codegraph-go |
0.1.0 | Go parser | ✅ Stable |
Quick Start
Using the Complete Solution (Database + Parser)
[]
= "0.1.1"
= "0.1.0"
= "0.2.0" # or rust, typescript, go
use CodeGraph;
use CodeParser;
use PythonParser;
use Path;
// Create parser and graph
let parser = new;
let mut graph = open?;
// Parse a file
let file_info = parser.parse_file?;
println!;
// Parse entire project
let project_info = parser.parse_directory?;
println!;
// Query the graph
let neighbors = graph.get_neighbors?;
Language-Specific Examples
use PythonParser;
use ;
let config = ParserConfig ;
let parser = with_config;
let mut graph = open?;
// Parse Python project
let info = parser.parse_directory?;
use RustParser;
use CodeParser;
let parser = new;
let mut graph = open?;
// Parse Rust source
let info = parser.parse_file?;
// Extracts: functions, structs, enums, traits, impl blocks, use statements
use TypeScriptParser;
use CodeParser;
let parser = new;
let mut graph = open?;
// Supports .ts, .tsx, .js, .jsx files
let info = parser.parse_file?;
// Extracts: functions, classes, interfaces, imports, JSX components
use GoParser;
use CodeParser;
let parser = new;
let mut graph = open?;
// Parse Go package
let info = parser.parse_directory?;
// Extracts: functions, structs, interfaces, imports
Core Principles
🔌 Unified Parser API
"One trait to parse them all."
All language parsers implement the same CodeParser trait, providing:
- Consistent API across languages
- Standardized entity types (functions, classes, imports)
- Uniform error handling and metrics
- Drop-in interchangeability
⚡ Performance First
"Sub-100ms queries or it didn't happen."
- Single node lookup: <1ms
- Neighbor query: <10ms
- Graph traversal (depth=5): <50ms
- 100K node graphs are practical
🧪 Test-Driven Development
"If it's not tested, it's broken."
- 421+ tests across entire workspace
- codegraph: 39 tests (85% coverage)
- parser-api: 12 tests with comprehensive entity validation
- Python: 111 tests (~90% coverage)
- Rust: 64 tests (40 unit + 24 integration)
- TypeScript: 63 tests (40 unit + 23 integration)
- Go: 54 tests (34 unit + 20 integration)
- Every public API tested with TDD methodology
🪄 Zero Magic
"Explicit over implicit, always."
- No global state
- No automatic file scanning
- No convention-over-configuration
- Explicit error handling (no panics in library code)
- No unsafe code
💾 Persistence is Primary
"Graphs outlive processes."
- RocksDB backend for production
- Crash-safe with write-ahead logging
- Atomic batch operations
- Memory backend for testing only
Using Just the Database
If you want to use your own parsers:
[]
= "0.1.1"
use ;
use Path;
// Create a persistent graph
let mut graph = open?;
// Add nodes manually
let file_id = graph.add_file?;
let func_id = graph.add_node?;
// Create relationships
graph.add_edge?;
// Query the graph
let neighbors = graph.get_neighbors?;
Architecture
codegraph is organized in clear layers:
User Tools (parsers, analysis)
↓
Code Helpers (convenience API)
↓
Query Builder (fluent interface)
↓
Core Graph (nodes, edges, algorithms)
↓
Storage Backend (RocksDB, memory)
Each layer:
- Has well-defined boundaries
- Can be tested independently
- Doesn't leak abstractions
- Has minimal dependencies on upper layers
Features
- Persistent Storage: Production-ready RocksDB backend
- Type-Safe API: Rust's type system prevents common errors
- Schema-less Properties: Flexible JSON properties on nodes and edges
- Efficient Queries: O(1) neighbor lookups with adjacency indexing
- Explicit Operations: No hidden behavior or magical conventions
- Comprehensive Tests: 85% test coverage (983/1158 lines)
- Zero Unsafe Code: Memory-safe by default
What We Provide
✅ Complete Solution
- Graph Database: Fast, persistent storage for code relationships
- Parser API: Unified interface for all language parsers
- Language Parsers: Production-ready Python, Rust, TypeScript, and Go parsers
- Analysis Foundation: Building blocks for custom code analysis tools
❌ Out of Scope
- Semantic Analysis: No type inference or advanced static analysis
- IDE Integration: No LSP server or editor plugins
- Build System: No compilation or dependency resolution
- Complete Framework: You build the analysis logic, we provide the infrastructure
Performance Targets
| Operation | Target | Actual |
|---|---|---|
| Node lookup | <1ms | ✅ ~7ns (1000x better!) |
| Neighbor query | <10ms | ✅ ~410ns - 40µs |
| BFS traversal (depth=5) | <50ms | ✅ ~5ms |
| Batch insert (10K nodes) | <500ms | ✅ ~7ms |
| 100K node + 500K edge load | <5s | ✅ ~3.3s |
Development
Workspace Commands
# Build all crates
# Test all crates (421+ tests)
# Test specific parser
# Generate documentation for all crates
Code Quality
# Format all code
# Lint with clippy (all warnings as errors)
# Check test coverage
# Run individual crate checks
Individual Crate Development
# Work on specific parser
# Add features to parser API
Examples
See the examples/ directory for complete examples:
basic_usage.rs- Creating and querying a simple graphcall_graph.rs- Function call analysis with syn integrationdependency_tree.rs- File dependency and circular dependency analysisimpact_analysis.rs- Complex query patterns for impact analysisvisualize.rs- Exporting graphs to DOT, JSON, CSV, and RDF formats
API Overview
Core Operations
// Node operations
let node_id = graph.add_node?;
let node = graph.get_node?;
graph.delete_node?;
// Edge operations
let edge_id = graph.add_edge?;
let neighbors = graph.get_neighbors?;
// Batch operations
graph.add_nodes_batch?;
graph.add_edges_batch?;
Helper Functions
use helpers;
// Code-specific operations
let file_id = add_file?;
let func_id = add_function?;
add_call?;
// Relationship queries
let callers = get_callers?;
let deps = get_file_dependencies?;
Query Builder
// Fluent query interface
let results = graph.query
.node_type
.in_file
.property
.name_contains
.execute?;
Graph Algorithms
// Transitive analysis
let all_deps = transitive_dependencies?;
let all_dependents = transitive_dependents?;
// Call chains
let paths = call_chain?;
// Circular dependencies
let cycles = circular_deps?;
Export Formats
use export;
// Graphviz DOT
export_dot?;
// D3.js JSON
export_json?;
// CSV (nodes and edges)
export_csv_nodes?;
export_csv_edges?;
// RDF N-Triples
export_triples?;
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Before contributing, please:
- Follow TDD methodology
- Ensure all tests pass
- Run
cargo fmtandcargo clippy
License
codegraph is licensed under the Apache License 2.0, which means:
✅ You can:
- Use in commercial products
- Modify and distribute
- Use in proprietary software
✅ You must:
- Include a copy of the license
- Disclose significant changes (in a CHANGES file)
- Include the patent grant notice
✅ You can't:
- Hold us liable
- Claim we endorse your product
This is a truly open license. There's no "gotcha" later where we switch to GPL or a commercial model. Apache-2.0 is forever.
Code of Conduct
This project adheres to the Rust Code of Conduct. See CODE_OF_CONDUCT.md.
Versioning
This project follows Semantic Versioning:
- v0.x: API may change between minor versions (with deprecation warnings)
- v1.0+: Stability guaranteed, breaking changes only in major versions
Current version: 0.1.1 (Initial release + formatting fixes)
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Roadmap
v0.2.0 (Current Release)
- Unified parser API with standardized types
- Python parser with comprehensive test coverage
- Rust parser with full AST extraction
- TypeScript/JavaScript parser with JSX/TSX support
- Go parser with import tracking
- 421+ tests across all crates
v0.3-0.5 (Near-term)
- Query language improvements (graph patterns, filters)
- More export formats (GraphML, Cypher, Neo4j)
- Performance optimizations (batch operations, caching)
- Parser enhancements (semantic relationships, type information)
v0.6-0.9 (Medium-term)
- Incremental updates (watch mode, delta parsing)
- Change tracking and diff analysis
- Statistics and metrics API
- CLI tool for parsing and querying
- Additional language parsers (Java, C++, C#)
v1.0+ (Long-term)
- Schema validation and constraints
- Full-text search integration
- Compression options for large graphs
- Distributed graphs for multi-repo analysis
Acknowledgments
This project draws inspiration from:
- Rust Language governance model
- SQLite's reliability principles
- Redis project philosophy
- Kubernetes governance structure
Built with ❤️ in Rust