How muvon/octocode works
1. What this repository is
Octocode is a single Rust application that turns a local repository into a searchable knowledge base. The core runtime has two user-facing entry points: a CLI for indexing/searching/analysis, and an MCP server for exposing those capabilities to AI clients like Claude or Cursor.
2. Top-level control flow
src/main.rs and src/commands/* form the command dispatcher. Commands such as index, search, view, commit, diff, review, explain, stats, watch, mcp, and graphrag route into the indexing, retrieval, or server subsystems. This makes the repo a multi-mode tool rather than a single-purpose library.
3. Indexing pipeline
src/indexer/* is the ingestion pipeline. It scans a target repository, filters paths, and breaks content into retrievable blocks or regions. The pipeline includes file processing, markdown processing, commit processing, differential processing, branch-aware logic, and batch processing so the index can be built incrementally or refreshed over time.
4. Language-aware code extraction
The indexer has language-specific modules under src/indexer/languages/* for Rust, Python, JavaScript/TypeScript, Go, Java, PHP, C++, Ruby, Bash, JSON, Markdown, and others. These extract structure such as functions, classes, imports, modules, headers, and signatures using tree-sitter-style parsing and language-specific heuristics. This is the boundary where raw text becomes structured code intelligence.
5. Semantic search and retrieval
The src/store/*, src/embedding/*, src/reranker.rs, and src/indexer/search.rs layers implement the retrieval path. The typical flow is: user query -> embedding generation -> candidate lookup in local storage -> reranking -> formatted results. The store layer appears to manage metadata, vector/block organization, and optimization of retrieval structures.
6. Knowledge graph / GraphRAG subsystem
src/indexer/graphrag/* and src/store/graphrag.rs are the graph-oriented part of the architecture. They build and query a relationship graph over code entities, files, and dependencies. This is the subsystem behind architecture-oriented queries and the MCP graphrag tool, and it sits alongside semantic search rather than replacing it.
7. AI and model integration
src/llm/* and src/embedding/* isolate external model interactions. The README indicates embedding/search features use providers such as Voyage AI, while some workflows can use local/offline embedding paths on supported platforms. The command set also includes review/commit-related AI features, so model access is a shared service rather than embedded in a single command.
8. MCP server boundary
src/mcp/* contains the Model Context Protocol server, handler layer, proxy support, and LSP-related helpers. It exposes tools like semantic search, file signature inspection, and GraphRAG queries to external AI clients. This is the main integration boundary between Octocode’s local index and third-party assistants.
9. LSP-backed semantic code support
The src/mcp/lsp/* modules add a language-server client/protocol layer for semantic code operations. This is a separate integration path from pure indexing: it lets the server obtain richer code context from editor/language tooling when needed, especially for code-aware MCP operations.
10. Watching, state, and concurrency
src/watch-style behavior is implemented through src/commands/watch.rs, src/mcp/watcher.rs, src/watcher_config.rs, src/state.rs, and src/lock.rs. Together these support long-running operation, repository monitoring, and coordination so the index can stay current without rebuilding everything from scratch.
11. Data model and utilities
Shared helpers live in src/utils/*, src/constants.rs, src/config.rs, and src/storage.rs. These handle path normalization, diff chunking, configuration loading, and repository-local storage decisions. The architecture is intentionally local-first: the repository path, config, lock/state, and on-disk index are the main operational boundaries.
12. Operational and delivery layer
The repo is packaged as a Rust CLI binary with Docker support, GitHub Actions CI/release workflows, benchmark tooling, and a static website/ for docs/demo content. These are supporting systems; they do not change the runtime architecture, but they show the project is shipped as a local executable plus an HTTP/MCP-capable service.
Main entry points: commands/mod.rs Commands · indexer/mod.rs Indexer · search.rs Search Prep · handlers.rs Handlers
Components 22
CLI
Command dispatch and user-facing modes
- Main · Program entry and startup flow
src/main.rs - Commands · Routes CLI subcommands to subsystems
src/commands/mod.rs - Index · Builds or refreshes the local index
src/commands/index.rs - Search · Runs repository search over indexed data
src/commands/search.rs - GraphRAG · Entry point for graph-oriented queries
src/commands/graphrag.rs - Watch · Keeps the index updated continuously
src/commands/watch.rs - MCP Cmd · Starts or manages the MCP server
src/commands/mcp.rs
Indexing
Repository ingestion, parsing, and incremental refresh
- Indexer · Scans files and converts repositories into structured blocks
src/indexer/mod.rs - File Proc · Handles file-level processing and filtering
src/indexer/file_processor.rs - Markdown · Special handling for markdown content
src/indexer/markdown_processor.rs - Batch Proc · Incremental and batched indexing execution
src/indexer/batch_processor.rs - Languages · Language-aware structural extraction layer
src/indexer/languages/mod.rs
Retrieval
Search, ranking, storage, and embeddings
- Search Prep · Builds queryable search structures from indexed content
src/indexer/search.rs - Store · Manages metadata, blocks, and retrieval structures
src/store/mod.rs - Embeddings · Produces vectors for semantic retrieval
src/embedding/mod.rs - Reranker · Reorders retrieved candidates by relevance
src/reranker.rs - Graph Store · Stores and queries relationship graph data
src/store/graphrag.rs
MCP
Model Context Protocol server and integrations
- Server · Exposes Octocode capabilities over MCP
src/mcp/server.rs - Handlers · Maps MCP tools to repository operations
src/mcp/handlers.rs - Semantic Code · Code-aware operations for MCP clients
src/mcp/semantic_code.rs - MCP GraphRAG · Graph-oriented MCP access
src/mcp/graphrag.rs - LSP Client · Connects to external language tooling
src/mcp/lsp/client.rs
Connections 25
- Main → Commands: dispatches · Starts command parsing and mode selection
- Commands → Index: index · Invokes repository indexing
- Commands → Search: search · Invokes semantic lookup
- Commands → GraphRAG: graph query · Invokes graph-based analysis
- Commands → Watch: watch · Runs incremental monitoring mode
- Commands → MCP Cmd: mcp · Launches the MCP boundary
- Index → Indexer: builds · Feeds repositories into the indexing pipeline
- Watch → Indexer: refreshes · Triggers ongoing reindexing work
- Indexer → File Proc: scans · Processes repository files and filters paths
- Indexer → Markdown: parses · Handles markdown-specific structure
- Indexer → Batch Proc: batches · Executes incremental batch indexing
- Indexer → Languages: extracts · Derives code structure from languages
- Languages → Search Prep: structures · Produces searchable code regions and signatures
- Search → Search Prep: queries · Prepares search candidates from indexed data
- Search Prep → Embeddings: vectorizes · Creates semantic query and content vectors
- Embeddings → Store: writes · Persists retrieval-ready blocks and metadata
- Search Prep → Store: looks up · Retrieves candidates from local storage
- Store → Reranker: feeds · Provides candidates for final ranking
- GraphRAG → Graph Store: uses · Queries relationship graph structures
- MCP Cmd → Server: starts · Runs the MCP server process
- Server → Handlers: routes · Dispatches tools to handler implementations
- Handlers → Semantic Code: serves · Provides code-aware MCP operations
- Handlers → MCP GraphRAG: serves · Exposes graph queries to AI clients
- Semantic Code → LSP Client: integrates · Uses language-server support for richer context
- MCP GraphRAG → Graph Store: queries · Reads graph data from the store layer