# slopus/happy-agent architecture

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

- Interactive diagram: https://gitdiagram.com/slopus/happy-agent
- Repository: https://github.com/slopus/happy-agent

## Overview

Happy Agent is a local, headless coding-agent runtime that unifies model-specific agent behavior behind durable sessions and a stable client API. A client request enters the daemon, which starts the runtime and binds its API transport; agents then use configured model providers and controlled compute to perform work, with state persisted for later events and sessions. The README also documents MCP, subagents, alternate agent harnesses, mobile synchronization, and remote terminals. Some subsystem paths are supported by the tree or source index but their internals were not sampled, so those connections are omitted or identified as documented at the README level.

Main entry points: [`packages/happy-agent-base/sources/Agent.ts`](https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-base/sources/Agent.ts) (Agent behavior), [`packages/happy-agent-modules/sources`](https://github.com/slopus/happy-agent/tree/main/packages/happy-agent-modules/sources) (Runtime startup), [`packages/happy-agent-base/sources/AgentStorage.ts`](https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-base/sources/AgentStorage.ts) (Agent storage), [`packages/happy-agent-client/sources/HappyAgentClient.ts`](https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-client/sources/HappyAgentClient.ts) (Desktop or API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Agent runtime"]
  node_daemon["Daemon entry<br/>[main.ts]"]
  node_runtime_start["Runtime startup"]
  node_agent["Agent behavior<br/>[Agent.ts]"]
  node_modules["Agent capabilities"]
end

subgraph group_execution["Execution and providers"]
  node_provider["Model providers"]
  node_compute["Compute and policy<br/>[ComputeModule.ts]"]
  node_processes["Managed processes"]
end

subgraph group_state["Sessions and state"]
  node_storage[("Agent storage<br/>[AgentStorage.ts]")]
  node_scheduling[("Scheduling state")]
  node_durable[("Durable functions")]
  node_user_input[("User input state")]
end

subgraph group_api["Client API"]
  node_client["Desktop or API client"]
  node_api["Daemon API<br/>[ApiModule.ts]"]
  node_protocol["API protocol<br/>[agents.ts]"]
end

subgraph group_extensions["Integrations"]
  node_mobile["Happy mobile sync"]
  node_alt_harness["Alternate harnesses"]
  node_terminal["Remote terminals"]
  node_wasm_terminal["Ghostty terminal<br/>[GhosttyTerminal.ts]"]
end

node_developer(("Developer"))

node_developer -->|"uses"| node_client
node_client -->|"requests"| node_api
node_api -->|"reaches daemon"| node_daemon
node_daemon -->|"starts runtime"| node_runtime_start
node_runtime_start -.->|"provides runtime"| node_agent
node_agent -->|"requests inference"| node_provider
node_agent -->|"executes tools"| node_compute
node_compute -.->|"manages processes"| node_processes
node_agent -->|"persists sessions"| node_storage
node_storage -->|"module migrations"| node_scheduling
node_storage -->|"module migrations"| node_durable
node_storage -->|"module migrations"| node_user_input
node_runtime_start -->|"loads capabilities"| node_modules
node_modules -->|"adds tools"| node_agent
node_api -->|"implements contract"| node_protocol
node_runtime_start -->|"enables synchronization"| node_mobile
node_agent -->|"can delegate loop"| node_alt_harness
node_client -->|"uses terminal API"| node_terminal
node_terminal -.->|"uses Ghostty"| node_wasm_terminal

click node_client "https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-client/sources/HappyAgentClient.ts"
click node_daemon "https://github.com/slopus/happy-agent/blob/main/packages/happy-agent/sources/main.ts"
click node_runtime_start "https://github.com/slopus/happy-agent/tree/main/packages/happy-agent-modules/sources"
click node_agent "https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-base/sources/Agent.ts"
click node_modules "https://github.com/slopus/happy-agent/tree/main/packages/happy-agent-modules/sources"
click node_provider "https://github.com/slopus/happy-agent/tree/main/packages/happy-providers/sources"
click node_compute "https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-modules/sources/compute/ComputeModule.ts"
click node_processes "https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-compute/sources/processes/NativeProcessManager.ts"
click node_storage "https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-base/sources/AgentStorage.ts"
click node_scheduling "https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-modules/sources/scheduling/SqliteSchedulingStorage.ts"
click node_durable "https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-modules/sources/durableFunctions/SqliteDurableFunctionsStorage.ts"
click node_user_input "https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-modules/sources/userInput/SqliteUserInputStorage.ts"
click node_api "https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-modules/sources/api/ApiModule.ts"
click node_protocol "https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-client/sources/protocol/agents.ts"
click node_mobile "https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-modules/sources/happy/HappySessionClient.ts"
click node_alt_harness "https://github.com/slopus/happy-agent/tree/main/packages/happy-agent-modules/sources"
click node_terminal "https://github.com/slopus/happy-agent/blob/main/packages/ghostty-web/sources/RemoteTerminalProtocolClient.ts"
click node_wasm_terminal "https://github.com/slopus/happy-agent/blob/main/packages/ghostty-wasm/sources/GhosttyTerminal.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_daemon,node_runtime_start,node_agent,node_modules toneBlue
class node_provider,node_compute,node_processes toneAmber
class node_storage,node_scheduling,node_durable,node_user_input toneMint
class node_client,node_api,node_protocol toneRose
class node_mobile,node_alt_harness,node_terminal,node_wasm_terminal,node_developer toneIndigo
```

## Components

### Agent runtime

- [Daemon entry](https://github.com/slopus/happy-agent/blob/main/packages/happy-agent/sources/main.ts): `packages/happy-agent/sources/main.ts`
- [Runtime startup](https://github.com/slopus/happy-agent/tree/main/packages/happy-agent-modules/sources): `packages/happy-agent-modules/sources`
- [Agent behavior](https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-base/sources/Agent.ts): `packages/happy-agent-base/sources/Agent.ts`
- [Agent capabilities](https://github.com/slopus/happy-agent/tree/main/packages/happy-agent-modules/sources): `packages/happy-agent-modules/sources`

### Execution and providers

- [Model providers](https://github.com/slopus/happy-agent/tree/main/packages/happy-providers/sources): `packages/happy-providers/sources`
- [Compute and policy](https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-modules/sources/compute/ComputeModule.ts): `packages/happy-agent-modules/sources/compute/ComputeModule.ts`
- [Managed processes](https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-compute/sources/processes/NativeProcessManager.ts): `packages/happy-agent-compute/sources/processes/NativeProcessManager.ts`

### Sessions and state

- [Agent storage](https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-base/sources/AgentStorage.ts): `packages/happy-agent-base/sources/AgentStorage.ts`
- [Scheduling state](https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-modules/sources/scheduling/SqliteSchedulingStorage.ts): `packages/happy-agent-modules/sources/scheduling/SqliteSchedulingStorage.ts`
- [Durable functions](https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-modules/sources/durableFunctions/SqliteDurableFunctionsStorage.ts): `packages/happy-agent-modules/sources/durableFunctions/SqliteDurableFunctionsStorage.ts`
- [User input state](https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-modules/sources/userInput/SqliteUserInputStorage.ts): `packages/happy-agent-modules/sources/userInput/SqliteUserInputStorage.ts`

### Client API

- [Desktop or API client](https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-client/sources/HappyAgentClient.ts): `packages/happy-agent-client/sources/HappyAgentClient.ts`
- [Daemon API](https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-modules/sources/api/ApiModule.ts): `packages/happy-agent-modules/sources/api/ApiModule.ts`
- [API protocol](https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-client/sources/protocol/agents.ts): `packages/happy-agent-client/sources/protocol/agents.ts`

### Integrations

- [Happy mobile sync](https://github.com/slopus/happy-agent/blob/main/packages/happy-agent-modules/sources/happy/HappySessionClient.ts): `packages/happy-agent-modules/sources/happy/HappySessionClient.ts`
- [Alternate harnesses](https://github.com/slopus/happy-agent/tree/main/packages/happy-agent-modules/sources): `packages/happy-agent-modules/sources`
- [Remote terminals](https://github.com/slopus/happy-agent/blob/main/packages/ghostty-web/sources/RemoteTerminalProtocolClient.ts): `packages/ghostty-web/sources/RemoteTerminalProtocolClient.ts`
- [Ghostty terminal](https://github.com/slopus/happy-agent/blob/main/packages/ghostty-wasm/sources/GhosttyTerminal.ts): `packages/ghostty-wasm/sources/GhosttyTerminal.ts`

### Other components

- **Developer**

## Connections

- Developer → Desktop or API client: uses
- Desktop or API client → Daemon API: requests
- Daemon API → Daemon entry: reaches daemon
- Daemon entry → Runtime startup: starts runtime (evidence: `packages/happy-agent/sources/main.ts`)
- Runtime startup → Agent behavior: provides runtime
- Agent behavior → Model providers: requests inference
- Agent behavior → Compute and policy: executes tools
- Compute and policy → Managed processes: manages processes
- Agent behavior → Agent storage: persists sessions
- Agent storage → Scheduling state: module migrations (evidence: `packages/happy-agent-base/sources/AgentStorage.ts`)
- Agent storage → Durable functions: module migrations (evidence: `packages/happy-agent-base/sources/AgentStorage.ts`)
- Agent storage → User input state: module migrations (evidence: `packages/happy-agent-base/sources/AgentStorage.ts`)
- Runtime startup → Agent capabilities: loads capabilities
- Agent capabilities → Agent behavior: adds tools
- Daemon API → API protocol: implements contract
- Runtime startup → Happy mobile sync: enables synchronization
- Agent behavior → Alternate harnesses: can delegate loop
- Desktop or API client → Remote terminals: uses terminal API
- Remote terminals → Ghostty terminal: uses Ghostty
