Self-hosting RelayFlow
This is the production deployment guide for running RelayFlow on your own infrastructure. It covers everything from a fresh host to a running instance with TLS.
Prerequisites
- Docker Engine + Docker Compose v2.
- A domain name with two DNS
Arecords pointed at the host: one for the web app, one for the API (e.g.app.example.comandapi.example.com). The bundled reverse proxy (Caddy) needs these to provision TLS certificates automatically. - Ports 80 and 443 open on the host.
Quick start
Save these three files into a directory on your host, keeping them in the same relative layout shown here (the Caddyfile goes in infra/docker/caddy/Caddyfile, next to the compose file).
# RelayFlow self-hosted production stack.
# Run: docker compose --profile prod up -d
services:
postgres:
image: postgres:16-alpine
profiles:
- prod
restart: unless-stopped
environment:
POSTGRES_DB: ${POSTGRES_DB:-relayflow}
POSTGRES_USER: ${POSTGRES_USER:-relayflow}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test:
- CMD-SHELL
- pg_isready -U ${POSTGRES_USER:-relayflow} -d ${POSTGRES_DB:-relayflow}
interval: 10s
timeout: 5s
retries: 5
deploy:
resources:
limits:
cpus: "1"
memory: 1g
redis:
image: redis:7-alpine
profiles:
- prod
restart: unless-stopped
command: redis-server --save 60 1 --loglevel warning
volumes:
- redis_data:/data
healthcheck:
test:
- CMD
- redis-cli
- ping
interval: 10s
timeout: 5s
retries: 5
deploy:
resources:
limits:
cpus: "0.5"
memory: 256m
migrate:
build:
context: .
dockerfile: infra/docker/flyway/Dockerfile
image: ghcr.io/odunlamizo/relayflow-migrate:${RELAYFLOW_VERSION:-latest}
profiles:
- prod
environment:
FLYWAY_URL: jdbc:postgresql://postgres:5432/${POSTGRES_DB:-relayflow}
FLYWAY_USER: ${POSTGRES_USER:-relayflow}
FLYWAY_PASSWORD: ${POSTGRES_PASSWORD:-}
command:
- -connectRetries=10
- migrate
depends_on:
postgres:
condition: service_healthy
restart: no
api:
build:
context: .
dockerfile: apps/api/Dockerfile
image: ghcr.io/odunlamizo/relayflow-api:${RELAYFLOW_VERSION:-latest}
profiles:
- prod
restart: unless-stopped
env_file: .env
environment:
DATABASE_URL: jdbc:postgresql://postgres:5432/${POSTGRES_DB:-relayflow}
DATABASE_USERNAME: ${POSTGRES_USER:-relayflow}
DATABASE_PASSWORD: ${POSTGRES_PASSWORD:-}
REDIS_URL: redis://redis:6379
LOG_FORMAT: ${LOG_FORMAT:-json}
JAVA_OPTS: ${JAVA_OPTS:--XX:MaxRAMPercentage=75}
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
migrate:
condition: service_completed_successfully
healthcheck:
test:
- CMD
- curl
- -f
- http://127.0.0.1:8080/health
interval: 10s
timeout: 3s
retries: 5
start_period: 45s
volumes:
- ./plugins:/app/plugins/custom:ro
- api_data:/app/data
read_only: true
tmpfs:
- /tmp
security_opt:
- no-new-privileges:true
deploy:
resources:
limits:
cpus: "2"
memory: 1g
web:
build:
context: .
dockerfile: apps/web/Dockerfile
image: ghcr.io/odunlamizo/relayflow-web:${RELAYFLOW_VERSION:-latest}
profiles:
- prod
restart: unless-stopped
environment:
RELAYFLOW_API_INTERNAL_URL: http://api:8080
depends_on:
api:
condition: service_healthy
healthcheck:
test:
- CMD
- wget
- -q
- --spider
- http://127.0.0.1:3000/api/health
interval: 10s
timeout: 3s
retries: 5
start_period: 20s
security_opt:
- no-new-privileges:true
deploy:
resources:
limits:
cpus: "1"
memory: 512m
caddy:
image: caddy:2-alpine
profiles:
- prod
restart: unless-stopped
ports:
- 80:80
- 443:443
volumes:
- ./infra/docker/caddy/Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
environment:
RELAYFLOW_WEB_DOMAIN: ${RELAYFLOW_WEB_DOMAIN}
RELAYFLOW_API_DOMAIN: ${RELAYFLOW_API_DOMAIN}
depends_on:
- web
- api
volumes:
postgres_data: null
redis_data: null
api_data: null
caddy_data: null
caddy_config: null
# RelayFlow production self-hosting configuration.
# Copy this file to `.env` and fill in the values below, then run:
# docker compose --profile prod up -d
# See docs/self-hosting.md for the full walkthrough.
# ── Domains (used by Caddy for automatic TLS — point DNS here first) ──────────
RELAYFLOW_WEB_DOMAIN=app.example.com
RELAYFLOW_API_DOMAIN=api.example.com
# ── Public service URLs (full https:// URLs, no trailing slash) ──────────────
# Web app address: CORS origin, invite links, redirect after login, Google redirect URI.
RELAYFLOW_WEB_BASE_URL=https://app.example.com
# API address: the webhook URLs Telegram and WhatsApp call.
RELAYFLOW_API_BASE_URL=https://api.example.com
# ── Database ────────────────────────────────────────────────────────────────
POSTGRES_DB=relayflow
POSTGRES_USER=relayflow
POSTGRES_PASSWORD= # REQUIRED, no default — generate: openssl rand -base64 24
# ── Security (REQUIRED, no safe default) ───────────────────────────────────
RELAYFLOW_ENCRYPTION_KEY= # REQUIRED — generate: openssl rand -base64 32
# The API refuses to start without this.
# ── Session cookies ─────────────────────────────────────────────────────────
SESSION_COOKIE_NAME=JSESSIONID
SESSION_COOKIE_SECURE=true # must be true — Caddy terminates TLS
SESSION_COOKIE_SAME_SITE=lax
SESSION_TIMEOUT=30m
# ── Google OAuth (optional) ─────────────────────────────────────────────────
# Authorized redirect URI to add in Google Cloud:
# <RELAYFLOW_WEB_BASE_URL>/backend/login/oauth2/code/google
GOOGLE_AUTH_ENABLED=false
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
# ── LLM providers (optional — at least one needed for AI agent features) ───
ANTHROPIC_API_KEY=
# OpenAI-compatible: any API that speaks OpenAI's chat completions format. The base URL includes /v1, for example
# OpenAI https://api.openai.com/v1
# Groq https://api.groq.com/openai/v1
# OpenRouter https://openrouter.ai/api/v1
# Ollama http://<ollama-host>:11434/v1 (no key needed)
OPENAI_COMPATIBLE_BASE_URL=
OPENAI_COMPATIBLE_API_KEY=
# The model is chosen in Settings → Providers, or for every workspace in Redis — see
# docs/self-hosting.md:
# redis-cli SET platform:llm:openai-compatible:model llama-3.3-70b-versatile
# ── Voice messages (optional) ───────────────────────────────────────────────
# Any OpenAI-format speech-to-text API. Blank means the OpenAI-compatible LLM settings above.
# Groq https://api.groq.com/openai/v1 (model whisper-large-v3-turbo)
# OpenAI https://api.openai.com/v1 (model whisper-1)
OPENAI_COMPATIBLE_TRANSCRIPTION_BASE_URL=
OPENAI_COMPATIBLE_TRANSCRIPTION_API_KEY=
# The model is chosen in Settings → Providers, or for every workspace in Redis:
# redis-cli SET platform:transcription:openai-compatible:model whisper-large-v3-turbo
# ── Email — SMTP (optional; blank host = no-op/log mode) ────────────────────
# Works with any provider: Resend, SES, Mailgun, Postmark, Gmail, self-hosted, etc.
SMTP_HOST=
SMTP_PORT=587
SMTP_USERNAME=
SMTP_PASSWORD=
SMTP_FROM=RelayFlow <noreply@example.com>
# ── Rate limiting (optional — all have safe defaults) ───────────────────────
RATE_LIMIT_ENABLED=true
RATE_LIMIT_LOGIN_LIMIT=5
RATE_LIMIT_LOGIN_WINDOW_SECONDS=60
RATE_LIMIT_SIGNUP_LIMIT=10
RATE_LIMIT_SIGNUP_WINDOW_SECONDS=3600
RATE_LIMIT_PUBLIC_API_LIMIT=60
RATE_LIMIT_PUBLIC_API_WINDOW_SECONDS=60
RATE_LIMIT_WEBHOOK_LIMIT=120
RATE_LIMIT_WEBHOOK_WINDOW_SECONDS=60
# ── Timeouts & retention (optional — safe defaults) ─────────────────────────
RELAYFLOW_HTTP_CONNECT_TIMEOUT_MS=10000
RELAYFLOW_HTTP_READ_TIMEOUT_MS=20000
RELAYFLOW_WEBHOOK_TIMEOUT_MS=10000
RELAYFLOW_INVITE_EXPIRY_DAYS=7
WORKFLOW_RUN_RETENTION_DAYS=90
AGENT_INVOCATION_LOG_RETENTION_DAYS=90
# ── Logging (optional) ──────────────────────────────────────────────────────
# json (Datadog and most agents), ecs (Elastic), gelf (Graylog), logfmt (Loki), or text (human-readable).
LOG_FORMAT=json
# Log level for RelayFlow code (DEBUG includes personal data such as email addresses).
LOG_LEVEL=INFO
# ── JVM (optional) ──────────────────────────────────────────────────────────
# Extra flags for the API's JVM. By default the heap may use 75% of the API
# container's memory limit (1g in docker-compose.yml) — raise that limit for
# heavier workloads rather than setting -Xmx here.
# JAVA_OPTS=-XX:MaxRAMPercentage=75
# ── Misc ─────────────────────────────────────────────────────────────────────
RELAYFLOW_VERSION=latest # image tag to pull/build — pin to a release tag in production
{$RELAYFLOW_API_DOMAIN} {
reverse_proxy api:8080
}
{$RELAYFLOW_WEB_DOMAIN} {
reverse_proxy web:3000
}
Then:
cp .env.example .envGenerate the two secrets that have no safe default:
openssl rand -base64 24 # → POSTGRES_PASSWORD
openssl rand -base64 32 # → RELAYFLOW_ENCRYPTION_KEYFill in .env: the two generated secrets and your domains (RELAYFLOW_WEB_DOMAIN, RELAYFLOW_API_DOMAIN, and the matching RELAYFLOW_WEB_BASE_URL/RELAYFLOW_API_BASE_URL).
Then start the stack:
docker compose --profile prod up -dRequired vs optional env vars
| Variable | Required? | Notes |
|---|---|---|
| POSTGRES_PASSWORD | Yes | No default — generate with openssl rand -base64 24 |
| RELAYFLOW_ENCRYPTION_KEY | Yes | No default — generate with openssl rand -base64 32. The API refuses to start without it. |
| RELAYFLOW_WEB_DOMAIN / RELAYFLOW_API_DOMAIN | Yes | Used by Caddy for automatic TLS |
| RELAYFLOW_WEB_BASE_URL / RELAYFLOW_API_BASE_URL | Yes | Must match the domains above exactly — see Troubleshooting |
| GOOGLE_AUTH_ENABLED / GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET | No | Off by default. In Google Cloud, add the redirect URI <RELAYFLOW_WEB_BASE_URL>/backend/login/oauth2/code/google |
| ANTHROPIC_API_KEY | No | For Anthropic models. AI agent features need this or the OpenAI-compatible provider below. You also need to pick the active provider in Redis — see the first-run walkthrough below. |
| OPENAI_COMPATIBLE_BASE_URL / OPENAI_COMPATIBLE_API_KEY | No | Any OpenAI-compatible API — OpenAI, Groq, OpenRouter, Ollama, vLLM, and more. The base URL includes /v1 (e.g. https://api.groq.com/openai/v1); the key can be empty for local servers. The model is set in Redis — see the first-run walkthrough below. Common URLs are listed in .env.example below. |
| SMTP_HOST / SMTP_PORT / SMTP_USERNAME / SMTP_PASSWORD / SMTP_FROM | No | Works with any SMTP provider (Resend, SES, Mailgun, Postmark, Gmail, self-hosted, etc.). Blank host runs email in no-op/log mode |
| JAVA_OPTS | No | Extra JVM flags for the API. Defaults to -XX:MaxRAMPercentage=75, so the heap can use 75% of the API container's 1 GB memory limit; raise the limit in docker-compose.yml for heavier workloads |
| Rate limiting, timeouts, retention vars | No | All have safe defaults — see .env.example below |
First-run walkthrough
- Confirm the one-shot
migrateservice applied all migrations and exited cleanly:docker compose --profile prod logs migrate - Confirm every service reports healthy:
docker compose --profile prod ps - Visit
https://<RELAYFLOW_WEB_DOMAIN>and complete the first admin signup. - Choose the LLM provider and model for each workspace in Settings → Providers (workspace owners). To set a default for every workspace instead, use Redis — changes take effect without a restart:
Nothing is chosen for you: without a provider and a model, the AI agent doesn't reply and conversations go to a person. Ollama isn't bundled here — run it separately and use the OpenAI-compatible provider withdocker compose --profile prod exec redis redis-cli SET platform:llm:provider OPENAI_COMPATIBLE # or ANTHROPIC docker compose --profile prod exec redis redis-cli SET platform:llm:openai-compatible:model openai/gpt-4o-miniOPENAI_COMPATIBLE_BASE_URL=http://<ollama-host>:11434/v1and no key.
Backups
Back up the Postgres volume regularly:
docker compose --profile prod exec postgres \
pg_dump -U relayflow relayflow > backup-$(date +%F).sqlRestore into a fresh instance with psql -U relayflow relayflow < backup.sql, or snapshot the postgres_data named volume directly at the infrastructure level.
Upgrades
- Bump
RELAYFLOW_VERSIONin.envto the new release tag. - Re-run migrations before restarting the app:
docker compose --profile prod run --rm migrate - Pull and restart:
docker compose --profile prod pull docker compose --profile prod up -d
Migrations are forward-only. There's no down-migration path, so plan upgrades accordingly.
Using your own reverse proxy
If you already run nginx, Traefik, or similar, skip the caddy service by naming the other services explicitly instead of using --profile prod:
docker compose up -d postgres redis migrate api weband point your existing proxy at web:3000 and api:8080 on the compose network instead.
Troubleshooting
- Browser console shows CORS errors —
RELAYFLOW_WEB_BASE_URLmust exactly match the public origin the browser is loading the web app from (scheme + host, no trailing slash) — the API uses it as the allowed CORS origin. - AI agent features return errors or do nothing — you need both a provider configured (
ANTHROPIC_API_KEY, or theOPENAI_COMPATIBLE_*variables) and that provider chosen, in Settings → Providers or with theplatform:llm:providerRedis key (see the first-run walkthrough above). Forgetting the second one is the usual cause. - API container exits immediately on a fresh install — check
docker compose --profile prod logs api— this is almost always a missingRELAYFLOW_ENCRYPTION_KEY, which fails fast with a clear message.