Magellan
A deterministic codebase mapping tool. Watches source files, extracts AST-level facts, and builds a searchable graph database of symbols and references.
What Magellan Does
- Watches directories for file changes (Create/Modify/Delete)
- Extracts AST-level facts: functions, classes, methods, enums, modules
- Tracks symbol references: function calls and type references (7 languages)
- Builds call graphs: caller → callee relationships (7 languages)
- Persists everything to a sqlitegraph database
- Handles errors gracefully - keeps running even when files are unreadable
- Shuts down cleanly on SIGINT/SIGTERM
What Magellan Does NOT Do
- No semantic analysis or type checking
- No LSP server or language features
- No async runtimes or background thread pools
- No config files
- No web APIs or network services
- No automatic database cleanup
Installation
# Binary will be at target/release/magellan
Requirements
- Rust 1.70+
- Linux/macOS (signal handling uses Unix signals)
- SQLite 3 (via sqlitegraph dependency)
Quick Start
# Start watching a project with initial scan
# Check status
# List all indexed files
# Query symbols in a file
# Find a symbol by name
# Show call references
# Export to JSON
Commands
watch
Watch a directory for source file changes and index them into the database.
| Argument | Description |
|---|---|
--root <DIR> |
Directory to watch recursively (required) |
--db <FILE> |
Path to sqlitegraph database (required) |
--debounce-ms <N> |
Debounce delay in milliseconds (default: 500) |
--scan-initial |
Scan directory for source files on startup |
status
Show database statistics.
$ magellan status --db ./magellan.db
files: 30
symbols: 349
references: 262
files
List all indexed files.
$ magellan files --db ./magellan.db
30 indexed files:
/path/to/src/main.rs
/path/to/src/lib.rs
...
query
List symbols in a file, optionally filtered by kind.
| Argument | Description |
|---|---|
--db <FILE> |
Path to database (required) |
--file <PATH> |
File path to query (required) |
--kind <KIND> |
Filter by symbol kind (optional) |
Valid kinds: Function, Method, Class, Interface, Enum, Module, Union, Namespace, TypeAlias
$ magellan query --db ./magellan.db --file src/main.rs --kind Function
/path/to/src/main.rs:
Line 13: Function print_usage
Line 64: Function parse_args
find
Find a symbol by name.
| Argument | Description |
|---|---|
--db <FILE> |
Path to database (required) |
--name <NAME> |
Symbol name to find (required) |
--path <PATH> |
Limit search to specific file (optional) |
$ magellan find --db ./magellan.db --name main
Found "main":
File: /path/to/src/main.rs
Kind: Function
Location: Line 229, Column 0
refs
Show incoming or outgoing calls for a symbol.
| Argument | Description |
|---|---|
--db <FILE> |
Path to database (required) |
--name <NAME> |
Symbol name (required) |
--path <PATH> |
File path containing the symbol (required) |
| `--direction <in | out>` |
$ magellan refs --db ./magellan.db --name parse_args --path src/main.rs --direction in
Calls TO "parse_args":
From: main (Function) at /path/to/src/main.rs:237
verify
Compare database state vs filesystem and report differences.
Exit codes: 0 = up to date, 1 = issues found
export
Export all graph data to JSON format.
Supported Languages
| Language | Extensions | Parser |
|---|---|---|
| Rust | .rs | tree-sitter-rust |
| C | .c, .h | tree-sitter-c |
| C++ | .cpp, .cc, .cxx, .hpp, .h | tree-sitter-cpp |
| Java | .java | tree-sitter-java |
| JavaScript | .js, .mjs | tree-sitter-javascript |
| TypeScript | .ts, .tsx | tree-sitter-typescript |
| Python | .py | tree-sitter-python |
Database Schema
Nodes:
File- path, hash, timestampsSymbol- name, kind, byte spans, line/columnReference- file, referenced symbol, locationCall- file, caller, callee, location
Edges:
DEFINES- File -> SymbolREFERENCES- Reference -> SymbolCALLS- Symbol -> Symbol
Symbol Kinds: Function, Method, Class, Interface, Enum, Module, Union, Namespace, TypeAlias, Unknown
Error Handling
Magellan continues processing even when individual files fail:
- Permission errors are logged and skipped
- Files with invalid syntax are skipped
- Database write errors cause exit (requires manual intervention)
Architecture
src/
├── main.rs # CLI entry point
├── lib.rs # Public API
├── watcher.rs # Filesystem watcher
├── indexer.rs # Event coordination
├── references.rs # Reference/Call fact types
├── verify.rs # Database verification logic
├── ingest/
│ ├── mod.rs # Parser dispatcher & Rust parser
│ ├── detect.rs # Language detection
│ ├── c.rs # C parser
│ ├── cpp.rs # C++ parser
│ ├── java.rs # Java parser
│ ├── javascript.rs # JavaScript parser
│ ├── typescript.rs # TypeScript parser
│ └── python.rs # Python parser
├── query_cmd.rs # Query command
├── find_cmd.rs # Find command
├── refs_cmd.rs # Refs command
├── verify_cmd.rs # Verify CLI handler
├── watch_cmd.rs # Watch CLI handler
└── graph/
├── mod.rs # CodeGraph API
├── schema.rs # Node/edge types
├── files.rs # File operations
├── symbols.rs # Symbol operations
├── references.rs # Reference node operations
├── calls.rs # Call edge operations
├── call_ops.rs # Call node operations
├── ops.rs # Graph indexing operations
├── query.rs # Query operations
├── count.rs # Count operations
├── export.rs # JSON export
├── scan.rs # Scanning operations
├── freshness.rs # Freshness checking
└── tests.rs # Graph tests
Testing
Test coverage: 172+ tests across 25+ test suites. All tests pass in <15 seconds.
Current Status
Version: 0.3.0 Status: Stable
Features:
- Symbol extraction for 7 languages ✅
- Reference extraction for 7 languages ✅ (NEW)
- Call graph indexing for 7 languages ✅ (NEW)
- Rename refactoring support (via codemcp) for 7 languages ✅ (NEW)
Known Limitations:
- Name-based reference matching (has false positives)
- No cross-crate/cross-file resolution
- No incremental parsing
- Single-threaded event processing
License
GPL-3.0-or-later
Dependencies
- notify - Filesystem watching
- tree-sitter - AST parsing
- sqlitegraph - Graph persistence
- signal-hook - Signal handling
- walkdir - Directory scanning