OS Trading Engine
Self-Hosting
Vercel + Railway

Vercel + Railway Deployment

Deploy Nexgent using a split architecture: Vercel for the Next.js frontend and Railway for the Express backend with managed PostgreSQL and Redis.


Architecture

┌─────────────────────┐         ┌─────────────────────────────────┐
│       Vercel        │         │            Railway              │
│                     │         │                                 │
│  ┌───────────────┐  │         │  ┌───────────────┐             │
│  │   Frontend    │  │  HTTPS  │  │    Backend    │             │
│  │   (Next.js)   │──┼────────▶│  │   (Express)   │             │
│  │               │  │   API   │  │               │             │
│  │               │◀─┼─────────┼──│   WebSocket   │             │
│  └───────────────┘  │         │  └───────┬───────┘             │
│                     │         │          │                      │
│  - CDN edge         │         │          │                      │
│  - Auto SSL         │         │  ┌───────┴───────┐             │
│  - Serverless       │         │  │               │             │
└─────────────────────┘         │  ▼               ▼             │
                                │ PostgreSQL    Redis            │
                                │ (managed)    (managed)         │
                                └─────────────────────────────────┘

Benefits:

  • Vercel: Optimized for Next.js, global CDN, automatic SSL
  • Railway: Simple deployment, managed databases, WebSocket support

Prerequisites


Railway Setup

Create Railway Project

  1. Go to Railway Dashboard (opens in a new tab)
  2. Click New Project
  3. Select Deploy from GitHub repo
  4. Connect your GitHub account and select your Nexgent fork

Add PostgreSQL

  1. In your Railway project, click New
  2. Select DatabaseAdd PostgreSQL
  3. Railway automatically provisions the database
  4. Note: Connection string is auto-injected as DATABASE_URL

Add Redis

  1. Click New again
  2. Select DatabaseAdd Redis
  3. Railway provisions Redis
  4. Note: Connection details are auto-injected

Configure Backend Service

Click on your backend service (the GitHub deployment) and configure:

Settings → General:

  • Root Directory: packages/backend
  • Build Command: pnpm install && pnpm build:backend
  • Start Command: pnpm --filter backend db:migrate:deploy && pnpm --filter backend start

Settings → Networking:

  • Enable Public Networking
  • Note the generated domain (e.g., your-app.up.railway.app)

Set Environment Variables

In the backend service, go to Variables and add:

# Auto-injected by Railway (verify these exist)
DATABASE_URL=<auto-injected>
REDIS_URL=<auto-injected>
 
# Manual configuration
NODE_ENV=production
PORT=4000
 
# CORS - your Vercel domain (add after Vercel setup)
CORS_ORIGIN=https://your-app.vercel.app
 
# Auth
JWT_SECRET=<generate-secure-secret>
 
# External APIs
JUPITER_API_KEY=your-jupiter-api-key
 
# Optional: For live trading
SOLANA_RPC_URL=https://your-rpc-endpoint
WALLET_1=<base58-private-key>
⚠️

Generate JWT_SECRET with: openssl rand -base64 32

Deploy

Railway auto-deploys on push to your main branch. You can also trigger manual deploys from the dashboard.

Verify deployment:

curl https://your-app.up.railway.app/api/v1/health
# Should return: {"status":"ok"}

Vercel Setup

Import Project

  1. Go to Vercel Dashboard (opens in a new tab)
  2. Click Add NewProject
  3. Import your Nexgent GitHub repository

Configure Build Settings

  • Framework Preset: Next.js
  • Root Directory: packages/frontend
  • Build Command: pnpm build
  • Output Directory: .next

Set Environment Variables

Add these environment variables:

# NextAuth.js
NEXTAUTH_URL=https://your-app.vercel.app
NEXTAUTH_SECRET=<generate-secure-secret>
 
# Backend API (your Railway URL)
NEXT_PUBLIC_API_URL=https://your-app.up.railway.app
⚠️

Generate NEXTAUTH_SECRET with: openssl rand -base64 32

Deploy

Click Deploy. Vercel will build and deploy your frontend.

Verify deployment:

Visit https://your-app.vercel.app - you should see the login page.


Update CORS Settings

After both services are deployed, update the backend CORS setting in Railway:

CORS_ORIGIN=https://your-app.vercel.app

Redeploy the backend service for changes to take effect.


Custom Domains

Vercel Custom Domain

  1. Go to your Vercel project → SettingsDomains
  2. Add your domain (e.g., app.yourdomain.com)
  3. Update DNS records as instructed
  4. Vercel automatically provisions SSL

Update environment variables:

NEXTAUTH_URL=https://app.yourdomain.com

Railway Custom Domain

  1. Go to your Railway service → SettingsNetworking
  2. Add custom domain (e.g., api.yourdomain.com)
  3. Update DNS records as instructed
  4. Railway automatically provisions SSL

Update environment variables:

# Railway backend
CORS_ORIGIN=https://app.yourdomain.com
 
# Vercel frontend
NEXT_PUBLIC_API_URL=https://api.yourdomain.com

Railway Configuration File

Nexgent includes a railway.json in the repository root:

{
  "$schema": "https://railway.app/railway.schema.json",
  "build": {
    "builder": "NIXPACKS",
    "buildCommand": "pnpm install && pnpm build:backend"
  },
  "deploy": {
    "startCommand": "pnpm --filter backend db:migrate:deploy && pnpm --filter backend start",
    "restartPolicyType": "ON_FAILURE",
    "restartPolicyMaxRetries": 10
  }
}

This configures automatic migrations on deploy and restart policies.


Environment Variable Reference

Railway Backend Variables

VariableRequiredDescription
DATABASE_URLYesPostgreSQL connection string (auto-injected)
REDIS_URLYesRedis connection string (auto-injected)
NODE_ENVYesSet to production
PORTYesServer port (usually 4000)
CORS_ORIGINYesFrontend URL for CORS
JWT_SECRETYesSecret for JWT signing
JUPITER_API_KEYYesJupiter API key
SOLANA_RPC_URLFor liveSolana RPC endpoint
WALLET_1For liveTrading wallet private key

Vercel Frontend Variables

VariableRequiredDescription
NEXTAUTH_URLYesFrontend URL
NEXTAUTH_SECRETYesSecret for NextAuth.js
NEXT_PUBLIC_API_URLYesBackend API URL

Monitoring

Railway Logs

  1. Go to your Railway project
  2. Click on the backend service
  3. Select DeploymentsView Logs

Vercel Logs

  1. Go to your Vercel project
  2. Select Deployments → click a deployment
  3. View Functions logs

Health Checks

Set up monitoring with services like:

Monitor these endpoints:

  • Backend: https://api.yourdomain.com/api/v1/health
  • Backend: https://api.yourdomain.com/api/v1/ready

Scaling

Railway Scaling

Railway automatically scales based on usage. For higher traffic:

  1. Go to SettingsService
  2. Adjust Memory and CPU limits
  3. Consider Railway Pro for higher limits

Vercel Scaling

Vercel's serverless functions scale automatically. The free tier is sufficient for most use cases.


Cost Estimation

Free Tier Limits

ServiceFree Tier
Vercel100GB bandwidth, unlimited deployments
Railway$5 credit/month, shared resources

Troubleshooting

Frontend Can't Connect to Backend

  1. Check CORS: Verify CORS_ORIGIN includes your Vercel domain
  2. Check URL: Verify NEXT_PUBLIC_API_URL is correct
  3. Check deployment: Ensure backend is deployed and healthy

Database Connection Errors

  1. Check Railway logs for connection errors
  2. Verify DATABASE_URL is set correctly
  3. Check PostgreSQL service is running in Railway

WebSocket Not Connecting

  1. WebSocket uses the same URL as API
  2. Verify backend is publicly accessible
  3. Check browser console for connection errors

Build Failures

Railway:

# Check build logs in Railway dashboard
# Common issues: missing dependencies, TypeScript errors

Vercel:

# Check build logs in Vercel dashboard
# Ensure NEXT_PUBLIC_* variables are set