Overview
Railway is the recommended platform for hosting the Nectr FastAPI backend. This guide walks you through deploying the backend with automatic migrations and environment configuration.The backend runs on Railway while the frontend deploys separately to Vercel. See Vercel Deployment for frontend setup.
Prerequisites
Before deploying to Railway, ensure you have:- A Railway account
- A forked copy of the Nectr repository
- API keys for required services (see below)
Required API Keys
Anthropic API Key
Get your API key from console.anthropic.com
GitHub OAuth App
Create a new OAuth App at github.com/settings/developersSet the Authorization callback URL to:Save these credentials:
GitHub Personal Access Token
Create a classic token at github.com/settings/tokens with
repo scope.This is used to post PR review comments.Neo4j Database
Sign up for a free Neo4j AuraDB instance at neo4j.com/cloud
Mem0 API Key
Get your API key from mem0.ai
Deployment Steps
Create New Project
- Log in to Railway
- Click New Project
- Select Deploy from GitHub repo
- Connect your GitHub account and select your Nectr fork
Add PostgreSQL Database
- In your Railway project, click New
- Select Database → PostgreSQL
- Railway will automatically provision a PostgreSQL database
- Copy the
DATABASE_URLfrom the database service
Configure Environment Variables
In your Railway service settings, add all required environment variables:
Configure Build Settings
Railway automatically detects the build configuration from The Dockerfile handles the build process:
railway.json:railway.json
Dockerfile
Deploy
- Railway will automatically start building and deploying
- Monitor the deployment logs in the Railway dashboard
- Database migrations run automatically on startup via Alembic
- Once deployed, copy your Railway app URL (e.g.,
https://nectr-production.up.railway.app)
Update OAuth Callback URL
Return to your GitHub OAuth App settings and update the Authorization callback URL:
Verify Deployment
Test your deployment with these endpoints:Automatic Migrations
Database migrations run automatically on every deployment via theapp.main:app lifespan context. The migration process:
- Connects to PostgreSQL using
DATABASE_URL - Runs all pending Alembic migrations
- Initializes Neo4j schema (constraints + indexes)
- Starts the FastAPI server
You can view migration logs in the Railway deployment console to ensure they complete successfully.
Continuous Deployment
Railway automatically deploys on every push to your default branch:- Push changes to GitHub
- Railway detects the commit
- Builds new Docker image
- Runs migrations
- Deploys with zero-downtime
Troubleshooting
Database connection errors
Database connection errors
Symptom: App fails to start with
asyncpg connection errorsSolution:- Verify
DATABASE_URLis set correctly - Ensure the URL uses
postgresql+asyncpg://prefix - Check that the Railway PostgreSQL service is running
- Verify network connectivity between services
Migration failures
Migration failures
Symptom: Alembic migrations fail during startupSolution:
- Check Railway logs for specific migration errors
- Verify database schema matches expected state
- Manually run migrations if needed:
Neo4j connection issues
Neo4j connection issues
Symptom: Neo4j health check failsSolution:
- Verify
NEO4J_URIusesneo4j+s://prefix for secure connections - Check credentials are correct
- Ensure Neo4j AuraDB instance is running
- Verify network access from Railway to Neo4j
Port binding errors
Port binding errors
Symptom: Uvicorn fails to bind to portSolution:
Railway automatically sets the Do not hardcode the port number.
PORT environment variable. The Procfile uses it:Monitoring & Logs
View Logs
Access real-time logs in the Railway dashboard:- Open your project
- Click on the service
- Navigate to Deployments → View Logs
Set Log Level
Control log verbosity with theLOG_LEVEL environment variable:
Scaling
Railway handles scaling automatically, but you can configure:- Restart Policy: Already set to
ON_FAILUREwith 10 retries - Resource Limits: Adjust in Railway project settings
- Region: Select closest to your users for lower latency
Cost Considerations
Railway pricing is based on usage:- Hobby Plan: $5/month + usage-based
- PostgreSQL: Included in usage
- Bandwidth: Pay-as-you-go
Railway offers a free trial with $5 credit. Monitor your usage in the Railway dashboard.
Next Steps
Deploy Frontend
Deploy the Next.js frontend to Vercel
Configure GitHub App
Set up GitHub OAuth and webhooks