Skip to main content

02 Containers and deployment

Status: Current Last verified: 579de4b

This is the one place that describes which services exist, how they talk and where they run. Other documents link here instead of repeating it.

Services​

ServiceCodeBuilt withRole
Dashboardsrc/apps/github-backup-dashboardNext.js 16 (App Router), React 19The web app and the public pages. Its server is the only thing a browser talks to: route handlers under /api/proxy/backup/* and /api/proxy/agent/* forward allowlisted requests to the API and the Observatory with the user's session.
Backup APIsrc/backend/github-backup-apiGo, Fiber v2, pgxFive services from one codebase (ADR 0002, 0010, 0017, 0018), each with its own binary and database role: identity (accounts, tokens, agents, linking workers, the waitlist), runs (queuing backups, the /v1 intake that linked workers report through; abandoned and missed runs, run retention, the owner's dead-man check), insights (each account's runs, results and logs, read only; the live log streams), notify (an account's alert channels and rules; it sends alerts of failed and missed runs and of billing events to Slack, Discord and signed webhooks; no e-mail, ADR 0020) and billing (the plans, checkouts, subscriptions, invoices and refunds, and the payment providers' webhooks). The bundle, github-backup-api, serves all five and is the only binary that migrates.
Observatorysrc/services/github-backup-observatoryPython 3.12, FastAPI, LangChainThe AI assistant: tool-calling chat over the account's runs, hybrid search (full text and pgvector) over failures, fixes and investigations, and reports the user reads in the dashboard and downloads (nothing is e-mailed, ADR 0020). It indexes failures from background jobs it claims from public.platform_jobs (ADR 0013), reading runs through the insights API.
MCP serversrc/backend/github-backup-mcpGo, mcp-goThe same data for AI agents over the Model Context Protocol: stdio for local agents, Streamable HTTP at /mcp. Clients send a personal access token. It holds no database URL: every tool calls the API or the Observatory.
Backup workersrc/services/github-backup-workerGo CLIRuns on the user's machine: lists the repositories, decides which changed, archives them into the user's storage and reports what it did. Its contract: 05 worker.
Docs and design sitessrc/apps/github-backup-docs, src/apps/github-backup-designDocusaurus, Next.js static exportStatic sites for this documentation and the design system, built locally; not hosted.
flowchart TD
browser(["Browser"])
agent(["AI agent"])

subgraph web["Web"]
dashboard["Dashboard (Next.js server)"]
end
subgraph backend["Backend"]
subgraph api["Backup API: one host, routed by path"]
identity["identity (Go)"]
runs["runs (Go)"]
insights["insights (Go)"]
notify["notify (Go)"]
end
observatory["Observatory (FastAPI)"]
mcp["MCP server (Go)"]
end
subgraph machines["User machines"]
selfhosted["Worker, self-hosted"]
linked["Worker, linked to an account"]
end

db[("PostgreSQL + pgvector")]
github[("GitHub")]
sink[("User's storage")]
openrouter["OpenRouter"]
receivers["Slack, Discord, webhooks"]

browser -->|"HTTPS, same origin"| dashboard
dashboard -->|"/api/proxy/backup: session JWT"| api
dashboard -->|"/api/proxy/agent: session JWT"| observatory
agent -->|"/mcp: personal token"| mcp
dashboard -->|"sign-in, landing numbers: its credential"| api
observatory -->|"its credential + X-Account-Id"| api
mcp -->|"user's token, or its credential for the owner"| api
mcp -->|"search: its credential + X-Account-Id"| observatory
api -->|SQL| db
observatory -->|SQL, pgvector| db
observatory --> openrouter
notify -->|"alerts: HTTPS to public addresses"| receivers
selfhosted --> github
linked --> github
selfhosted --> sink
linked --> sink
selfhosted -->|"SQL (runstore)"| db
linked -->|"/v1: agent token"| api

How each request is authenticated is in MULTI_USER_ARCHITECTURE.md; the main flows step by step are in 04 runtime flows.

Where they run​

The system runs on one Linux machine with deploy/selfhost (ADR 0019). The owner runs it on their own machine; anyone else can run the same files on theirs. Nothing is hosted on a platform.

Self-hosted machine
Dashboard, MCP serverContainers behind Caddy
Backup APIThe five services, one container each, behind Caddy
ObservatoryA container on the machine's Docker network only; it runs its own background jobs
DatabasePostgreSQL 16 with pgvector 0.8, in a container (volume ghb_pgdata)
Migrationsghb deploy, before the new release starts (migrate --roles)
Deployssudo ghb update on the machine
Settings and secrets/etc/ghb/selfhost.env, written by install.sh; the owner keeps an encrypted copy in fnox (docs/SECRETS.md)
MonitoringPrometheus, Grafana and the OpenTelemetry collector with --monitoring

One machine runs PostgreSQL, the five API services, the Observatory, the dashboard and the MCP server with Docker Compose, behind Caddy, the only container that publishes ports. install.sh installs Docker (Ubuntu, Debian), generates every secret into /etc/ghb/selfhost.env and starts the first release. Every public address comes from that file; none is written in the code. The machine is reached in one of three modes: three host names with Let's Encrypt (domain), one LAN address with Caddy's own CA and the API and MCP server on ports 8443 and 8444 (lan), or Cloudflare Tunnel with no open port (tunnel). Images are built from the checkout or pulled. ghb deploys (a dump, migrate --roles, start and wait, the previous release again when no migration ran), rolls back with the dump made before a migration, dumps the database nightly (a systemd timer, optionally copied to S3 with deploy/shared/db-backup) and restores. Caddy routes the API host by path (deploy/shared/caddy/api-routes.caddy: identity the account, tokens, agents, links and the waitlist; runs backup requests, research consent, the backup history's export and the /v1 intake; insights the history, the dashboard's numbers and the logs; notify /api/alerts; billing /api/billing, /public/billing and /webhooks). The MCP server starts only once Caddy and identity pass their health checks, because its startup check that personal tokens can be verified reaches identity through Caddy, and Caddy waits only for identity to start. The dashboard, the MCP server and the Observatory call the API through Caddy's internal listener (http://caddy:8080), which routes like the public host. Operating it: deploy/selfhost/README.md and 06 operations.

The worker runs wherever its user runs it: make setup installs it with a schedule (systemd user timers, launchd agents or crontab): an hourly check that backs up at the account's slot on a machine with a database or a link, otherwise a weekly run, or its container image runs on any machine.

docker-compose.yml at the root is the development stack, configured by .env (copied from the root .env.example): its own PostgreSQL, a one-shot migrate (the bundle), the five API services and a Caddy gateway on :8080 running the shared routes. The docs site (src/apps/github-backup-docs) and the design system site (src/apps/github-backup-design) build locally and are not hosted.

Images​

Only the images whose inputs changed since their last publish are rebuilt: scripts/image-inputs.sh compares the commit with the revision label of the image's latest tag over the image's Dockerfile, the files it copies and, for a Go binary, the packages it depends on (go list -deps), go.mod and go.sum. An image with no changed input gets the commit's tags (sha-<short sha>, latest when due) pointing at its previous build, so a deploy can always pin every image to one commit.

publish-images.yml builds, after CI passes on main, with SBOM and provenance:

  • github-backup-{identity,runs,insights,billing,notify}: one Go API service each, from src/backend/github-backup-api/Dockerfile.service (--build-arg SERVICE), for a deployment that runs one image per service;
  • github-backup-api: the bundle and the five service binaries (Compose and the migrate job; a Compose deployment picks one binary per service);
  • github-backup-{worker,mcp,observatory,dashboard};
  • github-backup-db-backup: pg_dump 16, age and curl (deploy/shared/db-backup) for encrypted database dumps.

Every image declares a health check, which Compose's depends_on: service_healthy and ghb deploy wait on. The Go images allow 5 s to start, except the MCP server's, which allows 90 s (MCP_API_WAIT_SECONDS, the time its startup keeps trying the backup API); the dashboard and the Observatory allow 180 s, because on a slow machine (a dual-core laptop with a spinning disk) they need over a minute, and a shorter start period marked them unhealthy and made ghb deploy roll back a good release. A passing check ends the start period at once, so a fast machine is not slowed. The start periods add up, because the dashboard starts only once the Observatory is healthy and the Observatory only once PostgreSQL is, so ghb deploy (WAIT_TIMEOUT) and the smoke test (SMOKE_TIMEOUT) wait up to 600 s for the whole stack.

Images are built for linux/amd64 and linux/arm64, on main and on v* tags: most self-hosted machines are x86_64, some arm64 (ADR 0019). They go to GHCR (ghcr.io/mishrashardendu22/...; Docker Hub too when its secrets are set). Tags: sha-<short sha>, latest, and versions for v* tags. A self-hosted machine with pulled images deploys sha- tags; release.yml attaches the worker and MCP binaries to GitHub releases.

The dashboard image needs no network beyond the npm registry: the three fonts the app uses are in src/apps/github-backup-dashboard/src/fonts (the latin files Google serves, under the SIL Open Font License) and next/font/local loads them, where next/font/google fetched them from Google during every build; pnpm in the image waits up to ten minutes per fetch, with five retries, for a slow link. CI's smoke job (ci.yml) builds the same images with one buildx builder, ghb-smoke, on the owner's workstation runners (06 operations, CI runners). The smoke job creates that builder, builds and removes it again while it holds the Docker host's lock, keeping its state volume buildx_buildkit_ghb-smoke0_state: its cache mounts (the pnpm store, the Go module cache, the Next.js cache) and layers survive between runs, so a run there downloads only what changed. Between runs no builder is registered, so docker buildx prune --builder ghb-smoke fails; when the host's disk runs short, docker volume rm buildx_buildkit_ghb-smoke0_state frees that cache while no smoke job runs (the runner scaler does this at its lowest disk tier), and docker builder prune does not touch it. Each publish job keeps its registry logins in a Docker config of its own (DOCKER_CONFIG under the job's temporary directory): the runners share one home, and parallel jobs logging in and out of the same ~/.docker/config.json refused one job's push a token and, after a cancelled run, left a stale GHCR login that refused every image pull on the host.

Go layout​

Each Go service keeps its entry point in cmd/<service>/main.go, its wiring in internal/app, its settings in config/, and its domain packages beside them (notify's in src/backend/github-backup-api/notify, its senders behind a port in notify/sender). Code shared by more than one Go service lives in src/platform/:

PackageResponsibilityUsed by
envfileLoads repository-relative .env files (ENV_FILE picks one); never overrides the environmentAPI, MCP, worker
loggingJSON logs with slog (time, level, msg, service), LOG_LEVEL, request idsAPI, MCP, worker
pgpoolThe pgx pool and an application_name per serviceAPI, worker
dbmigrateThe embedded schema migrations, their runner, and the service roles' grants (roles.sql)API, worker
gitexecRuns git with bounded output, process-group kills on timeout and redacted credentialsworker, MCP
githubapiThe GitHub REST client: pagination, rate-limit pauses, retriesworker
clientipThe client address behind trusted proxies (TRUSTED_PROXIES)API, MCP
ratelimitFixed-window counters per key, in processports/memory
portsA cache, rate limits, locks and a job queue as interfaces, each with an in-process (memory), a PostgreSQL (pgports, migration 000018) and a Valkey (valkeyports) adapter that pass one shared test suite (portstest). portset picks the adapters from the settings (ADR 0005); the Valkey tests need TEST_VALKEY_URLAPI, MCP (rate limits, RATELIMIT_BACKEND)
runstoreThe SQL of backup runs, worker state, the lease, requests and research samples, scoped to an account; shared by a self-hosted worker and the API's /v1 intakeAPI, worker
svcauthService credentials (ghb_svc_): making them, the hashed set (SERVICE_CREDENTIALS), and the policy of what each calling service may do by operationId (ADR 0009)API, MCP
tenancyAccounts, principals, tokens, the sign-up policy, the agent link flow, audit events and the principal cacheAPI, MCP, worker
pgtestIntegration-test helpers (TEST_DATABASE_URL)tests

Contracts​

What the services promise each other and their clients is written down in contracts/ (ADR 0003, contracts/README.md): an OpenAPI file per HTTP service and a JSON Schema per domain event. Each of the API's five services (identity, runs, insights, notify, billing) has a file written by hand, and they share common.json; a test checks every route against its service's file and every answer against the file of the service that serves it. The Observatory's is generated from its code. CI refuses a breaking change, and an operation that moves between the API's files is compared at its new home.