This guide shows how to deploy the NIJA platform using the recommended production stack:
cd /home/runner/work/Nija/Nija
# Generate secure JWT secret
export JWT_SECRET_KEY=$(python -c "import secrets; print(secrets.token_hex(32))")
# Set PostgreSQL password
export POSTGRES_PASSWORD=$(python -c "import secrets; print(secrets.token_hex(16))")
# Optional: Add your master trading account credentials
export COINBASE_API_KEY="your_key_here"
export COINBASE_API_SECRET="your_secret_here"
# Start all services (API, PostgreSQL, Redis)
docker-compose up -d
# Check status
docker-compose ps
# View logs
docker-compose logs -f api
# Check API health
curl http://localhost:8000/health
# Check API docs
open http://localhost:8000/api/docs
You should see:
{
"status": "healthy",
"timestamp": "2026-01-27T...",
"service": "NIJA FastAPI Backend",
"version": "2.0.0"
}
# Register a new user
curl -X POST http://localhost:8000/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "secure_password_123",
"subscription_tier": "basic"
}'
# Login (returns JWT token)
curl -X POST http://localhost:8000/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "secure_password_123"
}'
# Use the token from login response
export TOKEN="your_jwt_token_here"
# Get user profile
curl -X GET http://localhost:8000/api/user/profile \
-H "Authorization: Bearer $TOKEN"
# Start NIJA bot
curl -X POST http://localhost:8000/api/start_bot \
-H "Authorization: Bearer $TOKEN"
# Check bot status
curl -X GET http://localhost:8000/api/status \
-H "Authorization: Bearer $TOKEN"
cd /home/runner/work/Nija/Nija
pip install -r requirements.txt
export JWT_SECRET_KEY=$(python -c "import secrets; print(secrets.token_hex(32))")
export PORT=8000
export DEBUG=true
# Using uvicorn directly
uvicorn fastapi_backend:app --reload --port 8000
# Or using the Python script
python fastapi_backend.py
# JWT Secret (MUST be set for production)
JWT_SECRET_KEY=your_secret_key_here
# PostgreSQL (if using Docker Compose)
POSTGRES_PASSWORD=your_postgres_password
# Server Configuration
PORT=8000
DEBUG=false
JWT_EXPIRATION_HOURS=24
# Database URLs (auto-configured in Docker Compose)
DATABASE_URL=postgresql://user:pass@localhost:5432/nija
REDIS_URL=redis://localhost:6379/0
# Master Trading Account (optional)
COINBASE_API_KEY=...
COINBASE_API_SECRET=...
KRAKEN_PLATFORM_API_KEY=...
KRAKEN_PLATFORM_API_SECRET=...
# Build API container
docker-compose build api
# Build with no cache
docker-compose build --no-cache api
# Start all services
docker-compose up -d
# Start specific service
docker-compose up -d api
# View logs
docker-compose logs -f api
# Follow logs for all services
docker-compose logs -f
# Stop all services
docker-compose down
# Stop and remove volumes (β οΈ deletes database)
docker-compose down -v
# Remove all containers, networks, images
docker-compose down --rmi all -v
# Access PostgreSQL
docker-compose exec postgres psql -U nija_user -d nija
# Run SQL commands
docker-compose exec postgres psql -U nija_user -d nija -c "SELECT * FROM users;"
# Backup database
docker-compose exec postgres pg_dump -U nija_user nija > backup.sql
# Restore database
docker-compose exec -T postgres psql -U nija_user nija < backup.sql
# Access Redis CLI
docker-compose exec redis redis-cli
# Check keys
docker-compose exec redis redis-cli KEYS '*'
# Flush all data (β οΈ destructive)
docker-compose exec redis redis-cli FLUSHALL
For production at scale, deploy to Kubernetes:
# TODO: Create K8s manifests
# - Deployment for API (multiple replicas)
# - StatefulSet for user execution pods
# - Service for load balancing
# - Ingress for HTTPS
# - PostgreSQL operator or managed service
# - Redis cluster
# API health
curl http://localhost:8000/health
# Database health
docker-compose exec postgres pg_isready -U nija_user
# Redis health
docker-compose exec redis redis-cli ping
# API logs
docker-compose logs -f api
# PostgreSQL logs
docker-compose logs -f postgres
# Redis logs
docker-compose logs -f redis
# All logs
docker-compose logs -f
# Add Prometheus metrics
from prometheus_fastapi_instrumentator import Instrumentator
instrumentator = Instrumentator()
instrumentator.instrument(app).expose(app)
# Find process using port 8000
lsof -i :8000
# Kill process
kill -9 <PID>
# Or use different port
export PORT=8080
# Check PostgreSQL status
docker-compose ps postgres
# Restart PostgreSQL
docker-compose restart postgres
# Check logs
docker-compose logs postgres
# Check Redis status
docker-compose exec redis redis-cli ping
# Should return: PONG
# Rebuild container
docker-compose build --no-cache api
# Or reinstall dependencies locally
pip install -r requirements.txt
# Pull latest code
git pull origin main
# Rebuild and restart
docker-compose down
docker-compose build
docker-compose up -d
# Install Alembic
pip install alembic
# Initialize
alembic init migrations
# Create migration
alembic revision --autogenerate -m "description"
# Apply migration
alembic upgrade head
# Create Next.js app
npx create-next-app@latest web-dashboard --typescript --tailwind
# Install dependencies
cd web-dashboard
npm install axios socket.io-client
# Configure API URL
# .env.local:
NEXT_PUBLIC_API_URL=http://localhost:8000
# Create Flutter app
flutter create nija_mobile
# Add dependencies
# pubspec.yaml:
dependencies:
http: ^1.1.0
provider: ^6.1.1
flutter_secure_storage: ^9.0.0
AWS:
GCP:
Azure:
βββββββββββββββββββββββββββββββββββββββ
β Mobile App / Web Dashboard β
βββββββββββββββββββββββββββββββββββββββ€
β Flutter/RN | Next.js + React β
βββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββ
β FastAPI Backend (Layer 3) β
βββββββββββββββββββββββββββββββββββββββ€
β /api/start_bot β
β /api/stop_bot β
β /api/status β
β /api/positions β
β /api/pnl β
β /api/config β
βββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββ
β User Control Backend (Layer 2) β
βββββββββββββββββββββββββββββββββββββββ€
β Isolated execution per user β
β Risk management β
β Position tracking β
βββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββ
β NIJA Core Brain (Layer 1) β
βββββββββββββββββββββββββββββββββββββββ€
β π PRIVATE - Strategy Logic β
β π PRIVATE - AI Models β
βββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββ
β Exchanges (Coinbase, Kraken...) β
βββββββββββββββββββββββββββββββββββββββ
π Your NIJA engine is now wrapped as a headless microservice!
Users can start/stop trading, view stats, and manage settings without ever seeing your proprietary strategy logic.