# unohee/openswarm architecture

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

- Interactive diagram: https://gitdiagram.com/unohee/openswarm
- Repository: https://github.com/unohee/openswarm

## Overview

1. **What this repository is**
   OpenSwarm is a Node.js/TypeScript orchestrator for autonomous coding agents. Its job is not to implement one agent, but to coordinate many agent runs, route tasks from external systems, manage execution state, and persist memory/history across sessions.

2. **Top-level execution modes**
   The repo has two main operating shapes: a direct CLI/TUI experience for interactive use, and a daemon mode for autonomous operation. `src/index.ts` and `src/cli.ts` are the entry points for commands like `chat`, `run`, `exec`, `start`, `init`, and `validate`. The default `openswarm` command launches a terminal chat UI, while daemon mode powers scheduled work and integrations.

3. **Core configuration and service lifecycle**
   `src/core/` holds the foundational runtime boundary: config loading/validation, service startup/shutdown, event hub, tracing, and shared types. Configuration is YAML-driven with environment substitution, so most subsystems are wired from a central config rather than hardcoded. This layer is the control plane for the rest of the system.

4. **Provider abstraction for agent execution**
   `src/adapters/` is the key boundary between OpenSwarm and the external AI CLIs. It abstracts over Claude Code CLI and OpenAI Codex CLI, plus process registration and stream buffering. This means the orchestration layers above it can ask for “worker” or “reviewer” behavior without caring which CLI provider is executing underneath.

5. **Agent pipeline as the main work unit**
   `src/agents/` defines the actual role-based execution pipeline: worker, reviewer, tester, documenter, and auditor. The central flow is `pairPipeline.ts`, which runs Worker → Reviewer, with optional Tester and Documenter stages. `agentBus.ts` and related helpers coordinate message passing, review outcomes, stream parsing, and metrics across those roles.

6. **Autonomous daemon and scheduling**
   `src/automation/` is where unattended operation lives. The autonomous runner, scheduler, PR processor, long-running monitor, and conflict resolution logic combine to repeatedly pick up work, execute it, and recover from failures. This subsystem is what turns the project from a chat tool into a background agent service.

7. **Task selection and workflow control**
   `src/orchestration/` acts as the policy layer. It parses tasks, detects conflicts, schedules work, and decides what is safe to run next. The `decisionEngine` and related workflow code are the guardrails that keep tasks scoped, prioritized, and non-overlapping before they reach the agent pipeline.

8. **External system integrations**
   `src/linear/`, `src/discord/`, and `src/github/` are the main integration boundaries. Linear supplies issues and project state, Discord is the command-and-control surface for monitoring and runtime actions, and GitHub is used mainly for CI and PR status monitoring. These integrations feed tasks into the orchestrator and receive progress/results back out.

9. **Memory and knowledge subsystems**
   OpenSwarm has two distinct long-term cognition layers. `src/memory/` stores retrieved experience and beliefs using LanceDB-style vector memory and compaction logic, while `src/knowledge/` builds a static analysis graph of the repository for dependency and impact reasoning. In practice, memory is about “what happened before,” and knowledge is about “what code is connected to what.”

10. **Support tooling and local operator experience**
    `src/support/` contains the operator-facing utilities: TUI/dashboard rendering, chat backends, Git/worktree management, rollback, rate/quota tracking, and stuck detection. This is the glue that makes the system usable in local or semi-local execution, especially when tasks are running in separate worktrees or need recovery.

11. **State persistence and task rehydration**
    Runtime state is persisted in several places: a user state directory under `~/.openswarm/`, Claude/OpenSwarm JSON history files, and the config file. There is also a dedicated `src/taskState/` store and a Python model file for task-state modeling. The architecture therefore keeps short-lived execution state, long-lived memory, and task history as separate concerns.

12. **Locale, templates, and prompt composition**
    `src/locale/` and `templates/` are not just text assets; they are part of how the agent system is instructed and standardized. They provide localized prompts and role templates for bootstrapping agents, reviewing work, analyzing issues, and generating reports. This is an important boundary because prompt content is treated as a first-class runtime input.

13. **Operational packaging**
    The repo includes Docker, docker-compose, and macOS launchd scripts, which means it supports both containerized and native service deployment. Those files do not change the core architecture, but they matter for diagramming the runtime environment: the daemon can run as a long-lived service with external CLI tooling installed on the host.

14. **Primary data flow**
    The main flow is: Linear issues or Discord commands enter the system → orchestration/decision logic selects and scopes work → the agent pipeline runs through a provider adapter → results are written back to issue/task state, memory, and possibly GitHub/Discord updates. That loop is the architectural center of the repo, with memory/knowledge providing context and automation/scheduling keeping it running continuously.

Main entry points: [`src/agents/pairPipeline.ts`](https://github.com/unohee/openswarm/blob/main/src/agents/pairPipeline.ts) (Pair pipeline), [`src/automation/autonomousRunner.ts`](https://github.com/unohee/openswarm/blob/main/src/automation/autonomousRunner.ts) (Autonomous runner), [`src/orchestration/decisionEngine.ts`](https://github.com/unohee/openswarm/blob/main/src/orchestration/decisionEngine.ts) (Decision engine), [`src/core/service.ts`](https://github.com/unohee/openswarm/blob/main/src/core/service.ts) (Service lifecycle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_entry["Entry points"]
  node_src_index(("Main entry<br/>entrypoint<br/>[index.ts]"))
  node_src_cli["CLI commands<br/>command router<br/>[cli.ts]"]
  node_src_cli_prompt["Prompt handler<br/>prompt input<br/>[promptHandler.ts]"]
end

subgraph group_group_core["Core runtime"]
  node_core_config["Config<br/>[config.ts]"]
  node_core_service["Service lifecycle<br/>[service.ts]"]
  node_core_eventhub(("Event hub<br/>event bus<br/>[eventHub.ts]"))
  node_core_trace["Tracing<br/>telemetry<br/>[traceCollector.ts]"]
  node_core_types["Shared types<br/>contracts<br/>[types.ts]"]
end

subgraph group_group_agents["Agent pipeline"]
  node_adapters_index["Adapter layer<br/>provider facade<br/>[index.ts]"]
  node_adapters_claude["Claude CLI<br/>provider adapter<br/>[claude.ts]"]
  node_adapters_codex["Codex CLI<br/>provider adapter<br/>[codex.ts]"]
  node_agents_pipeline["Pair pipeline<br/>execution pipeline<br/>[pairPipeline.ts]"]
  node_agents_worker["Worker<br/>role<br/>[worker.ts]"]
  node_agents_reviewer["Reviewer<br/>role<br/>[reviewer.ts]"]
  node_agents_tester["Tester<br/>role<br/>[tester.ts]"]
  node_agents_documenter["Documenter<br/>role<br/>[documenter.ts]"]
  node_agents_bus(("Agent bus<br/>message coordination<br/>[agentBus.ts]"))
end

subgraph group_group_ops["Autonomy and ops"]
  node_orch_decision["Decision engine<br/>policy<br/>[decisionEngine.ts]"]
  node_orch_scheduler["Task scheduler<br/>workflow control<br/>[taskScheduler.ts]"]
  node_auto_runner["Autonomous runner<br/>daemon runtime"]
  node_auto_scheduler["Automation scheduler<br/>daemon scheduling<br/>[scheduler.ts]"]
  node_auto_monitor["Monitor<br/>health loop"]
end

subgraph group_group_integrations["Integrations"]
  node_discord_core["Discord core<br/>integration<br/>[discordCore.ts]"]
  node_github_api["GitHub<br/>integration<br/>[github.ts]"]
  node_linear_api["Linear<br/>integration<br/>[linear.ts]"]
  node_support_ops["Support tools<br/>operator tooling<br/>[index.ts]"]
end

subgraph group_group_context["Context systems"]
  node_memory_core[("Memory core<br/>persistent memory<br/>[memoryCore.ts]")]
  node_memory_compaction["Compaction<br/>memory maintenance<br/>[compaction.ts]"]
  node_knowledge_graph{{"Knowledge graph<br/>repo graph<br/>[graph.ts]"}}
  node_locale_prompts["Prompt templates<br/>prompt assets<br/>[en.ts]"]
  node_task_state[("Task state<br/>state store<br/>[store.ts]")]
end

node_src_index -->|"starts"| node_src_cli
node_src_cli -->|"interactive input"| node_src_cli_prompt
node_src_cli -->|"loads"| node_core_config
node_core_service -->|"publishes"| node_core_eventhub
node_core_service -->|"traces"| node_core_trace
node_core_service -->|"uses"| node_core_types
node_adapters_index -->|"selects"| node_adapters_claude
node_adapters_index -->|"selects"| node_adapters_codex
node_agents_pipeline -->|"runs"| node_agents_worker
node_agents_pipeline -->|"reviews"| node_agents_reviewer
node_agents_pipeline -.->|"optional"| node_agents_tester
node_agents_pipeline -.->|"optional"| node_agents_documenter
node_agents_worker -->|"executes via"| node_adapters_index
node_agents_reviewer -->|"reports"| node_agents_bus
node_agents_worker -->|"streams"| node_agents_bus
node_orch_decision -->|"orders"| node_orch_scheduler
node_auto_runner -->|"requests"| node_orch_decision
node_auto_scheduler -->|"drives"| node_auto_runner
node_auto_monitor -->|"watches"| node_auto_runner
node_discord_core -->|"commands"| node_orch_decision
node_linear_api -->|"feeds tasks"| node_orch_scheduler
node_github_api -->|"status"| node_auto_monitor
node_support_ops -->|"powers"| node_src_cli_prompt
node_support_ops -->|"persists"| node_task_state
node_memory_core -->|"maintains"| node_memory_compaction
node_agents_pipeline -->|"writes context"| node_memory_core
node_knowledge_graph -->|"informs"| node_orch_decision
node_locale_prompts -->|"templates"| node_agents_pipeline
node_task_state -->|"rehydrates"| node_auto_runner
node_core_config -->|"configures"| node_auto_runner

click node_src_index "https://github.com/unohee/openswarm/blob/main/src/index.ts"
click node_src_cli "https://github.com/unohee/openswarm/blob/main/src/cli.ts"
click node_src_cli_prompt "https://github.com/unohee/openswarm/blob/main/src/cli/promptHandler.ts"
click node_core_config "https://github.com/unohee/openswarm/blob/main/src/core/config.ts"
click node_core_service "https://github.com/unohee/openswarm/blob/main/src/core/service.ts"
click node_core_eventhub "https://github.com/unohee/openswarm/blob/main/src/core/eventHub.ts"
click node_core_trace "https://github.com/unohee/openswarm/blob/main/src/core/traceCollector.ts"
click node_core_types "https://github.com/unohee/openswarm/blob/main/src/core/types.ts"
click node_adapters_index "https://github.com/unohee/openswarm/blob/main/src/adapters/index.ts"
click node_adapters_claude "https://github.com/unohee/openswarm/blob/main/src/adapters/claude.ts"
click node_adapters_codex "https://github.com/unohee/openswarm/blob/main/src/adapters/codex.ts"
click node_agents_pipeline "https://github.com/unohee/openswarm/blob/main/src/agents/pairPipeline.ts"
click node_agents_worker "https://github.com/unohee/openswarm/blob/main/src/agents/worker.ts"
click node_agents_reviewer "https://github.com/unohee/openswarm/blob/main/src/agents/reviewer.ts"
click node_agents_tester "https://github.com/unohee/openswarm/blob/main/src/agents/tester.ts"
click node_agents_documenter "https://github.com/unohee/openswarm/blob/main/src/agents/documenter.ts"
click node_agents_bus "https://github.com/unohee/openswarm/blob/main/src/agents/agentBus.ts"
click node_orch_decision "https://github.com/unohee/openswarm/blob/main/src/orchestration/decisionEngine.ts"
click node_orch_scheduler "https://github.com/unohee/openswarm/blob/main/src/orchestration/taskScheduler.ts"
click node_auto_runner "https://github.com/unohee/openswarm/blob/main/src/automation/autonomousRunner.ts"
click node_auto_scheduler "https://github.com/unohee/openswarm/blob/main/src/automation/scheduler.ts"
click node_auto_monitor "https://github.com/unohee/openswarm/blob/main/src/automation/longRunningMonitor.ts"
click node_discord_core "https://github.com/unohee/openswarm/blob/main/src/discord/discordCore.ts"
click node_github_api "https://github.com/unohee/openswarm/blob/main/src/github/github.ts"
click node_linear_api "https://github.com/unohee/openswarm/blob/main/src/linear/linear.ts"
click node_support_ops "https://github.com/unohee/openswarm/blob/main/src/support/index.ts"
click node_memory_core "https://github.com/unohee/openswarm/blob/main/src/memory/memoryCore.ts"
click node_memory_compaction "https://github.com/unohee/openswarm/blob/main/src/memory/compaction.ts"
click node_knowledge_graph "https://github.com/unohee/openswarm/blob/main/src/knowledge/graph.ts"
click node_locale_prompts "https://github.com/unohee/openswarm/blob/main/src/locale/prompts/en.ts"
click node_task_state "https://github.com/unohee/openswarm/blob/main/src/taskState/store.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_src_index,node_src_cli,node_src_cli_prompt toneBlue
class node_core_config,node_core_service,node_core_eventhub,node_core_trace,node_core_types toneAmber
class node_adapters_index,node_adapters_claude,node_adapters_codex,node_agents_pipeline,node_agents_worker,node_agents_reviewer,node_agents_tester,node_agents_documenter,node_agents_bus toneMint
class node_orch_decision,node_orch_scheduler,node_auto_runner,node_auto_scheduler,node_auto_monitor toneRose
class node_discord_core,node_github_api,node_linear_api,node_support_ops toneIndigo
class node_memory_core,node_memory_compaction,node_knowledge_graph,node_locale_prompts,node_task_state toneTeal
```

## Components

### Entry points

CLI and command startup paths

- [Main entry](https://github.com/unohee/openswarm/blob/main/src/index.ts): entrypoint · Top-level Node.js launch path for the application · `src/index.ts`
- [CLI commands](https://github.com/unohee/openswarm/blob/main/src/cli.ts): command router · Dispatches interactive and utility commands such as chat, run, exec, start, init, and validate · `src/cli.ts`
- [Prompt handler](https://github.com/unohee/openswarm/blob/main/src/cli/promptHandler.ts): prompt input · Handles interactive command input for the TUI/CLI experience · `src/cli/promptHandler.ts`

### Core runtime

Configuration, lifecycle, tracing, and shared services

- [Config](https://github.com/unohee/openswarm/blob/main/src/core/config.ts): runtime config · Loads and validates YAML-driven configuration with environment substitution · `src/core/config.ts`
- [Service lifecycle](https://github.com/unohee/openswarm/blob/main/src/core/service.ts): lifecycle · Starts, wires, and shuts down core services · `src/core/service.ts`
- [Event hub](https://github.com/unohee/openswarm/blob/main/src/core/eventHub.ts): event bus · Shared internal event distribution and coordination · `src/core/eventHub.ts`
- [Tracing](https://github.com/unohee/openswarm/blob/main/src/core/traceCollector.ts): telemetry · Collects traces and runtime diagnostics · `src/core/traceCollector.ts`
- [Shared types](https://github.com/unohee/openswarm/blob/main/src/core/types.ts): contracts · Common runtime types and interfaces · `src/core/types.ts`

### Agent pipeline

Role-based execution and message flow

- [Adapter layer](https://github.com/unohee/openswarm/blob/main/src/adapters/index.ts): provider facade · Exports the execution provider abstraction used by higher layers · `src/adapters/index.ts`
- [Claude CLI](https://github.com/unohee/openswarm/blob/main/src/adapters/claude.ts): provider adapter · Adapter for Claude Code CLI execution · `src/adapters/claude.ts`
- [Codex CLI](https://github.com/unohee/openswarm/blob/main/src/adapters/codex.ts): provider adapter · Adapter for OpenAI Codex CLI execution · `src/adapters/codex.ts`
- [Pair pipeline](https://github.com/unohee/openswarm/blob/main/src/agents/pairPipeline.ts): execution pipeline · Coordinates Worker → Reviewer with optional Tester and Documenter stages · `src/agents/pairPipeline.ts`
- [Worker](https://github.com/unohee/openswarm/blob/main/src/agents/worker.ts): role · Primary task execution role · `src/agents/worker.ts`
- [Reviewer](https://github.com/unohee/openswarm/blob/main/src/agents/reviewer.ts): role · Validates and critiques worker output · `src/agents/reviewer.ts`
- [Tester](https://github.com/unohee/openswarm/blob/main/src/agents/tester.ts): role · Runs verification-oriented agent work · `src/agents/tester.ts`
- [Documenter](https://github.com/unohee/openswarm/blob/main/src/agents/documenter.ts): role · Produces documentation and summaries · `src/agents/documenter.ts`
- [Agent bus](https://github.com/unohee/openswarm/blob/main/src/agents/agentBus.ts): message coordination · Moves messages, outcomes, and metrics across agent roles · `src/agents/agentBus.ts`

### Autonomy and ops

Scheduling, daemon execution, and service management

- [Decision engine](https://github.com/unohee/openswarm/blob/main/src/orchestration/decisionEngine.ts): policy · Chooses what tasks are safe and ready to run · `src/orchestration/decisionEngine.ts`
- [Task scheduler](https://github.com/unohee/openswarm/blob/main/src/orchestration/taskScheduler.ts): workflow control · Orders and schedules work items before execution · `src/orchestration/taskScheduler.ts`
- [Autonomous runner](https://github.com/unohee/openswarm/blob/main/src/automation/autonomousRunner.ts): daemon runtime · Long-running unattended execution loop · `src/automation/autonomousRunner.ts`
- [Automation scheduler](https://github.com/unohee/openswarm/blob/main/src/automation/scheduler.ts): daemon scheduling · Repeating scheduling and handoff for background work · `src/automation/scheduler.ts`
- [Monitor](https://github.com/unohee/openswarm/blob/main/src/automation/longRunningMonitor.ts): health loop · Observes long-running activity and recovers from failures · `src/automation/longRunningMonitor.ts`

### Integrations

External systems and host-facing surfaces

- [Discord core](https://github.com/unohee/openswarm/blob/main/src/discord/discordCore.ts): integration · Discord command and event surface · `src/discord/discordCore.ts`
- [GitHub](https://github.com/unohee/openswarm/blob/main/src/github/github.ts): integration · GitHub status and PR-facing integration · `src/github/github.ts`
- [Linear](https://github.com/unohee/openswarm/blob/main/src/linear/linear.ts): integration · Issue and project source for tasks · `src/linear/linear.ts`
- [Support tools](https://github.com/unohee/openswarm/blob/main/src/support/index.ts): operator tooling · TUI, chat, worktree, rollback, quota, and recovery utilities · `src/support/index.ts`

### Context systems

Memory, knowledge, and prompt assets

- [Memory core](https://github.com/unohee/openswarm/blob/main/src/memory/memoryCore.ts): persistent memory · Stores retrieved experience and beliefs across sessions · `src/memory/memoryCore.ts`
- [Compaction](https://github.com/unohee/openswarm/blob/main/src/memory/compaction.ts): memory maintenance · Compresses and maintains long-term memory state · `src/memory/compaction.ts`
- [Knowledge graph](https://github.com/unohee/openswarm/blob/main/src/knowledge/graph.ts): repo graph · Builds repository dependency and impact context · `src/knowledge/graph.ts`
- [Prompt templates](https://github.com/unohee/openswarm/blob/main/src/locale/prompts/en.ts): prompt assets · Localized role templates and bootstrap prompts · `src/locale/prompts/en.ts`
- [Task state](https://github.com/unohee/openswarm/blob/main/src/taskState/store.ts): state store · Dedicated persistent store for task rehydration and runtime state · `src/taskState/store.ts`

## Connections

- Main entry → CLI commands: starts · Main entry hands control to command routing
- CLI commands → Prompt handler: interactive input · CLI delegates interactive use to the prompt handler
- CLI commands → Config: loads · Commands read configuration before executing
- Service lifecycle → Event hub: publishes · Service lifecycle wires the internal event hub
- Service lifecycle → Tracing: traces · Lifecycle emits diagnostics through tracing
- Service lifecycle → Shared types: uses · Shared runtime contracts shape service wiring
- Adapter layer → Claude CLI: selects · Provider facade exposes Claude execution
- Adapter layer → Codex CLI: selects · Provider facade exposes Codex execution
- Pair pipeline → Worker: runs · Pipeline begins with worker execution
- Pair pipeline → Reviewer: reviews · Pipeline routes worker output to review
- Pair pipeline → Tester: optional · Some flows add testing before completion
- Pair pipeline → Documenter: optional · Some flows add documentation generation
- Worker → Adapter layer: executes via · Worker delegates model work through the provider layer
- Reviewer → Agent bus: reports · Review results and signals move through the bus
- Worker → Agent bus: streams · Worker progress and outputs are coordinated by the bus
- Decision engine → Task scheduler: orders · Decision layer hands approved work to scheduling
- Autonomous runner → Decision engine: requests · Autonomous execution asks policy what to run next
- Automation scheduler → Autonomous runner: drives · Background scheduler triggers repeated runner cycles
- Monitor → Autonomous runner: watches · Monitoring observes and helps recover the daemon loop
- Discord core → Decision engine: commands · Discord commands enter task policy and control
- Linear → Task scheduler: feeds tasks · Linear issues become scheduled work items
- GitHub → Monitor: status · GitHub checks and PR state feed monitoring
- Support tools → Prompt handler: powers · Operator tooling backs chat and TUI flows
- Support tools → Task state: persists · Support utilities interact with durable task state
- Memory core → Compaction: maintains · Memory maintenance keeps long-term store manageable
- Pair pipeline → Memory core: writes context · Agent outcomes are stored for later recall
- Knowledge graph → Decision engine: informs · Repository knowledge helps decide what is safe or relevant to run
- Prompt templates → Pair pipeline: templates · Prompt assets shape role behavior and bootstrapping
- Task state → Autonomous runner: rehydrates · Persisted task state supports resuming execution
- Config → Autonomous runner: configures · Central config wires autonomous behavior
