skills/railway-deployment/SKILL.md
Railway deployment workflows, nixpacks configuration, environment management, and production troubleshooting
npx skillsauth add ainative-studio/ainativestudio-ide railway-deploymentInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
4 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill when:
Always start with proper nixpacks configuration:
nixPkgs${{ServiceName.VARIABLE}}Always bind to Railway's PORT environment variable:
port = int(os.environ.get('PORT', 8000))
Implement health check endpoints for Railway to monitor:
@app.get("/health")
async def health_check():
return {"status": "healthy"}
project/
├── backend/
│ ├── nixpacks.toml
│ └── requirements.txt
├── frontend/
│ ├── nixpacks.toml
│ └── package.json
└── railway.toml # Optional: multi-service config
Configure service references:
# In frontend service
VITE_API_URL=https://${{backend.RAILWAY_PUBLIC_DOMAIN}}
# In backend service
FRONTEND_URL=https://${{frontend.RAILWAY_PUBLIC_DOMAIN}}
# nixpacks.toml
[phases.build]
cmds = [
'pip install -r requirements.txt',
'alembic upgrade head' # Run migrations during build
]
Alternative: Separate migration service
# Create one-off migration job
railway run alembic upgrade head
[phases.setup]
nixPkgs = ['python310', 'postgresql']
nixLibs = ['libpq']
[phases.install]
cmds = ['pip install -r requirements.txt']
[start]
cmd = 'uvicorn main:app --host 0.0.0.0 --port $PORT'
[phases.setup]
nixPkgs = ['nodejs-18_x']
[phases.install]
cmds = ['npm ci']
[phases.build]
cmds = ['npm run build']
[start]
cmd = 'node dist/index.js'
[phases.setup]
nixPkgs = ['python310', 'nodejs-18_x', 'postgresql']
nixLibs = ['libpq']
[phases.install]
cmds = [
'pip install -r requirements.txt',
'cd frontend && npm ci'
]
[phases.build]
cmds = [
'cd frontend && npm run build',
'alembic upgrade head'
]
[start]
cmd = 'gunicorn main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:$PORT'
DATABASE_URL=${{Postgres.DATABASE_URL}}
DATABASE_PRIVATE_URL=${{Postgres.DATABASE_PRIVATE_URL}}
REDIS_URL=${{Redis.REDIS_URL}}
REDIS_PRIVATE_URL=${{Redis.REDIS_PRIVATE_URL}}
# Use private networking for internal communication
BACKEND_PRIVATE_URL=http://${{backend.RAILWAY_PRIVATE_DOMAIN}}
BACKEND_PUBLIC_URL=https://${{backend.RAILWAY_PUBLIC_DOMAIN}}
# Environment
ENVIRONMENT=production
DEBUG=false
# Security
JWT_SECRET_KEY=${{secrets.JWT_SECRET}}
ALLOWED_HOSTS=${{RAILWAY_PUBLIC_DOMAIN}}
# CORS
CORS_ORIGINS=https://${{frontend.RAILWAY_PUBLIC_DOMAIN}}
Error: "Package not found"
Error: "Command failed"
Error: "Application failed to respond"
0.0.0.0 not localhostError: "Database connection failed"
Always test locally first
nixpacks build . --name myapp
docker run -p 8000:8000 myapp
Use railway.toml for monorepos
[build]
builder = "nixpacks"
buildCommand = "cd backend && pip install -r requirements.txt"
[deploy]
startCommand = "cd backend && uvicorn main:app --host 0.0.0.0 --port $PORT"
restartPolicyType = "on-failure"
Set up health checks
@app.get("/health")
async def health():
# Check database connection
try:
await db.execute("SELECT 1")
return {"status": "healthy", "database": "connected"}
except:
return {"status": "unhealthy", "database": "disconnected"}
Configure logging
import logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
Use Railway CLI for debugging
railway login
railway link # Link to your project
railway logs # View logs
railway run python manage.py shell # Run commands
Railway handles this automatically with:
# Add custom domain in Railway dashboard
# Configure DNS:
CNAME record: your-domain.com -> your-app.up.railway.app
Use Railway's private networking for service-to-service communication:
# Faster and more secure than public URLs
INTERNAL_API_URL=http://${{backend.RAILWAY_PRIVATE_DOMAIN}}
# Use Railway environments (production, staging)
# Configure different variables per environment
ENVIRONMENT=${{RAILWAY_ENVIRONMENT}}
from sqlalchemy import create_engine
import os
DATABASE_URL = os.environ.get('DATABASE_URL')
if DATABASE_URL and DATABASE_URL.startswith('postgres://'):
DATABASE_URL = DATABASE_URL.replace('postgres://', 'postgresql://')
engine = create_engine(DATABASE_URL)
import os
import redis
REDIS_URL = os.environ.get('REDIS_URL')
redis_client = redis.from_url(REDIS_URL)
# railway.toml
[deploy]
volumes = [
{ name = "data", mountPath = "/app/data" }
]
import logging
import sys
logging.basicConfig(
stream=sys.stdout,
level=logging.INFO,
format='{"time": "%(asctime)s", "level": "%(levelname)s", "message": "%(message)s"}'
)
from prometheus_client import Counter, Histogram, generate_latest
request_count = Counter('http_requests_total', 'Total HTTP requests')
request_duration = Histogram('http_request_duration_seconds', 'HTTP request duration')
@app.get("/metrics")
async def metrics():
return Response(generate_latest(), media_type="text/plain")
# Login and setup
railway login
railway link
# Deployment
railway up # Deploy current directory
railway up --detach # Deploy without streaming logs
# Environment management
railway variables set KEY=value
railway variables delete KEY
# Logs and debugging
railway logs
railway logs --deployment <id>
railway shell # Open shell in deployment
# Service management
railway service # List services
railway domain # Manage domains
[phases.install]
# Use caching for faster rebuilds
cmds = [
'pip install --cache-dir /root/.cache/pip -r requirements.txt'
]
# Use production-grade servers
# Gunicorn with Uvicorn workers for async Python
import multiprocessing
workers = multiprocessing.cpu_count() * 2 + 1
worker_class = 'uvicorn.workers.UvicornWorker'
from sqlalchemy import create_engine
engine = create_engine(
DATABASE_URL,
pool_size=10,
max_overflow=20,
pool_pre_ping=True # Verify connections before use
)
When using this skill, provide:
See the references/ directory for detailed documentation on:
development
ZeroDB vector database best practices, semantic search patterns, RLHF workflows, and memory management. Use when working with ZeroDB APIs, vector search, or AI memory systems.
development
TDD/BDD workflows for FastAPI + React stack with pytest, vitest, and integration testing. Use when writing tests, configuring test runners, or implementing test-driven development.
tools
MCP server development patterns extending Anthropic's mcp-builder with AINative-specific conventions. Use when creating MCP servers, integrating ZeroDB, or building tool-based AI systems.
development
# API Design Skill You are an expert FastAPI backend architect specializing in RESTful API design, Pydantic data validation, and scalable backend systems. ## When to Use This Skill Use this skill when: - Designing new REST APIs or endpoints - Creating Pydantic models and schemas - Implementing authentication (JWT, OAuth) - Setting up error handling and validation - Structuring FastAPI applications - Working with OpenAPI/Swagger documentation ## Core Principles ### 1. RESTful Design - Use HT