Production Deployment
Complete guide for deploying Earna AI to production. This covers Vercel deployment, Supabase configuration, and environment setup.
Architecture Overview
Earna AI consists of three independent Next.js applications:
- Console - Main AI chat platform with multi-model support
- Landing Page - Marketing website with interactive visualizations
- Documentation - Nextra-based documentation site
Each app deploys independently to Vercel with its own:
package.json
andpackage-lock.json
vercel.json
configuration- Environment variables
- Custom domain
Vercel Deployment
Install Vercel CLI
pnpm add -g vercel
Deploy Console App
cd console
vercel --prod
# When prompted:
# - Scope: Select your team
# - Link to existing project: No (first time)
# - Project name: console
# - Framework: Next.js
# - Build settings: Use defaults
Deploy Landing Page
cd apps
vercel --prod
# Project name: apps
Deploy Documentation
cd docs-nextra
vercel --prod
# Project name: docs-nextra
Configure Environment Variables
Add environment variables via Vercel Dashboard or CLI:
Vercel Dashboard
- Go to vercel.com/dashboard
- Select your console project
- Navigate to Settings > Environment Variables
- Add each variable for Production environment
- Redeploy to apply changes
Supabase Setup
Database Configuration
Create Supabase Project
- Sign up at supabase.com
- Create new project with a strong database password
- Select region closest to your users
- Wait for project to initialize
Get API Credentials
From Settings > API, copy:
- Project URL:
https://xxxxx.supabase.co
- anon key: Public client key
- service_role key: Secret server key
Run Migrations
Execute migrations in SQL Editor in this exact order:
-- Directory: console/supabase/migrations/
-- 1. Core tables
20250118_create_tables.sql
-- 2. User management
20250119_create_users_table.sql
20250120_add_anonymous_field.sql
-- 3. Rate limiting
20250121_add_daily_message_count.sql
20250122_add_daily_pro_message_count.sql
20250123_add_daily_pro_reset.sql
-- 4. Messages
20250124_create_messages_table.sql
20250125_add_message_columns.sql
-- 5. Schema completion
20250126_add_missing_columns.sql
20250127_complete_schema.sql
-- 6. Storage
20250818_001_create_storage_bucket.sql
20250818_add_daily_reset_columns.sql
Configure Storage
- Go to Storage in dashboard
- Create bucket:
chat-attachments
- Settings:
- Private bucket: Yes
- Max file size: 10MB
- Allowed MIME types:
image/*,application/pdf
Enable Authentication
- Go to Authentication > Providers
- Enable Email authentication
- Configure OAuth (optional):
- GitHub
- Set URLs:
- Site URL:
https://console.yourdomain.com
- Redirect URLs:
https://console.yourdomain.com/auth/callback
- Site URL:
Environment Variables Reference
Required Variables
# Encryption (generate with: openssl rand -base64 32)
ENCRYPTION_KEY=your_base64_key_here
# Supabase - Client Side
NEXT_PUBLIC_SUPABASE_URL=https://xxxxx.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGci...
# Supabase - Server Side (same values)
SUPABASE_URL=https://xxxxx.supabase.co
SUPABASE_ANON_KEY=eyJhbGci...
SUPABASE_SERVICE_ROLE=eyJhbGci... # Secret!
# At least one AI provider
OPENAI_API_KEY=sk-proj-...
# OR
ANTHROPIC_API_KEY=sk-ant-api-...
# OR
GOOGLE_AI_API_KEY=AIzaSy...
Optional AI Providers
# Additional AI providers
MISTRAL_API_KEY=...
XAI_API_KEY=xai-...
PERPLEXITY_API_KEY=pplx-...
DEEPSEEK_API_KEY=...
# Local models
OLLAMA_BASE_URL=http://localhost:11434
Interactive Features
# HeyGen Avatars
HEYGEN_API_KEY=...
NEXT_PUBLIC_HEYGEN_API_URL=https://api.heygen.com
# Voice Mode (requires OpenAI)
NEXT_PUBLIC_OPENAI_API_KEY=sk-proj-...
Custom Domains
Configure DNS
Add these records to your domain:
Type | Name | Value |
---|---|---|
A | @ | 76.76.21.21 |
CNAME | console | cname.vercel-dns.com |
CNAME | docs | cname.vercel-dns.com |
CNAME | www | cname.vercel-dns.com |
Add to Vercel
For each project in Vercel Dashboard:
- Go to Settings > Domains
- Add your custom domain:
- Console:
console.yourdomain.com
- Landing:
yourdomain.com
andwww.yourdomain.com
- Docs:
docs.yourdomain.com
- Console:
- Vercel will automatically provision SSL certificates
Production Checklist
Security
- All sensitive env vars are in Vercel, not in code
-
SUPABASE_SERVICE_ROLE
is never exposed client-side - RLS policies are enabled on all Supabase tables
- Storage bucket has proper access controls
- CORS is configured correctly
- Rate limiting is enabled
- SSL/HTTPS is enforced
Performance
- Edge functions configured for API routes
- Database indexes created for frequent queries
- Image optimization enabled
- Proper caching headers set
Monitoring
- Error tracking configured (optional)
- Analytics enabled (optional)
- Uptime monitoring set up
- Database backups scheduled
CI/CD with GitHub Actions
Create .github/workflows/deploy.yml
:
name: Deploy to Vercel
on:
push:
branches: [main]
jobs:
deploy-console:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install dependencies
run: |
cd console
pnpm install --frozen-lockfile
- name: Build
run: |
cd console
pnpm build
env:
NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}
- name: Deploy to Vercel
run: |
cd console
vercel --prod --token ${{ secrets.VERCEL_TOKEN }}
Troubleshooting
Common Deployment Issues
Build Fails on Vercel
# Check build logs
vercel logs
# Common fixes:
# 1. Add all required env vars
# 2. Clear build cache
vercel --force
# 3. Check Node version
# Add to package.json:
"engines": {
"node": ">=20"
}
Environment Variables Not Working
- Ensure variables are added for correct environment (Production)
- Redeploy after adding variables
- Check for typos in variable names
- Verify both
NEXT_PUBLIC_
and server-side versions are set
Database Connection Issues
-- Check if tables exist
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public';
-- Verify RLS is enabled
SELECT schemaname, tablename, rowsecurity
FROM pg_tables
WHERE schemaname = 'public';
Authentication Redirect Issues
Update Supabase Auth settings:
- Site URL: Must match your production domain
- Redirect URLs: Include
/auth/callback
path
Scaling Considerations
Database
- Enable connection pooling in Supabase
- Add read replicas for high traffic
- Implement caching with Redis/Upstash
API Rate Limits
- Monitor AI provider usage
- Implement request queuing
- Cache common responses
- Use streaming for better UX
Edge Functions
Configure in vercel.json
:
{
"functions": {
"app/api/chat/route.ts": {
"maxDuration": 30,
"runtime": "edge"
}
},
"regions": ["iad1"]
}
Backup and Recovery
Database Backups
Supabase automatically backs up your database daily. For manual backups:
# Export data
pg_dump $DATABASE_URL > backup.sql
# Import data
psql $DATABASE_URL < backup.sql
Environment Variables Backup
# Export from Vercel
vercel env pull .env.production
# Store securely (not in Git!)
Monitoring
Vercel Analytics
Automatically enabled for tracking:
- Page views
- Web Vitals
- API performance
Supabase Dashboard
Monitor:
- Database queries
- Storage usage
- Auth events
- API requests
Custom Monitoring
Add application monitoring (optional):
// lib/monitoring.ts
export function trackEvent(name: string, properties?: any) {
// Add your analytics provider
console.log('Event:', name, properties);
}
Cost Optimization
Free Tier Limits
Vercel (Hobby):
- 100GB bandwidth/month
- 100GB-hours compute
- Unlimited deployments
Supabase (Free):
- 500MB database
- 1GB storage
- 50,000 auth users
- 2GB bandwidth
Cost Saving Tips
- Use Edge functions for better performance
- Enable caching for static content
- Optimize images with Next.js Image
- Use connection pooling for database
- Monitor AI API usage and set limits
Support
- GitHub Issues: github.com/identity-wael/earna-ai
- Vercel Support: vercel.com/support
- Supabase Support: supabase.com/support
Last updated on