Overview
The Athena ERP backend is a FastAPI application built with Python 3.12. This guide covers deploying to various platforms.Prerequisites
- Python 3.12 or higher
- PostgreSQL 16+ database (see Database Setup)
- Environment variables configured (see Environment Variables)
Technology Stack
- Framework: FastAPI 0.115+
- Server: Uvicorn with standard extras
- Database ORM: SQLAlchemy 2.0 (async)
- Migrations: Alembic 1.14+
- Database Driver: asyncpg 0.30+
- Authentication: python-jose with cryptography
- File Storage: boto3 (S3-compatible for R2)
- Error Tracking: Sentry SDK
Directory Structure
Deployment to Railway
Railway is the recommended platform for deploying the Athena backend.Step 1: Prepare Your Repository
Ensure your code is pushed to GitHub:Step 2: Create Railway Project
- Go to railway.app and sign in
- Click New Project
- Select Deploy from GitHub repo
- Choose your repository
- Railway will auto-detect the Python project
Step 3: Configure Build Settings
Railway should auto-detect the build, but verify:- Root Directory:
athena-api - Build Command:
pip install -e . - Start Command:
uvicorn app.main:app --host 0.0.0.0 --port $PORT
Step 4: Add Environment Variables
In Railway dashboard → Variables, add:Step 5: Run Database Migrations
In Railway → Settings → Deploy, add a custom build script:Step 6: Create Superadmin User
After deployment, create an admin user:Step 7: Generate Domain
Railway will provide a domain likeyour-app.up.railway.app. You can:
- Use the Railway domain
- Add a custom domain in Railway → Settings → Networking
Deployment to Render
Render is another excellent option.Step 1: Create Web Service
- Go to render.com and sign in
- Click New + → Web Service
- Connect your GitHub repository
- Configure:
- Name:
athena-api - Root Directory:
athena-api - Runtime: Python 3
- Build Command:
pip install -e . - Start Command:
uvicorn app.main:app --host 0.0.0.0 --port $PORT
- Name:
Step 2: Add Environment Variables
In Render dashboard → Environment, add all required variables (same as Railway).Step 3: Deploy
Render will automatically deploy. Monitor the logs for any errors.Step 4: Run Migrations
Create a migration job or run via Render Shell:Docker Deployment
For self-hosted or container-based deployments.Build Image
Run Container
Docker Compose (Full Stack)
Manual Deployment (VPS/Bare Metal)
For deploying to a VPS like DigitalOcean, Linode, or AWS EC2.Step 1: Install Dependencies
Step 2: Clone Repository
Step 3: Create Virtual Environment
Step 4: Configure Environment
Step 5: Run Migrations
Step 6: Configure Supervisor
Create/etc/supervisor/conf.d/athena-api.conf:
Step 7: Configure Nginx (Optional)
Create/etc/nginx/sites-available/athena-api:
Step 8: Setup SSL with Certbot
Post-Deployment
Verify Deployment
-
Health Check:
Should return:
-
API Documentation:
Visit
https://your-api-domain.com/docsfor interactive API docs -
Test Authentication:
Create Superadmin
Run the superadmin script:Monitor Logs
Railway: View logs in dashboard Render: View logs in dashboard Docker:Scaling
Horizontal Scaling
The API is stateless and can be scaled horizontally:- Railway: Adjust replicas in Settings → Scale
- Render: Adjust instance count in Settings → Scaling
- Docker: Use Docker Swarm or Kubernetes
- Manual: Run multiple Uvicorn workers:
Database Connection Pooling
For high traffic, use Supabase’s Session pooler or configure pgBouncer.Troubleshooting
”Module not found” errors
”Database connection failed”
Check:- DATABASE_URL format is correct
- Database is accessible from your hosting environment
- For Supabase, use pooler port 6543
”CORS errors”
Verify:- Frontend URL is in CORS_ORIGINS
- No trailing slashes
- Protocol matches (http/https)
“JWT decode error”
Ensure:- JWT_SECRET matches across all instances
- JWT_SECRET matches Supabase JWT secret (if using Supabase auth)
Migrations fail
Next Steps
Database Setup
Configure PostgreSQL and run migrations
Frontend Deployment
Deploy the React frontend
Environment Variables
Complete configuration reference
API Documentation
Explore the API endpoints