# Deployment

## Profiles

| Profile | Command | Output | Use |
|---|---|---|---|
| development | `fellow dev` | Nitro dev server + Fellow module server on Bun, state-preserving HMR ([ADR 0017](/docs/adr/0017-bun-nitro-without-vite)) | Local work |
| production | `fellow build` | `.output/` (Nitro server + `public/`), run with `bun .output/server/index.mjs` | Containers, VMs, PaaS — the default |
| compiled | `fellow build --profile compiled` | `.output/compiled/<name>` executable + `.output/compiled/public/` | Hosts without Bun, single-file delivery |
| static | `fellow build --preset static` | `.output/public/`: one HTML file per public page (`/docs/vue` → `docs/vue.html`), plus `public/` | Documentation and landing pages on a static host; no server, no database (see [`fellow docs pages`](/docs/pages)) |

The compiled profile builds the production output and then runs `bun build --compile` on it. Copy the executable and
the `public/` directory next to it together; static assets are served from there. Cross-compile with
`--target bun-linux-arm64` (any Bun target). Measured on the example application (4 CPUs, linux-x64): startup
170 ms vs 190 ms, idle memory about 49 MB vs 46 MB, the same throughput (≈77k req/s on health, ≈4.4k vs 4.0k req/s
on an authenticated tenant-scoped list), and a 104 MB executable. Reproduce with `bun benchmarks/profiles/run.ts`.
See [`fellow docs adr/0012-compiled-profile`](/docs/adr/0012-compiled-profile).

Migrations and CLI commands are not part of the executable: run `fellow migrate` from the release's source (or
a CI step) before starting new instances.

## Processes

| Process | Command | Scale |
|---|---|---|
| web | `bun .output/server/index.mjs` (or the executable) | horizontally, behind a load balancer |
| worker | `fellow work` | one or more; required when the app uses jobs, durable events, workflows or schedules |

Deploy both from the same release. On `SIGTERM` the worker finishes running jobs; the web process should be taken out
of rotation through `/__fellow/ready` first (see [`fellow docs operations`](/docs/operations)).

## Environment

| Variable | Required | Meaning |
|---|---|---|
| `DATABASE_URL` | yes | PostgreSQL with a role **without** `BYPASSRLS` (checked by `fellow doctor`) |
| `FELLOW_SECRET` | yes | Signs sessions and tokens; at least 32 random bytes |
| `NODE_ENV=production` | yes | Disables development tokens and verbose errors |
| `REDIS_URL` | with Redis | Used by `FELLOW_CACHE=redis` and `FELLOW_BROADCAST=redis` |
| `FELLOW_CACHE=redis` | several instances | Shared cache (memory is per process) |
| `FELLOW_BROADCAST=redis` | several processes | Real-time channels across instances and workers |
| `FELLOW_STORAGE=s3` | optional | Object storage instead of `FELLOW_STORAGE_PATH` on local disk |
| `FELLOW_TRUST_PROXY=true` | behind a proxy | Client IP from `X-Forwarded-For` (rate limits, audit) |
| `FELLOW_LOG_LEVEL` | optional | `debug`, `info` (default), `warn`, `error` |
| `FELLOW_SLOW_QUERY_MS` | optional | Slow query threshold (default 500) |
| `FELLOW_OPERATIONS_RETENTION_DAYS`, `FELLOW_AUDIT_RETENTION_DAYS` | optional | Retention of operations rows and audit entries |
| `FELLOW_BACKUP_DATABASE_URL` | for backups | Separate `BYPASSRLS` role used only by `fellow backup` / `fellow restore` |
| `OTEL_SERVICE_NAME`, `OTEL_EXPORTER_OTLP_ENDPOINT` | optional | OpenTelemetry export (see [`fellow docs operations`](/docs/operations)) |

## Checklist

1. `fellow check --tests` and `fellow build` in CI; `fellow upgrade:check` when the framework changes.
2. `fellow doctor` against the production database once (RLS role, migrations, isolation).
3. `fellow migrate` before rolling out; destructive migrations need `fellow approve`.
4. Health checks: liveness `/__fellow/health`, readiness `/__fellow/ready`.
5. At least one `fellow work` process; `fellow queue:status` shows live workers.
6. Scheduled `fellow backup` with `fellow backup:verify`, and `fellow retention:run`.
