# jergensturdley/9rh architecture

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

- Interactive diagram: https://gitdiagram.com/jergensturdley/9rh
- Repository: https://github.com/jergensturdley/9rh

## Overview

9rh is a local-repository coding agent, entered through its CLI or REPL. The core workflow selects a backend, runs an agent turn using repository tools, and records observed changes and outcomes as receipts and reports. Optional branches add team orchestration, spec framing, repair, rewind, and replay. The desktop app presents sessions and these run artifacts alongside a separate 9router console. Some links reflect README descriptions or import references in the SOURCE INDEX; unsampled desktop and runtime internals limit finer-grained control-flow claims.

Main entry points: [`src/agent.ts`](https://github.com/jergensturdley/9rh/blob/main/src/agent.ts) (Coding agent), [`src/index.ts`](https://github.com/jergensturdley/9rh/blob/main/src/index.ts) (CLI and REPL), [`src/replay/replayEngine.ts`](https://github.com/jergensturdley/9rh/blob/main/src/replay/replayEngine.ts) (Replay engine), [`desktop/src/renderer/app/App.tsx`](https://github.com/jergensturdley/9rh/blob/main/desktop/src/renderer/app/App.tsx) (Desktop shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and configuration"]
  node_cli["CLI and REPL<br/>[index.ts]"]
  node_config["Configuration<br/>[config.ts]"]
  node_backend["Backend selection<br/>[index.ts]"]
  node_tui["Terminal interface<br/>[tui.ts]"]
end

subgraph group_runtime["Agent runtime"]
  node_agent["Coding agent<br/>[agent.ts]"]
  node_reasoner["Reasoning<br/>[reasoner.ts]"]
  node_compression["Input compression"]
  node_skills["Skills<br/>[skills.ts]"]
end

subgraph group_execution["Execution and safety"]
  node_tools["Repository tools<br/>[tools.ts]"]
  node_sandbox["Sandbox execution<br/>[sandboxer.ts]"]
end

subgraph group_coordination["Coordination and recovery"]
  node_team["Team pipeline<br/>[orchestrator.ts]"]
  node_roles["Team roles<br/>[roles.ts]"]
  node_spec["Spec-driven testing"]
  node_repair["Repair and snapshots<br/>[snapshotManager.ts]"]
  node_rewind["Turn rewind<br/>[rewind.ts]"]
end

subgraph group_records["Run records"]
  node_replay["Replay engine<br/>[replayEngine.ts]"]
  node_events["Flight recorder<br/>[flightRecorder.ts]"]
  node_ledger[("Session ledger<br/>[ledger.ts]")]
  node_reports["Run reports<br/>[runReport.ts]"]
  node_visualization["Run visualization<br/>[visualization.ts]"]
end

subgraph group_desktop["Desktop workbench"]
  node_desktop["Desktop shell<br/>[App.tsx]"]
  node_agentpage["Agent sessions<br/>[AgentPage.tsx]"]
  node_replaypage["Replay viewer<br/>[ReplaysPage.tsx]"]
  node_routerpage["Router console<br/>[RouterPage.tsx]"]
  node_routerclient["Router client<br/>[routerClient.ts]"]
  node_routerupdate["Router updates<br/>[routerUpdate.ts]"]
end

node_user(("User"))
node_router["9router"]
node_llm["LLM endpoint"]

node_user -->|"submits task"| node_cli
node_cli -->|"selects backend"| node_backend
node_cli -->|"starts run"| node_agent
node_cli -->|"reads settings"| node_config
node_cli -->|"dispatches team task"| node_team
node_cli -->|"renders interaction"| node_tui
node_backend -.->|"connects optionally"| node_router
node_backend -->|"selects provider"| node_llm
node_agent -->|"requests completions"| node_llm
node_agent -->|"executes tools"| node_tools
node_agent -->|"uses reasoning"| node_reasoner
node_agent -->|"compresses input"| node_compression
node_agent -->|"loads skills"| node_skills
node_agent -->|"uses sandbox"| node_sandbox
node_agent -->|"frames tasks"| node_spec
node_agent -->|"captures snapshots"| node_repair
node_agent -->|"logs run events"| node_events
node_agent -->|"writes turn report"| node_reports
node_agent -.->|"records receipts"| node_ledger
node_team -->|"runs role pipeline"| node_roles
node_cli -->|"offers rewind"| node_rewind
node_cli -->|"replays run"| node_replay
node_events -->|"supplies run log"| node_replay
node_replay -->|"re-executes tools"| node_tools
node_replay -->|"restores snapshot"| node_repair
node_desktop -->|"routes to page"| node_agentpage
node_desktop -->|"routes to page"| node_replaypage
node_desktop -->|"routes to page"| node_routerpage
node_agentpage -.->|"hosts agent sessions"| node_agent
node_replaypage -.->|"views recorded runs"| node_events
node_routerpage -.->|"uses router services"| node_routerclient
node_routerupdate -->|"uses client"| node_routerclient
node_routerclient -.->|"calls local service"| node_router
node_agent -.->|"emits visualization data"| node_visualization

click node_cli "https://github.com/jergensturdley/9rh/blob/main/src/index.ts"
click node_config "https://github.com/jergensturdley/9rh/blob/main/src/config.ts"
click node_backend "https://github.com/jergensturdley/9rh/blob/main/src/backends/index.ts"
click node_agent "https://github.com/jergensturdley/9rh/blob/main/src/agent.ts"
click node_reasoner "https://github.com/jergensturdley/9rh/blob/main/src/reasoner/reasoner.ts"
click node_compression "https://github.com/jergensturdley/9rh/blob/main/src/inputCompression.ts"
click node_tools "https://github.com/jergensturdley/9rh/blob/main/src/tools.ts"
click node_sandbox "https://github.com/jergensturdley/9rh/blob/main/src/sandbox/sandboxer.ts"
click node_skills "https://github.com/jergensturdley/9rh/blob/main/src/skills.ts"
click node_team "https://github.com/jergensturdley/9rh/blob/main/src/orchestrator/orchestrator.ts"
click node_roles "https://github.com/jergensturdley/9rh/blob/main/src/orchestrator/roles.ts"
click node_spec "https://github.com/jergensturdley/9rh/blob/main/src/spec/specDrivenTesting.ts"
click node_repair "https://github.com/jergensturdley/9rh/blob/main/src/repair/snapshotManager.ts"
click node_rewind "https://github.com/jergensturdley/9rh/blob/main/src/rewind.ts"
click node_replay "https://github.com/jergensturdley/9rh/blob/main/src/replay/replayEngine.ts"
click node_events "https://github.com/jergensturdley/9rh/blob/main/src/flightRecorder.ts"
click node_ledger "https://github.com/jergensturdley/9rh/blob/main/src/ledger.ts"
click node_reports "https://github.com/jergensturdley/9rh/blob/main/src/reports/runReport.ts"
click node_visualization "https://github.com/jergensturdley/9rh/blob/main/src/visualization.ts"
click node_tui "https://github.com/jergensturdley/9rh/blob/main/src/tui.ts"
click node_desktop "https://github.com/jergensturdley/9rh/blob/main/desktop/src/renderer/app/App.tsx"
click node_agentpage "https://github.com/jergensturdley/9rh/blob/main/desktop/src/renderer/pages/AgentPage.tsx"
click node_replaypage "https://github.com/jergensturdley/9rh/blob/main/desktop/src/renderer/pages/ReplaysPage.tsx"
click node_routerpage "https://github.com/jergensturdley/9rh/blob/main/desktop/src/renderer/pages/RouterPage.tsx"
click node_routerclient "https://github.com/jergensturdley/9rh/blob/main/desktop/src/main/routerClient.ts"
click node_routerupdate "https://github.com/jergensturdley/9rh/blob/main/desktop/src/main/routerUpdate.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_cli,node_config,node_backend,node_tui,node_user toneBlue
class node_agent,node_reasoner,node_compression,node_skills toneAmber
class node_tools,node_sandbox,node_router toneMint
class node_team,node_roles,node_spec,node_repair,node_rewind toneRose
class node_replay,node_events,node_ledger,node_reports,node_visualization,node_llm toneIndigo
class node_desktop,node_agentpage,node_replaypage,node_routerpage,node_routerclient,node_routerupdate toneTeal
```

## Components

### Entry and configuration

- [CLI and REPL](https://github.com/jergensturdley/9rh/blob/main/src/index.ts): `src/index.ts`
- [Configuration](https://github.com/jergensturdley/9rh/blob/main/src/config.ts): `src/config.ts`
- [Backend selection](https://github.com/jergensturdley/9rh/blob/main/src/backends/index.ts): `src/backends/index.ts`
- [Terminal interface](https://github.com/jergensturdley/9rh/blob/main/src/tui.ts): `src/tui.ts`

### Agent runtime

- [Coding agent](https://github.com/jergensturdley/9rh/blob/main/src/agent.ts): `src/agent.ts`
- [Reasoning](https://github.com/jergensturdley/9rh/blob/main/src/reasoner/reasoner.ts): `src/reasoner/reasoner.ts`
- [Input compression](https://github.com/jergensturdley/9rh/blob/main/src/inputCompression.ts): `src/inputCompression.ts`
- [Skills](https://github.com/jergensturdley/9rh/blob/main/src/skills.ts): `src/skills.ts`

### Execution and safety

- [Repository tools](https://github.com/jergensturdley/9rh/blob/main/src/tools.ts): `src/tools.ts`
- [Sandbox execution](https://github.com/jergensturdley/9rh/blob/main/src/sandbox/sandboxer.ts): `src/sandbox/sandboxer.ts`

### Coordination and recovery

- [Team pipeline](https://github.com/jergensturdley/9rh/blob/main/src/orchestrator/orchestrator.ts): `src/orchestrator/orchestrator.ts`
- [Team roles](https://github.com/jergensturdley/9rh/blob/main/src/orchestrator/roles.ts): `src/orchestrator/roles.ts`
- [Spec-driven testing](https://github.com/jergensturdley/9rh/blob/main/src/spec/specDrivenTesting.ts): `src/spec/specDrivenTesting.ts`
- [Repair and snapshots](https://github.com/jergensturdley/9rh/blob/main/src/repair/snapshotManager.ts): `src/repair/snapshotManager.ts`
- [Turn rewind](https://github.com/jergensturdley/9rh/blob/main/src/rewind.ts): `src/rewind.ts`

### Run records

- [Replay engine](https://github.com/jergensturdley/9rh/blob/main/src/replay/replayEngine.ts): `src/replay/replayEngine.ts`
- [Flight recorder](https://github.com/jergensturdley/9rh/blob/main/src/flightRecorder.ts): `src/flightRecorder.ts`
- [Session ledger](https://github.com/jergensturdley/9rh/blob/main/src/ledger.ts): `src/ledger.ts`
- [Run reports](https://github.com/jergensturdley/9rh/blob/main/src/reports/runReport.ts): `src/reports/runReport.ts`
- [Run visualization](https://github.com/jergensturdley/9rh/blob/main/src/visualization.ts): `src/visualization.ts`

### Desktop workbench

- [Desktop shell](https://github.com/jergensturdley/9rh/blob/main/desktop/src/renderer/app/App.tsx): `desktop/src/renderer/app/App.tsx`
- [Agent sessions](https://github.com/jergensturdley/9rh/blob/main/desktop/src/renderer/pages/AgentPage.tsx): `desktop/src/renderer/pages/AgentPage.tsx`
- [Replay viewer](https://github.com/jergensturdley/9rh/blob/main/desktop/src/renderer/pages/ReplaysPage.tsx): `desktop/src/renderer/pages/ReplaysPage.tsx`
- [Router console](https://github.com/jergensturdley/9rh/blob/main/desktop/src/renderer/pages/RouterPage.tsx): `desktop/src/renderer/pages/RouterPage.tsx`
- [Router client](https://github.com/jergensturdley/9rh/blob/main/desktop/src/main/routerClient.ts): `desktop/src/main/routerClient.ts`
- [Router updates](https://github.com/jergensturdley/9rh/blob/main/desktop/src/main/routerUpdate.ts): `desktop/src/main/routerUpdate.ts`

### Other components

- **User**
- **9router**
- **LLM endpoint**

## Connections

- User → CLI and REPL: submits task (evidence: `README.md`)
- CLI and REPL → Backend selection: selects backend (evidence: `src/index.ts`)
- CLI and REPL → Coding agent: starts run (evidence: `src/index.ts`)
- CLI and REPL → Configuration: reads settings (evidence: `src/index.ts`)
- CLI and REPL → Team pipeline: dispatches team task (evidence: `src/index.ts`)
- CLI and REPL → Terminal interface: renders interaction (evidence: `src/index.ts`)
- Backend selection → 9router: connects optionally (evidence: `README.md`)
- Backend selection → LLM endpoint: selects provider (evidence: `README.md`)
- Coding agent → LLM endpoint: requests completions (evidence: `src/agent.ts`)
- Coding agent → Repository tools: executes tools (evidence: `src/agent.ts`)
- Coding agent → Reasoning: uses reasoning (evidence: `src/agent.ts`)
- Coding agent → Input compression: compresses input (evidence: `src/agent.ts`)
- Coding agent → Skills: loads skills (evidence: `src/agent.ts`)
- Coding agent → Sandbox execution: uses sandbox (evidence: `src/agent.ts`)
- Coding agent → Spec-driven testing: frames tasks (evidence: `src/agent.ts`)
- Coding agent → Repair and snapshots: captures snapshots (evidence: `src/agent.ts`)
- Coding agent → Flight recorder: logs run events (evidence: `src/agent.ts`)
- Coding agent → Run reports: writes turn report (evidence: `src/agent.ts`)
- Coding agent → Session ledger: records receipts (evidence: `README.md`)
- Team pipeline → Team roles: runs role pipeline (evidence: `src/orchestrator/orchestrator.ts`)
- CLI and REPL → Turn rewind: offers rewind (evidence: `src/index.ts`)
- CLI and REPL → Replay engine: replays run (evidence: `README.md`)
- Flight recorder → Replay engine: supplies run log (evidence: `src/flightRecorder.ts`)
- Replay engine → Repository tools: re-executes tools (evidence: `src/replay/replayEngine.ts`)
- Replay engine → Repair and snapshots: restores snapshot (evidence: `src/replay/replayEngine.ts`)
- Desktop shell → Agent sessions: routes to page (evidence: `desktop/src/renderer/app/App.tsx`)
- Desktop shell → Replay viewer: routes to page (evidence: `desktop/src/renderer/app/App.tsx`)
- Desktop shell → Router console: routes to page (evidence: `desktop/src/renderer/app/App.tsx`)
- Agent sessions → Coding agent: hosts agent sessions (evidence: `README.md`)
- Replay viewer → Flight recorder: views recorded runs (evidence: `README.md`)
- Router console → Router client: uses router services
- Router updates → Router client: uses client (evidence: `desktop/src/main/routerUpdate.ts`)
- Router client → 9router: calls local service (evidence: `README.md`)
- Coding agent → Run visualization: emits visualization data (evidence: `README.md`)
