This project is configured for deployment on Railway using multiple approaches:
Railway will automatically detect the nixpacks.toml file and use Nixpacks for building.
Railway will use the Dockerfile if Nixpacks is not preferred.
Fallback option using the Procfile.
railway.toml- Railway-specific configurationnixpacks.toml- Nixpacks build configurationDockerfile- Docker build configurationProcfile- Process configuration.dockerignore- Files to exclude from Docker build
Important: Do NOT upload your .env file to GitHub or Railway. Instead, set environment variables through Railway's dashboard.
- Go to your Railway project dashboard
- Click on the "Variables" tab
- Add each variable individually using the format:
VARIABLE_NAME=value
MONGODB_URL=mongodb+srv://username:password@cluster.mongodb.net/database
SECRET_KEY=your-super-secure-jwt-secret-key-generate-a-new-one
ALLOWED_ORIGINS=https://your-frontend-domain.com,https://your-app.vercel.app,http://localhost:3000
FRONTEND_URL=https://your-frontend-domain.netlify.app
Important for Splitwise OAuth: The FRONTEND_URL variable is critical for the Splitwise import functionality. It must be set to your production frontend URL (e.g., https://your-app.netlify.app or https://your-app.vercel.app). Without this, the OAuth callback will fail in production.
DATABASE_NAME=splitwiser
DEBUG=false
ACCESS_TOKEN_EXPIRE_MINUTES=15
REFRESH_TOKEN_EXPIRE_DAYS=30
ALGORITHM=HS256
Instead of uploading the Firebase service account JSON file, you need to set the following environment variables from your service account JSON:
FIREBASE_TYPE=service_account
FIREBASE_PROJECT_ID=your-project-id
FIREBASE_PRIVATE_KEY_ID=your-private-key-id
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
FIREBASE_CLIENT_EMAIL=your-service-account-email@project.iam.gserviceaccount.com
FIREBASE_CLIENT_ID=your-client-id
FIREBASE_AUTH_URI=https://accounts.google.com/o/oauth2/auth
FIREBASE_TOKEN_URI=https://oauth2.googleapis.com/token
FIREBASE_AUTH_PROVIDER_X509_CERT_URL=https://www.googleapis.com/oauth2/v1/certs
FIREBASE_CLIENT_X509_CERT_URL=https://www.googleapis.com/robot/v1/metadata/x509/your-service-account
To easily convert your Firebase service account JSON to environment variables, run:
python backend/convert_service_account_to_env.py backend/firebase-service-account.json
Important Note: The FIREBASE_PRIVATE_KEY must include all newlines. Railway's environment variables support multiline values, but be careful with the formatting.
If you're experiencing CORS issues (OPTIONS requests failing with 400 errors), follow these steps:
-
Verify ALLOWED_ORIGINS Environment Variable: Make sure your Railway deployment has the correct
ALLOWED_ORIGINSset with your frontend domain:ALLOWED_ORIGINS=https://your-frontend-domain.vercel.app,http://localhost:3000 -
Test CORS Configuration: Use the provided test script:
cd backend pip install requests # Edit test_cors.py to use your backend and frontend URLs python test_cors.py
-
Check Railway Logs: Look for CORS-related messages in your Railway deployment logs. The enhanced logging will show:
- Allowed CORS origins on startup
- OPTIONS request details
- Origin headers from requests
-
Common CORS Issues:
- Frontend domain not included in ALLOWED_ORIGINS
- Trailing slashes in URLs (e.g.,
https://domain.com/vshttps://domain.com) - HTTP vs HTTPS mismatch
- Wrong port numbers in localhost URLs
- Variable:
MONGODB_URL - Value:
mongodb+srv://myuser:mypassword@cluster0.abc123.mongodb.net/splitwiser
The app will automatically use these environment variables instead of the .env file.
-
Push to GitHub
git add . git commit -m "Add Railway deployment configuration" git push origin main
-
Connect to Railway
- Go to railway.app
- Sign in with GitHub
- Click "New Project"
- Select "Deploy from GitHub repo"
- Choose your repository
-
Configure Environment Variables
- In Railway dashboard, go to Variables tab
- Add all required environment variables listed above
-
Deploy
- Railway will automatically build and deploy
- Monitor the build logs for any issues
The build process will:
- Install Python 3.12
- Install dependencies from
requirements.txt - Start the FastAPI server with uvicorn
Your deployed API will be available at:
- Main API:
https://your-app.railway.app/ - Health check:
https://your-app.railway.app/health - API docs:
https://your-app.railway.app/docs
The Splitwise import functionality has been optimized for serverless and free-tier deployments:
- Async API Calls: All Splitwise API calls use
asyncio.to_thread()to prevent blocking - Parallel Expense Processing: Expenses are processed in parallel using
asyncio.gather()with a semaphore (limit: 10 concurrent operations) - Batch Preview Generation: Group expense counts are fetched concurrently during preview
- 5-10x faster imports on free-tier Railway deployments
- Reduced memory usage through controlled concurrency
- Better serverless behavior with non-blocking I/O operations
The default concurrency limit is set to 10 for Railway free tier. If you're on a paid plan with more resources, you can adjust the semaphore limits in:
backend/app/integrations/service.py-_import_expenses()method- Preview endpoint concurrency in
preview_splitwise_import()method
- Build fails: Check that all dependencies in
requirements.txtare valid - App won't start: Verify environment variables are set correctly
- CORS errors: Make sure
ALLOWED_ORIGINSincludes your frontend domain - Database connection: Verify
MONGODB_URLis correct and accessible - Splitwise OAuth fails: Ensure
FRONTEND_URLis set to your production frontend URL and matches the callback URL registered in your Splitwise app settings
Check Railway deployment logs in the dashboard for detailed error messages.