# 2youg1/sprawling-agents architecture

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

- Interactive diagram: https://gitdiagram.com/2youg1/sprawling-agents
- Repository: https://github.com/2youg1/sprawling-agents

## Overview

sprawling is a locally run, browser-based city for coordinating long-running work across resident agents in directory-backed buildings. The main workflow is: a person gives the Mayor a goal, plans dispatch work to buildings, residents run tasks and communicate, and the person follows progress, answers questions, and checks results. The README also documents the append-only Ledger, provider connections, performance monitoring, and privacy controls. The source excerpts show the client mount and shell, command construction, server boundary, and run worker; links for unsampled product subsystems rely on README statements.

Main entry points: [`client/src/ui.ts`](https://github.com/2youg1/sprawling-agents/blob/main/client/src/ui.ts) (City interface), [`crates/runtime/src/pipeline.rs`](https://github.com/2youg1/sprawling-agents/blob/main/crates/runtime/src/pipeline.rs) (Run pipeline), [`client/src/main.ts`](https://github.com/2youg1/sprawling-agents/blob/main/client/src/main.ts) (Client mount), [`crates/accounting/src/worker.rs`](https://github.com/2youg1/sprawling-agents/blob/main/crates/accounting/src/worker.rs) (Mayor planning)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser client"]
  node_client_mount["Client mount<br/>[main.ts]"]
  node_client_shell["Application shell<br/>[app.svelte]"]
  node_client_ui["City interface<br/>[ui.ts]"]
  node_client_commands["Command builder<br/>[commands.ts]"]
  node_client_route["Address routing<br/>[route.ts]"]
  node_client_socket["Live connection<br/>[socket.ts]"]
end

subgraph group_coordination["City coordination"]
  node_mayor["Mayor planning<br/>[worker.rs]"]
  node_plans["Hierarchical plans<br/>[worker.rs]"]
  node_buildings["Directory buildings<br/>[session.rs]"]
  node_agent_messages["Agent messaging<br/>[worker.rs]"]
end

subgraph group_execution["Agent execution"]
  node_residents["Resident agents<br/>[worker.rs]"]
  node_agent_runtime["Run pipeline<br/>[pipeline.rs]"]
  node_tools_sandbox["Tools and sandbox<br/>[engine.rs]"]
  node_results["Run results<br/>[run.svelte]"]
end

subgraph group_state["History and state"]
  node_ledger[("Append-only Ledger<br/>[sessions.rs]")]
  node_history_views["History and playback<br/>[record.svelte]"]
end

subgraph group_operations["Operations and integrations"]
  node_server["HTTP and socket server<br/>[server.rs]"]
  node_provider(("Model provider"))
  node_gateway["Provider gateway<br/>[router.rs]"]
  node_performance["Performance monitor<br/>[monitor.svelte]"]
  node_privacy["Privacy controls<br/>[service.rs]"]
  node_remote_access["Remote access<br/>[pairing.rs]"]
end

node_person(("Person"))

node_person -->|"opens city"| node_client_mount
node_client_mount -->|"mounts"| node_client_shell
node_client_shell -->|"presents"| node_client_ui
node_client_ui -.->|"builds commands"| node_client_commands
node_client_ui -->|"tracks views"| node_client_route
node_client_mount -->|"opens connection"| node_client_socket
node_client_socket -.->|"exchanges messages"| node_server
node_client_commands -.->|"sends commands"| node_server
node_server -.->|"routes work"| node_mayor
node_mayor -->|"writes roadmap"| node_plans
node_plans -->|"dispatches tasks"| node_buildings
node_buildings -->|"hosts residents"| node_residents
node_residents -->|"drives runs"| node_agent_runtime
node_agent_runtime -.->|"runs tools"| node_tools_sandbox
node_agent_runtime -.->|"requests model"| node_gateway
node_gateway -.->|"calls provider"| node_provider
node_residents -->|"coordinate messages"| node_agent_messages
node_mayor -->|"records history"| node_ledger
node_agent_runtime -.->|"records run history"| node_ledger
node_client_ui -->|"shows progress"| node_results
node_client_ui -->|"shows playback"| node_history_views
node_client_ui -->|"shows metrics"| node_performance
node_person -->|"configures privacy"| node_privacy
node_client_ui -.->|"pairs devices"| node_remote_access

click node_client_mount "https://github.com/2youg1/sprawling-agents/blob/main/client/src/main.ts"
click node_client_shell "https://github.com/2youg1/sprawling-agents/blob/main/client/src/app.svelte"
click node_client_ui "https://github.com/2youg1/sprawling-agents/blob/main/client/src/ui.ts"
click node_client_commands "https://github.com/2youg1/sprawling-agents/blob/main/client/src/core/commands.ts"
click node_client_route "https://github.com/2youg1/sprawling-agents/blob/main/client/src/core/route.ts"
click node_client_socket "https://github.com/2youg1/sprawling-agents/blob/main/client/src/core/socket.ts"
click node_server "https://github.com/2youg1/sprawling-agents/blob/main/crates/wire/src/server.rs"
click node_mayor "https://github.com/2youg1/sprawling-agents/blob/main/crates/accounting/src/worker.rs"
click node_plans "https://github.com/2youg1/sprawling-agents/blob/main/crates/accounting/src/worker.rs"
click node_buildings "https://github.com/2youg1/sprawling-agents/blob/main/crates/city/src/session.rs"
click node_residents "https://github.com/2youg1/sprawling-agents/blob/main/crates/accounting/src/worker.rs"
click node_agent_runtime "https://github.com/2youg1/sprawling-agents/blob/main/crates/runtime/src/pipeline.rs"
click node_tools_sandbox "https://github.com/2youg1/sprawling-agents/blob/main/crates/runtime/src/sandbox/engine.rs"
click node_gateway "https://github.com/2youg1/sprawling-agents/blob/main/crates/gateway/src/router.rs"
click node_agent_messages "https://github.com/2youg1/sprawling-agents/blob/main/crates/accounting/src/worker.rs"
click node_ledger "https://github.com/2youg1/sprawling-agents/blob/main/crates/storage/src/sessions.rs"
click node_results "https://github.com/2youg1/sprawling-agents/blob/main/client/src/views/run.svelte"
click node_history_views "https://github.com/2youg1/sprawling-agents/blob/main/client/src/views/record.svelte"
click node_performance "https://github.com/2youg1/sprawling-agents/blob/main/client/src/views/monitor.svelte"
click node_privacy "https://github.com/2youg1/sprawling-agents/blob/main/crates/sprawling/src/privacy/service.rs"
click node_remote_access "https://github.com/2youg1/sprawling-agents/blob/main/crates/remote_access/src/handshake/pairing.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_client_mount,node_client_shell,node_client_ui,node_client_commands,node_client_route,node_client_socket toneBlue
class node_mayor,node_plans,node_buildings,node_agent_messages toneAmber
class node_residents,node_agent_runtime,node_tools_sandbox,node_results toneMint
class node_ledger,node_history_views toneRose
class node_server,node_provider,node_gateway,node_performance,node_privacy,node_remote_access,node_person toneIndigo
```

## Components

### Browser client

- [Client mount](https://github.com/2youg1/sprawling-agents/blob/main/client/src/main.ts): `client/src/main.ts`
- [Application shell](https://github.com/2youg1/sprawling-agents/blob/main/client/src/app.svelte): `client/src/app.svelte`
- [City interface](https://github.com/2youg1/sprawling-agents/blob/main/client/src/ui.ts): `client/src/ui.ts`
- [Command builder](https://github.com/2youg1/sprawling-agents/blob/main/client/src/core/commands.ts): `client/src/core/commands.ts`
- [Address routing](https://github.com/2youg1/sprawling-agents/blob/main/client/src/core/route.ts): `client/src/core/route.ts`
- [Live connection](https://github.com/2youg1/sprawling-agents/blob/main/client/src/core/socket.ts): `client/src/core/socket.ts`

### City coordination

- [Mayor planning](https://github.com/2youg1/sprawling-agents/blob/main/crates/accounting/src/worker.rs): `crates/accounting/src/worker.rs`
- [Hierarchical plans](https://github.com/2youg1/sprawling-agents/blob/main/crates/accounting/src/worker.rs): `crates/accounting/src/worker.rs`
- [Directory buildings](https://github.com/2youg1/sprawling-agents/blob/main/crates/city/src/session.rs): `crates/city/src/session.rs`
- [Agent messaging](https://github.com/2youg1/sprawling-agents/blob/main/crates/accounting/src/worker.rs): `crates/accounting/src/worker.rs`

### Agent execution

- [Resident agents](https://github.com/2youg1/sprawling-agents/blob/main/crates/accounting/src/worker.rs): `crates/accounting/src/worker.rs`
- [Run pipeline](https://github.com/2youg1/sprawling-agents/blob/main/crates/runtime/src/pipeline.rs): `crates/runtime/src/pipeline.rs`
- [Tools and sandbox](https://github.com/2youg1/sprawling-agents/blob/main/crates/runtime/src/sandbox/engine.rs): `crates/runtime/src/sandbox/engine.rs`
- [Run results](https://github.com/2youg1/sprawling-agents/blob/main/client/src/views/run.svelte): `client/src/views/run.svelte`

### History and state

- [Append-only Ledger](https://github.com/2youg1/sprawling-agents/blob/main/crates/storage/src/sessions.rs): `crates/storage/src/sessions.rs`
- [History and playback](https://github.com/2youg1/sprawling-agents/blob/main/client/src/views/record.svelte): `client/src/views/record.svelte`

### Operations and integrations

- [HTTP and socket server](https://github.com/2youg1/sprawling-agents/blob/main/crates/wire/src/server.rs): `crates/wire/src/server.rs`
- **Model provider**
- [Provider gateway](https://github.com/2youg1/sprawling-agents/blob/main/crates/gateway/src/router.rs): `crates/gateway/src/router.rs`
- [Performance monitor](https://github.com/2youg1/sprawling-agents/blob/main/client/src/views/monitor.svelte): `client/src/views/monitor.svelte`
- [Privacy controls](https://github.com/2youg1/sprawling-agents/blob/main/crates/sprawling/src/privacy/service.rs): `crates/sprawling/src/privacy/service.rs`
- [Remote access](https://github.com/2youg1/sprawling-agents/blob/main/crates/remote_access/src/handshake/pairing.rs): `crates/remote_access/src/handshake/pairing.rs`

### Other components

- **Person**

## Connections

- Person → Client mount: opens city (evidence: `README.md`)
- Client mount → Application shell: mounts (evidence: `client/src/main.ts`)
- Application shell → City interface: presents (evidence: `client/src/app.svelte`)
- City interface → Command builder: builds commands (evidence: `client/src/ui.ts`)
- City interface → Address routing: tracks views (evidence: `client/src/app.svelte`)
- Client mount → Live connection: opens connection (evidence: `client/src/main.ts`)
- Live connection → HTTP and socket server: exchanges messages
- Command builder → HTTP and socket server: sends commands
- HTTP and socket server → Mayor planning: routes work
- Mayor planning → Hierarchical plans: writes roadmap (evidence: `README.md`)
- Hierarchical plans → Directory buildings: dispatches tasks (evidence: `README.md`)
- Directory buildings → Resident agents: hosts residents (evidence: `README.md`)
- Resident agents → Run pipeline: drives runs (evidence: `crates/accounting/src/worker.rs`)
- Run pipeline → Tools and sandbox: runs tools
- Run pipeline → Provider gateway: requests model
- Provider gateway → Model provider: calls provider
- Resident agents → Agent messaging: coordinate messages (evidence: `README.md`)
- Mayor planning → Append-only Ledger: records history (evidence: `README.md`)
- Run pipeline → Append-only Ledger: records run history
- City interface → Run results: shows progress (evidence: `README.md`)
- City interface → History and playback: shows playback (evidence: `README.md`)
- City interface → Performance monitor: shows metrics (evidence: `README.md`)
- Person → Privacy controls: configures privacy (evidence: `README.md`)
- City interface → Remote access: pairs devices
