crabmap 0.2.0

Rust code satellite map β€” index, query, and navigate your entire codebase
crabmap-0.2.0 is not a library.

πŸ¦€ Crabmap


Crabmap builds a durable, queryable knowledge graph of any Rust project. Give it to an AI agent β€” it understands the entire codebase without reading files one by one.

Think of it as a satellite map of your Rust codebase, while LSP (rust-analyzer) gives you a microscope for individual symbols.


✨ Why Crabmap?

LSP / rust-analyzer Crabmap
One symbol at a time Whole-project graph in one shot
Needs an open IDE Offline, portable JSON file
No "project overview" nav map β€” 8000-token architecture summary
Find references (flat list) query impact β€” full dependency propagation chains
No structural health checks analyze health β€” cycles, god modules, dead code
Human-first (hover, click) AI-first β€” designed for LLM context windows

πŸš€ Quick Start

# Install
cargo install crabmap

# Index a project
crabmap index /path/to/rust/project
# βœ“ indexed 9089 nodes, 14355 edges in 168 files

# AI architecture overview (compact)
crabmap nav map
# --full for entry points + feature clusters

# Find anything by name
crabmap query find "handler"
# --mode similar for structurally similar symbols

# Inspect a symbol (with source code)
crabmap query inspect main

# Trace call chains (both directions by default)
crabmap query trace load_config
# --direction up | down for one-way

# Scope: what's in a file or module?
crabmap query scope src/lib.rs
# --kind module for module declarations

# Explore interactively in the browser
crabmap serve

πŸ“¦ Commands

crabmap index β€” Build the graph

crabmap index .                           # Index current project
crabmap index --all .                     # Discover & index all Cargo projects
crabmap index --no-tests                  # Skip test files
crabmap index --no-semantic               # Skip rust-analyzer enrichment
crabmap index --output custom.json.gz     # Custom output path (gzipped)

crabmap query β€” Ask questions

Discover & Understand

crabmap query stats                       # Node/edge counts by kind/source/certainty
crabmap query symbols --limit 10          # List symbols (8 filter flags: --dead, --no-docs, --visibility, …)
crabmap query inspect main                # Symbol detail + source code
crabmap query find "config"               # Text search (--mode similar for structural similarity)
crabmap query scope src/lib.rs            # File contents (--kind module for module declarations)

Trace Relationships

crabmap query trace main                  # Both directions (--direction up | down)
crabmap query impact Runtime --depth 2    # Full impact: files_affected + call_sites + change_hints
crabmap query path main load_config       # Shortest call path between two symbols

Export

crabmap query export                      # JSON export (--format dot | mermaid)

crabmap nav β€” AI-oriented navigation

crabmap nav map               # Compact overview (~8k tokens, hot symbols)
crabmap nav map --full        # + entry points & feature clusters
crabmap nav quality           # Graph confidence score
crabmap nav health            # Cycles, god modules, dead code
crabmap nav report            # Generate GRAPH_REPORT.md + AGENT_GUIDE.md

crabmap analyze β€” Static analysis

crabmap analyze deps          # Module dependency matrix + recompile impact
crabmap analyze fanout        # File-level fan-in / fan-out
crabmap analyze tests <name>  # Call-graph-based test impact (score + call path)
crabmap analyze hotspots      # Git churn hotspots
crabmap analyze diff          # Graph diff vs git base

crabmap serve β€” Web UI

crabmap serve                         # Index + serve
crabmap serve --graph graph.json.gz   # Serve a pre-built graph
crabmap serve --watch                 # Auto-reindex on file changes

crabmap config β€” API Keys (for LLM features)

crabmap config --api-key sk-... --model gpt-4

🌐 Web UI

Launch crabmap serve and open http://127.0.0.1:7878:

  • Graph visualization β€” force-directed layout, color-coded by node/edge kind
  • Interactive exploration β€” click nodes to expand, drag to rearrange
  • Edge filtering β€” toggle relationship types (calls, declares, uses_type, …)
  • Detail drawer β€” inspect symbols, files, edges
  • Chinese UI β€” full zh-CN interface

πŸ§ͺ Tested On

Project Nodes Edges Warnings Quality
crabmap (self) 1007 2,063 0 99
ripgrep 9,089 14,355 0 96
tokio 14,176 28,831 0 98

All three projects indexed with zero warnings.


πŸ”§ How It Works

  1. cargo metadata β†’ discovers packages, targets, source files
  2. syn AST walk β†’ extracts structs, enums, functions, methods, impls, macros…
  3. Call resolution β†’ same-module priority, method-to-trait-impl matching
  4. rust-analyzer enrichment (optional) β†’ LSP call hierarchy for confirmed edges
  5. MIR lowering (optional) β†’ rustc MIR for dispatch sites
  6. Graph persistence β†’ gzip-compressed JSON (14Γ— smaller than raw)

πŸ“„ Graph Format

The output is a single JSON file (gzipped by default):

{
  "schema_version": 2,
  "project": { "root": ".", "packages": […] },
  "nodes": [
    { "id": "function:crabmap::run", "kind": "function", "name": "run", … }
  ],
  "edges": [
    { "from": "function:crabmap::main", "to": "function:crabmap::run",
      "kind": "calls", "source": "ast", "certainty": "definite" }
  ]
}
Edge Kind Meaning
calls Function/method call
declares Module declares a symbol
uses_type Type reference
contains File contains a module
imports use statement
has_method Impl block owns a method
implements Trait implementation
returns Return type
module_file File ↔ module mapping

πŸ›  Building from Source

git clone https://github.com/trtyr/crabmap.git
cd crabmap
cargo build --release
./target/release/crabmap --version
# crabmap 0.1.2 (abc1234 2026-05-21)

Requires Rust β‰₯ 1.85 (edition 2024).


πŸ“ Project Layout

src/
β”œβ”€β”€ main.rs            # CLI entry & command dispatch
β”œβ”€β”€ cli.rs             # clap argument definitions
β”œβ”€β”€ model.rs           # Core data model (Node, Edge, CodeGraph)
β”œβ”€β”€ analyzer/          # AST indexer (syn walk, 6 sub-modules)
β”œβ”€β”€ query/             # Graph traversal, search, filtering (6 sub-modules)
β”‚   β”œβ”€β”€ commands.rs    # inspect, trace, find, scope, impact
β”‚   β”œβ”€β”€ filter.rs      # SymbolFilter β€” 8 lightweight query flags
β”‚   β”œβ”€β”€ similar.rs     # Structural similarity by callee overlap
β”‚   └── source.rs      # Source code retrieval by line range
β”œβ”€β”€ ai/                # AI nav: map, guide, clusters, quality (5 sub-modules)
β”œβ”€β”€ web/               # Embedded HTTP server + viewer (6 sub-modules)
β”œβ”€β”€ rag/               # Retrieval: lexical β†’ embedding β†’ rerank (6 sub-modules)
β”œβ”€β”€ semantic/          # rust-analyzer LSP enrichment (3 sub-modules)
β”œβ”€β”€ store.rs           # Gzip JSON load/save + multi-project auto-discovery
β”œβ”€β”€ config.rs          # Global config (~/.config/crabmap/)
β”œβ”€β”€ health.rs          # Architecture risk detection
β”œβ”€β”€ mir.rs             # MIR lowering
β”œβ”€β”€ deps.rs            # Module dependency + recompile impact
β”œβ”€β”€ test_impact.rs     # Call-graph-based test impact analysis
└── …

web/
β”œβ”€β”€ index.html
β”œβ”€β”€ styles/            # CSS (dark theme)
└── src/               # JS (microkernel architecture)

skills/
└── crabmap.md         # AI agent usage guide (skill file)

πŸ“ License

MIT