# untrivial-ai/agent-orchestrator architecture

> Architecture diagram of the GitHub repository untrivial-ai/agent-orchestrator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/untrivial-ai/agent-orchestrator
- Repository: https://github.com/untrivial-ai/agent-orchestrator

## Overview

#### Purpose and entry points
Agent Orchestrator (AO) is a local, cross-platform desktop system for planning, launching, isolating, and supervising coding-agent tasks across repositories. The Electron desktop process starts/owns a local Go daemon; users can also operate the daemon through the `ao` CLI.
- `frontend/src/main.ts`
- `backend/main.go`
- `backend/cmd/ao/main.go`

#### Desktop client and local API boundary
The Electron main/preload/renderer split hosts the desktop shell, exposes controlled native capabilities, and renders the Kanban, session, chat, terminal, PR, browser, and settings surfaces. The renderer calls the local daemon HTTP API and consumes its event stream rather than directly controlling agents or storage.
- `frontend/src/main/daemon-owner.ts`
- `frontend/src/preload.ts`
- `frontend/src/renderer/router.tsx`
- `backend/internal/httpd/server.go`
- `backend/internal/httpd/controllers/sessions.go`

#### Daemon composition and application layer
The daemon is the backend composition root: it wires HTTP, persistence, lifecycle supervision, SCM/tracker observers, telemetry, terminals, mobile access, and event propagation. Domain types and port interfaces isolate core application logic from agent, runtime, database, and provider implementations.
- `backend/internal/daemon/daemon.go`
- `backend/internal/domain/session.go`
- `backend/internal/ports/agent.go`
- `backend/internal/service/session/service.go`

#### Session lifecycle, workspaces, and agents
A worker session is the core execution unit: task plus selected agent, runtime, and isolated workspace. Session management provisions worktrees or scratch directories, launches/attaches to agent processes, delivers prompts and attachments, tracks activity, supports agent/interface switching, and performs cleanup. Agent adapters normalize installation, authentication, hooks, activity detection, and native terminal behavior across many external coding CLIs.
- `backend/internal/session_manager/manager.go`
- `backend/internal/adapters/workspace/gitworktree/workspace.go`
- `backend/internal/adapters/workspace/scratch/workspace.go`
- `backend/internal/adapters/agent/registry/registry.go`
- `backend/internal/adapters/runtime/runtimeselect/runtimeselect.go`

#### Conversation and terminal execution paths
Structured chat uses pluggable chat drivers—primarily ACP and Codex app-server protocol implementations—to create conversations, stream activities, retain history/provider state, steer active work, and collect diffs and usage. Native-terminal sessions use PTY execution, tmux, or Windows ConPTY surfaces; the HTTP terminal mux bridges them to clients.
- `backend/internal/service/chat/service.go`
- `backend/internal/adapters/chatdriver/acp/driver.go`
- `backend/internal/adapters/chatdriver/codexappserver/driver.go`
- `backend/internal/terminal/manager.go`
- `backend/internal/httpd/terminal_mux.go`

#### Persistence, observations, and live operational state
SQLite is the local system of record for projects, workspaces, sessions, conversations, PR/review facts, notifications, usage, and settings. Change-data-capture broadcasts committed state changes to HTTP events. Background observers ingest agent activity, GitHub/GitLab SCM facts, tracker intake, and usage; lifecycle/status logic converts these facts into the board’s operational states and notifications.
- `backend/internal/storage/sqlite/db.go`
- `backend/internal/storage/sqlite/store/session_store.go`
- `backend/internal/cdc/broadcast.go`
- `backend/internal/observe/activity/observer.go`
- `backend/internal/lifecycle/manager.go`

#### External integrations and additional clients
The daemon integrates local Git/worktrees, agent executables, Docker cleanup, GitHub and GitLab APIs, PostHog telemetry, Expo push, Tailscale-assisted mobile access, and isolated browser/preview processes. The React Native mobile app connects to the same daemon-facing model for sessions, chat, PRs, notifications, and pairing. The repository also contains a separate Next.js marketing/docs site and Cloudflare waitlist/testimonial workers.
- `backend/internal/adapters/scm/github/provider.go`
- `backend/internal/adapters/telemetry/posthog.go`
- `backend/internal/mobilebridge/tailscaleserve.go`
- `backend/internal/push/expo.go`
- `packages/mobile/lib/api.ts`
- `frontend/src/landing/src/app/api/cloud-waitlist/route.ts`

Main entry points: [`backend/internal/session_manager/manager.go`](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/session_manager/manager.go) (Session manager), [`backend/internal/httpd/server.go`](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/httpd/server.go) (Local HTTP API), [`backend/internal/storage/sqlite/db.go`](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/storage/sqlite/db.go) (SQLite system of record), [`backend/internal/service/session/service.go`](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/service/session/service.go) (Session service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Clients"]
  node_electron["Electron desktop shell<br/>desktop client<br/>[main.ts]"]
  node_preload["Preload bridge<br/>capability bridge<br/>[preload.ts]"]
  node_renderer["React desktop UI<br/>renderer<br/>[router.tsx]"]
  node_cli["ao CLI<br/>CLI client<br/>[main.go]"]
  node_mobile["Mobile app<br/>React Native client<br/>[api.ts]"]
  node_daemon_owner["Daemon owner<br/>Electron process manager<br/>[daemon-owner.ts]"]
end

subgraph group_daemon["Local daemon"]
  node_daemon_root{{"Daemon composition root<br/>Go application<br/>[daemon.go]"}}
  node_http_api["Local HTTP API<br/>HTTP server<br/>[server.go]"]
  node_session_controller["Session API<br/>HTTP controller<br/>[sessions.go]"]
  node_session_service["Session service<br/>application service<br/>[service.go]"]
  node_terminal_mux["Terminal HTTP mux<br/>terminal transport<br/>[terminal_mux.go]"]
  node_sqlite[("SQLite system of record<br/>local database<br/>[db.go]")]
  node_cdc["Committed-change events<br/>CDC broadcaster<br/>[broadcast.go]"]
  node_observers["Observers and lifecycle<br/>operational state pipeline<br/>[observer.go]"]
end

subgraph group_execution["Session execution"]
  node_session_manager["Session manager<br/>lifecycle coordinator<br/>[manager.go]"]
  node_workspace["Isolated workspaces<br/>workspace adapters<br/>[workspace.go]"]
  node_agent_registry["Agent adapters<br/>agent registry<br/>[registry.go]"]
  node_runtime_selector["Runtime selection<br/>runtime adapter<br/>[runtimeselect.go]"]
  node_chat_service["Chat service<br/>conversation service<br/>[service.go]"]
  node_chat_drivers["ACP and Codex drivers<br/>chat protocol adapters<br/>[driver.go]"]
  node_terminal["Terminal manager<br/>PTY and tmux manager<br/>[manager.go]"]
end

subgraph group_external["External systems"]
  node_integrations{{"Local tools and providers<br/>external integrations<br/>[provider.go]"}}
  node_waitlist["Marketing waitlist worker<br/>Next.js API route<br/>[route.ts]"]
end

node_electron -->|"starts"| node_daemon_owner
node_daemon_owner -->|"owns"| node_daemon_root
node_preload -->|"native bridge"| node_renderer
node_renderer -->|"HTTP + events"| node_http_api
node_cli -->|"operates"| node_http_api
node_mobile -->|"daemon model"| node_http_api
node_daemon_root -->|"serves"| node_http_api
node_http_api -->|"routes sessions"| node_session_controller
node_session_controller -->|"invokes"| node_session_service
node_session_service -->|"coordinates"| node_session_manager
node_session_manager -->|"provisions"| node_workspace
node_session_manager -->|"launches agents"| node_agent_registry
node_session_manager -->|"selects runtime"| node_runtime_selector
node_chat_service -->|"conversation protocol"| node_chat_drivers
node_session_manager -->|"structured chat"| node_chat_service
node_session_manager -->|"native terminal"| node_terminal
node_terminal_mux -->|"bridges streams"| node_terminal
node_http_api -->|"terminal endpoint"| node_terminal_mux
node_session_service -->|"persists"| node_sqlite
node_chat_service -->|"stores history"| node_sqlite
node_sqlite -->|"committed changes"| node_cdc
node_cdc -->|"live events"| node_http_api
node_observers -->|"records facts and status"| node_sqlite
node_observers -->|"ingests and notifies"| node_integrations
node_session_manager -->|"Git, agents, cleanup"| node_integrations

click node_electron "https://github.com/untrivial-ai/agent-orchestrator/blob/main/frontend/src/main.ts"
click node_preload "https://github.com/untrivial-ai/agent-orchestrator/blob/main/frontend/src/preload.ts"
click node_renderer "https://github.com/untrivial-ai/agent-orchestrator/blob/main/frontend/src/renderer/router.tsx"
click node_cli "https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/cmd/ao/main.go"
click node_mobile "https://github.com/untrivial-ai/agent-orchestrator/blob/main/packages/mobile/lib/api.ts"
click node_daemon_owner "https://github.com/untrivial-ai/agent-orchestrator/blob/main/frontend/src/main/daemon-owner.ts"
click node_daemon_root "https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/daemon/daemon.go"
click node_http_api "https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/httpd/server.go"
click node_session_controller "https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/httpd/controllers/sessions.go"
click node_session_service "https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/service/session/service.go"
click node_session_manager "https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/session_manager/manager.go"
click node_workspace "https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/adapters/workspace/gitworktree/workspace.go"
click node_agent_registry "https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/adapters/agent/registry/registry.go"
click node_runtime_selector "https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/adapters/runtime/runtimeselect/runtimeselect.go"
click node_chat_service "https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/service/chat/service.go"
click node_chat_drivers "https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/adapters/chatdriver/acp/driver.go"
click node_terminal "https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/terminal/manager.go"
click node_terminal_mux "https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/httpd/terminal_mux.go"
click node_sqlite "https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/storage/sqlite/db.go"
click node_cdc "https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/cdc/broadcast.go"
click node_observers "https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/observe/activity/observer.go"
click node_integrations "https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/adapters/scm/github/provider.go"
click node_waitlist "https://github.com/untrivial-ai/agent-orchestrator/blob/main/frontend/src/landing/src/app/api/cloud-waitlist/route.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_electron,node_preload,node_renderer,node_cli,node_mobile,node_daemon_owner toneBlue
class node_daemon_root,node_http_api,node_session_controller,node_session_service,node_terminal_mux,node_sqlite,node_cdc,node_observers toneAmber
class node_session_manager,node_workspace,node_agent_registry,node_runtime_selector,node_chat_service,node_chat_drivers,node_terminal toneMint
class node_integrations,node_waitlist toneRose
```

## Components

### Clients

- [Electron desktop shell](https://github.com/untrivial-ai/agent-orchestrator/blob/main/frontend/src/main.ts): desktop client · Owns the local daemon and hosts desktop surfaces. · `frontend/src/main.ts`
- [Preload bridge](https://github.com/untrivial-ai/agent-orchestrator/blob/main/frontend/src/preload.ts): capability bridge · Exposes controlled native capabilities to the renderer. · `frontend/src/preload.ts`
- [React desktop UI](https://github.com/untrivial-ai/agent-orchestrator/blob/main/frontend/src/renderer/router.tsx): renderer · Kanban, session, chat, terminal, PR, browser, and settings views. · `frontend/src/renderer/router.tsx`
- [ao CLI](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/cmd/ao/main.go): CLI client · `backend/cmd/ao/main.go`
- [Mobile app](https://github.com/untrivial-ai/agent-orchestrator/blob/main/packages/mobile/lib/api.ts): React Native client · `packages/mobile/lib/api.ts`
- [Daemon owner](https://github.com/untrivial-ai/agent-orchestrator/blob/main/frontend/src/main/daemon-owner.ts): Electron process manager · Starts and supervises the local Go daemon. · `frontend/src/main/daemon-owner.ts`

### Local daemon

- [Daemon composition root](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/daemon/daemon.go): Go application · Wires local API, services, observers, and integrations. · `backend/internal/daemon/daemon.go`
- [Local HTTP API](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/httpd/server.go): HTTP server · Serves clients and publishes daemon events. · `backend/internal/httpd/server.go`
- [Session API](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/httpd/controllers/sessions.go): HTTP controller · `backend/internal/httpd/controllers/sessions.go`
- [Session service](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/service/session/service.go): application service · Applies session use cases through domain ports. · `backend/internal/service/session/service.go`
- [Terminal HTTP mux](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/httpd/terminal_mux.go): terminal transport · `backend/internal/httpd/terminal_mux.go`
- [SQLite system of record](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/storage/sqlite/db.go): local database · Persists projects, sessions, conversations, review facts, notifications, usage, and settings. · `backend/internal/storage/sqlite/db.go`
- [Committed-change events](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/cdc/broadcast.go): CDC broadcaster · Broadcasts persisted state changes to connected clients. · `backend/internal/cdc/broadcast.go`
- [Observers and lifecycle](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/observe/activity/observer.go): operational state pipeline · Ingests activity and provider facts into board status and notifications. · `backend/internal/observe/activity/observer.go`

### Session execution

- [Session manager](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/session_manager/manager.go): lifecycle coordinator · Provisions, launches, attaches, switches, and cleans up worker sessions. · `backend/internal/session_manager/manager.go`
- [Isolated workspaces](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/adapters/workspace/gitworktree/workspace.go): workspace adapters · Creates Git worktrees or scratch directories. · `backend/internal/adapters/workspace/gitworktree/workspace.go`
- [Agent adapters](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/adapters/agent/registry/registry.go): agent registry · Normalizes external coding CLI behavior and capabilities. · `backend/internal/adapters/agent/registry/registry.go`
- [Runtime selection](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/adapters/runtime/runtimeselect/runtimeselect.go): runtime adapter · `backend/internal/adapters/runtime/runtimeselect/runtimeselect.go`
- [Chat service](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/service/chat/service.go): conversation service · Streams conversations, activity, history, diffs, and usage. · `backend/internal/service/chat/service.go`
- [ACP and Codex drivers](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/adapters/chatdriver/acp/driver.go): chat protocol adapters · `backend/internal/adapters/chatdriver/acp/driver.go`
- [Terminal manager](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/terminal/manager.go): PTY and tmux manager · Runs native terminal sessions across supported platforms. · `backend/internal/terminal/manager.go`

### External systems

- [Local tools and providers](https://github.com/untrivial-ai/agent-orchestrator/blob/main/backend/internal/adapters/scm/github/provider.go): external integrations · Git, coding CLIs, SCM APIs, Docker, telemetry, push, Tailscale, and browser previews. · `backend/internal/adapters/scm/github/provider.go`
- [Marketing waitlist worker](https://github.com/untrivial-ai/agent-orchestrator/blob/main/frontend/src/landing/src/app/api/cloud-waitlist/route.ts): Next.js API route · Separate marketing/docs-site backend surface. · `frontend/src/landing/src/app/api/cloud-waitlist/route.ts`

## Connections

- Electron desktop shell → Daemon owner: starts
- Daemon owner → Daemon composition root: owns
- Preload bridge → React desktop UI: native bridge
- React desktop UI → Local HTTP API: HTTP + events
- ao CLI → Local HTTP API: operates
- Mobile app → Local HTTP API: daemon model
- Daemon composition root → Local HTTP API: serves
- Local HTTP API → Session API: routes sessions
- Session API → Session service: invokes
- Session service → Session manager: coordinates
- Session manager → Isolated workspaces: provisions
- Session manager → Agent adapters: launches agents
- Session manager → Runtime selection: selects runtime
- Chat service → ACP and Codex drivers: conversation protocol
- Session manager → Chat service: structured chat
- Session manager → Terminal manager: native terminal
- Terminal HTTP mux → Terminal manager: bridges streams
- Local HTTP API → Terminal HTTP mux: terminal endpoint
- Session service → SQLite system of record: persists
- Chat service → SQLite system of record: stores history
- SQLite system of record → Committed-change events: committed changes
- Committed-change events → Local HTTP API: live events
- Observers and lifecycle → SQLite system of record: records facts and status
- Observers and lifecycle → Local tools and providers: ingests and notifies
- Session manager → Local tools and providers: Git, agents, cleanup
