How suatkocar/codegraph works
Project type and purpose
• CodeGraph is an open-source code-intelligence engine and MCP (Model Context Protocol) server written in Rust.
• It indexes source code in 32 languages via tree-sitter, builds a semantic graph in SQLite (with FTS5 and vector indexes), exposes 44 “tools” over stdio (rmcp), and provides Git and security hooks for live synchronization.
File structure
• Top-level:
• Cargo.toml / Cargo.lock – Rust project metadata
• src/ – core Rust modules
• benches/, tests/ – benchmarks and test suites
• configs/, queries/, rules/ – built-in config and analysis artifacts
• npm/, HomebrewFormula/ – packaging for JS and Homebrew
• scripts/, install.sh / install.ps1 – installation helpers
• .github/, .githooks/ – CI and Git hook definitions
• src/ subdirectories map to major components:
• cli/ & main.rs – CLI entrypoints (clap-based commands: init, index, serve, query…)
• indexer/ – parser, extractor, pipeline (tree-sitter grammars + parallel SHA-256 incremental indexing)
• db/ – SQLite schema, converters, rusqlite integration
• graph/ – graph traversal, ranking, search, complexity, data-flow modules
• mcp/ – MCP server that wraps tools via #[tool] macros
• context/ – multi-tier LLM context assembly and token budgeting
• resolution/, security/, git/ – import resolution, security scanning, Git integrations
• config/, observability/, eval/ – configuration loading, structured logging, evaluation harness
README for additional insights
Source Files → tree-sitter → Extractor → SQLite DB → Query Engine → MCP Server + Hooks
• Design principles: synchronous core, async boundary at rmcp transport, static linking of grammars, catch_unwind for hook safety, idempotent init, feature-gated embeddings.
• Blue for core engine (parser, extractor, graph)
• Green for storage (SQLite DB)
• Orange for interface (CLI, MCP Server, Hooks)
• Grey for external/optional (ONNX embedder, Git, YAML rules)