Deployment
This guide covers deploying Snaapi to production, including Docker-based deployments, standalone binaries, and observability setup.
Production Setup
Before deploying, ensure you have:
- A PostgreSQL database accessible from your production environment
- All required environment variables configured (see Configuration)
APP_ENVset toproduction
Key production settings:
APP_ENV="production"
DATABASE_URL="postgres://user:password@db-host:5432/snaapi"
BETTER_AUTH_SECRET="<strong-random-secret>"
BETTER_AUTH_URL="https://your-domain.com"
SNAAPI_SESSION_SECRET="<strong-random-secret>"
SNAAPI_LOG_LEVEL="info"
SNAAPI_AUTO_MIGRATE=false
Docker Compose
Deploy Snaapi with Docker Compose for a self-contained setup:
# docker-compose.yml
services:
snaapi:
image: snaapi:latest
ports:
- "8000:8000"
environment:
- DATABASE_URL=postgres://user:password@db:5432/snaapi
- BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET}
- BETTER_AUTH_URL=${BETTER_AUTH_URL}
- APP_ENV=production
depends_on:
- db
db:
image: postgres:15
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: snaapi
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
docker compose up -d
The Snaapi Docker image uses a distroless base (gcr.io/distroless/cc-debian12)
and runs as a non-root user for security.
Deno Compile
Build a standalone binary with no runtime dependencies:
deno task compile
This produces dist/snaapi — a self-contained executable. To cross-compile for
other platforms:
# Linux x86_64
deno compile -A --unstable-kv --target x86_64-unknown-linux-gnu -o dist/snaapi-linux-x86_64 main.ts
# Linux ARM64
deno compile -A --unstable-kv --target aarch64-unknown-linux-gnu -o dist/snaapi-linux-aarch64 main.ts
# macOS x86_64
deno compile -A --unstable-kv --target x86_64-apple-darwin -o dist/snaapi-darwin-x86_64 main.ts
# macOS ARM64
deno compile -A --unstable-kv --target aarch64-apple-darwin -o dist/snaapi-darwin-aarch64 main.ts
Run the compiled binary:
./dist/snaapi
Observability
Snaapi includes built-in OpenTelemetry support for tracing and monitoring.
Enabling OpenTelemetry
Set the following environment variables:
OTEL_DENO=true
OTEL_SERVICE_NAME="snaapi-production"
Collector Setup
Configure an OpenTelemetry collector to receive traces from Snaapi. Example with a Grafana stack:
# otel-collector-config.yml
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
exporters:
otlp/tempo:
endpoint: tempo:4317
tls:
insecure: true
service:
pipelines:
traces:
receivers: [otlp]
exporters: [otlp/tempo]
What Is Traced
Snaapi instruments the following with OpenTelemetry spans:
- Middleware pipeline (authentication, authorization, field filtering)
- Database queries
- Event emission
- HTTP request handling
See the Configuration docs for all OTEL-related environment variables.