Skip to content

MGSLG Analytics Platform - Production Deployment Guide

MGSLG Analytics Platform - Production Deployment Guide

Section titled “MGSLG Analytics Platform - Production Deployment Guide”

Database: ✅ PostgreSQL seeded with 1,500+ participants Backend API: ✅ Real database queries implemented Frontend: ✅ Configured for production


  1. Railway Account (already have subscription)
  2. GitHub Repository - gedeza/mathew-goniwe (configured)
  3. PostgreSQL Database on Railway
  4. Domain (optional) - for custom URLs

Terminal window
# Login to Railway (if not already)
railway login
# Link repository
railway link

In Railway Dashboard → Backend Service → Variables:

# Application
ENVIRONMENT=production
SECRET_KEY=<generate-strong-secret-key>
# Database (provided by Railway PostgreSQL)
DATABASE_URL=${{Postgres.DATABASE_URL}}
# Redis (optional, add later)
REDIS_URL=${{Redis.REDIS_URL}}
# Application Settings
PORT=8000
LOG_LEVEL=INFO
# Mock Data (disable in production)
MOCK_DATA_ENABLED=false
Terminal window
# From project root
cd backend
railway up
# Or link GitHub for auto-deployment
# Railway Dashboard → Settings → Connect GitHub Repo
Terminal window
# SSH into Railway container or run locally against production DB
railway run python seed_database.py
Terminal window
# Get your backend URL
railway status
# Test health endpoint
curl https://your-backend-url.up.railway.app/api/health
# Test KPIs endpoint
curl https://your-backend-url.up.railway.app/api/dashboard/kpis

Expected Response:

{
"success": true,
"data": [
{
"title": "Total Participants",
"value": 1500,
"change": 12,
"changeType": "increase"
}
]
}

In Railway Dashboard:

  1. New → Service
  2. Select “Deploy from GitHub”
  3. Choose frontend directory

Build Command:

Terminal window
npm install && npm run build

Start Command:

Terminal window
npm start

Root Directory:

/frontend
NEXT_PUBLIC_API_URL=https://your-backend-url.up.railway.app
NODE_ENV=production
Terminal window
cd frontend
railway up

Visit: https://your-frontend-url.up.railway.app


VariableValueNotes
ENVIRONMENTproduction
DATABASE_URL${{Postgres.DATABASE_URL}}Auto-populated
SECRET_KEYGenerate securelyUse openssl rand -hex 32
PORT8000Railway default
LOG_LEVELINFO
MOCK_DATA_ENABLEDfalseUse real data
VariableValueNotes
NEXT_PUBLIC_API_URLBackend Railway URLe.g., https://mgslg-backend.up.railway.app
NODE_ENVproduction

Section titled “Option A: Use Railway PostgreSQL (Recommended)”
  1. Railway Dashboard → New → Database → PostgreSQL
  2. Copy connection string
  3. Set as DATABASE_URL in backend service
  4. Run seed script:
Terminal window
railway run --service backend python seed_database.py
Terminal window
# Create database
createdb mgslg_analytics_prod
# Update DATABASE_URL
export DATABASE_URL="postgresql://user:pass@host:5432/mgslg_analytics_prod"
# Run seed script
python backend/seed_database.py

  1. Railway Dashboard → Backend Service → Settings
  2. Add custom domain: api.mgslg-analytics.com
  3. Update DNS:
    • Type: CNAME
    • Name: api
    • Value: <railway-domain>.up.railway.app
  1. Railway Dashboard → Frontend Service → Settings

  2. Add custom domain: mgslg-analytics.com

  3. Update DNS:

    • Type: CNAME
    • Name: @ or www
    • Value: <railway-domain>.up.railway.app
  4. Update Frontend Environment:

    NEXT_PUBLIC_API_URL=https://api.mgslg-analytics.com

Backend:

  • /api/health - Service health status
  • /docs - API documentation (development only)

Frontend:

  • / - Main dashboard

Railway provides built-in monitoring:

  • CPU/Memory usage
  • Request logs
  • Error tracking
  • Deployment history

Terminal window
# 1. Deploy backend
cd backend
railway up --service backend
# 2. Seed database (first time only)
railway run --service backend python seed_database.py
# 3. Deploy frontend
cd ../frontend
railway up --service frontend
# 4. Check status
railway status
Terminal window
# Railway auto-deploys on git push if GitHub is connected
git add .
git commit -m "Update feature"
git push origin main
# Or manually deploy
railway up

  • Health check returns {"success": true, "data": {"status": "healthy"}}
  • KPIs endpoint returns 1,500 participants
  • Geographic endpoint returns 6 provinces
  • Database has 1,500+ participant records
  • Logs show no errors
  • Main dashboard loads successfully
  • KPIs display real data (1,500 participants)
  • Geographic performance shows provinces
  • No console errors
  • API calls succeed (check Network tab)
  • Frontend successfully connects to backend API
  • Data loads without fallback to mock data
  • All dashboard pages functional
  • ML Analytics page loads
  • Reports page accessible

Database Connection Errors:

5432/db
# Check DATABASE_URL format
echo $DATABASE_URL
# Railway format: postgresql://user:pass@host:5432/db
# Backend automatically adds +asyncpg

Migration Errors:

Terminal window
# Reset database (CAUTION: Deletes all data)
railway run --service backend python seed_database.py

API Connection Errors:

Terminal window
# Check NEXT_PUBLIC_API_URL is set
railway variables --service frontend
# Test backend URL manually
curl https://your-backend-url.up.railway.app/api/health

Build Errors:

Terminal window
# Clear cache and rebuild
railway logs --service frontend
# Check Node version (should be 18+)

After deployment, you’ll have:

  • Frontend: https://<frontend-service>.up.railway.app
  • Backend: https://<backend-service>.up.railway.app
  • API Docs: Disabled in production (security)

  1. Secrets Management:

    • Use Railway environment variables
    • Never commit .env files
    • Rotate SECRET_KEY regularly
  2. Database Security:

    • Use Railway PostgreSQL (private networking)
    • Enable SSL connections
    • Regular backups (Railway auto-backup)
  3. API Security:

    • CORS configured for frontend domain only
    • Rate limiting (add later)
    • Input validation with Pydantic
  4. POPIA Compliance:

    • Data anonymization for analytics
    • Audit trails enabled
    • Consent management (add later)

ServiceCostNotes
Starter Plan$5Base subscription
PostgreSQL$5-10Based on usage
Backend ServiceIncludedIn plan
Frontend ServiceIncludedIn plan
Total$10-15/monthHobby project range
ServiceCostNotes
Pro Plan$20
PostgreSQL$10Larger database
Redis$5Caching
Total$35/monthProduction-ready

  1. Test all endpoints with real stakeholder scenarios
  2. Monitor logs for first 24 hours
  3. Verify data integrity in production database
  4. Create backup of production database
  5. Document any issues encountered
  1. Add authentication (JWT tokens)
  2. Implement Redis caching for performance
  3. Add ML predictions for career progression
  4. Set up monitoring (Sentry, LogRocket)
  5. Create demo video walkthrough

  • Railway Docs: https://docs.railway.app
  • Project README: /README.md
  • Local Setup: /LOCAL-DEMO-SETUP.md
  • Backend API Docs: /docs (when running)

Generated: 2025-09-30 Platform: MGSLG Analytics Platform v1.0 Deployment Target: Railway Status: ✅ Ready for Production Deployment