Railway Deployment
Deploy CodeSpar to Railway with one-click setup, environment variable configuration, custom domains, and monitoring.
Railway Deployment
Railway is the recommended platform for deploying CodeSpar to the cloud. It offers one-click deploys from GitHub, automatic HTTPS, and built-in monitoring.
One-Click Deploy
The fastest way to deploy CodeSpar:
- Fork the
codespar/codesparrepository to your GitHub account - Go to Railway and create a new project
- Select "Deploy from GitHub Repo"
- Choose your forked
codespar/codesparrepository - Railway will auto-detect the Dockerfile and begin building
Required Environment Variables
After the initial deploy, set these environment variables in the Railway dashboard under Settings > Variables:
| Variable | Required | Notes |
|---|---|---|
ANTHROPIC_API_KEY | Yes | Your Anthropic API key |
GITHUB_TOKEN | Yes | GitHub PAT with repo scope |
PROJECT_NAME | No | Your project name (default: codespar) |
ADMIN_NAME | No | Admin display name |
WEBHOOK_BASE_URL | Recommended | Your Railway public URL (e.g., https://codespar-production.up.railway.app) |
Setting Variables via CLI
You can also use the Railway CLI:
PORT Configuration
Railway automatically sets the PORT environment variable to 8080. CodeSpar reads this automatically — you do not need to set it manually.
If you see port-related errors, verify that:
- You have not hardcoded
PORT=3000in your Railway variables - Your Dockerfile uses
ENV PORT=3000as a default but CodeSpar respects the runtimePORTvalue
Adding Channels
Slack
Discord
Telegram
WhatsApp requires an Evolution API instance. You can add it as a separate Railway service:
- Add a new service in your Railway project
- Deploy the Evolution API image:
atendai/evolution-api:latest - Set the
AUTHENTICATION_API_KEYvariable on the Evolution service - Set the following on your CodeSpar service:
Note: Use Railway's internal networking (*.railway.internal) for service-to-service communication.
Adding a Database
PostgreSQL
- Click "+ New" in your Railway project
- Select "Database" > "PostgreSQL"
- Railway auto-provisions the database and sets
DATABASE_URL - Add the reference variable to your CodeSpar service:
Redis
- Click "+ New" in your Railway project
- Select "Database" > "Redis"
- Add the reference variable:
Custom Domain Setup
Railway provides a default URL like https://codespar-production.up.railway.app. To use a custom domain:
- Go to your service's Settings > Networking
- Click "+ Custom Domain"
- Enter your domain (e.g.,
codespar.example.com) - Add the provided CNAME record to your DNS provider:
- Wait for DNS propagation (usually 5–30 minutes)
- Railway auto-provisions an SSL certificate via Let's Encrypt
After setting up the custom domain, update WEBHOOK_BASE_URL:
Monitoring and Logs
Viewing Logs
Railway Dashboard:
- Go to your service > Deployments > click a deployment > View Logs
Railway CLI:
Metrics
Railway provides built-in metrics for:
- CPU usage
- Memory usage
- Network traffic
- Disk usage
Access these from the service's Metrics tab in the dashboard.
Health Monitoring
Set up a health check endpoint in Railway:
- Go to Settings > Deploy > Health Check
- Set the path to
/api/agents - Set the timeout to
10s
Railway will restart the service if the health check fails.
Deployment Configuration
Build Settings
Railway auto-detects the Dockerfile. If you need to customize:
| Setting | Value |
|---|---|
| Builder | Dockerfile |
| Dockerfile path | ./Dockerfile |
| Watch paths | / (rebuild on any change) |
Scaling
Railway supports horizontal scaling on paid plans:
- Hobby plan: Single instance, 512 MB RAM, shared CPU
- Pro plan: Multiple instances, up to 8 GB RAM, dedicated CPU
- Enterprise: Custom resource allocation
For CodeSpar, a single instance with 512 MB RAM is sufficient for most teams. Scale up if you have many concurrent agent tasks.
Restart Policy
Railway automatically restarts crashed services. The default behavior is:
- Restart on crash
- Backoff on repeated crashes (1s, 2s, 4s, 8s... up to 5 minutes)
Example Full Configuration
A complete Railway setup with all services:
Troubleshooting
Service won't start
- Check logs for missing environment variables
- Verify
ANTHROPIC_API_KEYandGITHUB_TOKENare set - Ensure you have not hardcoded
PORT(Railway sets it automatically)
Webhooks not received
- Verify
WEBHOOK_BASE_URLmatches your Railway URL or custom domain - Check that the URL is publicly accessible (not behind a VPN)
- Test with a curl request to
{WEBHOOK_BASE_URL}/webhooks/github
Channel connection failures
- Check channel-specific environment variables are correctly set
- For WhatsApp, verify the Evolution API service is running
- Use the Channel API to check status and reconnect
Next Steps
- Docker Configuration — Self-hosted Docker deployment
- Configuration — All environment variables
- Multi-Channel Setup — Enable multiple channels