# truekiwwy/rustiphy architecture

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

- Interactive diagram: https://gitdiagram.com/truekiwwy/rustiphy
- Repository: https://github.com/truekiwwy/rustiphy
- Video tour (about a minute): https://gitdiagram.com/truekiwwy/rustiphy/video

## Overview

rustiphy builds and incrementally maintains a code graph, then serves compact architecture and code context to AI agents through MCP or CLI commands. The main indexing path is documented and partly visible in scan, extraction, graph, and storage sources. README statements establish user-facing capabilities; unsampled command handlers and MCP internals are represented only where documented, so some internal links are intentionally omitted.

Main entry points: [`crates/rustiphy-cli/src/main.rs`](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-cli/src/main.rs) (Command dispatcher), [`crates/rustiphy-cli/src/mcp.rs`](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-cli/src/mcp.rs) (MCP server), [`crates/rustiphy-core/src/graph.rs`](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-core/src/graph.rs) (Code graph), [`crates/rustiphy-core/src/sync.rs`](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-core/src/sync.rs) (Index reconciliation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI and serving"]
  node_cli_main["Command dispatcher<br/>[main.rs]"]
  node_index_loader["Index loader<br/>[index.rs]"]
  node_mcp_server["MCP server<br/>[mcp.rs]"]
  node_agent_setup["Agent setup<br/>[setup.rs]"]
  node_web_viewer["Graph viewer<br/>[view.rs]"]
  node_watcher["File watcher<br/>[watch.rs]"]
  node_semantic_command["Enrich command<br/>[semantic.rs]"]
  node_benchmark["Token benchmark<br/>[bench.rs]"]
end

subgraph group_indexing["Code indexing"]
  node_scanner["Repository scanner<br/>[scan.rs]"]
  node_language_parser["Language support<br/>[lang.rs]"]
  node_extractor["AST extractor<br/>[extract.rs]"]
  node_code_graph["Code graph<br/>[graph.rs]"]
  node_communities["Community detection<br/>[community.rs]"]
  node_graph_model["Graph model<br/>[model.rs]"]
  node_reconciliation["Index reconciliation<br/>[sync.rs]"]
  node_index_store[("Persistent index<br/>[storage.rs]")]
end

subgraph group_context["Compact context"]
  node_slice_engine["Graph slicer<br/>[slicer.rs]"]
  node_dsl_renderer["Compact graph DSL<br/>[dsl.rs]"]
  node_token_counter["Token budgeting<br/>[tokens.rs]"]
  node_file_skeleton["File skeletonizer<br/>[skeleton.rs]"]
  node_architecture_map["Architecture map<br/>[map.rs]"]
end

subgraph group_summaries["Semantic summaries"]
  node_summary_enricher["Summary enricher<br/>[enricher.rs]"]
  node_llm_client["LLM client<br/>[client.rs]"]
end

node_developer(("Repository user"))
node_agent(("AI coding agent"))
node_local_llm{{"OpenAI-compatible LLM"}}

node_developer -->|"runs commands"| node_cli_main
node_agent -->|"sends MCP requests"| node_mcp_server
node_cli_main -->|"auto configures"| node_agent_setup
node_cli_main -->|"starts server"| node_mcp_server
node_cli_main -->|"builds or enriches"| node_semantic_command
node_cli_main -->|"loads query index"| node_index_loader
node_cli_main -->|"slices graph"| node_slice_engine
node_cli_main -->|"skeletonizes file"| node_file_skeleton
node_developer -->|"keeps index current"| node_watcher
node_developer -->|"explores graph"| node_web_viewer
node_developer -->|"compares token cost"| node_benchmark
node_index_loader -->|"scans fallback"| node_scanner
node_index_loader -->|"refreshes stored graph"| node_reconciliation
node_scanner -->|"extracts files"| node_extractor
node_scanner -->|"detects language"| node_language_parser
node_code_graph -->|"uses file facts"| node_extractor
node_code_graph -->|"detects communities"| node_communities
node_code_graph -->|"models graph entities"| node_graph_model
node_reconciliation -->|"scans changes"| node_scanner
node_reconciliation -->|"updates graph"| node_code_graph
node_reconciliation -->|"persists updates"| node_index_store
node_index_store -->|"stores graph state"| node_code_graph
node_slice_engine -->|"renders slice"| node_dsl_renderer
node_slice_engine -->|"budgets output"| node_token_counter
node_architecture_map -->|"formats map"| node_dsl_renderer
node_semantic_command -->|"requests summaries"| node_summary_enricher
node_summary_enricher -->|"requests completions"| node_llm_client
node_llm_client -->|"calls completion API"| node_local_llm
node_agent_setup -->|"registers server and skill"| node_agent
node_mcp_server -.->|"keeps index fresh"| node_watcher
node_mcp_server -.->|"serves map"| node_architecture_map
node_mcp_server -.->|"serves context slices"| node_slice_engine

click node_cli_main "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-cli/src/main.rs"
click node_index_loader "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-cli/src/index.rs"
click node_mcp_server "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-cli/src/mcp.rs"
click node_agent_setup "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-cli/src/setup.rs"
click node_web_viewer "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-cli/src/view.rs"
click node_watcher "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-cli/src/watch.rs"
click node_semantic_command "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-cli/src/semantic.rs"
click node_benchmark "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-cli/src/bench.rs"
click node_scanner "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-core/src/scan.rs"
click node_language_parser "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-core/src/lang.rs"
click node_extractor "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-core/src/extract.rs"
click node_code_graph "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-core/src/graph.rs"
click node_communities "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-core/src/community.rs"
click node_graph_model "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-core/src/model.rs"
click node_reconciliation "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-core/src/sync.rs"
click node_index_store "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-core/src/storage.rs"
click node_slice_engine "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-compact/src/slicer.rs"
click node_dsl_renderer "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-compact/src/dsl.rs"
click node_token_counter "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-compact/src/tokens.rs"
click node_file_skeleton "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-compact/src/skeleton.rs"
click node_architecture_map "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-compact/src/map.rs"
click node_summary_enricher "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-llm/src/enricher.rs"
click node_llm_client "https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-llm/src/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_cli_main,node_index_loader,node_mcp_server,node_agent_setup,node_web_viewer,node_watcher,node_semantic_command,node_benchmark,node_developer toneBlue
class node_scanner,node_language_parser,node_extractor,node_code_graph,node_communities,node_graph_model,node_reconciliation,node_index_store toneAmber
class node_slice_engine,node_dsl_renderer,node_token_counter,node_file_skeleton,node_architecture_map toneMint
class node_summary_enricher,node_llm_client toneRose
class node_agent,node_local_llm toneIndigo
```

## Components

### CLI and serving

- [Command dispatcher](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-cli/src/main.rs): `crates/rustiphy-cli/src/main.rs`
- [Index loader](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-cli/src/index.rs): `crates/rustiphy-cli/src/index.rs`
- [MCP server](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-cli/src/mcp.rs): `crates/rustiphy-cli/src/mcp.rs`
- [Agent setup](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-cli/src/setup.rs): `crates/rustiphy-cli/src/setup.rs`
- [Graph viewer](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-cli/src/view.rs): `crates/rustiphy-cli/src/view.rs`
- [File watcher](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-cli/src/watch.rs): `crates/rustiphy-cli/src/watch.rs`
- [Enrich command](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-cli/src/semantic.rs): `crates/rustiphy-cli/src/semantic.rs`
- [Token benchmark](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-cli/src/bench.rs): `crates/rustiphy-cli/src/bench.rs`

### Code indexing

- [Repository scanner](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-core/src/scan.rs): `crates/rustiphy-core/src/scan.rs`
- [Language support](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-core/src/lang.rs): `crates/rustiphy-core/src/lang.rs`
- [AST extractor](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-core/src/extract.rs): `crates/rustiphy-core/src/extract.rs`
- [Code graph](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-core/src/graph.rs): `crates/rustiphy-core/src/graph.rs`
- [Community detection](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-core/src/community.rs): `crates/rustiphy-core/src/community.rs`
- [Graph model](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-core/src/model.rs): `crates/rustiphy-core/src/model.rs`
- [Index reconciliation](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-core/src/sync.rs): `crates/rustiphy-core/src/sync.rs`
- [Persistent index](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-core/src/storage.rs): `crates/rustiphy-core/src/storage.rs`

### Compact context

- [Graph slicer](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-compact/src/slicer.rs): `crates/rustiphy-compact/src/slicer.rs`
- [Compact graph DSL](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-compact/src/dsl.rs): `crates/rustiphy-compact/src/dsl.rs`
- [Token budgeting](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-compact/src/tokens.rs): `crates/rustiphy-compact/src/tokens.rs`
- [File skeletonizer](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-compact/src/skeleton.rs): `crates/rustiphy-compact/src/skeleton.rs`
- [Architecture map](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-compact/src/map.rs): `crates/rustiphy-compact/src/map.rs`

### Semantic summaries

- [Summary enricher](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-llm/src/enricher.rs): `crates/rustiphy-llm/src/enricher.rs`
- [LLM client](https://github.com/truekiwwy/rustiphy/blob/main/crates/rustiphy-llm/src/client.rs): `crates/rustiphy-llm/src/client.rs`

### Other components

- **Repository user**
- **AI coding agent**
- **OpenAI-compatible LLM**

## Connections

- Repository user → Command dispatcher: runs commands (evidence: `README.md`)
- AI coding agent → MCP server: sends MCP requests (evidence: `README.md`)
- Command dispatcher → Agent setup: auto configures (evidence: `crates/rustiphy-cli/src/main.rs`)
- Command dispatcher → MCP server: starts server (evidence: `crates/rustiphy-cli/src/main.rs`)
- Command dispatcher → Enrich command: builds or enriches (evidence: `crates/rustiphy-cli/src/main.rs`)
- Command dispatcher → Index loader: loads query index (evidence: `crates/rustiphy-cli/src/main.rs`)
- Command dispatcher → Graph slicer: slices graph (evidence: `crates/rustiphy-cli/src/main.rs`)
- Command dispatcher → File skeletonizer: skeletonizes file (evidence: `crates/rustiphy-cli/src/main.rs`)
- Repository user → File watcher: keeps index current (evidence: `README.md`)
- Repository user → Graph viewer: explores graph (evidence: `README.md`)
- Repository user → Token benchmark: compares token cost (evidence: `README.md`)
- Index loader → Repository scanner: scans fallback (evidence: `crates/rustiphy-cli/src/index.rs`)
- Index loader → Index reconciliation: refreshes stored graph (evidence: `crates/rustiphy-cli/src/index.rs`)
- Repository scanner → AST extractor: extracts files (evidence: `crates/rustiphy-core/src/scan.rs`)
- Repository scanner → Language support: detects language (evidence: `crates/rustiphy-core/src/scan.rs`)
- Code graph → AST extractor: uses file facts (evidence: `crates/rustiphy-core/src/graph.rs`)
- Code graph → Community detection: detects communities (evidence: `crates/rustiphy-core/src/graph.rs`)
- Code graph → Graph model: models graph entities (evidence: `crates/rustiphy-core/src/graph.rs`)
- Index reconciliation → Repository scanner: scans changes (evidence: `crates/rustiphy-core/src/sync.rs`)
- Index reconciliation → Code graph: updates graph (evidence: `crates/rustiphy-core/src/sync.rs`)
- Index reconciliation → Persistent index: persists updates (evidence: `crates/rustiphy-core/src/sync.rs`)
- Persistent index → Code graph: stores graph state (evidence: `crates/rustiphy-core/src/storage.rs`)
- Graph slicer → Compact graph DSL: renders slice (evidence: `crates/rustiphy-compact/src/slicer.rs`)
- Graph slicer → Token budgeting: budgets output (evidence: `crates/rustiphy-compact/src/slicer.rs`)
- Architecture map → Compact graph DSL: formats map (evidence: `crates/rustiphy-compact/src/map.rs`)
- Enrich command → Summary enricher: requests summaries (evidence: `README.md`)
- Summary enricher → LLM client: requests completions (evidence: `crates/rustiphy-llm/src/enricher.rs`)
- LLM client → OpenAI-compatible LLM: calls completion API (evidence: `crates/rustiphy-llm/src/client.rs`)
- Agent setup → AI coding agent: registers server and skill (evidence: `README.md`)
- MCP server → File watcher: keeps index fresh (evidence: `README.md`)
- MCP server → Architecture map: serves map (evidence: `README.md`)
- MCP server → Graph slicer: serves context slices (evidence: `README.md`)
