This guide covers deploying SadakAI to production environments.
┌─────────────────────────────────────────────────────────────┐
│ CDN (Cloudflare) │
└────────────────────────┬────────────────────────────────────┘
│
┌──────────────┴──────────────┐
│ │
┌────▼────┐ ┌────▼────┐
│ Vercel │ │ Railway │
│Frontend │ │ API │
└─────────┘ └────┬────┘
│
┌─────────────────┼─────────────────┐
│ │ │
┌────▼────┐ ┌────▼────┐ ┌────▼────┐
│ Neon DB │ │ R2 │ │ Sentry │
│(Postgres)│ │(Storage)│ │(Logs) │
└─────────┘ └─────────┘ └─────────┘
# Install Vercel CLI
npm i -g vercel
# Navigate to dashboard
cd dashboard
# Login to Vercel
vercel login
# Deploy
vercel --prodOr connect your GitHub repository to Vercel:
- Go to https://vercel.com
- Import your repository
- Configure:
- Framework: Next.js
- Build Command: npm run build
- Output Directory: .next
- Add environment variables
- Deploy
# Install Railway CLI
npm i -g @railway/cli
# Login
railway login
# Create project
railway init
# Add PostgreSQL plugin
railway add -p postgres
# Deploy
railway upOr use Railway's GitHub integration.
# Clone and configure
git clone https://github.com/your-username/SadakAI.git
cd SadakAI
# Edit environment
cp .env.example .env
nano .env
# Deploy
docker-compose -f docker-compose.prod.yml up -d# Database - Use PostgreSQL in production
DATABASE_URL=postgresql://user:password@host:5432/sadakai
# Cloudflare R2 Storage (recommended for production)
R2_ENDPOINT=https://your-account.r2.cloudflarestorage.com
R2_ACCESS_KEY=your_access_key
R2_SECRET_KEY=your_secret_key
R2_BUCKET=sadakai-images
# API Security
API_KEY=generate_strong_random_key
# Model Path
MODEL_PATH=/app/weights/best.ptNEXT_PUBLIC_API_URL=https://your-api-domain.com- Create account at https://neon.tech
- Create new project
- Copy connection string
- Add to environment variables
# Add PostgreSQL to Railway project
railway add -p postgres- Create project at https://supabase.com
- Get connection string from settings
- Enable PostGIS extension:
CREATE EXTENSION postgis;
- Create Cloudflare account
- Create R2 bucket
- Get API credentials
- Add to environment
# Update storage service for S3
import boto3
s3 = boto3.client('s3',
aws_access_key_id=AWS_ACCESS_KEY,
aws_secret_access_key=AWS_SECRET_KEY,
region_name='us-east-1'
)- Enable HTTPS everywhere
- Set strong API keys
- Configure CORS properly
- Add rate limiting
- Enable database encryption
- Set up monitoring (Sentry)
- Configure backups
- Use environment variables for secrets
# Install Sentry SDK
pip install sentry-sdk
# Configure in main.py
import sentry_sdk
sentry_sdk.init(
dsn="your-sentry-dsn",
traces_sample_rate=0.1
)# Add to layout.tsx
import LogRocket from 'logrocket';
LogRocket.init('your-app-id');# .github/workflows/deploy.yml
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Deploy to Vercel
run: |
npm i -g vercel
vercel --prod --token=${{ secrets.VERCEL_TOKEN }}-
Enable Image Optimization
// next.config.js images: { domains: ['your-bucket.r2.cloudflarestorage.com'], }
-
Add Caching Headers
// next.config.js async headers() { return [ { source: '/:path*', headers: [ { key: 'Cache-Control', value: 'public, max-age=3600' } ] } ] }
- Enable Gzip Compression
- Use Redis for Caching (optional)
- Configure Worker Processes
gunicorn api.main:app -w 4 -k uvicorn.workers.UvicornWorker
# Clear cache and rebuild
rm -rf .next
npm run build- Check logs:
railway logs - Verify DATABASE_URL
- Check model weights exist
- Verify API is accessible
- Check CORS settings
- Ensure map tiles accessible
For deployment issues:
- Check application logs
- Verify environment variables
- Test database connection
- Contact maintainer
# Pull latest changes
git pull origin main
# Rebuild
npm run build# Pull latest changes
git pull origin main
# Rebuild Docker image
docker-compose build api
# Restart services
docker-compose restart apiNeed help? Open an issue on GitHub or contact the maintainer.