# yvgude/lean-ctx architecture

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

- Interactive diagram: https://gitdiagram.com/yvgude/lean-ctx
- Repository: https://github.com/yvgude/lean-ctx

## Overview

LeanCTX is a local context gateway for AI tools and applications: supported tool calls are selected, governed, and delivered with usage or recovery evidence, while the host retains its agent loop and model call. The graph includes the documented MCP, CLI, hook, proxy, and SDK surfaces, plus continuity and knowledge capabilities. Relationship evidence is limited to the README and the sampled/indexed files; unsampled subsystem internals are represented only where their paths are supported.

Main entry points: [`rust/crates/lean-ctx-server/src/server/call_tool/pipeline.rs`](https://github.com/yvgude/lean-ctx/blob/main/rust/crates/lean-ctx-server/src/server/call_tool/pipeline.rs) (Call delivery), [`rust/crates/lean-ctx-server/src/tools/registered/ctx_read_engine.rs`](https://github.com/yvgude/lean-ctx/blob/main/rust/crates/lean-ctx-server/src/tools/registered/ctx_read_engine.rs) (Context reads), [`rust/crates/lean-ctx/src/cli/engine_cmd.rs`](https://github.com/yvgude/lean-ctx/blob/main/rust/crates/lean-ctx/src/cli/engine_cmd.rs) (CLI paths), [`rust/crates/lean-ctx-hooks/src/hooks/agents`](https://github.com/yvgude/lean-ctx/tree/main/rust/crates/lean-ctx-hooks/src/hooks/agents) (Agent hooks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Tool entry points"]
  node_mcp["MCP server<br/>[pipeline.rs]"]
  node_cli["CLI paths<br/>[engine_cmd.rs]"]
  node_hooks["Agent hooks"]
  node_proxy["Tool proxy<br/>[pipeline.rs]"]
end

subgraph group_gateway["Context gateway"]
  node_gateway["Call delivery<br/>[pipeline.rs]"]
  node_read["Context reads<br/>[ctx_read_engine.rs]"]
  node_search["Search and views"]
  node_shell["Shell compression<br/>[engine.rs]"]
  node_policy["Access controls<br/>[runtime.rs]"]
  node_engine["Engine interface"]
  node_recovery["Source recovery<br/>[storage.rs]"]
end

subgraph group_continuity["Continuity and evidence"]
  node_session[("Session records<br/>[session_storage.rs]")]
  node_knowledge["Knowledge and tasks"]
  node_evidence["Usage evidence<br/>[receipts.rs]"]
end

subgraph group_clients["Client integrations"]
  node_rustclient["Rust client<br/>[client.rs]"]
  node_tsclient["TypeScript client<br/>[client.ts]"]
  node_hermes["Hermes adapter<br/>[engine.py]"]
  node_vscode["VS Code bridge<br/>[manager.ts]"]
end

node_host(("AI tool or app"))

node_host -->|"calls tools"| node_mcp
node_host -->|"uses commands"| node_cli
node_host -->|"uses integration"| node_hooks
node_host -->|"routes calls"| node_proxy
node_mcp -->|"dispatches calls"| node_gateway
node_gateway -->|"serves reads"| node_read
node_gateway -->|"selects context"| node_search
node_gateway -->|"compresses output"| node_shell
node_gateway -->|"applies controls"| node_policy
node_gateway -->|"executes context"| node_engine
node_read -->|"retains references"| node_recovery
node_gateway -->|"records continuity"| node_session
node_gateway -->|"supports learning"| node_knowledge
node_gateway -->|"records delivery"| node_evidence
node_gateway -->|"delivers context"| node_host
node_host -->|"embeds engine"| node_rustclient
node_host -->|"embeds engine"| node_tsclient
node_host -->|"uses engine"| node_hermes
node_host -.->|"uses bridge"| node_vscode

click node_mcp "https://github.com/yvgude/lean-ctx/blob/main/rust/crates/lean-ctx-server/src/server/call_tool/pipeline.rs"
click node_cli "https://github.com/yvgude/lean-ctx/blob/main/rust/crates/lean-ctx/src/cli/engine_cmd.rs"
click node_hooks "https://github.com/yvgude/lean-ctx/tree/main/rust/crates/lean-ctx-hooks/src/hooks/agents"
click node_proxy "https://github.com/yvgude/lean-ctx/blob/main/rust/crates/lean-ctx-proxy/src/forward/pipeline.rs"
click node_gateway "https://github.com/yvgude/lean-ctx/blob/main/rust/crates/lean-ctx-server/src/server/call_tool/pipeline.rs"
click node_read "https://github.com/yvgude/lean-ctx/blob/main/rust/crates/lean-ctx-server/src/tools/registered/ctx_read_engine.rs"
click node_search "https://github.com/yvgude/lean-ctx/tree/main/rust/crates/lean-ctx-server/src/tools/ctx_knowledge"
click node_shell "https://github.com/yvgude/lean-ctx/blob/main/rust/src/shell/compress/engine.rs"
click node_policy "https://github.com/yvgude/lean-ctx/blob/main/rust/src/core/policy/runtime.rs"
click node_engine "https://github.com/yvgude/lean-ctx/blob/main/rust/src/core/engine_interface.rs"
click node_recovery "https://github.com/yvgude/lean-ctx/blob/main/rust/src/core/ccr/storage.rs"
click node_session "https://github.com/yvgude/lean-ctx/blob/main/rust/src/core/context_checkpoint/session_storage.rs"
click node_knowledge "https://github.com/yvgude/lean-ctx/tree/main/rust/crates/lean-ctx-hive/src/knowledge"
click node_evidence "https://github.com/yvgude/lean-ctx/blob/main/rust/crates/lean-ctx-hive/src/receipts.rs"
click node_rustclient "https://github.com/yvgude/lean-ctx/blob/main/clients/rust/lean-ctx-client/src/client.rs"
click node_tsclient "https://github.com/yvgude/lean-ctx/blob/main/cookbook/sdk/src/client.ts"
click node_hermes "https://github.com/yvgude/lean-ctx/blob/main/integrations/hermes-lean-ctx/engine.py"
click node_vscode "https://github.com/yvgude/lean-ctx/blob/main/packages/vscode-lean-ctx/src/bridge/manager.ts"

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_mcp,node_cli,node_hooks,node_proxy toneBlue
class node_gateway,node_read,node_search,node_shell,node_policy,node_engine,node_recovery toneAmber
class node_session,node_knowledge,node_evidence toneMint
class node_rustclient,node_tsclient,node_hermes,node_vscode toneRose
class node_host toneIndigo
```

## Components

### Tool entry points

- [MCP server](https://github.com/yvgude/lean-ctx/blob/main/rust/crates/lean-ctx-server/src/server/call_tool/pipeline.rs): `rust/crates/lean-ctx-server/src/server/call_tool/pipeline.rs`
- [CLI paths](https://github.com/yvgude/lean-ctx/blob/main/rust/crates/lean-ctx/src/cli/engine_cmd.rs): `rust/crates/lean-ctx/src/cli/engine_cmd.rs`
- [Agent hooks](https://github.com/yvgude/lean-ctx/tree/main/rust/crates/lean-ctx-hooks/src/hooks/agents): `rust/crates/lean-ctx-hooks/src/hooks/agents`
- [Tool proxy](https://github.com/yvgude/lean-ctx/blob/main/rust/crates/lean-ctx-proxy/src/forward/pipeline.rs): `rust/crates/lean-ctx-proxy/src/forward/pipeline.rs`

### Context gateway

- [Call delivery](https://github.com/yvgude/lean-ctx/blob/main/rust/crates/lean-ctx-server/src/server/call_tool/pipeline.rs): `rust/crates/lean-ctx-server/src/server/call_tool/pipeline.rs`
- [Context reads](https://github.com/yvgude/lean-ctx/blob/main/rust/crates/lean-ctx-server/src/tools/registered/ctx_read_engine.rs): `rust/crates/lean-ctx-server/src/tools/registered/ctx_read_engine.rs`
- [Search and views](https://github.com/yvgude/lean-ctx/tree/main/rust/crates/lean-ctx-server/src/tools/ctx_knowledge): `rust/crates/lean-ctx-server/src/tools/ctx_knowledge`
- [Shell compression](https://github.com/yvgude/lean-ctx/blob/main/rust/src/shell/compress/engine.rs): `rust/src/shell/compress/engine.rs`
- [Access controls](https://github.com/yvgude/lean-ctx/blob/main/rust/src/core/policy/runtime.rs): `rust/src/core/policy/runtime.rs`
- [Engine interface](https://github.com/yvgude/lean-ctx/blob/main/rust/src/core/engine_interface.rs): `rust/src/core/engine_interface.rs`
- [Source recovery](https://github.com/yvgude/lean-ctx/blob/main/rust/src/core/ccr/storage.rs): `rust/src/core/ccr/storage.rs`

### Continuity and evidence

- [Session records](https://github.com/yvgude/lean-ctx/blob/main/rust/src/core/context_checkpoint/session_storage.rs): `rust/src/core/context_checkpoint/session_storage.rs`
- [Knowledge and tasks](https://github.com/yvgude/lean-ctx/tree/main/rust/crates/lean-ctx-hive/src/knowledge): `rust/crates/lean-ctx-hive/src/knowledge`
- [Usage evidence](https://github.com/yvgude/lean-ctx/blob/main/rust/crates/lean-ctx-hive/src/receipts.rs): `rust/crates/lean-ctx-hive/src/receipts.rs`

### Client integrations

- [Rust client](https://github.com/yvgude/lean-ctx/blob/main/clients/rust/lean-ctx-client/src/client.rs): `clients/rust/lean-ctx-client/src/client.rs`
- [TypeScript client](https://github.com/yvgude/lean-ctx/blob/main/cookbook/sdk/src/client.ts): `cookbook/sdk/src/client.ts`
- [Hermes adapter](https://github.com/yvgude/lean-ctx/blob/main/integrations/hermes-lean-ctx/engine.py): `integrations/hermes-lean-ctx/engine.py`
- [VS Code bridge](https://github.com/yvgude/lean-ctx/blob/main/packages/vscode-lean-ctx/src/bridge/manager.ts): `packages/vscode-lean-ctx/src/bridge/manager.ts`

### Other components

- **AI tool or app**

## Connections

- AI tool or app → MCP server: calls tools
- AI tool or app → CLI paths: uses commands
- AI tool or app → Agent hooks: uses integration
- AI tool or app → Tool proxy: routes calls
- MCP server → Call delivery: dispatches calls (evidence: `rust/crates/lean-ctx-server/src/server/call_tool/pipeline.rs`)
- Call delivery → Context reads: serves reads
- Call delivery → Search and views: selects context
- Call delivery → Shell compression: compresses output
- Call delivery → Access controls: applies controls
- Call delivery → Engine interface: executes context (evidence: `rust/src/core/engine_interface.rs`)
- Context reads → Source recovery: retains references
- Call delivery → Session records: records continuity
- Call delivery → Knowledge and tasks: supports learning
- Call delivery → Usage evidence: records delivery
- Call delivery → AI tool or app: delivers context
- AI tool or app → Rust client: embeds engine
- AI tool or app → TypeScript client: embeds engine
- AI tool or app → Hermes adapter: uses engine (evidence: `integrations/hermes-lean-ctx/engine.py`)
- AI tool or app → VS Code bridge: uses bridge
