# cluesmith/codev architecture

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

- Interactive diagram: https://gitdiagram.com/cluesmith/codev
- Repository: https://github.com/cluesmith/codev

## Overview

1. **Repository shape**
   - This is a TypeScript monorepo for a human-AI development platform, not a single app.
   - The main runtime packages are `packages/codev` (CLI/orchestration), `packages/dashboard` (web UI), `packages/vscode` (editor extension), `packages/core` (shared logic), and `packages/types` (API/SSE/WebSocket contracts).

2. **Top-level product boundary**
   - Codev’s core idea is “specs first”: human-authored context lives in `codev/` or `codev-skeleton/`, then AI agents consume those documents to produce plans, implementations, reviews, and retrospectives.
   - The repo therefore has two distinct layers: the **tooling/runtime** and the **knowledge/process artifacts** that guide work.

3. **CLI and orchestration layer**
   - `packages/codev` is the main distribution package and exposes the user-facing commands (`codev`, `afx`, `consult`, `porch`, `team`).
   - This package orchestrates project initialization, adoption into existing repos, consulting, spawning builders, and protocol-driven workflows.

4. **Agent Farm / `afx` subsystem**
   - The largest subsystem is `packages/codev/src/agent-farm`, which manages autonomous builders and the “architect-builder” workflow.
   - It includes command handlers, local state, a SQLite-backed DB/migrations, terminal/session management, worktree handling, spawning, sending instructions, cleanup, cron/tower support, and server endpoints for the dashboard.
   - Its main boundary is between **local process/worktree control** and **UI/API surfaces** that display or manipulate those sessions.

5. **Terminal and shell process model**
   - Agent Farm persists AI sessions via “shellper” terminal processes in `packages/codev/src/terminal` and related agent-farm utilities.
   - The shell layer is an isolation boundary: each builder gets its own terminal/session and typically its own git worktree, allowing parallel execution with limited interference.

6. **Dashboard frontend**
   - `packages/dashboard` is a Vite/React UI that visualizes the current workspace, builders, terminals, backlog, PRs, team state, open files, analytics, and alerts.
   - It communicates with the Agent Farm backend through SSE and related API endpoints, and it owns the interactive presentation boundary for humans.

7. **VS Code extension**
   - `packages/vscode` is a separate integration layer that embeds Codev workflows inside the editor.
   - It connects to the same backend state and events, adds commands for spawn/send/review/worktree handling, and mirrors parts of the dashboard via VS Code views, terminal adapters, and link providers.

8. **Shared domain logic**
   - `packages/core` holds reusable non-UI business logic such as agent naming, area grouping, auth, workspace helpers, and builder utilities.
   - `packages/types` defines the contracts for HTTP APIs, SSE events, and websocket messages so the CLI, dashboard, and extension stay aligned.

9. **Protocols and content-driven workflows**
   - `codev/protocols` and `codev-skeleton/protocols` define the lifecycle documents and prompts for workflows like `spir`, `air`, `bugfix`, `maintain`, `research`, `spike`, and `release`.
   - These are not just docs; they are the control plane for AI behavior, supplying protocol JSON, builder prompts, consult types, and templates for specs/plans/reviews.

10. **Project-local artifacts**
   - The `codev/` tree stores real project history: specs, plans, reviews, maintain logs, project state, and team notes.
   - `codev-skeleton/` is the installable template that seeds a new project with the same structure, protocols, roles, prompts, and reference docs.

11. **External integrations**
   - The system integrates with Git providers through shell-based forge adapters for GitHub, GitLab, Gitea, and Linear, primarily to read issues/PRs, comment, merge, and inspect state.
   - It also integrates with AI CLIs/models such as Claude Code, Gemini, Codex, and optionally OpenCode, which are treated as pluggable builder/architect shells.
   - Cloud/tower support adds remote access and registration flows for running the dashboard and builders off-machine.

12. **Data flow from idea to merge**
   - The normal flow is: issue/spec → protocol documents → spawn builder in isolated worktree → builder writes code/tests → review/consultation gates → PR creation/merge.
   - Human oversight happens mostly at document review and approval points; the runtime emits status, terminal output, and workspace state back to dashboard/VS Code.

13. **State and persistence boundaries**
   - Runtime state is split between durable docs in git, local operational state in SQLite/config files, and ephemeral terminal/session processes.
   - That separation matters architecturally: knowledge is versioned in the repo, while execution state is local and recoverable.

14. **Tooling and verification**
   - The repo is heavily tested with Vitest for unit/integration logic and Playwright for end-to-end flows, especially Agent Farm and dashboard behavior.
   - CI workflows, scripts, and release machinery are part of the operational boundary, ensuring the CLI, UI, and extension stay coordinated across packages.

Main entry points: [`packages/codev/src/agent-farm`](https://github.com/cluesmith/codev/tree/main/packages/codev/src/agent-farm) (Agent Farm), [`packages/codev/src/cli.ts`](https://github.com/cluesmith/codev/blob/main/packages/codev/src/cli.ts) (Codev CLI), [`packages/dashboard/src/components/App.tsx`](https://github.com/cluesmith/codev/blob/main/packages/dashboard/src/components/App.tsx) (Dashboard), [`packages/vscode/src/extension.ts`](https://github.com/cluesmith/codev/blob/main/packages/vscode/src/extension.ts) (VS Code ext)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime packages"]
  node_codev_cli["Codev CLI<br/>orchestrator<br/>[cli.ts]"]
  node_agent_farm["Agent Farm<br/>builder runtime"]
  node_terminal["Terminal shellper<br/>pty/session layer"]
  node_porch["Porch workflows<br/>protocol runner"]
  node_consult["Consult tool<br/>review/query"]
  node_dashboard["Dashboard<br/>web UI<br/>[App.tsx]"]
  node_vscode["VS Code ext<br/>editor integration<br/>[extension.ts]"]
  node_core["Shared core<br/>domain helpers"]
  node_types["API contracts<br/>sse/ws/http types"]
end

subgraph group_knowledge["Repo knowledge"]
  node_protocols["Protocols<br/>workflow specs"]
  node_project_docs["Project docs<br/>repo state"]
  node_skeleton["Skeleton<br/>template seed"]
end

subgraph group_integrations["External integrations"]
  node_forge["Forge adapters<br/>git provider integration"]
  node_ai_shells["AI shells<br/>model adapters"]
  node_tower["Tower/cloud<br/>remote runtime<br/>[tower-server.ts]"]
end

subgraph group_tooling["Tooling"]
  node_tests_cli["CLI tests<br/>vitest/e2e"]
  node_tests_ui["UI tests<br/>vitest/playwright"]
  node_ci_release["CI release<br/>workflow/scripts<br/>[workflows]"]
end

node_codev_cli -->|"drives builders"| node_agent_farm
node_codev_cli -->|"runs protocols"| node_porch
node_codev_cli -->|"offers consult"| node_consult
node_codev_cli -->|"uses forge"| node_forge
node_codev_cli -->|"invokes models"| node_ai_shells
node_agent_farm -->|"manages sessions"| node_terminal
node_agent_farm -->|"serves state"| node_dashboard
node_agent_farm -->|"streams events"| node_vscode
node_agent_farm -->|"shares logic"| node_core
node_agent_farm -->|"emits contracts"| node_types
node_terminal -->|"remote shell"| node_tower
node_porch -->|"loads workflow docs"| node_protocols
node_project_docs -->|"contain prompts"| node_protocols
node_skeleton -->|"seeds protocols"| node_protocols
node_dashboard -->|"consumes events"| node_types
node_dashboard -->|"uses helpers"| node_core
node_vscode -->|"consumes events"| node_types
node_vscode -->|"uses helpers"| node_core
node_forge -->|"updates issues"| node_project_docs
node_ai_shells -->|"follow prompts"| node_protocols
node_tower -->|"feeds UI"| node_dashboard
node_tests_cli -->|"verifies"| node_codev_cli
node_tests_ui -->|"verifies"| node_dashboard
node_tests_ui -->|"verifies"| node_vscode
node_ci_release -->|"runs"| node_tests_cli
node_ci_release -->|"runs"| node_tests_ui
node_ci_release -->|"ships docs"| node_project_docs

click node_codev_cli "https://github.com/cluesmith/codev/blob/main/packages/codev/src/cli.ts"
click node_agent_farm "https://github.com/cluesmith/codev/tree/main/packages/codev/src/agent-farm"
click node_terminal "https://github.com/cluesmith/codev/tree/main/packages/codev/src/terminal"
click node_porch "https://github.com/cluesmith/codev/tree/main/packages/codev/src/commands/porch"
click node_consult "https://github.com/cluesmith/codev/tree/main/packages/codev/src/commands/consult"
click node_dashboard "https://github.com/cluesmith/codev/blob/main/packages/dashboard/src/components/App.tsx"
click node_vscode "https://github.com/cluesmith/codev/blob/main/packages/vscode/src/extension.ts"
click node_core "https://github.com/cluesmith/codev/tree/main/packages/core/src"
click node_types "https://github.com/cluesmith/codev/tree/main/packages/types/src"
click node_protocols "https://github.com/cluesmith/codev/tree/main/codev/protocols"
click node_project_docs "https://github.com/cluesmith/codev/tree/main/codev"
click node_skeleton "https://github.com/cluesmith/codev/tree/main/codev-skeleton"
click node_forge "https://github.com/cluesmith/codev/tree/main/packages/codev/scripts/forge"
click node_ai_shells "https://github.com/cluesmith/codev/tree/main/packages/codev/src/commands/consult"
click node_tower "https://github.com/cluesmith/codev/blob/main/packages/codev/src/agent-farm/servers/tower-server.ts"
click node_tests_cli "https://github.com/cluesmith/codev/tree/main/packages/codev/src/__tests__"
click node_tests_ui "https://github.com/cluesmith/codev/tree/main/packages/dashboard/__tests__"
click node_ci_release "https://github.com/cluesmith/codev/blob/main/.github/workflows"

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_codev_cli,node_agent_farm,node_terminal,node_porch,node_consult,node_dashboard,node_vscode,node_core,node_types toneBlue
class node_protocols,node_project_docs,node_skeleton toneAmber
class node_forge,node_ai_shells,node_tower toneMint
class node_tests_cli,node_tests_ui,node_ci_release toneRose
```

## Components

### Runtime packages

CLI, orchestration, UI, editor integration, and shared contracts.

- [Codev CLI](https://github.com/cluesmith/codev/blob/main/packages/codev/src/cli.ts): orchestrator · User-facing commands and top-level orchestration for init, adopt, consult, porch, team, and afx. · `packages/codev/src/cli.ts`
- [Agent Farm](https://github.com/cluesmith/codev/tree/main/packages/codev/src/agent-farm): builder runtime · Autonomous builder workflow, session control, local state, and dashboard/server surfaces. · `packages/codev/src/agent-farm`
- [Terminal shellper](https://github.com/cluesmith/codev/tree/main/packages/codev/src/terminal): pty/session layer · Isolated shell/session model for persistent AI processes and worktree-bound execution. · `packages/codev/src/terminal`
- [Porch workflows](https://github.com/cluesmith/codev/tree/main/packages/codev/src/commands/porch): protocol runner · Protocol-driven lifecycle for specify, plan, implement, review, and PR-gated advancement. · `packages/codev/src/commands/porch`
- [Consult tool](https://github.com/cluesmith/codev/tree/main/packages/codev/src/commands/consult): review/query · Stateless consultation path for reviews, metrics, and PR-oriented guidance. · `packages/codev/src/commands/consult`
- [Dashboard](https://github.com/cluesmith/codev/blob/main/packages/dashboard/src/components/App.tsx): web UI · Vite/React workspace view for builders, terminals, backlog, PRs, alerts, and analytics. · `packages/dashboard/src/components/App.tsx`
- [VS Code ext](https://github.com/cluesmith/codev/blob/main/packages/vscode/src/extension.ts): editor integration · Editor-side commands, views, terminal adapters, and link providers over the shared backend. · `packages/vscode/src/extension.ts`
- [Shared core](https://github.com/cluesmith/codev/tree/main/packages/core/src): domain helpers · Reusable business logic for names, grouping, auth, workspace, and builder helpers. · `packages/core/src`
- [API contracts](https://github.com/cluesmith/codev/tree/main/packages/types/src): sse/ws/http types · Shared request/event/message contracts for CLI, dashboard, and extension alignment. · `packages/types/src`

### Repo knowledge

Project-local specs, protocols, prompts, and durable workflow artifacts.

- [Protocols](https://github.com/cluesmith/codev/tree/main/codev/protocols): workflow specs · Protocol schemas, prompts, consult-types, and templates that define AI behavior. · `codev/protocols`
- [Project docs](https://github.com/cluesmith/codev/tree/main/codev): repo state · Durable specs, plans, reviews, maintain logs, team notes, and project state in git. · `codev`
- [Skeleton](https://github.com/cluesmith/codev/tree/main/codev-skeleton): template seed · Installable starter tree that seeds new repos with the same workflow structure. · `codev-skeleton`

### External integrations

Forge, AI CLI, and cloud/tower boundaries used by the runtime.

- [Forge adapters](https://github.com/cluesmith/codev/tree/main/packages/codev/scripts/forge): git provider integration · Shell adapters for GitHub, GitLab, Gitea, and Linear issue/PR operations. · `packages/codev/scripts/forge`
- [AI shells](https://github.com/cluesmith/codev/tree/main/packages/codev/src/commands/consult): model adapters · Pluggable builder/architect shells for Claude, Gemini, Codex, and optional OpenCode. · `packages/codev/src/commands/consult`
- [Tower/cloud](https://github.com/cluesmith/codev/blob/main/packages/codev/src/agent-farm/servers/tower-server.ts): remote runtime · Remote access, registration, tunnel, websocket, and daemon flows for off-machine use. · `packages/codev/src/agent-farm/servers/tower-server.ts`

### Tooling

Tests, CI, and release workflows that keep the platform coordinated.

- [CLI tests](https://github.com/cluesmith/codev/tree/main/packages/codev/src/__tests__): vitest/e2e · CLI, porch, consult, terminal, and agent-farm test coverage. · `packages/codev/src/__tests__`
- [UI tests](https://github.com/cluesmith/codev/tree/main/packages/dashboard/__tests__): vitest/playwright · Dashboard and VS Code component, hook, and end-to-end verification. · `packages/dashboard/__tests__`
- [CI release](https://github.com/cluesmith/codev/blob/main/.github/workflows): workflow/scripts · GitHub workflows, scripts, hooks, install, and release automation across the monorepo. · `.github/workflows`

## Connections

- Codev CLI → Agent Farm: drives builders · The CLI dispatches afx/agent-farm commands for spawning, sending, cleanup, status, and team flows.
- Codev CLI → Porch workflows: runs protocols · Porch commands implement lifecycle execution for specs-first workflows.
- Codev CLI → Consult tool: offers consult · Consult is a user-facing command surface for reviews and advisory flows.
- Codev CLI → Forge adapters: uses forge · CLI operations read and update Git provider state through shell adapters.
- Codev CLI → AI shells: invokes models · Builder and consultation execution is delegated to external model shells.
- Agent Farm → Terminal shellper: manages sessions · Agent Farm owns shellper/pty session lifecycle and builder isolation.
- Agent Farm → Dashboard: serves state · Dashboard views consume Agent Farm server endpoints and live events.
- Agent Farm → VS Code ext: streams events · VS Code subscribes to the same workspace/session state and commands.
- Agent Farm → Shared core: shares logic · Name grouping, auth, workspace helpers, and builder utilities are shared.
- Agent Farm → API contracts: emits contracts · HTTP, SSE, and websocket payloads are defined by shared types.
- Terminal shellper → Tower/cloud: remote shell · Terminal sessions can be mirrored or controlled through tower/remote flows.
- Porch workflows → Protocols: loads workflow docs · Protocol JSON, prompts, consult-types, and templates define each workflow stage.
- Project docs → Protocols: contain prompts · The repo-local docs and state are the durable content consumed by protocols.
- Skeleton → Protocols: seeds protocols · The skeleton copies the same protocol and template structure into new projects.
- Dashboard → API contracts: consumes events · The UI is bound to the shared API/SSE contract.
- Dashboard → Shared core: uses helpers · Dashboard presentation and grouping reuse shared domain helpers.
- VS Code ext → API contracts: consumes events · The extension stays aligned through the same API and event contracts.
- VS Code ext → Shared core: uses helpers · Editor-side grouping, workspace, and auth logic reuse shared code.
- Forge adapters → Project docs: updates issues · Forge adapters connect external issue/PR state back into repo workflows.
- AI shells → Protocols: follow prompts · Model shells execute protocol-specific prompts and templates.
- Tower/cloud → Dashboard: feeds UI · Remote runtime state is surfaced in the dashboard presentation layer.
- CLI tests → Codev CLI: verifies · Vitest and e2e tests cover command behavior and orchestration.
- UI tests → Dashboard: verifies · Component and end-to-end tests cover the UI boundary.
- UI tests → VS Code ext: verifies · Extension tests validate commands, views, and workspace integration.
- CI release → CLI tests: runs · CI gates CLI and integration test suites.
- CI release → UI tests: runs · CI gates dashboard and extension test suites.
- CI release → Project docs: ships docs · Release and maintenance workflows keep repo docs and artifacts in sync.
