Skip to main content

Overview

This guide covers self-hosting Deltalytix on your own infrastructure. You’ll learn how to set up the database, configure environment variables, and deploy with Docker.
Self-hosting requires managing your own infrastructure, security, and backups. For a managed solution, use deltalytix.app.

Prerequisites

Before you begin, ensure you have:

Node.js 20+

Or Bun (recommended for better performance)

PostgreSQL 16

Or use the included Docker Compose setup

Docker & Docker Compose

For containerized deployment

Git

To clone the repository

Required External Services

You’ll need accounts and API keys for:
All services offer free tiers suitable for development and small deployments.

Installation Steps

1

Clone the Repository

git clone https://github.com/hugodemenez/deltalytix.git
cd deltalytix
2

Install Dependencies

Using Bun (recommended):
bun install
Or using npm:
npm install
Bun is significantly faster for installation and development. Install it with:
curl -fsSL https://bun.sh/install | bash
3

Configure Environment Variables

Create a .env.local file in the root directory:
cp .env.example .env.local
See the Environment Configuration section below for detailed setup.
4

Set Up PostgreSQL Database

5

Run Database Migrations

Initialize the database schema:
# Generate Prisma client
npx prisma generate

# Run migrations
npx prisma migrate deploy
For development with auto-migration:
npx prisma migrate dev
Always use migrate deploy in production. migrate dev is for development only.
6

Start Development Server

# With Bun
bun dev

# Or with npm
npm run dev
Open http://localhost:3000 to view the application.

Environment Configuration

Configure your .env.local file with the following variables:

Database Configuration

# PostgreSQL connection strings
DATABASE_URL="postgresql://username:password@host:port/database?pgbouncer=true&connection_limit=1"
DIRECT_URL="postgresql://username:password@host:port/database"
  • DATABASE_URL - Connection pooler for serverless/edge functions (uses pgbouncer)
  • DIRECT_URL - Direct connection for migrations and admin operations
If you’re not using connection pooling, both can be the same URL.

Supabase Configuration

# Get these from: Supabase Dashboard → Settings → API
NEXT_PUBLIC_SUPABASE_URL="https://xxxxx.supabase.co"
NEXT_PUBLIC_SUPABASE_ANON_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
1

Create Supabase Project

  1. Go to supabase.com and create a new project
  2. Wait for the database to provision (~2 minutes)
2

Configure Authentication

Navigate to AuthenticationProviders:
  1. Enable Discord provider
  2. Add your Discord OAuth credentials (see Discord section below)
  3. Enable Email provider if you want email/password auth
3

Set Up Storage

Create storage buckets for user uploads:
  1. Go to StorageCreate bucket
  2. Create buckets:
    • trade-images - For trade screenshots
    • journal-images - For journal entries
  3. Configure public access policies as needed

Discord OAuth Setup

DISCORD_ID="your_application_client_id"
DISCORD_SECRET="your_application_client_secret"
REDIRECT_URL="http://localhost:3000/api/auth/callback"
1

Create Discord Application

  1. Visit Discord Developer Portal
  2. Click New Application
  3. Give it a name (e.g., “Deltalytix Local”)
2

Configure OAuth2

  1. Go to OAuth2General
  2. Add redirect URI:
    • Development: http://localhost:3000/api/auth/callback
    • Production: https://yourdomain.com/api/auth/callback
  3. Copy Client ID and Client Secret
3

Set Required Scopes

In OAuth2URL Generator, enable:
  • identify - Access user’s basic profile
  • email - Access user’s email address

OpenAI Configuration

OPENAI_API_KEY="sk-proj-xxxxxxxxxxxx"
Get your API key from platform.openai.com.
AI features use GPT-4 for best results. Expect ~$0.01-0.05 per analysis depending on trade volume.

Stripe Configuration

NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="pk_test_xxxxxxxxxxxx"
STRIPE_SECRET_KEY="sk_test_xxxxxxxxxxxx"
STRIPE_WEBHOOK_SECRET="whsec_xxxxxxxxxxxx"
1

Create Stripe Account

Sign up at stripe.com and complete verification.
2

Get API Keys

From your Stripe Dashboard:
  1. Go to DevelopersAPI keys
  2. Copy Publishable key and Secret key
  3. Use test keys for development
3

Set Up Webhook

  1. Go to DevelopersWebhooks
  2. Add endpoint: https://yourdomain.com/api/stripe/webhook
  3. Select events to listen for:
    • checkout.session.completed
    • customer.subscription.updated
    • customer.subscription.deleted
    • invoice.payment_succeeded
    • invoice.payment_failed
  4. Copy the Signing secret
For local testing, use Stripe CLI:
stripe listen --forward-to localhost:3000/api/stripe/webhook
4

Create Products

In ProductsAdd product, create your subscription tiers:
  • Individual plan (e.g., $29/month)
  • Team plan (e.g., $99/month)
  • Business plan (e.g., $299/month)

Security & Optional Services

# Encryption key for sensitive data (32+ random characters)
ENCRYPTION_KEY="your-secure-random-encryption-key-here"

# Email service (optional, for notifications)
RESEND_API_KEY="re_xxxxxxxxxxxx"
SUPPORT_EMAIL="[email protected]"
SUPPORT_TEAM_EMAIL="[email protected]"

# GitHub integration (optional, for update notifications)
GITHUB_TOKEN="ghp_xxxxxxxxxxxx"
NEXT_PUBLIC_REPO_OWNER="hugodemenez"
NEXT_PUBLIC_REPO_NAME="deltalytix"

# Community
NEXT_PUBLIC_DISCORD_INVITATION="https://discord.gg/your-invite-link"
# On Linux/macOS
openssl rand -base64 32

# Or using Node.js
node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"

Docker Deployment

For production deployment with Docker:
1

Review Docker Compose Configuration

The included docker-compose.yml sets up:
  • PostgreSQL 16 database with persistent storage
  • Database migrations service
  • Next.js application with Bun runtime
docker-compose.yml
services:
  db:
    image: postgres:16
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-devuser}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-devpass}
      POSTGRES_DB: ${POSTGRES_DB:-deltalytix_dev}
    volumes:
      - deltalytix-postgres:/var/lib/postgresql/data
  
  migrate:
    image: oven/bun:1
    depends_on:
      db:
        condition: service_healthy
    command: sh -c "bun i prisma pg@latest && bunx prisma migrate deploy"
  
  app:
    build:
      context: .
      dockerfile: Dockerfile.bun
    ports:
      - "3000:3000"
    depends_on:
      migrate:
        condition: service_completed_successfully
2

Create Production Environment File

Create a .env file (not .env.local) with your production values:
# Database (internal Docker network)
POSTGRES_USER=deltalytix
POSTGRES_PASSWORD=your-secure-password-here
POSTGRES_DB=deltalytix_production

# Application
DATABASE_URL=postgresql://deltalytix:your-password@db:5432/deltalytix_production
NEXT_PUBLIC_APP_URL=https://yourdomain.com

# ... rest of your production environment variables
Never commit .env to version control. Add it to .gitignore.
3

Build and Deploy

# Build the application
docker-compose build

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f app

# Check service status
docker-compose ps
The application will be available at http://localhost:3000.
4

Set Up Reverse Proxy (Production)

For production, use nginx or Caddy as a reverse proxy:
server {
    listen 80;
    server_name yourdomain.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_cache_bypass $http_upgrade;
    }
}

Database Management

Viewing Data with Prisma Studio

# Start Prisma Studio (GUI database browser)
npx prisma studio
This opens a web interface at http://localhost:5555 where you can:
  • View and edit database records
  • Test queries
  • Explore relationships

Creating Database Backups

# Backup PostgreSQL database
docker-compose exec db pg_dump -U deltalytix deltalytix_production > backup_$(date +%Y%m%d).sql

# Restore from backup
docker-compose exec -T db psql -U deltalytix deltalytix_production < backup_20260301.sql
Schedule automated backups for production. Consider using managed database services like Supabase or AWS RDS for automatic backups.

Schema Migrations

When updating Deltalytix, you may need to run new migrations:
# Pull latest changes
git pull origin main

# Install dependencies
bun install

# Run new migrations
npx prisma migrate deploy

# Restart the application
docker-compose restart app

Monitoring & Maintenance

Health Checks

Monitor your deployment with health check endpoints:
# Check application health
curl http://localhost:3000/api/health

# Check database connection
curl http://localhost:3000/api/health/db

Logs

# View application logs
docker-compose logs -f app

# View database logs
docker-compose logs -f db

# View all logs
docker-compose logs -f

Resource Usage

# Monitor container resources
docker stats

# View disk usage
docker-compose exec app df -h
For production deployments, consider setting up monitoring with tools like Grafana, Prometheus, or Datadog.

Updating Deltalytix

To update to the latest version:
1

Backup Your Database

Always create a backup before updating:
docker-compose exec db pg_dump -U deltalytix deltalytix_production > backup_pre_update.sql
2

Pull Latest Changes

git pull origin main
3

Update Dependencies

bun install
4

Run Migrations

npx prisma migrate deploy
5

Rebuild and Restart

docker-compose build app
docker-compose up -d

Troubleshooting

Error: Can't reach database serverSolutions:
  1. Verify PostgreSQL is running:
    docker-compose ps db
    
  2. Check connection string in .env.local
  3. Ensure database port (5432) is not blocked by firewall
  4. Test connection manually:
    psql "postgresql://user:pass@localhost:5432/dbname"
    
Error: OAuth redirect URI mismatchSolutions:
  1. Verify redirect URI in Discord Developer Portal matches:
    • Local: http://localhost:3000/api/auth/callback
    • Production: https://yourdomain.com/api/auth/callback
  2. Check REDIRECT_URL in .env.local
  3. Ensure Discord application has correct scopes (identify, email)
Error: Webhook signature verification failedSolutions:
  1. Verify STRIPE_WEBHOOK_SECRET matches your Stripe webhook endpoint
  2. For local development, use Stripe CLI:
    stripe listen --forward-to localhost:3000/api/stripe/webhook
    
  3. Check that your webhook endpoint is publicly accessible (production)
  4. Verify selected events in Stripe Dashboard match your handler
Error: OpenAI API key invalidSolutions:
  1. Verify OPENAI_API_KEY starts with sk-proj- or sk-
  2. Check API key has sufficient credits
  3. Test API key directly:
    curl https://api.openai.com/v1/models \
      -H "Authorization: Bearer $OPENAI_API_KEY"
    
  4. Ensure you’re using a valid model (gpt-4 or gpt-3.5-turbo)
Error: Build fails during bun install or next buildSolutions:
  1. Increase Docker memory allocation (Settings → Resources → Memory)
  2. Clear Docker build cache:
    docker-compose build --no-cache
    
  3. Check for Node.js version compatibility in Dockerfile.bun
  4. Verify all environment variables are set before building

Production Checklist

Before deploying to production:
1

Security

  • Use strong, unique passwords for database
  • Set secure ENCRYPTION_KEY (32+ characters)
  • Enable HTTPS with valid SSL certificate
  • Configure CORS for your domain only
  • Enable Supabase Row Level Security (RLS)
  • Set up rate limiting on API routes
2

Environment

  • All environment variables set to production values
  • NODE_ENV=production
  • Production Stripe keys (not test keys)
  • Production OpenAI API key with billing set up
  • Correct redirect URLs for OAuth providers
3

Database

  • Automated backups configured
  • Database connection pooling enabled
  • Migrations tested on staging environment
  • Database performance monitoring set up
4

Monitoring

  • Error tracking configured (e.g., Sentry)
  • Uptime monitoring set up
  • Log aggregation configured
  • Resource usage alerts enabled
5

Performance

  • CDN configured for static assets
  • Image optimization enabled
  • Database indexes created
  • Caching strategy implemented

Need Help?

Discord Community

Get help from the community and core team

GitHub Issues

Report bugs or request features

Documentation

Check other guides for specific features

Email Support

Contact [email protected] for assistance

Build docs developers (and LLMs) love