# muyinjiangxue/llm architecture

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

- Interactive diagram: https://gitdiagram.com/muyinjiangxue/llm
- Repository: https://github.com/muyinjiangxue/llm

## Overview

1. **What this repository is**
   - This project is a **CLI agent harness** called **Claw Code**. The README says the **canonical implementation is the Rust workspace under `rust/`**, while the checked-in `src/` tree is a **Python companion/reference workspace** used for audits, parity checks, and supporting tooling.

2. **Top-level architecture**
   - The system is organized around a **command-line agent loop**: parse user intent, initialize runtime state, coordinate model/tool execution, persist session history, and present output.
   - The main runtime boundary is the **CLI binary**, with supporting subsystems for **sessions, tools, permissions, queries, remote access, and interactive UI modes**.

3. **Primary execution path**
   - User entry starts from the CLI entrypoints (`src/main.py`, `src/entrypoints`, `src/cli`, `src/commands.py`).
   - From there, the app flows into **bootstrap/system initialization**, then into a **coordinator/executor layer** that decides how to run prompts, tools, and interactive modes.
   - This is the central path an architecture diagram should show: **input → initialization → orchestration → tool/model interaction → output/session update**.

4. **Agent orchestration layer**
   - The `coordinator`, `assistant`, `task`, `tasks`, `command_graph`, and `execution_registry` modules suggest a **graph- or registry-based orchestration model** for agent actions.
   - This layer is where higher-level behavior lives: selecting commands, managing task state, sequencing tool calls, and controlling the agent loop rather than directly doing I/O.

5. **Model and query integration**
   - `query.py`, `query_engine.py`, `QueryEngine.py`, `models.py`, `tool_pool.py`, `tools.py`, and `Tool.py` indicate a dedicated **model/tool mediation boundary**.
   - The repo appears to centralize request shaping, tool selection, and response handling here, which is the part that would connect to external model APIs such as **Anthropic/OpenAI-style API keys** mentioned in the README.

6. **Session, history, and local state**
   - `session_store.py`, `history.py`, `transcript.py`, `state/`, `memdir/`, `projectOnboardingState.py`, and `context.py` form the **persistence and recall layer**.
   - This is the part responsible for keeping **conversation/session context**, transcript history, local working state, and onboarding/memory artifacts that the agent needs across runs.

7. **Permissions, hooks, and policy boundaries**
   - `permissions.py`, `hooks/`, `costHook.py`, `cost_tracker.py`, and `prefetch.py` suggest a **governance layer** around execution.
   - In diagram terms, this layer sits between orchestration and side effects, enforcing **what can run, what can be fetched, and how usage/cost is tracked**.

8. **Tooling and external integrations**
   - The repo includes dedicated subsystems for **remote execution and bridging**: `remote/`, `remote_runtime.py`, `bridge/`, `upstreamproxy/`, `server/`, and `services/`.
   - These modules likely separate **local agent logic** from **remote/proxy/server-backed capabilities**, letting the CLI interact with services or upstream systems without mixing transport concerns into core orchestration.

9. **Interactive and alternative UI surfaces**
   - `replLauncher.py`, `dialogLaunchers.py`, `interactiveHelpers.py`, `ink.py`, `screens/`, `outputStyles/`, `keybindings/`, `vim/`, and `voice/` point to multiple **interaction front-ends** beyond a plain prompt.
   - These are presentation/adaptation layers around the same core agent runtime, not separate business logic.

10. **Bootstrap, startup, and native/platform support**
   - `bootstrap/`, `bootstrap_graph.py`, `system_init.py`, `deferred_init.py`, `runtime.py`, `direct_modes.py`, and `native_ts/` represent **startup wiring and platform-specific setup**.
   - This is the boundary where the app decides how to initialize subsystems, resolve runtime mode, and prepare the environment before the agent loop begins.

11. **Reference data and parity/audit support**
   - `reference_data/`, `parity_audit.py`, `migrations/`, and `_archive_helper.py` support **snapshotting and compatibility checks**.
   - The many `reference_data/subsystems/*.json` files indicate the Python tree is also used as an **inventory of subsystem shapes** for parity with the Rust implementation and for architectural auditing.

12. **Packaging, build, and delivery**
   - The repo includes `Containerfile`, `install.sh`, GitHub CI workflows, and docs such as `docs/container.md`.
   - Operationally, this is a **build-from-source** project with container-first support, but the README makes clear the **Rust workspace is the production surface** and the Python tree is ancillary.

13. **How to draw the architecture**
   - A useful diagram should show:
     - **CLI entrypoint**
     - **bootstrap/system init**
     - **orchestration/coordinator**
     - **model/query + tools**
     - **session/state/history**
     - **policy/hooks/cost control**
     - **remote/server/bridge integrations**
     - **interactive UI adapters**
   - The key boundary is that **core agent logic is separated from runtime adapters and persistence**, with the Rust workspace acting as the primary implementation and `src/` providing companion/reference structure.

Main entry points: [`src/coordinator`](https://github.com/muyinjiangxue/llm/tree/main/src/coordinator) (Coordinator), [`src/bridge`](https://github.com/muyinjiangxue/llm/tree/main/src/bridge) (Bridge), [`src/entrypoints`](https://github.com/muyinjiangxue/llm/tree/main/src/entrypoints) (Entrypoints), [`src/cli`](https://github.com/muyinjiangxue/llm/tree/main/src/cli) (CLI layer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry"]
  node_main(("CLI main<br/>entrypoint<br/>[main.py]"))
  node_entrypoints["Entrypoints<br/>dispatch"]
  node_cli["CLI layer<br/>commands"]
  node_commands["Commands<br/>command map<br/>[commands.py]"]
end

subgraph group_runtime["Runtime"]
  node_system_init["System init<br/>startup<br/>[system_init.py]"]
  node_bootstrap["Bootstrap<br/>wiring"]
  node_runtime_node(("Runtime<br/>mode select<br/>[runtime.py]"))
  node_coordinator{{"Coordinator<br/>orchestrator"}}
  node_assistant["Assistant<br/>agent core"]
  node_tasks["Tasks<br/>task state<br/>[tasks.py]"]
  node_command_graph["Command graph<br/>execution graph<br/>[command_graph.py]"]
  node_query_engine{{"Query engine<br/>model gateway<br/>[query_engine.py]"}}
  node_tools["Tools<br/>tooling<br/>[tools.py]"]
  node_tool_pool["Tool pool<br/>selection<br/>[tool_pool.py]"]
end

subgraph group_state["State"]
  node_session_store[("Session store<br/>persistence<br/>[session_store.py]")]
  node_history["History<br/>transcript<br/>[history.py]"]
  node_context["Context<br/>memory<br/>[context.py]"]
end

subgraph group_policy["Policy"]
  node_permissions["Permissions<br/>policy<br/>[permissions.py]"]
  node_hooks["Hooks<br/>governance"]
  node_cost_tracker["Cost tracker<br/>metering<br/>[cost_tracker.py]"]
end

subgraph group_integrations["Integrations"]
  node_remote_runtime["Remote runtime<br/>remote exec<br/>[remote_runtime.py]"]
  node_bridge["Bridge<br/>adapter"]
  node_server["Server"]
  node_upstreamproxy["Upstream proxy"]
end

subgraph group_ui["UI"]
  node_repl(("REPL/UI<br/>interactive ui<br/>[replLauncher.py]"))
  node_dialogs["Dialogs<br/>interactive ui<br/>[dialogLaunchers.py]"]
  node_ink["Ink UI<br/>presentation<br/>[ink.py]"]
  node_screens["Screens<br/>presentation"]
end

node_main -->|"start"| node_entrypoints
node_entrypoints -->|"dispatch"| node_cli
node_cli -->|"route"| node_commands
node_commands -->|"initialize"| node_bootstrap
node_bootstrap -->|"setup"| node_system_init
node_system_init -->|"select mode"| node_runtime_node
node_runtime_node -->|"run loop"| node_coordinator
node_coordinator -->|"delegate"| node_assistant
node_assistant -->|"sequence"| node_tasks
node_tasks -->|"plan"| node_command_graph
node_coordinator -->|"model calls"| node_query_engine
node_query_engine -->|"invoke"| node_tools
node_tools -->|"resolve"| node_tool_pool
node_coordinator -->|"check"| node_permissions
node_coordinator -->|"intercept"| node_hooks
node_hooks -->|"meter"| node_cost_tracker
node_coordinator -->|"persist"| node_session_store
node_session_store -->|"record"| node_history
node_history -->|"load"| node_context
node_coordinator -->|"bridge"| node_remote_runtime
node_remote_runtime -->|"adapt"| node_bridge
node_bridge -->|"serve"| node_server
node_bridge -->|"proxy"| node_upstreamproxy
node_coordinator -->|"interactive"| node_repl
node_repl -->|"launch"| node_dialogs
node_dialogs -->|"render"| node_ink
node_ink -->|"show"| node_screens

click node_main "https://github.com/muyinjiangxue/llm/blob/main/src/main.py"
click node_entrypoints "https://github.com/muyinjiangxue/llm/tree/main/src/entrypoints"
click node_cli "https://github.com/muyinjiangxue/llm/tree/main/src/cli"
click node_commands "https://github.com/muyinjiangxue/llm/blob/main/src/commands.py"
click node_system_init "https://github.com/muyinjiangxue/llm/blob/main/src/system_init.py"
click node_bootstrap "https://github.com/muyinjiangxue/llm/tree/main/src/bootstrap"
click node_runtime_node "https://github.com/muyinjiangxue/llm/blob/main/src/runtime.py"
click node_coordinator "https://github.com/muyinjiangxue/llm/tree/main/src/coordinator"
click node_assistant "https://github.com/muyinjiangxue/llm/tree/main/src/assistant"
click node_tasks "https://github.com/muyinjiangxue/llm/blob/main/src/tasks.py"
click node_command_graph "https://github.com/muyinjiangxue/llm/blob/main/src/command_graph.py"
click node_query_engine "https://github.com/muyinjiangxue/llm/blob/main/src/query_engine.py"
click node_tools "https://github.com/muyinjiangxue/llm/blob/main/src/tools.py"
click node_tool_pool "https://github.com/muyinjiangxue/llm/blob/main/src/tool_pool.py"
click node_session_store "https://github.com/muyinjiangxue/llm/blob/main/src/session_store.py"
click node_history "https://github.com/muyinjiangxue/llm/blob/main/src/history.py"
click node_context "https://github.com/muyinjiangxue/llm/blob/main/src/context.py"
click node_permissions "https://github.com/muyinjiangxue/llm/blob/main/src/permissions.py"
click node_hooks "https://github.com/muyinjiangxue/llm/tree/main/src/hooks"
click node_cost_tracker "https://github.com/muyinjiangxue/llm/blob/main/src/cost_tracker.py"
click node_remote_runtime "https://github.com/muyinjiangxue/llm/blob/main/src/remote_runtime.py"
click node_bridge "https://github.com/muyinjiangxue/llm/tree/main/src/bridge"
click node_server "https://github.com/muyinjiangxue/llm/tree/main/src/server"
click node_upstreamproxy "https://github.com/muyinjiangxue/llm/tree/main/src/upstreamproxy"
click node_repl "https://github.com/muyinjiangxue/llm/blob/main/src/replLauncher.py"
click node_dialogs "https://github.com/muyinjiangxue/llm/blob/main/src/dialogLaunchers.py"
click node_ink "https://github.com/muyinjiangxue/llm/blob/main/src/ink.py"
click node_screens "https://github.com/muyinjiangxue/llm/tree/main/src/screens"

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_entrypoints,node_cli,node_commands toneBlue
class node_system_init,node_bootstrap,node_runtime_node,node_coordinator,node_assistant,node_tasks,node_command_graph,node_query_engine,node_tools,node_tool_pool toneAmber
class node_session_store,node_history,node_context toneMint
class node_permissions,node_hooks,node_cost_tracker toneRose
class node_remote_runtime,node_bridge,node_server,node_upstreamproxy toneIndigo
class node_repl,node_dialogs,node_ink,node_screens toneTeal
```

## Components

### Entry

CLI startup and command dispatch

- [CLI main](https://github.com/muyinjiangxue/llm/blob/main/src/main.py): entrypoint · Top-level process start and handoff into command handling · `src/main.py`
- [Entrypoints](https://github.com/muyinjiangxue/llm/tree/main/src/entrypoints): dispatch · Entry surface for CLI invocations and modes · `src/entrypoints`
- [CLI layer](https://github.com/muyinjiangxue/llm/tree/main/src/cli): commands · Command parsing and user-facing command wiring · `src/cli`
- [Commands](https://github.com/muyinjiangxue/llm/blob/main/src/commands.py): command map · Command definitions and routing into the runtime · `src/commands.py`

### Runtime

Initialization, orchestration, and agent execution

- [System init](https://github.com/muyinjiangxue/llm/blob/main/src/system_init.py): startup · Bootstraps runtime state and environment setup · `src/system_init.py`
- [Bootstrap](https://github.com/muyinjiangxue/llm/tree/main/src/bootstrap): wiring · Startup graph and initialization coordination · `src/bootstrap`
- [Runtime](https://github.com/muyinjiangxue/llm/blob/main/src/runtime.py): mode select · Resolves execution mode and overall runtime behavior · `src/runtime.py`
- [Coordinator](https://github.com/muyinjiangxue/llm/tree/main/src/coordinator): orchestrator · Central agent loop orchestration and execution control · `src/coordinator`
- [Assistant](https://github.com/muyinjiangxue/llm/tree/main/src/assistant): agent core · Primary agent behavior and task-facing logic · `src/assistant`
- [Tasks](https://github.com/muyinjiangxue/llm/blob/main/src/tasks.py): task state · Task lifecycle and sequencing support · `src/tasks.py`
- [Command graph](https://github.com/muyinjiangxue/llm/blob/main/src/command_graph.py): execution graph · Represents command and action relationships for execution · `src/command_graph.py`
- [Query engine](https://github.com/muyinjiangxue/llm/blob/main/src/query_engine.py): model gateway · Model-facing request shaping and response mediation · `src/query_engine.py`
- [Tools](https://github.com/muyinjiangxue/llm/blob/main/src/tools.py): tooling · Tool definitions and tool invocation surface · `src/tools.py`
- [Tool pool](https://github.com/muyinjiangxue/llm/blob/main/src/tool_pool.py): selection · Tool discovery and selection boundary · `src/tool_pool.py`

### State

Session history, memory, and local persistence

- [Session store](https://github.com/muyinjiangxue/llm/blob/main/src/session_store.py): persistence · Session checkpointing and local run state · `src/session_store.py`
- [History](https://github.com/muyinjiangxue/llm/blob/main/src/history.py): transcript · Conversation history and prior-turn recall · `src/history.py`
- [Context](https://github.com/muyinjiangxue/llm/blob/main/src/context.py): memory · Shared working context for the agent loop · `src/context.py`

### Policy

Permissions, hooks, and cost controls

- [Permissions](https://github.com/muyinjiangxue/llm/blob/main/src/permissions.py): policy · Execution allow/deny and user authorization boundary · `src/permissions.py`
- [Hooks](https://github.com/muyinjiangxue/llm/tree/main/src/hooks): governance · Extensibility and side-effect interception points · `src/hooks`
- [Cost tracker](https://github.com/muyinjiangxue/llm/blob/main/src/cost_tracker.py): metering · Usage and cost accounting across runs · `src/cost_tracker.py`

### Integrations

Remote, server, and proxy boundaries

- [Remote runtime](https://github.com/muyinjiangxue/llm/blob/main/src/remote_runtime.py): remote exec · Remote execution and runtime bridging layer · `src/remote_runtime.py`
- [Bridge](https://github.com/muyinjiangxue/llm/tree/main/src/bridge): adapter · Adapter boundary between local agent logic and external services · `src/bridge`
- [Server](https://github.com/muyinjiangxue/llm/tree/main/src/server): service · Local or remote server-side capabilities exposed to the CLI · `src/server`
- [Upstream proxy](https://github.com/muyinjiangxue/llm/tree/main/src/upstreamproxy): proxy · Proxy layer for upstream or mediated external access · `src/upstreamproxy`

### UI

Interactive front-ends and presentation

- [REPL/UI](https://github.com/muyinjiangxue/llm/blob/main/src/replLauncher.py): interactive ui · Interactive command surface beyond plain batch CLI · `src/replLauncher.py`
- [Dialogs](https://github.com/muyinjiangxue/llm/blob/main/src/dialogLaunchers.py): interactive ui · Dialog launchers and interactive mode helpers · `src/dialogLaunchers.py`
- [Ink UI](https://github.com/muyinjiangxue/llm/blob/main/src/ink.py): presentation · Terminal presentation and rendering helpers · `src/ink.py`
- [Screens](https://github.com/muyinjiangxue/llm/tree/main/src/screens): presentation · Screen-based interactive views and layouts · `src/screens`

## Connections

- CLI main → Entrypoints: start · Process entry routes into CLI entry surfaces
- Entrypoints → CLI layer: dispatch · Entrypoints dispatch into the command layer
- CLI layer → Commands: route · CLI commands map user intent into executable actions
- Commands → Bootstrap: initialize · Command execution begins by wiring startup state
- Bootstrap → System init: setup · Bootstrap prepares the system initialization path
- System init → Runtime: select mode · Initialization resolves the active runtime mode
- Runtime → Coordinator: run loop · Runtime hands control to the agent orchestrator
- Coordinator → Assistant: delegate · Coordinator delegates higher-level agent behavior
- Assistant → Tasks: sequence · Assistant manages task lifecycle and progression
- Tasks → Command graph: plan · Task execution is represented through a command graph
- Coordinator → Query engine: model calls · Orchestration sends work to the model/query boundary
- Query engine → Tools: invoke · Model responses can trigger tool execution
- Tools → Tool pool: resolve · Tool execution is mediated by tool selection
- Coordinator → Permissions: check · Execution is gated by permissions policy
- Coordinator → Hooks: intercept · Hooks observe and modify execution boundaries
- Hooks → Cost tracker: meter · Governance layer tracks usage and cost impacts
- Coordinator → Session store: persist · Agent progress is written to session storage
- Session store → History: record · Session state retains transcript history
- History → Context: load · Past turns inform current working context
- Coordinator → Remote runtime: bridge · Orchestration can hand off to remote execution
- Remote runtime → Bridge: adapt · Remote access is adapted through bridge modules
- Bridge → Server: serve · Bridge connects local logic to server capabilities
- Bridge → Upstream proxy: proxy · Bridge may route through upstream proxies
- Coordinator → REPL/UI: interactive · Interactive modes are surfaced through the REPL UI
- REPL/UI → Dialogs: launch · REPL can open dialog-based interaction flows
- Dialogs → Ink UI: render · Dialogs use terminal presentation helpers
- Ink UI → Screens: show · Presentation renders screen-based views
