ComplaintrComplaintr

Deployment

Deploy Complaintr to production.

The simplest way to deploy Complaintr is with Docker Compose:

# Clone the repository
git clone <repo-url> && cd complaintr

# Configure environment
cp .env.example .env
# Edit .env with your production values

# Start all services
docker compose up --build -d

This starts three services:

  • db: PostgreSQL 17 Alpine on port 5432
  • web: Next.js app on port 3000
  • telegram-bot: Telegram bot for notifications and complaint submissions

Environment Variables for Production

Set these in your .env file or as environment variables:

VariableProduction Value
DATABASE_URLPostgreSQL connection (use the db service hostname)
BETTER_AUTH_SECRETRandom 64-char string generated with openssl rand -hex 32
BETTER_AUTH_URLYour production URL (e.g., https://complaintr.example.com)
GOOGLE_CLIENT_IDGoogle OAuth client ID (create in Google Cloud Console)
GOOGLE_CLIENT_SECRETGoogle OAuth client secret
ADMIN_EMAILSComma-separated list of admin email addresses
TELEGRAM_BOT_TOKENBot token from @BotFather (optional, for Telegram features)

Google OAuth Configuration

  1. Go to Google Cloud Console
  2. Create an OAuth 2.0 Client ID
  3. Add authorized redirect URIs:
    • https://your-domain.com/api/auth/callback/google
  4. Copy the Client ID and Secret to your .env

Manual Deployment

Prerequisites

  • Bun 1.3.4+
  • PostgreSQL 17
  • Node.js (for some build tools)

Build

bun install
bun run build

The web app builds to apps/web/.next/standalone/.

Run

# Start PostgreSQL
docker compose up db -d

# Push database schema
bun run db:push

# Start the web app
cd apps/web && bun run start

Reverse Proxy (Nginx)

Example Nginx configuration for production:

server {
    listen 80;
    server_name complaintr.example.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;
    }
}

SSL (Let's Encrypt)

Use Certbot with Nginx:

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d complaintr.example.com

Health Checks

The web app includes a health check endpoint:

curl http://localhost:3000/api/health

The Docker Compose configuration uses this for container health checks.

Database Backups

# Backup
pg_dump postgresql://complaintr:complaintr@localhost:5432/complaintr > backup.sql

# Restore
psql postgresql://complaintr:complaintr@localhost:5432/complaintr < backup.sql

Monitoring

Logs

  • Web app: stdout (Next.js server logs)
  • Telegram bot: stderr (console.error for operational logs)
  • Database: PostgreSQL logs within the Docker container

Analytics

Complaintr does not include built-in analytics. Consider adding:

  • Plausible or Umami for privacy-friendly page analytics
  • Sentry for error tracking
  • Grafana + Prometheus for infrastructure monitoring

Scaling Considerations

For high-traffic deployments:

  • Database: Use a managed PostgreSQL service (Supabase, Neon, AWS RDS)
  • Web app: Run multiple instances behind a load balancer
  • Sessions: Better Auth stores sessions in PostgreSQL, which scales with your database
  • Rate limiting: Currently PostgreSQL-based. For large scale, consider Redis for rate limit storage
  • File storage: Not applicable (Complaintr does not handle user file uploads)

On this page