Docs/Self-Hosting

Self-Hosting

Deploy Realm3Lab tools on your own infrastructure with Docker.


Prerequisites

  • Docker and Docker Compose
  • PostgreSQL 16+ (or use the included Docker service)
  • Node.js 22+ (for development only)

Quick Start

Clone the repository and start all services:

git clone https://github.com/realm3lab/r3-x.git
cd r3-x
docker compose up -d

This starts:

ServicePortDescription
postgres5432PostgreSQL database
minio9000/9001Object storage (dev)
web3000R3-X application
cms3001R3 CMS application
landing3002Landing page

Environment Variables

R3-X (apps/x/.env.prod)

# Database
DATABASE_URL=postgresql://user:pass@host:5432/r3x

# Auth
BETTER_AUTH_SECRET=your-secret-key
BETTER_AUTH_URL=https://x.yourdomain.com
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret

# Storage (MinIO or Cloudflare R2)
STORAGE_ENDPOINT=https://your-r2-endpoint
STORAGE_ACCESS_KEY=your-access-key
STORAGE_SECRET_KEY=your-secret-key
STORAGE_BUCKET=your-bucket
STORAGE_PUBLIC_URL=https://your-public-url

# AI
OPENAI_API_KEY=sk-your-key
GEMINI_API_KEY=your-gemini-key

# Social Platforms
META_APP_ID=your-meta-app-id
META_APP_SECRET=your-meta-app-secret
INSTAGRAM_APP_ID=your-instagram-app-id
INSTAGRAM_APP_SECRET=your-instagram-app-secret

R3 CMS (apps/cms/.env.prod)

# Database
DATABASE_URL=postgresql://user:pass@host:5432/r3x

# Auth
BETTER_AUTH_SECRET=your-secret-key
BETTER_AUTH_URL=https://cms.yourdomain.com

Storage Options

MinIO (Development)

MinIO is included in the Docker Compose setup for local development. It provides S3-compatible object storage.

Cloudflare R2 (Production)

For production, we recommend Cloudflare R2:

  1. Create an R2 bucket in your Cloudflare dashboard
  2. Generate API tokens with read/write access
  3. Set the STORAGE_* environment variables
  4. R2 uses virtual-hosted style URLs — the bucket name is NOT included in the public URL path

Database Migrations

Migrations run automatically on container startup via start.sh. To run manually:

npx drizzle-kit generate  # Generate from schema changes
npx drizzle-kit migrate   # Apply migrations

Reverse Proxy

Use a reverse proxy (nginx, Caddy, Cloudflare Tunnel) to serve each app on its own subdomain:

x.yourdomain.com     → localhost:3000  (R3-X)
cms.yourdomain.com   → localhost:3001  (R3 CMS)
yourdomain.com       → localhost:3002  (Landing)

GCP Cloud Run

Each app builds as a standalone Docker image suitable for Cloud Run:

# Build and push
docker build -f apps/x/Dockerfile -t gcr.io/your-project/r3x-app .
docker push gcr.io/your-project/r3x-app

# Deploy
gcloud run deploy r3x-app \
  --image gcr.io/your-project/r3x-app \
  --port 3000 \
  --set-env-vars "DATABASE_URL=..."