# Deploy each app separately (/docs/self-host/individual-apps)



`docker-compose.prod.yml` runs everything together, but every app has its own Dockerfile and can
be deployed on its own: on different hosts, scaled independently, or only the ones you need. All
builds run **from the repository root**, because the Dockerfiles copy the shared workspace
(`bun.lock`, `packages/`).

| App     | Dockerfile                | Needs                     | Required?                          |
| ------- | ------------------------- | ------------------------- | ---------------------------------- |
| API     | `apps/api/Dockerfile`     | Postgres, (Redis)         | Yes                                |
| Worker  | `apps/api/Dockerfile`     | Postgres, (Redis)         | Yes, unless the API runs it itself |
| Console | `apps/web/Dockerfile`     | The API, reachable by URL | Yes, to use the UI                 |
| Docs    | `apps/docs/Dockerfile`    | Nothing                   | No                                 |
| Landing | `apps/landing/Dockerfile` | Nothing                   | No                                 |

## API, worker and migrations [#api-worker-and-migrations]

The API, the worker and the migration step are **one image** (`apps/api/Dockerfile`); the command
picks the process.

```bash
docker build -f apps/api/Dockerfile -t decision-control-api .
```

| Process | Command                            | Port                       |
| ------- | ---------------------------------- | -------------------------- |
| API     | `bun src/index.ts` (image default) | `3000` (`PORT`)            |
| Worker  | `bun src/worker.ts`                | None (`METRICS_PORT` opt.) |
| Migrate | `bunx --bun prisma migrate deploy` | None                       |

All three read the same environment (see [Configuration](/docs/self-host/configuration)). The
required variables are `DATABASE_URL`, `WEB_ORIGIN`, `API_KEY_PEPPER`,
`CREDENTIALS_ENCRYPTION_KEY` and `WEBHOOK_SIGNING_SECRET`.

```bash
# 1. Migrate — before every release, and before the new API starts.
docker run --rm --env-file .env decision-control-api bunx --bun prisma migrate deploy

# 2. API — stateless, run as many as you need.
docker run -d --env-file .env -e WORKER_ENABLED=false -e TRUST_PROXY=true \
  -e REDIS_URL=redis://redis:6379 -e RATE_LIMIT_STORE=redis \
  -p 3000:3000 decision-control-api

# 3. Worker — outbox delivery and housekeeping. One or more.
docker run -d --env-file .env decision-control-api bun src/worker.ts
```

* Set `WORKER_ENABLED=false` on the API when a separate worker runs; leave it on for a
  single-process deployment and skip step 3.
* Set `REDIS_URL` and `RATE_LIMIT_STORE=redis` as soon as you run more than one API replica, so
  rate limits are shared. Without Redis each replica counts on its own.
* Set `TRUST_PROXY=true` (and `TRUST_PROXY_HOPS`) only when a proxy you control sits in front, so
  `X-Forwarded-For` is the real client address.
* Probes: `GET /healthz` (liveness) and `GET /readyz` (readiness). The worker serves no HTTP, so
  disable the image's HTTP healthcheck for it.
* The worker needs `SIGTERM` and about 40 s of grace to finish its batch.

## Console [#console]

A static build served by nginx that also forwards `/api` to the API, so the browser stays on one
origin (first-party session cookie, no CORS).

```bash
docker build -f apps/web/Dockerfile \
  --build-arg VITE_DOCS_URL=https://docs.example.com \
  -t decision-control-web .

docker run -d -p 8080:80 -e API_UPSTREAM=http://api.internal:3000 decision-control-web
```

* `VITE_DOCS_URL` is a **build** argument (Vite inlines it). Changing it means rebuilding.
* `API_UPSTREAM` is a **runtime** variable: where `/api` and `/healthz` are forwarded.
* The console's public URL is the API's `WEB_ORIGIN`. If you place the API on a different origin
  than the console, route `/api` to it at your load balancer instead; the console only works
  against the same origin.
* nginx resolves `API_UPSTREAM` through Docker's embedded DNS (`127.0.0.11`). Outside a Docker
  network (ECS, Kubernetes, VMs) use an IP, or skip the proxy and route `/api` at the load
  balancer, as in [AWS](/docs/self-host/aws).

## Docs [#docs]

```bash
docker build -f apps/docs/Dockerfile -t decision-control-docs .
docker run -d -p 8081:80 decision-control-docs
```

A static Fumadocs site. No variables, no API. Point `VITE_DOCS_URL` of the console at its public
URL.

## Landing [#landing]

```bash
docker build -f apps/landing/Dockerfile \
  --build-arg SITE_URL=https://example.com \
  --build-arg PUBLIC_APP_URL=https://decisions.example.com \
  --build-arg PUBLIC_DOCS_URL=https://docs.example.com \
  -t decision-control-landing .

docker run -d -p 8082:80 decision-control-landing
```

A static Astro site. Every `PUBLIC_*` value (app, docs and GitHub URLs, the legal entity, address
and contact emails, governing law, status URL) is baked in at build time: change one, rebuild.

## Without Docker [#without-docker]

The static apps are plain files: `bun run --filter @decision-control/web build` writes
`apps/web/dist`, and the docs and landing builds write `apps/docs/.output/public` and
`apps/landing/dist`. Serve them from any static host or CDN. The console needs `/api` routed to
the API on the same origin, and SPA fallback to `index.html`.

## Recommended order [#recommended-order]

1. Postgres (and Redis, if you scale the API).
2. Migrate.
3. API, then worker.
4. Console.
5. Docs and landing, any time.
