# cloudbase/garm architecture

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

- Interactive diagram: https://gitdiagram.com/cloudbase/garm
- Repository: https://github.com/cloudbase/garm

## Overview

GARM is a self-hosted manager for ephemeral GitHub Actions and Gitea runners. Administrators configure forge entities, pools or scale sets, then incoming workflow-job webhooks or GitHub’s native scale-set queue drive runner provisioning; providers create the compute instances, and agents report runner state. The repository also exposes an API, CLI, browser UI, templates, object storage, and monitoring. The map combines README-described capabilities with sampled routing and worker code; several runtime links are documented at a high level but their detailed implementations were not sampled.

Main entry points: [`apiserver/controllers/controllers.go`](https://github.com/cloudbase/garm/blob/main/apiserver/controllers/controllers.go) (API handlers), [`workers/scaleset/controller.go`](https://github.com/cloudbase/garm/blob/main/workers/scaleset/controller.go) (Scale-set workers), [`workers/entity/controller.go`](https://github.com/cloudbase/garm/blob/main/workers/entity/controller.go) (Entity workers), [`apiserver/routers/routers.go`](https://github.com/cloudbase/garm/blob/main/apiserver/routers/routers.go) (HTTP router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_management["Management surfaces"]
  node_cli["GARM CLI"]
  node_webui["Web UI"]
  node_api_client["API clients"]
end

subgraph group_control["API and configuration"]
  node_router["HTTP router<br/>[routers.go]"]
  node_handlers["API handlers<br/>[controllers.go]"]
  node_auth["Authentication"]
  node_entity_config["Forge entities and pools"]
  node_templates["Runner templates<br/>[templates.go]"]
end

subgraph group_scaling["Runner orchestration"]
  node_entity_controller["Entity workers<br/>[controller.go]"]
  node_pool_scaling["Pool scaling"]
  node_scale_sets["Scale-set workers<br/>[controller.go]"]
  node_instance_manager["Instance lifecycle"]
end

subgraph group_integrations["Persistence and integrations"]
  node_provider_adapter["Provider adapters"]
  node_forge_api["Forge API integration<br/>[client.go]"]
  node_database[("Embedded SQL store")]
  node_agent["Runner agent channel"]
  node_object_store["Agent tools and objects<br/>[object_store.go]"]
  node_metrics["Metrics and events"]
end

node_admin(("Administrator"))
node_forge(("GitHub / Gitea"))
node_cloud(("Infrastructure provider"))

node_admin -->|"manages via"| node_cli
node_admin -.->|"manages via"| node_webui
node_cli -->|"calls"| node_api_client
node_webui -.->|"uses"| node_api_client
node_api_client -.->|"sends requests"| node_router
node_router -->|"routes to"| node_handlers
node_router -->|"applies middleware"| node_auth
node_forge -->|"posts job webhook"| node_handlers
node_handlers -->|"dispatches job"| node_entity_controller
node_entity_config -.->|"configures entities"| node_entity_controller
node_entity_controller -->|"loads entities"| node_database
node_entity_controller -.->|"coordinates pools"| node_pool_scaling
node_forge -->|"queues scale-set jobs"| node_scale_sets
node_scale_sets -->|"loads scale sets"| node_database
node_pool_scaling -.->|"requests instances"| node_instance_manager
node_scale_sets -.->|"provisions instances"| node_instance_manager
node_instance_manager -->|"creates instances"| node_provider_adapter
node_provider_adapter -->|"manages compute"| node_cloud
node_scale_sets -.->|"reconciles runners"| node_forge_api
node_templates -.->|"supplies configuration"| node_entity_config
node_handlers -.->|"serves tool operations"| node_object_store
node_agent -.->|"reports state"| node_handlers
node_handlers -->|"registers metrics client"| node_metrics

click node_cli "https://github.com/cloudbase/garm/tree/main/cmd/garm-cli/cmd"
click node_webui "https://github.com/cloudbase/garm/tree/main/webapp/src/routes"
click node_api_client "https://github.com/cloudbase/garm/tree/main/client"
click node_router "https://github.com/cloudbase/garm/blob/main/apiserver/routers/routers.go"
click node_handlers "https://github.com/cloudbase/garm/blob/main/apiserver/controllers/controllers.go"
click node_auth "https://github.com/cloudbase/garm/tree/main/auth"
click node_entity_config "https://github.com/cloudbase/garm/tree/main/runner"
click node_templates "https://github.com/cloudbase/garm/blob/main/runner/templates.go"
click node_entity_controller "https://github.com/cloudbase/garm/blob/main/workers/entity/controller.go"
click node_pool_scaling "https://github.com/cloudbase/garm/tree/main/runner/pool"
click node_scale_sets "https://github.com/cloudbase/garm/blob/main/workers/scaleset/controller.go"
click node_instance_manager "https://github.com/cloudbase/garm/blob/main/workers/provider/instance_manager.go"
click node_provider_adapter "https://github.com/cloudbase/garm/tree/main/runner/providers"
click node_forge_api "https://github.com/cloudbase/garm/blob/main/util/github/client.go"
click node_database "https://github.com/cloudbase/garm/tree/main/database/sql"
click node_agent "https://github.com/cloudbase/garm/tree/main/workers/websocket/agent"
click node_object_store "https://github.com/cloudbase/garm/blob/main/runner/object_store.go"
click node_metrics "https://github.com/cloudbase/garm/tree/main/metrics"

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_webui,node_api_client toneBlue
class node_router,node_handlers,node_auth,node_entity_config,node_templates toneAmber
class node_entity_controller,node_pool_scaling,node_scale_sets,node_instance_manager toneMint
class node_provider_adapter,node_forge_api,node_database,node_agent,node_object_store,node_metrics toneRose
class node_admin,node_forge,node_cloud toneIndigo
```

## Components

### Management surfaces

- [GARM CLI](https://github.com/cloudbase/garm/tree/main/cmd/garm-cli/cmd): `cmd/garm-cli/cmd`
- [Web UI](https://github.com/cloudbase/garm/tree/main/webapp/src/routes): `webapp/src/routes`
- [API clients](https://github.com/cloudbase/garm/tree/main/client): `client`

### API and configuration

- [HTTP router](https://github.com/cloudbase/garm/blob/main/apiserver/routers/routers.go): `apiserver/routers/routers.go`
- [API handlers](https://github.com/cloudbase/garm/blob/main/apiserver/controllers/controllers.go): `apiserver/controllers/controllers.go`
- [Authentication](https://github.com/cloudbase/garm/tree/main/auth): `auth`
- [Forge entities and pools](https://github.com/cloudbase/garm/tree/main/runner): `runner`
- [Runner templates](https://github.com/cloudbase/garm/blob/main/runner/templates.go): `runner/templates.go`

### Runner orchestration

- [Entity workers](https://github.com/cloudbase/garm/blob/main/workers/entity/controller.go): `workers/entity/controller.go`
- [Pool scaling](https://github.com/cloudbase/garm/tree/main/runner/pool): `runner/pool`
- [Scale-set workers](https://github.com/cloudbase/garm/blob/main/workers/scaleset/controller.go): `workers/scaleset/controller.go`
- [Instance lifecycle](https://github.com/cloudbase/garm/blob/main/workers/provider/instance_manager.go): `workers/provider/instance_manager.go`

### Persistence and integrations

- [Provider adapters](https://github.com/cloudbase/garm/tree/main/runner/providers): `runner/providers`
- [Forge API integration](https://github.com/cloudbase/garm/blob/main/util/github/client.go): `util/github/client.go`
- [Embedded SQL store](https://github.com/cloudbase/garm/tree/main/database/sql): `database/sql`
- [Runner agent channel](https://github.com/cloudbase/garm/tree/main/workers/websocket/agent): `workers/websocket/agent`
- [Agent tools and objects](https://github.com/cloudbase/garm/blob/main/runner/object_store.go): `runner/object_store.go`
- [Metrics and events](https://github.com/cloudbase/garm/tree/main/metrics): `metrics`

### Other components

- **Administrator**
- **GitHub / Gitea**
- **Infrastructure provider**

## Connections

- Administrator → GARM CLI: manages via
- Administrator → Web UI: manages via
- GARM CLI → API clients: calls (evidence: `cmd/garm-cli/cmd/controller.go`)
- Web UI → API clients: uses
- API clients → HTTP router: sends requests
- HTTP router → API handlers: routes to (evidence: `apiserver/routers/routers.go`)
- HTTP router → Authentication: applies middleware (evidence: `apiserver/routers/routers.go`)
- GitHub / Gitea → API handlers: posts job webhook
- API handlers → Entity workers: dispatches job (evidence: `apiserver/controllers/controllers.go`)
- Forge entities and pools → Entity workers: configures entities (evidence: `workers/entity/controller.go`)
- Entity workers → Embedded SQL store: loads entities (evidence: `workers/entity/controller.go`)
- Entity workers → Pool scaling: coordinates pools
- GitHub / Gitea → Scale-set workers: queues scale-set jobs
- Scale-set workers → Embedded SQL store: loads scale sets (evidence: `workers/scaleset/controller.go`)
- Pool scaling → Instance lifecycle: requests instances
- Scale-set workers → Instance lifecycle: provisions instances
- Instance lifecycle → Provider adapters: creates instances (evidence: `workers/provider/instance_manager.go`)
- Provider adapters → Infrastructure provider: manages compute
- Scale-set workers → Forge API integration: reconciles runners
- Runner templates → Forge entities and pools: supplies configuration
- API handlers → Agent tools and objects: serves tool operations
- Runner agent channel → API handlers: reports state (evidence: `apiserver/controllers/controllers.go`)
- API handlers → Metrics and events: registers metrics client (evidence: `apiserver/controllers/controllers.go`)
