This guide provides step-by-step instructions for deploying the NIJA trading platform to production.
NIJA consists of several components that can be deployed together or separately:
The fastest way to get started is using Docker Compose:
# Clone repository
git clone https://github.com/your-org/nija.git
cd nija
# Copy environment file
cp .env.example .env
# Edit .env with your configuration
nano .env
# Start all services
docker-compose up -d
# Check logs
docker-compose logs -f
# Stop services
docker-compose down
# JWT Configuration
JWT_SECRET_KEY=your-secure-random-secret-key-here
JWT_EXPIRATION_HOURS=24
# PostgreSQL Database
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_DB=nija
POSTGRES_USER=nija_user
POSTGRES_PASSWORD=your-secure-password
# Or use single DATABASE_URL
DATABASE_URL=postgresql://nija_user:password@postgres:5432/nija
# API Configuration
PORT=8000
DEBUG=false
ALLOWED_ORIGINS=https://yourdomain.com,https://app.yourdomain.com
TRUSTED_HOSTS=yourdomain.com,app.yourdomain.com
# Rate Limiting
RATE_LIMIT_REQUESTS=100
RATE_LIMIT_WINDOW=60
# Vault (Optional)
VAULT_ADDR=http://vault:8200
VAULT_TOKEN=your-vault-token
# Redis (Optional)
REDIS_URL=redis://redis:6379/0
# Generate JWT secret
python -c "import secrets; print(secrets.token_hex(32))"
# Generate database password
python -c "import secrets; print(secrets.token_urlsafe(32))"
Railway provides automatic deployment with PostgreSQL provisioning.
Sign up at railway.app
npm install -g @railway/cli
railway login
railway init
railway link
railway add postgresql
railway up
.env.examplePORT=8000https://your-app.railway.apphttps://your-app.railway.app/api/docsssh -i your-key.pem ubuntu@your-instance-ip
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USER
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
git clone https://github.com/your-org/nija.git
cd nija
cp .env.example .env
nano .env # Edit configuration
docker-compose up -d
sudo apt install nginx certbot python3-certbot-nginx
Create /etc/nginx/sites-available/nija:
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /ws {
proxy_pass http://localhost:8000/ws;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
Enable site and SSL:
sudo ln -s /etc/nginx/sites-available/nija /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
sudo certbot --nginx -d yourdomain.com
curl https://sdk.cloud.google.com | bash
gcloud init
gcloud builds submit --tag gcr.io/PROJECT-ID/nija-api
gcloud run deploy nija-api \
--image gcr.io/PROJECT-ID/nija-api \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--set-env-vars DATABASE_URL=$DATABASE_URL,JWT_SECRET_KEY=$JWT_SECRET_KEY
For production scale, use Kubernetes:
# Apply Kubernetes configs
kubectl apply -f k8s/
See k8s/ directory for complete Kubernetes manifests.
# Using Docker Compose
docker-compose exec api python init_database.py --demo-user
# Or locally
python init_database.py --demo-user
# Apply all migrations
alembic upgrade head
# Check current version
alembic current
# Create backup
docker-compose exec postgres pg_dump -U nija_user nija > backup_$(date +%Y%m%d).sql
# Restore backup
docker-compose exec -T postgres psql -U nija_user nija < backup_20260129.sql
# Check API health
curl https://yourdomain.com/health
# Check database health
docker-compose exec api python -c "from database.db_connection import init_database, check_database_health; init_database(); print(check_database_health())"
# All services
docker-compose logs -f
# API only
docker-compose logs -f api
# Database only
docker-compose logs -f postgres
# Last 100 lines
docker-compose logs --tail=100 api
Add these endpoints to your monitoring:
GET /health - Service healthGET /api/info - API infoConsider integrating:
Before going to production:
Scale API servers:
# Docker Compose
docker-compose up -d --scale api=3
# Kubernetes
kubectl scale deployment nija-api --replicas=5
For high load:
Use a load balancer (Nginx, HAProxy, or cloud LB):
upstream nija_backend {
least_conn;
server api1:8000;
server api2:8000;
server api3:8000;
}
server {
listen 80;
location / {
proxy_pass http://nija_backend;
}
}
# Check logs
docker-compose logs api
# Common issues:
# 1. Database not ready -> Wait for postgres to initialize
# 2. Missing env vars -> Check .env file
# 3. Port already in use -> Change PORT in .env
# Test database connection
docker-compose exec postgres psql -U nija_user -d nija -c "SELECT 1;"
# Check database is running
docker-compose ps postgres
# Restart database
docker-compose restart postgres
# Check resource usage
docker stats
# Limit container resources in docker-compose.yml:
services:
api:
deploy:
resources:
limits:
memory: 512M
If deployment fails:
# Docker Compose
docker-compose down
git checkout previous-working-commit
docker-compose up -d
# Database rollback
alembic downgrade -1
/api/docs (Swagger UI)DATABASE_SETUP.mdMULTI_USER_PLATFORM_ARCHITECTURE.mdSECURITY.mdDocument Version: 1.0 Last Updated: January 29, 2026 Status: Production Ready