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.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:- Supabase - Authentication and real-time features (free tier available)
- OpenAI - AI-powered insights and field mapping (get API key)
- Stripe - Payment processing for subscriptions (create account)
- Discord - OAuth authentication (developer portal)
- Resend (optional) - Email notifications (sign up)
All services offer free tiers suitable for development and small deployments.
Installation Steps
Configure Environment Variables
Create a See the Environment Configuration section below for detailed setup.
.env.local file in the root directory:Set Up PostgreSQL Database
- Docker Compose (Recommended)
- Existing PostgreSQL
- Supabase
The easiest way to get started:The database will be available at:
Start Development Server
Environment Configuration
Configure your.env.local file with the following variables:
Database Configuration
Why two database URLs?
Why two database URLs?
- DATABASE_URL - Connection pooler for serverless/edge functions (uses pgbouncer)
- DIRECT_URL - Direct connection for migrations and admin operations
Supabase Configuration
Create Supabase Project
- Go to supabase.com and create a new project
- Wait for the database to provision (~2 minutes)
Configure Authentication
Navigate to Authentication → Providers:
- Enable Discord provider
- Add your Discord OAuth credentials (see Discord section below)
- Enable Email provider if you want email/password auth
Discord OAuth Setup
Create Discord Application
- Visit Discord Developer Portal
- Click New Application
- Give it a name (e.g., “Deltalytix Local”)
Configure OAuth2
- Go to OAuth2 → General
- Add redirect URI:
- Development:
http://localhost:3000/api/auth/callback - Production:
https://yourdomain.com/api/auth/callback
- Development:
- Copy Client ID and Client Secret
OpenAI Configuration
AI features use GPT-4 for best results. Expect ~$0.01-0.05 per analysis depending on trade volume.
Stripe Configuration
Create Stripe Account
Sign up at stripe.com and complete verification.
Get API Keys
From your Stripe Dashboard:
- Go to Developers → API keys
- Copy Publishable key and Secret key
- Use test keys for development
Set Up Webhook
- Go to Developers → Webhooks
- Add endpoint:
https://yourdomain.com/api/stripe/webhook - Select events to listen for:
checkout.session.completedcustomer.subscription.updatedcustomer.subscription.deletedinvoice.payment_succeededinvoice.payment_failed
- Copy the Signing secret
Security & Optional Services
Generate a secure encryption key
Generate a secure encryption key
Docker Deployment
For production deployment with Docker: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
Database Management
Viewing Data with Prisma Studio
http://localhost:5555 where you can:
- View and edit database records
- Test queries
- Explore relationships
Creating Database Backups
Schema Migrations
When updating Deltalytix, you may need to run new migrations:Monitoring & Maintenance
Health Checks
Monitor your deployment with health check endpoints:Logs
Resource Usage
For production deployments, consider setting up monitoring with tools like Grafana, Prometheus, or Datadog.
Updating Deltalytix
To update to the latest version:Troubleshooting
Database connection errors
Database connection errors
Error:
Can't reach database serverSolutions:- Verify PostgreSQL is running:
- Check connection string in
.env.local - Ensure database port (5432) is not blocked by firewall
- Test connection manually:
Discord OAuth not working
Discord OAuth not working
Error:
OAuth redirect URI mismatchSolutions:- Verify redirect URI in Discord Developer Portal matches:
- Local:
http://localhost:3000/api/auth/callback - Production:
https://yourdomain.com/api/auth/callback
- Local:
- Check
REDIRECT_URLin.env.local - Ensure Discord application has correct scopes (
identify,email)
Stripe webhooks failing
Stripe webhooks failing
Error:
Webhook signature verification failedSolutions:- Verify
STRIPE_WEBHOOK_SECRETmatches your Stripe webhook endpoint - For local development, use Stripe CLI:
- Check that your webhook endpoint is publicly accessible (production)
- Verify selected events in Stripe Dashboard match your handler
AI features not working
AI features not working
Error:
OpenAI API key invalidSolutions:- Verify
OPENAI_API_KEYstarts withsk-proj-orsk- - Check API key has sufficient credits
- Test API key directly:
- Ensure you’re using a valid model (gpt-4 or gpt-3.5-turbo)
Docker build failures
Docker build failures
Error: Build fails during
bun install or next buildSolutions:- Increase Docker memory allocation (Settings → Resources → Memory)
- Clear Docker build cache:
- Check for Node.js version compatibility in
Dockerfile.bun - Verify all environment variables are set before building
Production Checklist
Before deploying to production: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
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
Database
- Automated backups configured
- Database connection pooling enabled
- Migrations tested on staging environment
- Database performance monitoring set up
Monitoring
- Error tracking configured (e.g., Sentry)
- Uptime monitoring set up
- Log aggregation configured
- Resource usage alerts enabled
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