# muvon/octocode architecture

> Architecture diagram of the GitHub repository muvon/octocode, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/muvon/octocode
- Repository: https://github.com/muvon/octocode

## Overview

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: [`src/commands/mod.rs`](https://github.com/muvon/octocode/blob/master/src/commands/mod.rs) (Commands), [`src/indexer/mod.rs`](https://github.com/muvon/octocode/blob/master/src/indexer/mod.rs) (Indexer), [`src/indexer/search.rs`](https://github.com/muvon/octocode/blob/master/src/indexer/search.rs) (Search Prep), [`src/mcp/handlers.rs`](https://github.com/muvon/octocode/blob/master/src/mcp/handlers.rs) (Handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI"]
  node_main["Main<br/>binary entry<br/>[main.rs]"]
  node_commands["Commands<br/>dispatcher<br/>[mod.rs]"]
  node_index_cmd["Index<br/>cli command<br/>[index.rs]"]
  node_search_cmd["Search<br/>cli command<br/>[search.rs]"]
  node_graphrag_cmd["GraphRAG<br/>cli command<br/>[graphrag.rs]"]
  node_watch_cmd["Watch<br/>cli command<br/>[watch.rs]"]
  node_mcp_cmd["MCP Cmd<br/>cli command<br/>[mcp.rs]"]
end

subgraph group_indexing["Indexing"]
  node_indexer["Indexer<br/>pipeline<br/>[mod.rs]"]
  node_file_proc["File Proc<br/>ingest stage<br/>[file_processor.rs]"]
  node_markdown_proc["Markdown<br/>ingest stage"]
  node_batch_proc["Batch Proc<br/>pipeline stage<br/>[batch_processor.rs]"]
  node_lang_extract["Languages<br/>code extraction<br/>[mod.rs]"]
end

subgraph group_retrieval["Retrieval"]
  node_search_indexer["Search Prep<br/>retrieval prep<br/>[search.rs]"]
  node_store[("Store<br/>local storage<br/>[mod.rs]")]
  node_embeddings(("Embeddings<br/>model adapter<br/>[mod.rs]"))
  node_reranker["Reranker<br/>ranking<br/>[reranker.rs]"]
  node_graphrag_store[("Graph Store<br/>graph storage<br/>[graphrag.rs]")]
end

subgraph group_mcp["MCP"]
  node_mcp_server["Server<br/>[server.rs]"]
  node_handlers["Handlers<br/>[handlers.rs]"]
  node_semantic_code["Semantic Code<br/>code context<br/>[semantic_code.rs]"]
  node_mcp_graphrag["MCP GraphRAG<br/>mcp tool<br/>[graphrag.rs]"]
  node_lsp_client["LSP Client<br/>language server integration<br/>[client.rs]"]
end

node_main -->|"dispatches"| node_commands
node_commands -->|"index"| node_index_cmd
node_commands -->|"search"| node_search_cmd
node_commands -->|"graph query"| node_graphrag_cmd
node_commands -->|"watch"| node_watch_cmd
node_commands -->|"mcp"| node_mcp_cmd
node_index_cmd -->|"builds"| node_indexer
node_watch_cmd -->|"refreshes"| node_indexer
node_indexer -->|"scans"| node_file_proc
node_indexer -->|"parses"| node_markdown_proc
node_indexer -->|"batches"| node_batch_proc
node_indexer -->|"extracts"| node_lang_extract
node_lang_extract -->|"structures"| node_search_indexer
node_search_cmd -->|"queries"| node_search_indexer
node_search_indexer -->|"vectorizes"| node_embeddings
node_embeddings -->|"writes"| node_store
node_search_indexer -->|"looks up"| node_store
node_store -->|"feeds"| node_reranker
node_graphrag_cmd -->|"uses"| node_graphrag_store
node_mcp_cmd -->|"starts"| node_mcp_server
node_mcp_server -->|"routes"| node_handlers
node_handlers -->|"serves"| node_semantic_code
node_handlers -->|"serves"| node_mcp_graphrag
node_semantic_code -->|"integrates"| node_lsp_client
node_mcp_graphrag -->|"queries"| node_graphrag_store

click node_main "https://github.com/muvon/octocode/blob/master/src/main.rs"
click node_commands "https://github.com/muvon/octocode/blob/master/src/commands/mod.rs"
click node_index_cmd "https://github.com/muvon/octocode/blob/master/src/commands/index.rs"
click node_search_cmd "https://github.com/muvon/octocode/blob/master/src/commands/search.rs"
click node_graphrag_cmd "https://github.com/muvon/octocode/blob/master/src/commands/graphrag.rs"
click node_watch_cmd "https://github.com/muvon/octocode/blob/master/src/commands/watch.rs"
click node_mcp_cmd "https://github.com/muvon/octocode/blob/master/src/commands/mcp.rs"
click node_indexer "https://github.com/muvon/octocode/blob/master/src/indexer/mod.rs"
click node_file_proc "https://github.com/muvon/octocode/blob/master/src/indexer/file_processor.rs"
click node_markdown_proc "https://github.com/muvon/octocode/blob/master/src/indexer/markdown_processor.rs"
click node_batch_proc "https://github.com/muvon/octocode/blob/master/src/indexer/batch_processor.rs"
click node_lang_extract "https://github.com/muvon/octocode/blob/master/src/indexer/languages/mod.rs"
click node_search_indexer "https://github.com/muvon/octocode/blob/master/src/indexer/search.rs"
click node_store "https://github.com/muvon/octocode/blob/master/src/store/mod.rs"
click node_embeddings "https://github.com/muvon/octocode/blob/master/src/embedding/mod.rs"
click node_reranker "https://github.com/muvon/octocode/blob/master/src/reranker.rs"
click node_graphrag_store "https://github.com/muvon/octocode/blob/master/src/store/graphrag.rs"
click node_mcp_server "https://github.com/muvon/octocode/blob/master/src/mcp/server.rs"
click node_handlers "https://github.com/muvon/octocode/blob/master/src/mcp/handlers.rs"
click node_semantic_code "https://github.com/muvon/octocode/blob/master/src/mcp/semantic_code.rs"
click node_mcp_graphrag "https://github.com/muvon/octocode/blob/master/src/mcp/graphrag.rs"
click node_lsp_client "https://github.com/muvon/octocode/blob/master/src/mcp/lsp/client.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_commands,node_index_cmd,node_search_cmd,node_graphrag_cmd,node_watch_cmd,node_mcp_cmd toneBlue
class node_indexer,node_file_proc,node_markdown_proc,node_batch_proc,node_lang_extract toneAmber
class node_search_indexer,node_store,node_embeddings,node_reranker,node_graphrag_store toneMint
class node_mcp_server,node_handlers,node_semantic_code,node_mcp_graphrag,node_lsp_client toneRose
```

## Components

### CLI

Command dispatch and user-facing modes

- [Main](https://github.com/muvon/octocode/blob/master/src/main.rs): binary entry · Program entry and startup flow · `src/main.rs`
- [Commands](https://github.com/muvon/octocode/blob/master/src/commands/mod.rs): dispatcher · Routes CLI subcommands to subsystems · `src/commands/mod.rs`
- [Index](https://github.com/muvon/octocode/blob/master/src/commands/index.rs): cli command · Builds or refreshes the local index · `src/commands/index.rs`
- [Search](https://github.com/muvon/octocode/blob/master/src/commands/search.rs): cli command · Runs repository search over indexed data · `src/commands/search.rs`
- [GraphRAG](https://github.com/muvon/octocode/blob/master/src/commands/graphrag.rs): cli command · Entry point for graph-oriented queries · `src/commands/graphrag.rs`
- [Watch](https://github.com/muvon/octocode/blob/master/src/commands/watch.rs): cli command · Keeps the index updated continuously · `src/commands/watch.rs`
- [MCP Cmd](https://github.com/muvon/octocode/blob/master/src/commands/mcp.rs): cli command · Starts or manages the MCP server · `src/commands/mcp.rs`

### Indexing

Repository ingestion, parsing, and incremental refresh

- [Indexer](https://github.com/muvon/octocode/blob/master/src/indexer/mod.rs): pipeline · Scans files and converts repositories into structured blocks · `src/indexer/mod.rs`
- [File Proc](https://github.com/muvon/octocode/blob/master/src/indexer/file_processor.rs): ingest stage · Handles file-level processing and filtering · `src/indexer/file_processor.rs`
- [Markdown](https://github.com/muvon/octocode/blob/master/src/indexer/markdown_processor.rs): ingest stage · Special handling for markdown content · `src/indexer/markdown_processor.rs`
- [Batch Proc](https://github.com/muvon/octocode/blob/master/src/indexer/batch_processor.rs): pipeline stage · Incremental and batched indexing execution · `src/indexer/batch_processor.rs`
- [Languages](https://github.com/muvon/octocode/blob/master/src/indexer/languages/mod.rs): code extraction · Language-aware structural extraction layer · `src/indexer/languages/mod.rs`

### Retrieval

Search, ranking, storage, and embeddings

- [Search Prep](https://github.com/muvon/octocode/blob/master/src/indexer/search.rs): retrieval prep · Builds queryable search structures from indexed content · `src/indexer/search.rs`
- [Store](https://github.com/muvon/octocode/blob/master/src/store/mod.rs): local storage · Manages metadata, blocks, and retrieval structures · `src/store/mod.rs`
- [Embeddings](https://github.com/muvon/octocode/blob/master/src/embedding/mod.rs): model adapter · Produces vectors for semantic retrieval · `src/embedding/mod.rs`
- [Reranker](https://github.com/muvon/octocode/blob/master/src/reranker.rs): ranking · Reorders retrieved candidates by relevance · `src/reranker.rs`
- [Graph Store](https://github.com/muvon/octocode/blob/master/src/store/graphrag.rs): graph storage · Stores and queries relationship graph data · `src/store/graphrag.rs`

### MCP

Model Context Protocol server and integrations

- [Server](https://github.com/muvon/octocode/blob/master/src/mcp/server.rs): mcp server · Exposes Octocode capabilities over MCP · `src/mcp/server.rs`
- [Handlers](https://github.com/muvon/octocode/blob/master/src/mcp/handlers.rs): tool handlers · Maps MCP tools to repository operations · `src/mcp/handlers.rs`
- [Semantic Code](https://github.com/muvon/octocode/blob/master/src/mcp/semantic_code.rs): code context · Code-aware operations for MCP clients · `src/mcp/semantic_code.rs`
- [MCP GraphRAG](https://github.com/muvon/octocode/blob/master/src/mcp/graphrag.rs): mcp tool · Graph-oriented MCP access · `src/mcp/graphrag.rs`
- [LSP Client](https://github.com/muvon/octocode/blob/master/src/mcp/lsp/client.rs): language server integration · Connects to external language tooling · `src/mcp/lsp/client.rs`

## Connections

- 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
