Railway Expert

The Railway Expert agent specializes in Railway deployment, configuration, scaling, and best practices for modern application hosting.

Expertise Areas#

  • Railway Fundamentals - Projects, services, environments
  • Project Setup - CLI usage and configuration
  • Database Services - PostgreSQL, Redis, MySQL
  • Next.js Deployment - Standalone builds and Docker
  • Scaling - Horizontal scaling and resource allocation
  • Monitoring - Logs, metrics, health checks
  • CI/CD Integration - GitHub Actions and deployment pipelines

Usage Examples#

Project Deployment#

Use the railway-expert agent to set up a Railway deployment for a Next.js application with PostgreSQL.

Response includes:

  • Project initialization
  • Database provisioning
  • Environment variables
  • Deployment configuration

Database Setup#

Use the railway-expert agent to provision and configure PostgreSQL with connection pooling.

Response includes:

  • Database service setup
  • Connection string configuration
  • Environment variable references
  • Prisma integration

Health Monitoring#

Use the railway-expert agent to implement health checks and monitoring for a production application.

Response includes:

  • Health endpoint implementation
  • Railway configuration
  • Monitoring setup
  • Alert configuration

Best Practices Applied#

1. Deployment#

  • Standalone output for Next.js
  • Proper Dockerfile optimization
  • Environment-based configuration
  • Preview environments for PRs

2. Database#

  • Connection pooling setup
  • Environment variable references
  • Backup configuration
  • Migration strategies

3. Scaling#

  • Resource allocation
  • Horizontal scaling setup
  • Regional deployment
  • Performance monitoring

4. Operations#

  • Health check endpoints
  • Log aggregation
  • Metric collection
  • Incident response

Common Patterns#

Railway Configuration#

1# railway.toml 2[build] 3builder = "nixpacks" 4buildCommand = "npm run build" 5 6[deploy] 7startCommand = "npm run start" 8healthcheckPath = "/api/health" 9healthcheckTimeout = 300 10restartPolicyType = "ON_FAILURE" 11restartPolicyMaxRetries = 3 12 13[deploy.resources] 14memory = "512Mi" 15cpu = 0.5

Next.js Standalone Build#

1// next.config.js 2/** @type {import('next').NextConfig} */ 3const nextConfig = { 4 output: 'standalone', 5 experimental: { 6 outputFileTracingRoot: process.cwd(), 7 }, 8}; 9 10module.exports = nextConfig;

Health Check Endpoint#

1// app/api/health/route.ts 2export async function GET() { 3 try { 4 // Check database 5 await prisma.$queryRaw`SELECT 1`; 6 7 return Response.json({ 8 status: 'healthy', 9 timestamp: new Date().toISOString(), 10 }); 11 } catch (error) { 12 return Response.json( 13 { status: 'unhealthy', error: error.message }, 14 { status: 503 } 15 ); 16 } 17}

CI/CD with GitHub Actions#

1# .github/workflows/railway.yml 2name: Deploy to Railway 3 4on: 5 push: 6 branches: [main] 7 8jobs: 9 deploy: 10 runs-on: ubuntu-latest 11 steps: 12 - uses: actions/checkout@v4 13 14 - name: Install Railway CLI 15 run: npm install -g @railway/cli 16 17 - name: Deploy 18 run: railway up 19 env: 20 RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}

Environment Variables#

1# Set variables with Railway CLI 2railway variables set KEY=value 3railway variables set DATABASE_URL=${{Postgres.DATABASE_URL}} 4 5# Reference other services 6DATABASE_URL=${{Postgres.DATABASE_URL}} 7REDIS_URL=${{Redis.REDIS_URL}}

Sample Prompts#

TaskPrompt
Initial setup"Set up a Railway project for a Next.js app"
Database"Add PostgreSQL and configure Prisma connection"
Scaling"Configure auto-scaling for production traffic"
Monitoring"Set up health checks and logging"
CI/CD"Create GitHub Actions workflow for Railway deployment"

Configuration#

1// bootspring.config.js 2module.exports = { 3 agents: { 4 customInstructions: { 5 'railway-expert': ` 6 - Use standalone output for Next.js 7 - Configure proper health checks 8 - Set up environment variables correctly 9 - Enable connection pooling for databases 10 - Implement CI/CD pipelines 11 `, 12 }, 13 }, 14 deployment: { 15 platform: 'railway', 16 database: 'postgresql', 17 }, 18};