# cline/kanban architecture

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

- Interactive diagram: https://gitdiagram.com/cline/kanban
- Repository: https://github.com/cline/kanban

## Overview

1. **What this repo is**
   Kanban is a local, repo-scoped agent orchestration tool. You run it from the root of an existing git repo; it starts a Node-based runtime server and opens a browser UI. The main product boundary is between the backend runtime that manages workspaces, tasks, terminals, and git state, and the React/Vite web UI that renders the board and controls.

2. **Top-level architecture**
   The repository is effectively split into two applications:
   - `src/`: the local runtime, CLI entrypoint, task/worktree orchestration, agent integrations, and APIs
   - `web-ui/`: the browser client, with board UI, detail panels, terminal controls, git views, and settings
   Supporting code includes tests, release tooling, docs, and CI workflows, but the core architecture lives in those two packages.

3. **Core domain model: projects, tasks, and boards**
   The central business object is a task card on a kanban board. Cards belong to a project/workspace, can be linked into dependency chains, and transition through states like active, reviewed, trash, or completed. Board-specific logic lives in `src/core/task-board-mutations.ts`, `src/core/kanban-command.ts`, and the matching UI state in `web-ui/src/state/board-state.ts` and drag-rule helpers.

4. **Workspace and git isolation**
   A major architectural feature is that each task runs in its own git worktree. The workspace layer handles cloning, initializing, syncing, history inspection, path sandboxing, and worktree path resolution. This isolation is what lets Kanban run many agents in parallel without merge conflicts. Files like `src/workspace/task-worktree.ts`, `git-sync.ts`, `git-history.ts`, and `path-sandbox.ts` define that boundary, while the UI exposes worktree-aware views and git history panels.

5. **Terminal and agent execution subsystem**
   Agent execution is centered around terminal sessions backed by PTYs. The backend manages terminal lifecycles, session state machines, state mirroring, output filtering, and websocket transport. Key pieces are `src/terminal/pty-session.ts`, `session-manager.ts`, `session-state-machine.ts`, `terminal-session-service.ts`, and `ws-server.ts`. On the UI side, persistent terminals and session geometry are managed separately so users can keep a stable terminal experience across reloads.

6. **CLI agent integration layer**
   Kanban supports multiple external CLI agents rather than implementing its own model runtime. The `src/terminal/agent-registry.ts`, `agent-session-adapters.ts`, and `commands/hook-events/*` files show the adapter-based design for different agents such as Codex, Kiro, Droid, and related hook/event formats. This layer normalizes agent output, tool calls, and hook data into a common runtime shape so the board can show “latest message” or tool activity per task.

7. **Cline SDK bridge**
   There is a dedicated integration boundary under `src/cline-sdk/` for Cline-specific runtime behavior. This includes provider/runtime/session services, message storage, telemetry, slash commands, and event adapters. Architecturally, this acts as a compatibility layer between Kanban’s own task/worktree model and the Cline agent/runtime abstractions used by the product’s sidebar chat and task automation features.

8. **Backend API and state distribution**
   The browser talks to the runtime through a typed API surface built with tRPC and websocket state streaming. The routers in `src/trpc/` expose project, workspace, runtime, and hooks operations, while `src/server/runtime-state-hub.ts` and `runtime-server.ts` push live state updates to the UI. This split lets the UI query authoritative state, then subscribe to incremental updates for task progress, workspace changes, terminal state, and runtime events.

9. **Security, workspace access, and shutdown**
   The runtime includes explicit boundaries for local access and safe lifecycle management. Passcode/auth handling gates websocket upgrade and runtime access, workspace metadata monitors track available repos, and shutdown coordination ensures terminals, sessions, and child processes are cleaned up coherently. These concerns are handled in `src/security/passcode-manager.ts`, `src/server/shutdown-coordinator.ts`, `src/server/process-termination.ts`, and related runtime shutdown utilities.

10. **Web UI composition**
   The UI is a single-page React app with substantial domain-specific panels: kanban board, task detail view, diff viewer, git history, terminal panels, onboarding, runtime settings, and project navigation. Its internal data flow is built around runtime hooks (`web-ui/src/runtime/*` and `web-ui/src/hooks/*`) that consume tRPC queries, runtime streams, and local persistence. This is where the product experience is assembled, but it delegates all authoritative state changes to the backend runtime.

11. **Persistence and local state**
   Persistent state is split between backend-managed workspace/task state and frontend-local preferences. Backend state covers task/workspace metadata, runtime session state, and terminal state mirrors; frontend state covers UI layout, resizing, onboarding, theme, and local storage. The separation is deliberate so the board can reload and reconnect without losing the underlying task execution model.

12. **Telemetry, update, and release tooling**
   The repo includes optional product telemetry and release automation, but these are supporting concerns rather than core runtime dependencies. Sentry/PostHog/Featurebase integration lives mostly in the web UI and telemetry modules, while auto-update, CI, publish workflows, changelog extraction, and release commands are managed in `scripts/`, `.github/workflows/`, and release docs. These affect deployment and observability, not the main control flow of task execution.

13. **How data flows end to end**
   The typical flow is: user opens a repo → CLI starts local runtime server → UI connects and loads board/workspace state → user creates or starts a task → backend creates a task-specific worktree and terminal session → agent runs through the terminal/hook adapter layer → runtime streams status, output, and diffs back to the UI → user reviews, commits, or chains the next linked task. That loop is the core architecture to capture in any diagram.

14. **Important architectural boundary to diagram**
   The most important boundary is between the browser-facing UI and the local execution engine. Everything that mutates git, launches terminals, or talks to agents stays in the Node runtime; everything that presents the board, diffs, and controls stays in `web-ui/`. The worktree-per-task model sits at the center of that boundary and is the reason the system can run many autonomous tasks in parallel.

Main entry points: [`src/server/runtime-server.ts`](https://github.com/cline/kanban/blob/main/src/server/runtime-server.ts) (Runtime server), [`web-ui/src/App.tsx`](https://github.com/cline/kanban/blob/main/web-ui/src/App.tsx) (App shell), [`web-ui/src/runtime/use-runtime-state-stream.ts`](https://github.com/cline/kanban/blob/main/web-ui/src/runtime/use-runtime-state-stream.ts) (Runtime hooks), [`src/workspace/task-worktree.ts`](https://github.com/cline/kanban/blob/main/src/workspace/task-worktree.ts) (Workspace layer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Node runtime"]
  node_cli["CLI<br/>entrypoint<br/>[cli.ts]"]
  node_runtime_server["Runtime server<br/>http/ws server<br/>[runtime-server.ts]"]
  node_state_hub(("State hub<br/>live state stream"))
  node_trpc_api["tRPC API<br/>typed API<br/>[app-router.ts]"]
  node_workspace_layer[("Workspace layer<br/>git/worktree orchestration<br/>[task-worktree.ts]")]
  node_board_core["Board core<br/>task model"]
  node_terminal_core["Terminal core<br/>pty/session runtime"]
  node_agent_adapters["Agent adapters<br/>cli integration"]
  node_cline_bridge["Cline bridge<br/>compatibility layer"]
  node_workspace_state["Workspace state<br/>local runtime state<br/>[workspace-state.ts]"]
end

subgraph group_frontend["Web UI"]
  node_web_app["App shell<br/>react entrypoint<br/>[App.tsx]"]
  node_board_ui["Board UI<br/>kanban surface<br/>[kanban-board.tsx]"]
  node_detail_views["Detail panels<br/>task detail area"]
  node_git_views["Git views<br/>review surface"]
  node_terminal_ui["Terminal UI<br/>persistent terminal"]
  node_runtime_hooks["Runtime hooks<br/>data/runtime layer"]
  node_board_state["Board state<br/>ui state<br/>[board-state.ts]"]
  node_local_persistence["Local persistence<br/>browser storage"]
end

subgraph group_support["Supporting code"]
  node_passcode(("Access gate<br/>security"))
  node_shutdown["Shutdown coordinator<br/>lifecycle control"]
  node_update["Updater<br/>release/update<br/>[update.ts]"]
end

node_cli -->|"starts"| node_runtime_server
node_runtime_server -->|"gates"| node_passcode
node_runtime_server -->|"publishes"| node_state_hub
node_runtime_server -->|"serves"| node_trpc_api
node_runtime_server -->|"orchestrates"| node_workspace_layer
node_runtime_server -->|"runs"| node_terminal_core
node_runtime_server -->|"mutates"| node_board_core
node_runtime_server -->|"adapts"| node_agent_adapters
node_runtime_server -->|"bridges"| node_cline_bridge
node_runtime_server -->|"persists"| node_workspace_state
node_runtime_server -->|"coordinates"| node_shutdown
node_runtime_server -->|"checks"| node_update
node_workspace_layer -->|"feeds"| node_board_core
node_workspace_layer -->|"isolates"| node_terminal_core
node_agent_adapters -->|"uses"| node_terminal_core
node_cline_bridge -->|"normalizes"| node_agent_adapters
node_trpc_api -->|"queries"| node_web_app
node_state_hub -->|"streams"| node_runtime_hooks
node_web_app -->|"renders"| node_board_ui
node_web_app -->|"renders"| node_detail_views
node_web_app -->|"renders"| node_git_views
node_web_app -->|"contains"| node_terminal_ui
node_web_app -->|"consumes"| node_runtime_hooks
node_board_ui -->|"uses"| node_board_state
node_detail_views -->|"reads"| node_board_state
node_git_views -->|"loads"| node_runtime_hooks
node_terminal_ui -->|"stores"| node_local_persistence
node_runtime_hooks -->|"syncs"| node_local_persistence

click node_cli "https://github.com/cline/kanban/blob/main/src/cli.ts"
click node_runtime_server "https://github.com/cline/kanban/blob/main/src/server/runtime-server.ts"
click node_state_hub "https://github.com/cline/kanban/blob/main/src/server/runtime-state-hub.ts"
click node_trpc_api "https://github.com/cline/kanban/blob/main/src/trpc/app-router.ts"
click node_workspace_layer "https://github.com/cline/kanban/blob/main/src/workspace/task-worktree.ts"
click node_board_core "https://github.com/cline/kanban/blob/main/src/core/task-board-mutations.ts"
click node_terminal_core "https://github.com/cline/kanban/blob/main/src/terminal/terminal-session-service.ts"
click node_agent_adapters "https://github.com/cline/kanban/blob/main/src/terminal/agent-session-adapters.ts"
click node_cline_bridge "https://github.com/cline/kanban/blob/main/src/cline-sdk/cline-session-runtime.ts"
click node_workspace_state "https://github.com/cline/kanban/blob/main/src/state/workspace-state.ts"
click node_passcode "https://github.com/cline/kanban/blob/main/src/security/passcode-manager.ts"
click node_shutdown "https://github.com/cline/kanban/blob/main/src/server/shutdown-coordinator.ts"
click node_update "https://github.com/cline/kanban/blob/main/src/update/update.ts"
click node_web_app "https://github.com/cline/kanban/blob/main/web-ui/src/App.tsx"
click node_board_ui "https://github.com/cline/kanban/blob/main/web-ui/src/components/kanban-board.tsx"
click node_detail_views "https://github.com/cline/kanban/blob/main/web-ui/src/components/card-detail-view.tsx"
click node_git_views "https://github.com/cline/kanban/blob/main/web-ui/src/components/git-history-view.tsx"
click node_terminal_ui "https://github.com/cline/kanban/blob/main/web-ui/src/terminal/persistent-terminal-manager.ts"
click node_runtime_hooks "https://github.com/cline/kanban/blob/main/web-ui/src/runtime/use-runtime-state-stream.ts"
click node_board_state "https://github.com/cline/kanban/blob/main/web-ui/src/state/board-state.ts"
click node_local_persistence "https://github.com/cline/kanban/blob/main/web-ui/src/storage/local-storage-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_cli,node_runtime_server,node_state_hub,node_trpc_api,node_workspace_layer,node_board_core,node_terminal_core,node_agent_adapters,node_cline_bridge,node_workspace_state toneBlue
class node_web_app,node_board_ui,node_detail_views,node_git_views,node_terminal_ui,node_runtime_hooks,node_board_state,node_local_persistence toneAmber
class node_passcode,node_shutdown,node_update toneMint
```

## Components

### Node runtime

Local execution engine, git/worktree orchestration, agents, and API server.

- [CLI](https://github.com/cline/kanban/blob/main/src/cli.ts): entrypoint · Starts the local runtime from a repo root. · `src/cli.ts`
- [Runtime server](https://github.com/cline/kanban/blob/main/src/server/runtime-server.ts): http/ws server · Hosts the local API, browser transport, and runtime lifecycle. · `src/server/runtime-server.ts`
- [State hub](https://github.com/cline/kanban/blob/main/src/server/runtime-state-hub.ts): live state stream · Broadcasts authoritative runtime state to the UI. · `src/server/runtime-state-hub.ts`
- [tRPC API](https://github.com/cline/kanban/blob/main/src/trpc/app-router.ts): typed API · Project, workspace, runtime, and hooks routers. · `src/trpc/app-router.ts`
- [Workspace layer](https://github.com/cline/kanban/blob/main/src/workspace/task-worktree.ts): git/worktree orchestration · Clone, sync, sandbox, inspect, and resolve task-specific worktrees. · `src/workspace/task-worktree.ts`
- [Board core](https://github.com/cline/kanban/blob/main/src/core/task-board-mutations.ts): task model · Defines task cards, board mutations, commands, and task state transitions. · `src/core/task-board-mutations.ts`
- [Terminal core](https://github.com/cline/kanban/blob/main/src/terminal/terminal-session-service.ts): pty/session runtime · Manages PTY sessions, session state, output filtering, and websocket transport. · `src/terminal/terminal-session-service.ts`
- [Agent adapters](https://github.com/cline/kanban/blob/main/src/terminal/agent-session-adapters.ts): cli integration · Normalizes external agent CLIs and hook events into Kanban's runtime shape. · `src/terminal/agent-session-adapters.ts`
- [Cline bridge](https://github.com/cline/kanban/blob/main/src/cline-sdk/cline-session-runtime.ts): compatibility layer · Dedicated SDK/runtime boundary for Cline-specific messaging, telemetry, and sessions. · `src/cline-sdk/cline-session-runtime.ts`
- [Workspace state](https://github.com/cline/kanban/blob/main/src/state/workspace-state.ts): local runtime state · Backend-managed workspace metadata and runtime session state. · `src/state/workspace-state.ts`

### Web UI

React/Vite application that renders the board and controls.

- [App shell](https://github.com/cline/kanban/blob/main/web-ui/src/App.tsx): react entrypoint · Bootstraps the browser client and top-level providers. · `web-ui/src/App.tsx`
- [Board UI](https://github.com/cline/kanban/blob/main/web-ui/src/components/kanban-board.tsx): kanban surface · Renders the board, cards, columns, and drag interactions. · `web-ui/src/components/kanban-board.tsx`
- [Detail panels](https://github.com/cline/kanban/blob/main/web-ui/src/components/card-detail-view.tsx): task detail area · Shows diffs, chat, file tree, history, and agent terminal panels. · `web-ui/src/components/card-detail-view.tsx`
- [Git views](https://github.com/cline/kanban/blob/main/web-ui/src/components/git-history-view.tsx): review surface · Displays commit history, refs, and diff inspection tools. · `web-ui/src/components/git-history-view.tsx`
- [Terminal UI](https://github.com/cline/kanban/blob/main/web-ui/src/terminal/persistent-terminal-manager.ts): persistent terminal · Keeps terminal sessions and geometry stable across reloads. · `web-ui/src/terminal/persistent-terminal-manager.ts`
- [Runtime hooks](https://github.com/cline/kanban/blob/main/web-ui/src/runtime/use-runtime-state-stream.ts): data/runtime layer · Client-side hooks for tRPC queries, state streams, and workspace sync. · `web-ui/src/runtime/use-runtime-state-stream.ts`
- [Board state](https://github.com/cline/kanban/blob/main/web-ui/src/state/board-state.ts): ui state · Client-side board model and drag rules for task movement. · `web-ui/src/state/board-state.ts`
- [Local persistence](https://github.com/cline/kanban/blob/main/web-ui/src/storage/local-storage-store.ts): browser storage · Stores UI preferences, layout, and workspace-local browser state. · `web-ui/src/storage/local-storage-store.ts`

### Supporting code

Security, telemetry, update, and release-related subsystems.

- [Access gate](https://github.com/cline/kanban/blob/main/src/security/passcode-manager.ts): security · Passcode-based local access control for runtime and websocket upgrades. · `src/security/passcode-manager.ts`
- [Shutdown coordinator](https://github.com/cline/kanban/blob/main/src/server/shutdown-coordinator.ts): lifecycle control · Coordinates terminal, process, and server shutdown. · `src/server/shutdown-coordinator.ts`
- [Updater](https://github.com/cline/kanban/blob/main/src/update/update.ts): release/update · Handles auto-update checks and application updates. · `src/update/update.ts`

## Connections

- CLI → Runtime server: starts · Launches the local Node runtime and serves the browser app.
- Runtime server → Access gate: gates · Protects local access and websocket upgrades.
- Runtime server → State hub: publishes · Streams live runtime state to connected clients.
- Runtime server → tRPC API: serves · Exposes typed queries and mutations to the UI.
- Runtime server → Workspace layer: orchestrates · Coordinates task worktrees, sync, and repo inspection.
- Runtime server → Terminal core: runs · Manages PTY-backed task sessions and websocket transport.
- Runtime server → Board core: mutates · Applies board actions and task lifecycle changes.
- Runtime server → Agent adapters: adapts · Normalizes hook/event formats from external agent CLIs.
- Runtime server → Cline bridge: bridges · Connects Kanban task execution to Cline SDK abstractions.
- Runtime server → Workspace state: persists · Maintains authoritative workspace and runtime session state.
- Runtime server → Shutdown coordinator: coordinates · Cleans up terminals, sessions, and child processes.
- Runtime server → Updater: checks · Supports optional update and release flows.
- Workspace layer → Board core: feeds · Task/worktree state underpins board transitions and dependencies.
- Workspace layer → Terminal core: isolates · Creates per-task worktrees for parallel execution.
- Agent adapters → Terminal core: uses · Runs agents through terminal sessions and hook payloads.
- Cline bridge → Agent adapters: normalizes · Maps Cline runtime behavior into the common agent execution model.
- tRPC API → App shell: queries · Provides authoritative data and commands to the browser client.
- State hub → Runtime hooks: streams · Delivers incremental task, workspace, and terminal updates.
- App shell → Board UI: renders · Composes the main kanban surface.
- App shell → Detail panels: renders · Shows task-specific panels and inspectors.
- App shell → Git views: renders · Surfaces commit history and diff review views.
- App shell → Terminal UI: contains · Hosts persistent terminal panels and session controls.
- App shell → Runtime hooks: consumes · Uses hooks for tRPC, runtime streams, and workspace sync.
- Board UI → Board state: uses · Applies client-side task ordering and drag rules.
- Detail panels → Board state: reads · Follows the selected task and board context.
- Git views → Runtime hooks: loads · Fetches history and diff data from the runtime.
- Terminal UI → Local persistence: stores · Keeps geometry and session preferences across reloads.
- Runtime hooks → Local persistence: syncs · Caches UI and workspace-local browser state.
