---
title: "Infrastructure and deployment"
description: "Coolify, frp, Traefik, Pulumi and networking."
---

![Infrastructure topology](/blume-assets/content/docs/architecture/diagrams/10-infrastructure-topology.png)

## Layers

| Layer | Tool | Scope |
|---|---|---|
| Hardware / cloud | Pulumi (real providers) | VPS, volumes, firewall, DNS, frp config, Coolify install |
| Runtime & routing | **Coolify** (Docker + Traefik) | Projects, apps, Compose services, TLS, deployments |
| Tenant composition | Control plane + **one Pulumi stack per tenant** (the Coolify Terraform provider through Pulumi's Any Terraform Provider, ADR-020) | Per-tenant resources, via Coolify's own API |

The separation follows the discussion's conclusion: do not mutate Coolify's
runtime behind its back; use its API for everything it manages.

## Coolify facts that constrain the design

* Self-hosted REST API under `/api/v1`; API must be enabled; bearer tokens are
  bound to a user/team with `read`/`write`/`deploy`/`delete` permissions and
  project/environment/resource access.
* **A restricted write token is not a server security boundary** (Compose and
  bind mounts are privileged). Treat the Coolify token as root-equivalent on
  the host: only the worker holds it, rotate on schedule.
* Webhook/Git auto-deploy are not used for tenants; the CP triggers deployments.
* The **token abilities** the control plane needs are `read`, `write`,
  `deploy`, `read:sensitive` and `delete`: `deploy` to start a service,
  `delete` for Pulumi `destroy`, and `read:sensitive` to read back values the
  provider must compare (drift detection — without it, a changed env var is
  invisible to `refresh`). A token without `delete` fails on
  `DELETE /projects/{uuid}` with `403 Missing required permissions: delete`.

### Behaviors found in the first bring-up

Each of these cost a failed deploy on prod; the stack encodes the answer, so do not "simplify" it.
The symptom-first version is in [12](/architecture/bastion-runbook#troubleshooting).

| Coolify behavior | Consequence in the stack |
|---|---|
| The API refuses `enable_ssl` on a database | TLS is switched in the UI; the stack reads the real state from the API (`base:corePostgresTls`) and refuses to plan when it is off |
| `start` on a running service is a no-op | services get a **restart** action whose `triggers` hash the compose and the values |
| `${VAR}` in a **label** is not interpolated (the placeholder reaches Traefik verbatim) | router rules use real hostnames; plugin middlewares configured by labels (`traefikoidc`) carry their secrets inside the compose, which is therefore a Pulumi secret |
| An empty `EnvsBulk` is rejected (`Bulk data is required`) | a service with no variables gets no bulk resource |
| Deleting an `EnvsBulk` leaves the variables in Coolify | stale variables are removed through the API by hand, then the service is restarted |
| The compose is parsed as **YAML 1.1** (a date is a timestamp, then an epoch) | the renderer serializes with the 1.1 schema so such values stay quoted |
| Traefik router/service names are global to the proxy; the same name with another rule unroutes both | names carry the host (`https-0-<id>-<host-slug>`) |
| Coolify's CA is not in the apps' trust store | `sslmode=no-verify` for node-postgres clients, `require` for libpq/pgx ([08](/architecture/data-storage-secrets#transport-encryption-core-cluster)) |
| The API has no file read | the Zitadel bootstrap PAT is read over `ssh` + `docker cp` on the first setup only |
| A project's environment is named by us | environments are named after the stack (`prod`), never `<project>-<stack>` |

## Coolify layout

Everything we own lives in the **root team** of the Coolify instance (a
separate team is out of scope for now) in projects with a `fortspace-` prefix:

| Project | Contents | Managed by |
|---|---|---|
| `fortspace-platform` | Zitadel (+ login v2, issuer `https://id.<domain>`), Mailpit, CP (`cp-migrate` + api/worker/console), Infisical, LiveKit, Egress, RustFS, core Postgres/Redis — the platform's own services | base infrastructure: Pulumi project `base` in `bastion/`, **applied on prod** (procedure and troubleshooting: [12](/architecture/bastion-runbook)) |
| `fortspace-tenant-<slug>` | the tenant's stack: go-meet, redis, tuwunel (+ future modules) | **one Pulumi stack per tenant** (Pulumi project `tenant`, stack `<slug>`) |
| `fortspace-data-pool` | **no resources yet** — project + environment placed on the `fortspace-data-net` destination; shard Postgres instances are added on demand by the CP's `shard.add` | base infrastructure creates the project/environment; the CP creates the shards |

The base stack's own state cannot live in the core Postgres it creates, so it uses a
file/S3/Pulumi Cloud backend (see `bastion/README.md`); the `pulumi_state` database
it creates serves the tenant stacks only. **Prod today uses the default `file://.state`
backend on the operator's workstation** — a single point of failure (the state and the generated
passwords live there; it is git-ignored). Back it up after every `up`, or move it to S3 / Pulumi
Cloud (not to the platform's own RustFS or Postgres: chicken and egg). See
[12](/architecture/bastion-runbook#what-you-must-not-lose). Networks: `fortspace-platform-net` for the
platform services (not `office-suite-net`, which belongs to the retired blueprint)
and `fortspace-data-net` for the data pool only — the only shared resources that need
to reach the tenant shards are on it.

### Platform bootstrap (after the first `up`)

`bastion/scripts/platform-setup.sh [stack]` runs on the **workstation** against the
public URLs and drives `control-plane/tools/prod`: Infisical instance bootstrap +
platform secrets (from the stack outputs) + `cp-worker`/`cp-broker` identities;
Zitadel projects/roles/apps/machine users; then `pulumi config set --secret
controlPlaneSecrets` **and** `--secret rustfsOidc` in the base stack, so a second
`pulumi up` starts the CP fully wired and turns the RustFS console on. Idempotent.

**The first run uses the first-instance admin PAT** (read over `ssh` + `docker cp` from
the `zitadel-bootstrap` volume — the Coolify API has no file read). It then creates the
`platform-setup` machine user (`IAM_OWNER`, key in
`/platform/zitadel#SETUP_KEY_JSON`), proves the key works, **revokes the PAT** and
deletes `admin.pat`. Later runs need no ssh ([03](/architecture/identity-access), ADR-023).

What it creates in Zitadel: the projects `Fortspace Cockpit` (cockpit OIDC app), `Fortspace Console` and `Fortspace Workspace` with their roles;
the `Fortspace Admin` project (role `superadmin`, never granted to tenants) with the
RustFS console OIDC app; the `cp-provisioner` and `platform-setup` machine users; the
first superadmin (the seeded `operator`); **MFA enforced** on the platform org.

People get the full set with `bastion/scripts/superadmin.sh grant <email>`
(`revoke` takes it back) — see [03](/architecture/identity-access#oidc-coverage-and-superadmins).

### The control plane's images and the registry login

The CP runs as four Compose services in `fortspace-platform`: `cp-migrate` (one-shot that applies
the SQL migrations and exits), `cp-api`, `cp-worker` and `cp-cockpit`. They wait for the migrate
one-shot (`service_completed_successfully`), so a fresh database is migrated before anything reads
it.

The four images (`ghcr.io/fortspace/control-plane-{api,worker,cockpit,migrate}`) are **private
GHCR packages**, built by the control plane's own workflow. Two consequences:

* **The tag is pinned.** `base:controlPlaneTag` holds a `sha-<short>` or a release version.
  `latest` exists only after a release tag, and `edge` moves with every push to the CP's `main`.
* **The Coolify host needs a registry login.** The base stack owns it — a server-level
  `coolify_server_docker_registry` resource (`base:registry` + the secret `base:registryToken`,
  a classic PAT with `read:packages`). It is the base stack and not the CP worker, because the
  worker's own image comes from the same private registry: a login applied by the worker would
  arrive too late. The same login serves the tenant stacks' `go-meet` image.

The stack refuses to plan when the control plane is enabled but its secret values are missing
(they only exist after the platform setup), so the order — base `up` → setup → CP `up` — is
enforced rather than remembered.

Infisical's `ENCRYPTION_KEY`/`AUTH_SECRET`, the Zitadel masterkey, the Infisical admin
password and the Coolify local account are escrowed offline, never in Infisical
([08](/architecture/data-storage-secrets), [10](/architecture/security-operations#break-glass)).

### The stack's state and who deploys it

The base stack (`bastion/`, Pulumi project `base`) is applied from an operator workstation
**and** from GitHub Actions: a merge on the control plane's `main` publishes the images and
triggers the deploy (ADR-030). Two consequences:

* **The state cannot live on a workstation.** It is in an S3-compatible object storage
  bucket in the EU (Scaleway `nl-ams`, ADR-029), versioned, with bucket-scoped keys. The
  passphrase secrets provider still encrypts the secrets in it. The platform's own Postgres
  and RustFS cannot hold it: the stack creates them.
* **GitHub holds the platform's credentials.** The deploy runs in the `prod` GitHub
  Environment: the Coolify token (root on the host), the Pulumi passphrase and the bucket
  key. The cross-repository hop (control plane → bastion) uses a GitHub App installed on the
  bastion repository only.

The procedure, the migration and the exact settings are in
[12](/architecture/bastion-runbook#4-state-and-deploys).

> **Reserved prefix.** `fortspace-tenant-` is reserved for tenant projects: no
> other project may use it (the data pool is `fortspace-data-pool`, because
> `fortspace-tenant-pool` would collide with a tenant whose slug is `pool`).

> **The `fortspace-` prefix is the guard.** The instance already carries a
> project named `fortspace` (created before this layout). The adapter only
> manages projects named `fortspace-tenant-<slug>`, so a name that does not
> carry the prefix can never be adopted or deleted by a stack. The guard is
> code and tests, **not** a Coolify permission: a root-team token reaches every
> project (see [10](/architecture/security-operations#exceptions-and-known-risks)).

Tags are **team-scoped** (a tag name is unique per team), so a shared tag
created by one stack would be deleted by that stack's `destroy` and break the
others. Each tenant stack therefore creates its own tag `tenant-<slug>`.

Networks: `fortspace-platform-net` (external Docker network, a Coolify destination)
is used by `fortspace-platform`; `fortspace-data-net` carries only the data-pool shard
Postgres. Tenant projects get their own network; the only paths to the shared plane
are the public HTTPS endpoints (CP API `api.<domain>`, cockpit `cockpit.<domain>`,
Zitadel `id.<domain>`, Infisical `infisical.<domain>`, RustFS `s3.<domain>` and its
console `storage.<domain>`) and the shard host on `fortspace-data-net`. On a single host these names resolve over the
Docker bridge; on multiple hosts, over the private network.

## Edge and ports (diagram 10)

Platform domain: **`fortspace.eu`** (single `prod` stack for now). Platform hosts:

| Host | Service |
|---|---|
| `id.fortspace.eu` | Zitadel (single issuer) + login v2 |
| `api.fortspace.eu` | Control-plane API: LiveKit token broker, webhook router, `/admin/v1` |
| `cockpit.fortspace.eu` | Operator cockpit |
| `livekit.fortspace.eu` | LiveKit signaling (media over frp) |
| `infisical.fortspace.eu` | Infisical |
| `s3.fortspace.eu` | RustFS S3 |
| `storage.fortspace.eu` | RustFS console (admin UI, OIDC-only: superadmins) |
| `mail.fortspace.eu` | Mailpit UI (until a prod EU SMTP relay) |

Tenant hosts are `<module>.<slug>.fortspace.eu` ([02](/architecture/tenancy-isolation), ADR-035,
[13](/architecture/tenant-hosts)); a tenant's own domain is a later upsell.

* DNS (Scaleway): `*.<platform-domain>` → public VPS, `livekit.<platform-domain>` included (no
  HTTP proxy in front: UDP media must reach the VPS directly).
* frp: `frpc` on the private host connects out to `frps` on the VPS and
  forwards TCP 80/443 → Traefik, and the media ports TCP 7885 / UDP 7886 →
  the host's 7883 / 7884 → the container's 7881 / 7882.
* Caddy holds 443 on the VPS (L4: SNI → Headscale, everything else → frp), so
  `frps` listens on **8443** for HTTPS and 8080 for HTTP, and the `https`
  proxy points at the Coolify host's 443. frp routes TCP and UDP **by port**,
  never by domain (only HTTP/HTTPS can be routed by host), so a second LiveKit
  needs its own port pair: the old prototype deployment keeps 7881 / 7882.
* LiveKit: `use_external_ip: false`; `node_ip` is resolved from the A record of
  `LIVEKIT_DOMAIN` by `livekit-init` (draft `compose.livekit.yaml`), because
  STUN would discover the wrong address behind frp.
* Traefik terminates TLS (Let's Encrypt). Zitadel (issuer `id.<domain>`) needs
  `h2c` to the API container and a path split for login v2 (`/ui/v2/login` priority
  100), as in `compose.zitadel.yaml`. Mailpit's UI is routed on `mail.<domain>`;
  its SMTP port 1025 stays internal (alias `mailpit` on the platform network). Zitadel
  and Infisical both send there (Infisical: `SMTP_HOST=mailpit`, port 1025, plain SMTP,
  from `noreply@infisical.<domain>`). The UI has **no login of its own** and holds every
  Zitadel and Infisical mail (init codes, invites, password resets): a known exposure until
  the prod EU relay replaces it ([03](/architecture/identity-access), [10](/architecture/security-operations)). `base:mailpitAuthEnabled` closes it
  meanwhile: an OIDC login in front of the UI (Traefik plugin `traefikoidc`, registered in
  Coolify's proxy; the operator's external pocket-id as provider; an allow-list of emails).
  The plugin reads its configuration from the container's Docker labels and Coolify does not
  interpolate a label, so the client id, secret and session key are **part of the compose** of
  that service (encrypted in the Pulumi state, readable in Coolify's database and in the
  container's labels).
* LiveKit's `webhook:` block points at the CP router
  (`https://api.<domain>/internal/v1/livekit/webhook`), signed with the LiveKit API
  key whose secret the broker holds ([06](/architecture/calls-livekit)).
* Certificates: `*.fortspace.eu` does not cover `meet.acme.fortspace.eu`. Decided (ADR-035): a
  Traefik DNS-01 resolver with Scaleway, one certificate per tenant; it goes in after a check of
  Scaleway's wildcard/empty-non-terminal behaviour and with a narrowly scoped key, and until then a
  tenant can use one HTTP-01 certificate (its product hosts as SANs) through the existing
  `letsencrypt` resolver. Design and trade-offs: [13](/architecture/tenant-hosts#certificates-and-dns-for-productslugfortspaceeu).
* Response headers the edge adds where the service does not (ADR-035): `s3.` answers with
  `Content-Security-Policy: sandbox` (tenant uploads never run on the platform domain; a PDF then
  downloads instead of rendering inline), `storage.` and `mail.` with `X-Frame-Options: SAMEORIGIN`;
  Infisical runs with `HTTPS_ENABLED=true` so its cookies are `Secure`. The deploy's verify step
  checks the three headers.

## Reference of what exists vs. what to change

| Draft file | State | Required change |
|---|---|---|
| `compose.livekit.yaml` | LiveKit, init container, Egress | Done in `bastion/`: no global `RUSTFS_*` on Egress, `webhook:` → CP router, keys held by broker |
| `compose.meet.yaml` | La Suite Django backend + frontend (Keycloak OIDC) | Superseded by go-meet tenant template; keep as parity reference |
| `compose.zitadel.yaml` | Zitadel + login v2, bootstrap PAT volume | Done in `bastion/`: v4.20.6, first-instance org `fortspace-platform` (human `operator`, machine `bootstrap-admin`, PAT in the volume), the Login UI signs its session cookie (`ZITADEL_SESSION_COOKIE_SECRET`, its own secret since v4.19.2), SMTP → Mailpit until a prod EU relay exists (created via the Zitadel API then — env credentials are not persisted, zitadel#11765); the Fortspace project is created by `tools/prod` (the PAT is revoked after the first run) |
| `compose.keycloak.yaml` | Keycloak | Deprecated |
| `compose.yaml` | Original monolith stack (Django meet) | Reference only |
| `postgres/01..04_*.sh` | Schemas per product | Applied by the bastion's `core-postgres-bootstrap` one-shot (control_plane + pgboss schemas, dedicated DBs); `meet` lives in the tenant pool |
| `livekit-server.yaml` | Keys via `LIVEKIT_KEYS`, Redis TLS via sed | Done in `bastion/`: `webhook:` block → CP router; `room` defaults still open |
| go-meet `dev-local/` | Local compose (Postgres, RustFS, LiveKit, Keycloak/Zitadel, Traefik) | Keep for dev; mirror tenant template |

### Tenant Compose template (sketch)

```yaml
# rendered per tenant by the provisioner; only non-secret values inlined
services:
  go-meet:
    image: ghcr.io/<org>/go-meet:${GOMEET_VERSION}
    entrypoint: ["infisical","run","--projectId","${INFISICAL_PROJECT_ID}","--path","/tenants/${SLUG}/meet","--","/go-meet"]
    environment:
      INFISICAL_CLIENT_ID: ${INFISICAL_CLIENT_ID}
      INFISICAL_CLIENT_SECRET: ${INFISICAL_CLIENT_SECRET}
      OIDC_USE_PKCE: "true"
      LIVEKIT_BROKER_URL: https://api.${PLATFORM_DOMAIN}/internal/v1
    networks: [tenant, shared-egress]
  redis:
    image: redis:7
    command: ["redis-server","--requirepass","${REDIS_PASSWORD}"]
    networks: [tenant]
  tuwunel:
    image: ghcr.io/matrix-construct/tuwunel:${TUWUNEL_VERSION}
    volumes: ["tuwunel-data:/var/lib/tuwunel"]
    networks: [tenant]
networks: { tenant: {}, shared-egress: { external: true } }
volumes: { tuwunel-data: {} }
```

## Environments

| Env | Purpose | Notes |
|---|---|---|
| local | Developer machine | `go-meet/dev-local/` compose (+ mock mode); CP with docker-compose + Zitadel dev |
| staging | Full topology, small | One VPS pair; acceptance tests listed in go-meet `STAGING-ACCEPTANCE.md` |
| production | EU-resident | Public VPS + private host(s); regional pinning in tenant row |

## Scaling plan

| Axis | Now | Next |
|---|---|---|
| Tenants per host | tens | Add Coolify servers; tenants record the server in their orchestrator reference |
| Postgres | data pool empty at first | `shard.add` (CP queue) creates shards on demand in `fortspace-data-pool` on `fortspace-data-net`; relocate large tenants |
| LiveKit | 1 node | N nodes need distinct public media endpoints; Redis already shared; consider moving media off frp |
| Egress | 1 worker | Scale workers horizontally (CPU bound) |
| Control plane | 2 API + 2 workers | Split broker as its own deployment if join latency demands |

## Migration path off Coolify

Store only generic references in `tenants`; implement `DokployAdapter` or a
Kubernetes adapter; migrate tenant by tenant: dump DB, deploy on the new
engine, restore volumes, switch DNS, destroy the old stack. Base infra stays
untouched in Pulumi.
