Deployment Guide — Cardsite Link Manager
Staging on GCP (Cloud Run, Cloud SQL, deployed by CI from
main) has its own guides: deploy-gcp.md to set it up, staging.md to use it (ADR-0177). This page covers local development and the self-hosted production host.
Prerequisites
- Docker 24+ and Docker Compose v2
- 2GB+ RAM (4GB recommended for production)
- PostgreSQL 16 (included in Docker stack)
- Redis 7 (included in Docker stack)
- Domain with DNS configured (for production)
Local Development
Quick Start
# 1. Clone and configure
cp .env.example .env
# Edit .env with your settings (see Environment Variables below)
# 2. Start all services
make up
# 3. Access the app
# Frontend: http://localhost:3000
# API: http://localhost:8080
# API health: http://localhost:8080/health
# API ready: http://localhost:8080/ready (DB ping + dependency JSON)
# Metrics: http://localhost:8080/metrics (Prometheus text)
# (18810 is the PRODUCTION port — see the Production section below)
Available Commands
make help lists them; DEVELOPMENT.md names the daily ones.
Database Migrations
Migrations never run automatically — neither in production nor in Docker. The server binary expects the schema to already be in place. They are applied by a separate command, cmd/migrate, which keeps a ledger of what it applied in a schema_migrations table (ADR-0167):
cd apps/api
go build -o migrate ./cmd/migrate # or: go run ./cmd/migrate …
./migrate status # every migration: applied, baseline or pending
./migrate up # apply what is pending, in order, then stop
./migrate down 1 # revert the newest applied migration
DATABASE_URLis the database (or-database URL);-dirdefaults tomigrationsin the working directory. The API image ships it as/migratebeside/migrations:docker compose exec api /migrate -dir /migrations up.- Each migration runs in its own transaction together with its ledger row, so it is applied and recorded, or neither. A migration that PostgreSQL refuses inside a transaction (
CREATE INDEX CONCURRENTLY, 000018) runs one statement at a time instead; its statements areIF NOT EXISTS, so a retry after a failure is safe. upstops at the first error and exits non-zero. Nothing after the failed file runs, and the failed file is not recorded. A pending migration numbered below an applied one is refused rather than applied out of order.- Two runners cannot overlap:
up,downandbaselinehold a PostgreSQL advisory lock. statusmarks an applied file whose contents changed since (never edit an applied migration).
A database migrated before the ledger existed (by hand with psql, by the Docker init hook, or by the old deploy loop) has tables and no schema_migrations. up refuses it rather than replaying everything from 000001. Record what is already there once, then use up as normal:
./migrate baseline 44 # every migration through 000044 is already applied
./migrate up # applies 000045 onwards
Pick the version from what was last applied (the CHANGELOG upgrade notes, or the newest object present: plans.is_default is 000043, the plans rows Starter…Enterprise are 000045). baseline refuses a database whose ledger already has rows.
Duplicate
Freeplans. The old production deploy re-applied every file on every release with errors ignored, and each run inserted anotherFreeplan. Aftermigrate up, runpsql "$DATABASE_URL" -v ON_ERROR_STOP=1 -f scripts/remove-duplicate-default-plans.sqlonce: it deletes the copies nobody is on and lists any that still have accounts.
CI's migration-lint job enforces sequential numbering and matching .up.sql/.down.sql pairs.
Upgrading an existing deployment past 2026-08-11: migrations 000026 (workspaces), 000027 (block version), and 000028 (history workspace scope) must be applied before booting the new binary — the startup schema guards refuse to start without them. 000026 also backfills a personal workspace per user, so apply it during a maintenance window, not concurrently with heavy writes.
Upgrading past v1.2.0: migrations 000031–000044 carry four decisions about existing data (the capability grant, the single default plan, the H1 rewrite, legacy
plan_id = 0). The checks to run on a copy first are the upgrade notes at the top ofCHANGELOG.md, stated once there.
Production Deployment (systemd + Caddy)
The live instance at prod.cardsite.io (serving cardsite.com, card.site, and crd.site) runs on operator-one:
Architecture
- Backend: Go binary (
cardsite-api) managed by systemd, listening on127.0.0.1:18810 - Frontend: Static files built into
apps/web/dist/, served by Caddy - Database: PostgreSQL 16 on localhost
- Reverse proxy: Caddy (auto Let's Encrypt TLS, HTTP→HTTPS redirect, HSTS)
- Config:
.env.production(gitignored), loaded by systemd unitEnvironmentFile=
Deploy Steps
# On the production server
cd /var/www/production/cardsite
git pull origin main
# Frontend (most common)
cd apps/web && npm run build
# Backend (only if Go code changed): migrations first, then the binary
cd apps/api && go build -o ../../cardsite-api ./cmd/server && go build -o ../../migrate ./cmd/migrate
../../migrate status && ../../migrate up # stops, non-zero, on a failed migration
sudo systemctl restart cardsite-api
# Verify
curl http://localhost:18810/ready | jq
sudo journalctl -u cardsite-api -n 50 --no-pager
Key Details
- API runs on port
18810behind Caddy reverse proxy - Caddy handles HTTPS (auto Let's Encrypt) and static file serving from
apps/web/dist/ - Uploads stored at
/var/www/production/cardsite/uploads(controlled byUPLOAD_PATH) - The binary does NOT auto-run migrations — run
migrate upbefore restarting it (see "Database Migrations" above) - Structured
slogJSON logs go to journald; tail withjournalctl -u cardsite-api -f
Customer domains and SSL (on-demand TLS)
A customer's own domain serves its resources at yourdomain.com/slug and yourdomain.com/@slug. Every public lookup resolves by (host, slug) (ADR-0169). For the domain to work:
- The customer points the domain at the server and verifies it in the app (
domains.is_enabledandis_verified). - Caddy obtains its certificate on first request, after asking the API whether the name is a verified customer domain:
{
on_demand_tls {
ask http://127.0.0.1:18810/internal/tls/ask
}
}
# Every other host is a customer domain: certificate on demand, traffic to the API.
https:// {
tls {
on_demand
}
reverse_proxy 127.0.0.1:18810
}
GET /internal/tls/ask?domain=<name> answers 200 only for an enabled, verified domain; 404 otherwise, 400 for a malformed name and 503 if the lookup fails. Never expose /internal/ publicly. The API answers bare addresses (/{slug}, /@{slug}) on any host, so a customer domain proxied to it serves short links, files and static pages directly, and hands pages (bio page, vCard, event, payment) to the app with ?host=<domain>.
Alternative: Docker Compose (Coolify)
Docker Compose files are also available for containerized deployment:
1. Configure Coolify
- Add the repository in Coolify dashboard
- Select Docker Compose as the build method
- Point to both compose files:
-f docker-compose.yml -f deploy/compose.prod.yml(the prod file is an override, not a standalone stack)
2. Set Environment Variables
In the Coolify dashboard, configure all required environment variables (see below).
3. Configure Domain
- Set
APP_URLto your production domain - Configure Coolify's built-in reverse proxy (Traefik/Caddy)
- Enable HTTPS (automatic with Let's Encrypt)
4. Deploy
Coolify will:
- Build Docker images from each service's Dockerfile
- Start all services with production configurations
Migrations are never auto-run by the binary — see "Database Migrations" above. Before the first Coolify deploy, run migrate up against the target database (see "Database Migrations"), then enable the service.
Docker Compose Configuration
Development (docker-compose.yml)
- Hot reload enabled for both frontend and backend
- Ports exposed on localhost
- Volume mounts for live code changes
Production (deploy/compose.prod.yml)
- Optimized multi-stage builds
- No source code volume mounts
- Health checks enabled
- Restart policies configured
- Internal network for service-to-service communication
Environment Variables
Required
| Variable | Description | Example |
|---|---|---|
DATABASE_URL | PostgreSQL connection string | postgres://user:pass@db:5432/cardsite?sslmode=disable |
JWT_SECRET | Secret for JWT token signing (min 32 chars; generate via openssl rand -hex 32). With ENV=production the server refuses to start on the committed docker-compose fallback (dev_only_…) or on a value with fewer than 10 distinct characters | your-secret-key-here |
PORT | API server port | 18810 |
APP_URL | Public base URL (used in emails, unsubscribe links, OAuth callbacks) | https://cardsite.com |
UPLOAD_PATH | Filesystem path for uploads (when S3 not configured) | /var/www/production/cardsite/uploads |
Optional — Email (SMTP)
| Variable | Description |
|---|---|
SMTP_HOST | SMTP server hostname |
SMTP_PORT | SMTP server port (587 for TLS) |
SMTP_USERNAME | SMTP username |
SMTP_PASSWORD | SMTP password |
SMTP_FROM | Sender email address |
SMTP_FROM_NAME | Sender display name |
BOUNCE_WEBHOOK_SECRET | Shared secret the ESP or SMTP relay sends in the X-Bounce-Secret header to POST /api/v1/emails/bounce ({"email","bounce_type":"hard|soft|complaint","reason"}). Unset = the endpoint is disabled (404). A recorded hard bounce or complaint suppresses every later send to that address. In production it must pass the same strength check as JWT_SECRET |
Optional — Payment Gateways (20 supported)
Key names are the ones apps/api/internal/config/config.go reads.
| Variable | Description |
|---|---|
STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET | Stripe |
PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PAYPAL_WEBHOOK_ID | PayPal |
RAZORPAY_KEY_ID, RAZORPAY_KEY_SECRET, RAZORPAY_WEBHOOK_SECRET | Razorpay |
COINBASE_API_KEY, COINBASE_WEBHOOK_SECRET | Coinbase Commerce |
MOLLIE_API_KEY | Mollie |
PADDLE_VENDOR_ID, PADDLE_VENDOR_AUTH_CODE, PADDLE_PUBLIC_KEY | Paddle (classic) |
PADDLE_BILLING_API_KEY, PADDLE_BILLING_WEBHOOK_SECRET | Paddle Billing |
PAYSTACK_SECRET_KEY, PAYSTACK_PUBLIC_KEY | Paystack |
FLUTTERWAVE_SECRET_KEY, FLUTTERWAVE_WEBHOOK_SECRET | Flutterwave |
MERCADOPAGO_ACCESS_TOKEN | Mercado Pago |
IYZICO_API_KEY, IYZICO_SECRET_KEY, IYZICO_SANDBOX | Iyzico |
CRYPTO_COM_SECRET_KEY, CRYPTO_COM_WEBHOOK_SECRET | Crypto.com Pay |
YOOKASSA_SHOP_ID, YOOKASSA_SECRET_KEY | YooKassa |
PLISIO_SECRET_KEY | Plisio |
PLISIO_WHITELABEL_SECRET_KEY | Plisio Whitelabel |
LEMONSQUEEZY_API_KEY, LEMONSQUEEZY_SIGNING_SECRET, LEMONSQUEEZY_STORE_ID | LemonSqueezy |
MYFATOORAH_API_KEY, MYFATOORAH_SECRET_KEY, MYFATOORAH_API_ENDPOINT | MyFatoorah |
REVOLUT_SECRET_KEY | Revolut |
MIDTRANS_SERVER_KEY | Midtrans |
PAYU_MERCHANT_POS_ID, PAYU_SIGNATURE_KEY, PAYU_OAUTH_CLIENT_ID, PAYU_OAUTH_SECRET | PayU |
KLARNA_USERNAME, KLARNA_PASSWORD, KLARNA_MODE | Klarna |
PAYPAL_SANDBOX, IYZICO_SANDBOX, MIDTRANS_SANDBOX, PAYU_SANDBOX, REVOLUT_SANDBOX (default true), PADDLE_BILLING_SANDBOX (default false) | Sandbox switches — set the first five to false for production; each is true unless the value is exactly false |
Optional — OAuth Providers (6 supported)
Most can also be configured via the admin UI at /admin/settings → Integrations instead of env vars.
| Variable | Description |
|---|---|
GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET | |
FACEBOOK_APP_ID, FACEBOOK_APP_SECRET | |
DISCORD_CLIENT_ID, DISCORD_CLIENT_SECRET | Discord |
LINKEDIN_CLIENT_ID, LINKEDIN_CLIENT_SECRET | |
MICROSOFT_CLIENT_ID, MICROSOFT_CLIENT_SECRET | Microsoft |
X_CONSUMER_KEY, X_CONSUMER_SECRET, X_ACCESS_TOKEN, X_ACCESS_TOKEN_SECRET | X (Twitter) |
Optional — AI & Services
| Variable | Description |
|---|---|
OPENAI_API_KEY | OpenAI API key (GPT, DALL·E, Whisper, TTS) |
GOOGLE_CLOUD_TTS_API_KEY, AWS_POLLY_ACCESS_KEY, AWS_POLLY_SECRET_KEY, AWS_POLLY_REGION | Text-to-speech providers for the AI synthesis surface |
TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_FROM_NUMBER, TWILIO_WHATSAPP_FROM | SMS / WhatsApp notification handlers |
GEMINI_API_KEY | Google Gemini API key. Either this or OPENAI_API_KEY is enough to bring the AI router up; with neither, every generation call answers 503 |
GEOIP_DB_PATH | Path to MaxMind GeoLite2 .mmdb file (enables country/city display rules). Reported inactive if the file cannot be opened, not merely if unset |
REDIS_URL | Redis connection URL (optional — API degrades gracefully without it) |
IMAGE_OPTIMIZER_PROVIDER | local, resmushit or custom. Anything else, or unset, disables upload optimization |
IMAGE_OPTIMIZER_API_KEY, IMAGE_OPTIMIZER_ENDPOINT, IMAGE_OPTIMIZER_QUALITY | For the custom provider; the endpoint and quality (85) default when unset |
EMAIL_SHIELD_API_KEY | Enables signup email-domain validation. Without it no domain is checked |
EMAIL_SHIELD_ENDPOINT, EMAIL_SHIELD_WHITELISTED_DOMAINS | Endpoint override (defaults when unset) and a comma-separated always-allow list |
OG_IMAGES_API_KEY or OG_IMAGES_SELF_API_KEY | Either one enables the dynamic Open Graph image service |
OG_IMAGES_ENDPOINT, OG_IMAGES_QUALITY (80), OG_IMAGES_REFRESH_INTERVAL (10), OG_IMAGES_TITLE, OG_IMAGES_TITLE_COLOR (#000000), OG_IMAGES_BACKGROUND_COLOR (#ffffff), OG_IMAGES_BACKGROUND_URL, OG_IMAGES_LOGO_URL, OG_IMAGES_BORDER_RADIUS (10) | Rendering options; defaults in parentheses |
Which of these a running server actually picked up is visible at
/admin/plugins, reported from the services the process constructed rather than
from a list in the page (ADR-0014).
Status is read at startup, so a change here applies on the next restart.
Optional — Serving
| Variable | Description |
|---|---|
DOMAIN_VERIFICATION_TARGET | This deployment's own hostname — what a customer's custom domain must CNAME to (or share addresses with, at an apex) for POST /domains/{id}/verify to mark it verified. Unset, the endpoint answers 503 rather than verifying: a check that cannot run has not succeeded (ADR-0095) |
EDGE_SECRET | Shared with a TLS edge that cannot send the visitor's Host itself, because the platform behind it routes by Host (Cloud Run; ADR-0183). A request carrying it in X-Cardsite-Edge has its Host taken from X-Forwarded-Host and its client address from X-Cardsite-Client-Addr; without it neither header is believed. Unset on a self-hosted deployment |
LOG_LEVEL | Log level read at startup; info when unset |
ENV | development or production; selects dev defaults. production also refuses to start on a weak JWT_SECRET or BOUNCE_WEBHOOK_SECRET (the committed dev_only_… value, under 32 characters, or under 10 distinct characters) |
API_RATE_LIMIT_PER_MINUTE | Authenticated-API limit per principal (default 60) |
PUBLIC_RATE_LIMIT_PER_MINUTE | Public-surface limit per client address — redirects, public pages, webhooks, auth endpoints (default 300). Test stacks raise it; production leaves it (ADR-0163) |
AUTH_RATE_LIMIT_ATTEMPTS, AUTH_RATE_LIMIT_WINDOW_MINUTES | Auth-endpoint lockout per IP (default 6 per 10 minutes) |
TRUSTED_PROXIES | Comma-separated CIDRs or addresses whose X-Forwarded-For / X-Real-IP the API believes — the Caddy or nginx host in front of it. Unset, the client address is the TCP peer, so a proxied deployment applies the per-IP limits above per proxy rather than per client, geolocates every click to the proxy, and matches the IP blocklist against the proxy; set it, and never to 0.0.0.0/0 (ADR-0160, ADR-0163) |
Optional — URL lifecycle (track 009)
Every window is a number of days; the defaults are compiled in
(apps/api/internal/config/lifecycle.go) and are the charter's. Nothing is
taken from a customer unless LIFECYCLE_TAKING_ENABLED is set: with it
unset the daily sweeps only notice quiet resources and tell their owners, and
every notice says so (ADR-0114,
ADR-0116).
The windows themselves are an owner decision (009 Blocker 3); the defaults are
safe because they arm nothing.
| Variable | Default | Description |
|---|---|---|
LIFECYCLE_TAKING_ENABLED | false | Arms the transitions that stop serving (notified → lapsed) and release the slug (lapsed → released). Off, the sweeps notice and notify only |
LIFECYCLE_QUIET_DAYS | 60 | Days without use after which a resource is notified. Use is a visit, an edit, or the owner signing in |
LIFECYCLE_NOTICE_QUIET_DAYS | 60 | Day the first notice is sent (notice.quiet): 30 days before release |
LIFECYCLE_NOTICE_WARNING_DAYS | 83 | Day the lapse warning is sent: 7 days before release |
LIFECYCLE_NOTICE_FINAL_DAYS | 89 | Day the final notice about the name is sent: 24 hours before release |
LIFECYCLE_LAPSE_DAYS | 90 | Days quiet after which a notified resource stops serving (only when armed) |
LIFECYCLE_RELEASE_DAYS | 0 | Days after the lapse the slug is released (only when armed); 0 releases it on the lapse day, the Overview's 90 days |
LIFECYCLE_RECLAIM_DAYS | 0 | Days after a release the name stays the former workspace's to take back; unset or 0 reserves nothing, the Overview's "available to others" (ADR-0121) |
The defaults are the Overview's Free policy as far as the per-resource model expresses it (ADR-0171): released at 90 days with no sign-in and no traffic, with notices 30 days, 7 days and 24 hours before. The Overview's 3-day notice, the paid ladder (90 days after a subscription lapses, six notices), the 12-month archive window and the 3-year paid reservation are not expressed. LIFECYCLE_TAKING_ENABLED stays false by default, so out of the box nothing stops serving and no address is released; arming it is the owner's call.
Optional — Archive address (track 009 phase 04)
| Variable | Default | Description |
|---|---|---|
ARCHIVE_ORIGIN | unset | The origin archived documents are addressed under, e.g. https://archive.example.com. Unset, archives live under the app's own origin at the prefix below. The address is final once customers have been told it (ADR-0119); the domain is 009 Blocker 1 |
ARCHIVE_PATH_PREFIX | /archive/ | The path the archive page renders at and the API composes addresses from. Gate rule L7 holds both halves to the same default |
Optional — Artifact hosting (track 010)
Every bound is read before a byte is written, and an upload that exceeds one is refused whole (ADR-0125). Sizes take a plain byte count.
| Variable | Default | Description |
|---|---|---|
HOSTING_MAX_FILE_BYTES | 10485760 (10 MB) | Per-upload cap for every file this product stores |
HOSTING_MAX_BUNDLE_BYTES | 10485760 | Cap on a zip bundle as uploaded |
HOSTING_MAX_ENTRY_BYTES | 10485760 | Cap on any one entry inside a bundle |
HOSTING_MAX_BUNDLE_ENTRIES | 2000 | Entries a bundle may contain |
HOSTING_MAX_BUNDLE_TOTAL_BYTES | 52428800 (50 MB) | Cap on a bundle's total expansion |
HOSTING_MAX_COMPRESSION_RATIO | 100 | Expansion-to-archive ratio above which a bundle is refused (zip-bomb bound) |
HOSTING_STATIC_POLICY | inert | What an author's static page may load and run (ADR-0184): inert (ADR-0103: inline styles and data: only), external (also styles, images, fonts and media over https; no script) or scripted (also the page's own scripts and outbound fetches, sandboxed without allow-same-origin). Anything else is inert. Staging runs scripted; production stays inert until user pages have their own domain |
HOSTING_ARTIFACT_ORIGIN | unset | Scheme and host a hosted bundle's document may load its own files from. Unset is a working deployment whose artifacts cannot load their neighbours (sandbox gives them an opaque origin, which 'self' never matches — ADR-0128). Which origin is 010 Blocker 3 and the public-origin decision |
Optional — S3-Compatible Storage (CDN offload, P2-4)
| Variable | Description |
|---|---|
S3_ENDPOINT | S3 endpoint (omit for AWS S3 default) |
S3_REGION | Region, e.g. us-east-1 |
S3_BUCKET | Bucket name |
S3_ACCESS_KEY | Access key |
S3_SECRET_KEY | Secret key |
S3_BASE_URL | Public CDN base URL prefixed onto returned upload URLs |
S3_USE_PATH_STYLE | true for path-style addressing (DO Spaces, Wasabi, Vultr); false for virtual-hosted |
S3_BASE_PATH | Key prefix inside the bucket |
Optional — CAPTCHA
| Variable | Description |
|---|---|
CAPTCHA_PROVIDER | recaptcha, hcaptcha, or turnstile |
CAPTCHA_SITE_KEY | CAPTCHA site/public key |
CAPTCHA_SECRET_KEY | CAPTCHA secret/server key |
Health Checks
# Liveness — lightweight ping (always public, always 200)
curl http://localhost:18810/health
# Readiness — DB ping + dependency status (used by load balancer)
curl http://localhost:18810/ready
# {"status":"ok","checks":{"db":"ok"}}
# Prometheus metrics
curl http://localhost:18810/metrics
# # HELP requests_total Total HTTP requests
# # TYPE requests_total counter
# requests_total 12345
# ...
Logging
The API uses log/slog JSON output in production. Every line carries request_id, user_id, method, path, status, duration_ms.
# Tail live
sudo journalctl -u cardsite-api -f -o cat | jq
# Find all errors for a specific request
sudo journalctl -u cardsite-api --since "1h ago" -o cat | jq 'select(.request_id == "abc123…")'
Backups & Disaster Recovery
RPO / RTO targets
| Metric | Target |
|---|---|
| RPO (Recovery Point Objective) | ≤ 1 hour (hourly WAL shipping) |
| RTO (Recovery Time Objective) | ≤ 4 hours (restore from latest backup) |
Daily logical backup (pg_dump)
Run as a cron job on the database host (or in a sidecar container):
# /etc/cron.d/cardsite-backup
0 2 * * * postgres pg_dump -Fc "$DATABASE_URL" \
> /var/backups/cardsite/cardsite_$(date +%Y%m%d).dump 2>&1
# Rotate — keep 30 days
30 2 * * * postgres find /var/backups/cardsite -name "*.dump" -mtime +30 -delete
Point-in-time recovery (WAL archiving)
Enable continuous archiving in postgresql.conf:
wal_level = replica
archive_mode = on
archive_command = 'aws s3 cp %p s3://YOUR_BUCKET/wal/%f'
Then pg_basebackup for the base snapshot:
pg_basebackup -h localhost -U postgres -D /var/backups/cardsite/base \
-Ft -z -Xs -P
aws s3 sync /var/backups/cardsite/base s3://YOUR_BUCKET/base/
Restore procedure (from dump)
# 1. Create a fresh database
createdb -U postgres cardsite_restore
# 2. Restore from the latest dump
pg_restore -Fc -U postgres -d cardsite_restore /var/backups/cardsite/cardsite_YYYYMMDD.dump
# 3. Point the API at the restored database
DATABASE_URL="postgres://user:pass@localhost:5432/cardsite_restore" \
sudo systemctl restart cardsite-api
# 4. Verify the restore
psql cardsite_restore -c "SELECT COUNT(*) FROM users;"
Restore procedure (point-in-time)
# 1. Stop the primary
sudo systemctl stop postgresql
# 2. Restore base backup
rm -rf /var/lib/postgresql/16/main/*
tar -xzf /var/backups/cardsite/base/base.tar.gz -C /var/lib/postgresql/16/main/
# 3. Write recovery.conf (PostgreSQL 12+: recovery.signal + postgresql.conf)
cat >> /var/lib/postgresql/16/main/postgresql.conf <<EOF
restore_command = 'aws s3 cp s3://YOUR_BUCKET/wal/%f %p'
recovery_target_time = 'YYYY-MM-DD HH:MM:SS UTC'
recovery_target_action = promote
EOF
touch /var/lib/postgresql/16/main/recovery.signal
# 4. Start and verify
sudo systemctl start postgresql
psql -U postgres -c "SELECT now();"
Quarterly restore drill
- Provision a scratch VM (different cloud account).
- Restore from the most recent dump.
- Run
go test ./...against the restored DB. - Measure wall-clock time — update RTO if it drifts above 4 h.
- Destroy the scratch VM.
Email Deliverability (SPF / DKIM / DMARC)
Cardsite sends transactional mail via SMTP. For reliable inbox delivery:
SPF record
Add a TXT record on your sending domain:
v=spf1 include:_spf.YOUR_ESP.com ~all
For self-hosted Postfix:
v=spf1 ip4:YOUR_SERVER_IP ~all
DKIM
Generate a 2048-bit key pair and configure your MTA to sign outbound mail:
# Postfix + OpenDKIM
opendkim-genkey -t -s mail -d yourdomain.com
# Publish mail._domainkey.yourdomain.com TXT = (public key)
Verify with: dig TXT mail._domainkey.yourdomain.com
DMARC record
_dmarc.yourdomain.com. TXT "v=DMARC1; p=quarantine; rua=mailto:dmarc@yourdomain.com; pct=100"
Start with p=none while monitoring, then graduate to quarantine/reject.
Bounce handling
Cardsite writes bounces to the email_bounces table via POST /api/v1/emails/bounce.
Wire your ESP's DSN webhook to call this endpoint with:
{ "email": "user@example.com", "bounce_type": "hard", "reason": "550 No such user" }
The email service will skip future sends to hard-bounced addresses.
One-click unsubscribe (RFC 8058)
Marketing/broadcast emails sent via EmailService.SendMarketing() automatically include:
List-Unsubscribe: <https://cardsite.com/unsubscribe?token=...>
List-Unsubscribe-Post: List-Unsubscribe=One-Click
This satisfies Gmail/Yahoo's 2024 bulk-sender requirements.
Troubleshooting
API won't start
- Check
DATABASE_URLis correct and PostgreSQL is running - Check logs:
sudo journalctl -u cardsite-api -n 200 --no-pager - Verify migrations were applied — the binary will fail on a missing column with a clear pgx error
Frontend can't reach API
VITE_API_URLis only needed when the SPA and the API are on different origins (dev's docker-compose setshttp://localhost:8080). The production image'sapps/web/nginx.confproxies/api,/admin-api,/l/,/uploads,/webhookand the health probes to theapiservice, so adeploy/compose.prod.ymldeployment leaves it unset and every call is same-origin;/b/{slug}and/@{slug}stay with the SPA, since each is an app page that fetches its payload under/api/public. Behind Caddy, proxy the same prefixes to the API on 18810- Check CORS configuration allows the frontend origin
- Check the
X-Requested-WithCSRF guard isn't blocking — axios sets it automatically; curl needs-H "X-Requested-With: XMLHttpRequest"for POST/PUT/DELETE
Redis connection errors
- Redis is optional — the API degrades gracefully without it
- If
REDIS_URLis set, ensure Redis is running
Payment webhooks not working
- Verify webhook secret environment variables are set correctly
- Check webhook URL is accessible from the payment provider
- Review logs for signature verification errors
Source: docs/DEPLOYMENT.md