7.5 KiB
7.5 KiB
🚀 PRODUCTION DEPLOYMENT GUIDE
This guide covers deploying the Institutional Trader platform to production.
Table of Contents
- Environment Configuration
- Backend Deployment (Railway)
- Frontend Deployment (Vercel)
- Self-Hosting with Nginx
- Monitoring & Health Checks
- Security Checklist
1. Environment Configuration
Backend Production .env
Create a .env file in the backend directory with the following variables:
# Production Environment Variables
NODE_ENV=production
PORT=3000
# Supabase Configuration
SUPABASE_URL=your_production_supabase_url
SUPABASE_ANON_KEY=your_production_anon_key
SUPABASE_SERVICE_KEY=your_service_role_key
# Direct PostgreSQL Connection (optional, for heavy queries)
# Get this from: Supabase Dashboard > Settings > Database > Connection String (URI)
DATABASE_URL=postgresql://postgres:[password]@db.[project-ref].supabase.co:5432/postgres
# CORS Configuration
CORS_ORIGIN=https://your-frontend-domain.com
# Security
JWT_SECRET=your_super_secret_jwt_key_min_32_chars
RATE_LIMIT_WINDOW=15
RATE_LIMIT_MAX=100
# Error Tracking (optional)
SENTRY_DSN=your_sentry_dsn_here
Frontend Production .env
Create a .env.production file in the frontend directory:
VITE_API_URL=https://your-backend-domain.com
VITE_WS_URL=wss://your-backend-domain.com
VITE_SUPABASE_URL=your_supabase_url
VITE_SUPABASE_ANON_KEY=your_anon_key
2. Backend Deployment (Railway)
Prerequisites
- Install Railway CLI:
npm install -g railway
- Login to Railway:
railway login
Deployment Steps
- Initialize Railway project:
cd backend
railway init
- Link to existing project (if applicable):
railway link
- Set environment variables:
railway variables set NODE_ENV=production
railway variables set PORT=3000
railway variables set SUPABASE_URL=your_url
railway variables set SUPABASE_ANON_KEY=your_anon_key
railway variables set SUPABASE_SERVICE_KEY=your_service_key
railway variables set CORS_ORIGIN=https://your-frontend-domain.com
railway variables set RATE_LIMIT_WINDOW=15
railway variables set RATE_LIMIT_MAX=100
railway variables set JWT_SECRET=your_jwt_secret_min_32_chars
Or set them via Railway Dashboard:
- Go to your project → Variables tab
- Add each variable individually
- Deploy:
railway up
- View logs:
railway logs
Railway Configuration
The railway.toml file is already configured with:
- Build command:
npm install && npm run build - Start command:
npm start - Health check endpoint:
/health - Auto-restart on failure
3. Frontend Deployment (Vercel)
Prerequisites
- Install Vercel CLI:
npm install -g vercel
- Login to Vercel:
vercel login
Deployment Steps
- Navigate to frontend directory:
cd frontend
- Deploy to preview:
vercel
- Deploy to production:
vercel --prod
- Set environment variables in Vercel Dashboard:
- Go to your project → Settings → Environment Variables
- Add all
VITE_*variables for Production environment
Vercel Configuration
The vercel.json file is already configured for:
- Static build from
distdirectory - SPA routing (all routes →
index.html) - Environment variables support
4. Self-Hosting with Nginx
Prerequisites
- Ubuntu/Debian server with Nginx installed
- SSL certificate (Let's Encrypt recommended)
- Node.js installed on server
Setup Steps
- Install dependencies on server:
# Backend
cd backend
npm install --production
# Frontend
cd frontend
npm install
npm run build
- Set up systemd service for backend:
sudo nano /etc/systemd/system/flow-api.service
Add:
[Unit]
Description=Flow Platform API
After=network.target
[Service]
Type=simple
User=your-user
WorkingDirectory=/path/to/institutional_trader/backend
Environment=NODE_ENV=production
ExecStart=/usr/bin/node src/server.js
Restart=always
[Install]
WantedBy=multi-user.target
Enable and start:
sudo systemctl enable flow-api
sudo systemctl start flow-api
- Configure Nginx:
Copy nginx.conf.example to /etc/nginx/sites-available/your-domain and update:
- Replace
yourdomain.comwith your domain - Update SSL certificate paths
- Update root path for frontend
- Update proxy_pass URLs if needed
Enable site:
sudo ln -s /etc/nginx/sites-available/your-domain /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
- Set up SSL with Let's Encrypt:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com -d api.yourdomain.com
5. Monitoring & Health Checks
Health Check Endpoint
The backend includes an enhanced health check at /health:
curl https://api.yourdomain.com/health
Response includes:
- Status (ok/degraded)
- Timestamp
- Uptime
- Database connection status
- Database latency
Uptime Monitoring
Set up monitoring with:
- UptimeRobot (free): Monitor
/healthendpoint - Pingdom: Full-page monitoring
- Sentry: Error tracking (configure
SENTRY_DSN)
Logs
Railway:
railway logs --tail
Vercel:
- View in Dashboard → Deployments → Logs
Self-hosted:
# Backend logs
sudo journalctl -u flow-api -f
# Nginx logs
sudo tail -f /var/log/nginx/access.log
sudo tail -f /var/log/nginx/error.log
6. Security Checklist
- All environment variables set in production
JWT_SECRETis at least 32 characters and randomSUPABASE_SERVICE_KEYis kept secret (never in frontend)- CORS origin set to production frontend URL only
- Rate limiting enabled (default: 100 requests per 15 minutes)
- SSL/TLS certificates installed and valid
- Security headers configured (Helmet)
- Health check endpoint configured
- Error tracking configured (Sentry)
- Database connection pooling enabled
- Caching layer configured for performance
.envfiles excluded from git (verify.gitignore)- Production build optimized (check bundle sizes)
Performance Optimizations
Already Implemented
-
Backend:
- Compression middleware (gzip)
- Connection pooling (PostgreSQL)
- Request caching (NodeCache)
- Rate limiting
-
Frontend:
- Code splitting (vendor chunks)
- Asset optimization
- Production build minification
Additional Recommendations
- CDN: Use Cloudflare or similar for static assets
- Database: Enable connection pooling in Supabase
- Caching: Consider Redis for distributed caching
- Monitoring: Set up APM (Application Performance Monitoring)
Troubleshooting
Backend won't start
- Check environment variables:
railway variables
- Check logs:
railway logs
- Verify database connection:
curl https://api.yourdomain.com/health
Frontend build fails
- Check environment variables are set
- Verify API URLs are correct
- Check build logs:
vercel logs [deployment-url]
WebSocket connection fails
- Verify
VITE_WS_URLuseswss://(notws://) - Check Nginx WebSocket configuration
- Verify backend WebSocket route is accessible
Support
For issues or questions:
- Check logs first
- Verify environment variables
- Test health check endpoint
- Review security checklist
Your platform is now production-ready! 🎉