# runmaestro/maestro architecture

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

- Interactive diagram: https://gitdiagram.com/runmaestro/maestro
- Repository: https://github.com/runmaestro/maestro

## Overview

#### Purpose and Entry Points
Maestro is a cross-platform desktop orchestrator for multiple local/remote AI coding-agent sessions, automation, project worktrees, and remote control. Its primary Electron entry is `src/main/index.ts`; the React desktop renderer starts at `src/renderer/main.tsx` and composes `src/renderer/App.tsx`. Headless automation is exposed through the CLI at `src/cli/index.ts`; `src/maestro-p/index.ts` is a companion process-oriented interface.

#### Runtime Topology and Boundaries
The application separates Electron main-process authority from an untrusted renderer. Main owns windows, filesystem, agent subprocesses, persistence, IPC, local web services, and privileged integrations; renderer owns interactive UI/state. Preload bridges expose constrained APIs between them: `src/main/preload/index.ts`, `src/main/ipc/handlers/index.ts`, and `src/renderer/services/ipcWrapper.ts`. Shared contracts and domain types live in `src/shared/`, notably `src/shared/agent-run/types.ts` and `src/shared/cue-pipeline-types.ts`.

#### Agent Session Execution
Agent definitions, discovery, capabilities, spawn choices, and usage sampling are centralized in `src/main/agents/definitions.ts`, `src/main/agents/detector.ts`, and `src/main/agents/capabilities.ts`. The process layer launches local PTY/child processes, OpenCode servers, or SSH commands and normalizes lifecycle streams through `src/main/process-manager/ProcessManager.ts`, `src/main/process-manager/runners/SshCommandRunner.ts`, and `src/main/parsers/parser-factory.ts`. Output, errors, session IDs, token usage, and exits are forwarded to UI/state through `src/main/process-listeners/index.ts`.

#### Desktop Session Workspace
The renderer presents concurrently managed AI, terminal, browser, and file tabs. Session lifecycle and execution coordination are concentrated in `src/renderer/hooks/agent/useAgentExecution.ts`, `src/renderer/hooks/session/useSessionLifecycle.ts`, and `src/renderer/stores/sessionStore.ts`. The principal workspace composition is `src/renderer/components/AppShell.tsx`, `src/renderer/components/MainPanel/MainPanel.tsx`, and `src/renderer/components/TabBar/TabBar.tsx`. Provider session persistence/import is implemented in `src/main/storage/claude-session-storage.ts`, `src/main/storage/codex-session-storage.ts`, and `src/main/storage/opencode-session-storage.ts`.

#### Auto Run, Campaigns, and Worktrees
Auto Run executes markdown/playbook tasks or goal-driven work in fresh/resumed agent sessions, with recovery and event capture. Main-process capture/recovery is in `src/main/agent-run/capture-service.ts`, `src/main/agent-run/recover-runs.ts`, and `src/main/agent-run/producers.ts`; UI control is rooted in `src/renderer/components/AutoRun/AutoRun.tsx`. Shared campaign and run contracts sit in `src/shared/campaign/types.ts` and `src/shared/agent-run/lifecycle.ts`. Git worktrees provide isolation for parallel agent work; worktree workflows are surfaced via `src/renderer/hooks/batch/useWorktreeManager.ts`.

#### Cue Automation and Orchestration
Cue is a durable pipeline engine with YAML-configured graphs, trigger sources, fan-in/fan-out handling, queued runs, recovery, and agent/shell/notification executors. Its core control path is `src/main/cue/cue-engine.ts`, `src/main/cue/cue-dispatch-service.ts`, and `src/main/cue/cue-run-manager.ts`. Trigger adapters include filesystem, schedule, GitHub polling, heartbeat, and task scanning under `src/main/cue/triggers/`. The visual graph editor serializes between UI graph state and pipeline YAML through `src/renderer/components/CuePipelineEditor/CuePipelineEditor.tsx` and `src/renderer/components/CuePipelineEditor/utils/pipelineToYaml.ts`.

#### Extensions, Remote Access, and External Services
The plugin platform verifies identity/signatures, gates permissions and network egress, and runs extensions in sandbox/background/panel hosts: `src/main/plugins/plugin-manager.ts`, `src/main/plugins/plugin-sandbox-host.ts`, and `src/shared/plugins/permissions.ts`. A built-in HTTP/WebSocket server enables mobile/remote control via `src/main/web-server/WebServer.ts`, `src/main/web-server/routes/wsRoute.ts`, and `src/web/hooks/useWebSocket.ts`; remote tunneling is managed by `src/main/tunnel-manager.ts`. External dependencies are locally installed AI CLIs (Claude Code, Codex, OpenCode, Factory Droid, Copilot CLI, Qwen, Oh My Pi), SSH/Git, optional GitHub polling/CLI, Cloudflare tunneling, and WakaTime/Sentry integrations.

#### Persistence and Observability
Application settings and migrations use main-process stores in `src/main/stores/index.ts`. Durable analytics, usage, and lifecycle data are handled by `src/main/stats/stats-db.ts`, `src/main/stats/session-lifecycle.ts`, and `src/main/stats/token-usage/token-usage-accessor.ts`. These feed the renderer’s usage dashboard and operational views rather than being the execution source of truth.

Main entry points: [`src/main/index.ts`](https://github.com/RunMaestro/Maestro/blob/main/src/main/index.ts) (Electron main), [`src/main/process-manager/ProcessManager.ts`](https://github.com/RunMaestro/Maestro/blob/main/src/main/process-manager/ProcessManager.ts) (Process manager), [`src/main/cue/cue-engine.ts`](https://github.com/RunMaestro/Maestro/blob/main/src/main/cue/cue-engine.ts) (Cue pipeline engine), [`src/renderer/hooks/agent/useAgentExecution.ts`](https://github.com/RunMaestro/Maestro/blob/main/src/renderer/hooks/agent/useAgentExecution.ts) (Session coordination)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_electron_main["Electron main<br/>privileged runtime<br/>[index.ts]"]
  node_renderer_entry["React renderer<br/>desktop UI runtime<br/>[main.tsx]"]
  node_cli["Headless CLI<br/>automation entry<br/>[index.ts]"]
  node_process_interface["Process interface<br/>companion entry<br/>[index.ts]"]
end

subgraph group_desktop["Desktop boundary"]
  node_preload_ipc{{"Preload &amp; IPC<br/>trusted bridge<br/>[index.ts]"}}
  node_ipc_wrapper["IPC wrapper<br/>renderer service<br/>[ipcWrapper.ts]"]
  node_app_shell["Session workspace<br/>workspace UI<br/>[AppShell.tsx]"]
  node_session_coordination["Session coordination<br/>renderer state"]
  node_shared_contracts["Shared contracts<br/>domain contracts<br/>[types.ts]"]
end

subgraph group_execution["Agent execution"]
  node_agent_catalog["Agent catalog<br/>agent discovery<br/>[definitions.ts]"]
  node_process_manager["Process manager<br/>process orchestration<br/>[ProcessManager.ts]"]
  node_process_listeners["Process event streams<br/>lifecycle forwarding<br/>[index.ts]"]
  node_local_agents{{"AI CLIs, SSH &amp; Git<br/>external tools"}}
  node_session_storage[("Provider session storage<br/>session persistence")]
end

subgraph group_automation["Automation"]
  node_auto_run["Auto Run<br/>run automation<br/>[capture-service.ts]"]
  node_cue_engine["Cue pipeline engine<br/>durable orchestrator<br/>[cue-engine.ts]"]
  node_cue_triggers["Cue triggers<br/>trigger adapters"]
  node_cue_editor["Cue graph editor<br/>pipeline UI"]
end

subgraph group_integrations["Extensions &amp; remote"]
  node_plugins["Plugin platform<br/>sandboxed extensions<br/>[plugin-manager.ts]"]
  node_remote_server["Remote control server<br/>HTTP/WebSocket service<br/>[WebServer.ts]"]
  node_tunnel["Tunnel manager<br/>remote access<br/>[tunnel-manager.ts]"]
end

node_stores[("Settings &amp; migrations<br/>application store<br/>[index.ts]")]
node_stats[("Usage &amp; lifecycle analytics<br/>analytics store<br/>[stats-db.ts]")]

node_renderer_entry -->|"renders"| node_app_shell
node_app_shell -->|"coordinates sessions"| node_session_coordination
node_session_coordination -->|"invokes"| node_ipc_wrapper
node_ipc_wrapper -->|"bridges"| node_preload_ipc
node_preload_ipc -->|"IPC handlers"| node_electron_main
node_electron_main -->|"owns"| node_agent_catalog
node_agent_catalog -->|"selects runner"| node_process_manager
node_process_manager -->|"launches"| node_local_agents
node_process_manager -->|"emits lifecycle"| node_process_listeners
node_process_listeners -->|"updates UI"| node_session_coordination
node_process_manager -->|"persists sessions"| node_session_storage
node_electron_main -->|"hosts"| node_auto_run
node_auto_run -->|"creates or resumes runs"| node_process_manager
node_electron_main -->|"hosts"| node_cue_engine
node_cue_triggers -->|"start runs"| node_cue_engine
node_cue_engine -->|"executes agent or shell stages"| node_process_manager
node_cue_editor -->|"edits pipeline YAML"| node_cue_engine
node_electron_main -->|"hosts"| node_plugins
node_electron_main -->|"hosts"| node_remote_server
node_tunnel -->|"exposes"| node_remote_server
node_electron_main -->|"reads settings"| node_stores
node_process_listeners -->|"records usage"| node_stats
node_stats -->|"dashboard data"| node_app_shell
node_shared_contracts -.->|"types"| node_session_coordination
node_shared_contracts -.->|"run contracts"| node_auto_run
node_shared_contracts -.->|"pipeline contracts"| node_cue_engine
node_cli -->|"headless automation"| node_auto_run
node_process_interface -->|"process control"| node_process_manager

click node_electron_main "https://github.com/RunMaestro/Maestro/blob/main/src/main/index.ts"
click node_renderer_entry "https://github.com/RunMaestro/Maestro/blob/main/src/renderer/main.tsx"
click node_cli "https://github.com/RunMaestro/Maestro/blob/main/src/cli/index.ts"
click node_process_interface "https://github.com/RunMaestro/Maestro/blob/main/src/maestro-p/index.ts"
click node_preload_ipc "https://github.com/RunMaestro/Maestro/blob/main/src/main/preload/index.ts"
click node_ipc_wrapper "https://github.com/RunMaestro/Maestro/blob/main/src/renderer/services/ipcWrapper.ts"
click node_app_shell "https://github.com/RunMaestro/Maestro/blob/main/src/renderer/components/AppShell.tsx"
click node_session_coordination "https://github.com/RunMaestro/Maestro/blob/main/src/renderer/hooks/agent/useAgentExecution.ts"
click node_shared_contracts "https://github.com/RunMaestro/Maestro/blob/main/src/shared/agent-run/types.ts"
click node_agent_catalog "https://github.com/RunMaestro/Maestro/blob/main/src/main/agents/definitions.ts"
click node_process_manager "https://github.com/RunMaestro/Maestro/blob/main/src/main/process-manager/ProcessManager.ts"
click node_process_listeners "https://github.com/RunMaestro/Maestro/blob/main/src/main/process-listeners/index.ts"
click node_session_storage "https://github.com/RunMaestro/Maestro/blob/main/src/main/storage/claude-session-storage.ts"
click node_auto_run "https://github.com/RunMaestro/Maestro/blob/main/src/main/agent-run/capture-service.ts"
click node_cue_engine "https://github.com/RunMaestro/Maestro/blob/main/src/main/cue/cue-engine.ts"
click node_cue_triggers "https://github.com/RunMaestro/Maestro/blob/main/src/main/cue/triggers/cue-trigger-source-registry.ts"
click node_cue_editor "https://github.com/RunMaestro/Maestro/blob/main/src/renderer/components/CuePipelineEditor/CuePipelineEditor.tsx"
click node_plugins "https://github.com/RunMaestro/Maestro/blob/main/src/main/plugins/plugin-manager.ts"
click node_remote_server "https://github.com/RunMaestro/Maestro/blob/main/src/main/web-server/WebServer.ts"
click node_tunnel "https://github.com/RunMaestro/Maestro/blob/main/src/main/tunnel-manager.ts"
click node_stores "https://github.com/RunMaestro/Maestro/blob/main/src/main/stores/index.ts"
click node_stats "https://github.com/RunMaestro/Maestro/blob/main/src/main/stats/stats-db.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_main,node_renderer_entry,node_cli,node_process_interface toneBlue
class node_preload_ipc,node_ipc_wrapper,node_app_shell,node_session_coordination,node_shared_contracts toneAmber
class node_agent_catalog,node_process_manager,node_process_listeners,node_local_agents,node_session_storage toneMint
class node_auto_run,node_cue_engine,node_cue_triggers,node_cue_editor toneRose
class node_plugins,node_remote_server,node_tunnel toneIndigo
class node_stores,node_stats toneNeutral
```

## Components

### Entry points

- [Electron main](https://github.com/RunMaestro/Maestro/blob/main/src/main/index.ts): privileged runtime · Owns desktop authority and privileged services. · `src/main/index.ts`
- [React renderer](https://github.com/RunMaestro/Maestro/blob/main/src/renderer/main.tsx): desktop UI runtime · `src/renderer/main.tsx`
- [Headless CLI](https://github.com/RunMaestro/Maestro/blob/main/src/cli/index.ts): automation entry · `src/cli/index.ts`
- [Process interface](https://github.com/RunMaestro/Maestro/blob/main/src/maestro-p/index.ts): companion entry · `src/maestro-p/index.ts`

### Desktop boundary

- [Preload & IPC](https://github.com/RunMaestro/Maestro/blob/main/src/main/preload/index.ts): trusted bridge · Constrained API boundary between renderer and main. · `src/main/preload/index.ts`
- [IPC wrapper](https://github.com/RunMaestro/Maestro/blob/main/src/renderer/services/ipcWrapper.ts): renderer service · `src/renderer/services/ipcWrapper.ts`
- [Session workspace](https://github.com/RunMaestro/Maestro/blob/main/src/renderer/components/AppShell.tsx): workspace UI · Composes tabs and concurrent agent, terminal, browser, and file views. · `src/renderer/components/AppShell.tsx`
- [Session coordination](https://github.com/RunMaestro/Maestro/blob/main/src/renderer/hooks/agent/useAgentExecution.ts): renderer state · Coordinates session lifecycle and agent execution. · `src/renderer/hooks/agent/useAgentExecution.ts`
- [Shared contracts](https://github.com/RunMaestro/Maestro/blob/main/src/shared/agent-run/types.ts): domain contracts · Cross-runtime agent-run, cue, and campaign types. · `src/shared/agent-run/types.ts`

### Agent execution

- [Agent catalog](https://github.com/RunMaestro/Maestro/blob/main/src/main/agents/definitions.ts): agent discovery · Selects installed agents, capabilities, and spawn options. · `src/main/agents/definitions.ts`
- [Process manager](https://github.com/RunMaestro/Maestro/blob/main/src/main/process-manager/ProcessManager.ts): process orchestration · Launches PTY, child-process, OpenCode, and SSH executions. · `src/main/process-manager/ProcessManager.ts`
- [Process event streams](https://github.com/RunMaestro/Maestro/blob/main/src/main/process-listeners/index.ts): lifecycle forwarding · Forwards output, errors, usage, and exits to UI state. · `src/main/process-listeners/index.ts`
- **AI CLIs, SSH & Git**: external tools
- [Provider session storage](https://github.com/RunMaestro/Maestro/blob/main/src/main/storage/claude-session-storage.ts): session persistence · Persists and imports Claude, Codex, and OpenCode sessions. · `src/main/storage/claude-session-storage.ts`

### Automation

- [Auto Run](https://github.com/RunMaestro/Maestro/blob/main/src/main/agent-run/capture-service.ts): run automation · Runs playbook or goal work with capture and recovery. · `src/main/agent-run/capture-service.ts`
- [Cue pipeline engine](https://github.com/RunMaestro/Maestro/blob/main/src/main/cue/cue-engine.ts): durable orchestrator · Dispatches queued YAML pipeline runs and recovery. · `src/main/cue/cue-engine.ts`
- [Cue triggers](https://github.com/RunMaestro/Maestro/blob/main/src/main/cue/triggers/cue-trigger-source-registry.ts): trigger adapters · Filesystem, schedule, GitHub, heartbeat, and task sources. · `src/main/cue/triggers/cue-trigger-source-registry.ts`
- [Cue graph editor](https://github.com/RunMaestro/Maestro/blob/main/src/renderer/components/CuePipelineEditor/CuePipelineEditor.tsx): pipeline UI · Serializes visual pipeline graphs to YAML. · `src/renderer/components/CuePipelineEditor/CuePipelineEditor.tsx`

### Extensions & remote

- [Plugin platform](https://github.com/RunMaestro/Maestro/blob/main/src/main/plugins/plugin-manager.ts): sandboxed extensions · Verifies plugins and gates permissions, hosts, and egress. · `src/main/plugins/plugin-manager.ts`
- [Remote control server](https://github.com/RunMaestro/Maestro/blob/main/src/main/web-server/WebServer.ts): HTTP/WebSocket service · Serves mobile and remote-control connections. · `src/main/web-server/WebServer.ts`
- [Tunnel manager](https://github.com/RunMaestro/Maestro/blob/main/src/main/tunnel-manager.ts): remote access · `src/main/tunnel-manager.ts`

### Other components

- [Settings & migrations](https://github.com/RunMaestro/Maestro/blob/main/src/main/stores/index.ts): application store · `src/main/stores/index.ts`
- [Usage & lifecycle analytics](https://github.com/RunMaestro/Maestro/blob/main/src/main/stats/stats-db.ts): analytics store · Operational data feeds dashboard views, not execution control. · `src/main/stats/stats-db.ts`

## Connections

- React renderer → Session workspace: renders
- Session workspace → Session coordination: coordinates sessions
- Session coordination → IPC wrapper: invokes
- IPC wrapper → Preload & IPC: bridges
- Preload & IPC → Electron main: IPC handlers
- Electron main → Agent catalog: owns
- Agent catalog → Process manager: selects runner
- Process manager → AI CLIs, SSH & Git: launches
- Process manager → Process event streams: emits lifecycle
- Process event streams → Session coordination: updates UI
- Process manager → Provider session storage: persists sessions
- Electron main → Auto Run: hosts
- Auto Run → Process manager: creates or resumes runs
- Electron main → Cue pipeline engine: hosts
- Cue triggers → Cue pipeline engine: start runs
- Cue pipeline engine → Process manager: executes agent or shell stages
- Cue graph editor → Cue pipeline engine: edits pipeline YAML
- Electron main → Plugin platform: hosts
- Electron main → Remote control server: hosts
- Tunnel manager → Remote control server: exposes
- Electron main → Settings & migrations: reads settings
- Process event streams → Usage & lifecycle analytics: records usage
- Usage & lifecycle analytics → Session workspace: dashboard data
- Shared contracts → Session coordination: types
- Shared contracts → Auto Run: run contracts
- Shared contracts → Cue pipeline engine: pipeline contracts
- Headless CLI → Auto Run: headless automation
- Process interface → Process manager: process control
