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
- GitHub account (for deployment integration)
- Vercel account (sign up (opens in a new tab))
- Railway account (sign up (opens in a new tab))
- Jupiter API key (get one (opens in a new tab))
Railway Setup
Create Railway Project
- Go to Railway Dashboard (opens in a new tab)
- Click New Project
- Select Deploy from GitHub repo
- Connect your GitHub account and select your Nexgent fork
Add PostgreSQL
- In your Railway project, click New
- Select Database → Add PostgreSQL
- Railway automatically provisions the database
- Note: Connection string is auto-injected as
DATABASE_URL
Add Redis
- Click New again
- Select Database → Add Redis
- Railway provisions Redis
- 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
- Go to Vercel Dashboard (opens in a new tab)
- Click Add New → Project
- 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.appGenerate 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.appRedeploy the backend service for changes to take effect.
Custom Domains
Vercel Custom Domain
- Go to your Vercel project → Settings → Domains
- Add your domain (e.g.,
app.yourdomain.com) - Update DNS records as instructed
- Vercel automatically provisions SSL
Update environment variables:
NEXTAUTH_URL=https://app.yourdomain.comRailway Custom Domain
- Go to your Railway service → Settings → Networking
- Add custom domain (e.g.,
api.yourdomain.com) - Update DNS records as instructed
- Railway automatically provisions SSL
Update environment variables:
# Railway backend
CORS_ORIGIN=https://app.yourdomain.com
# Vercel frontend
NEXT_PUBLIC_API_URL=https://api.yourdomain.comRailway 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
| Variable | Required | Description |
|---|---|---|
DATABASE_URL | Yes | PostgreSQL connection string (auto-injected) |
REDIS_URL | Yes | Redis connection string (auto-injected) |
NODE_ENV | Yes | Set to production |
PORT | Yes | Server port (usually 4000) |
CORS_ORIGIN | Yes | Frontend URL for CORS |
JWT_SECRET | Yes | Secret for JWT signing |
JUPITER_API_KEY | Yes | Jupiter API key |
SOLANA_RPC_URL | For live | Solana RPC endpoint |
WALLET_1 | For live | Trading wallet private key |
Vercel Frontend Variables
| Variable | Required | Description |
|---|---|---|
NEXTAUTH_URL | Yes | Frontend URL |
NEXTAUTH_SECRET | Yes | Secret for NextAuth.js |
NEXT_PUBLIC_API_URL | Yes | Backend API URL |
Monitoring
Railway Logs
- Go to your Railway project
- Click on the backend service
- Select Deployments → View Logs
Vercel Logs
- Go to your Vercel project
- Select Deployments → click a deployment
- 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:
- Go to Settings → Service
- Adjust Memory and CPU limits
- 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
| Service | Free Tier |
|---|---|
| Vercel | 100GB bandwidth, unlimited deployments |
| Railway | $5 credit/month, shared resources |
Troubleshooting
Frontend Can't Connect to Backend
- Check CORS: Verify
CORS_ORIGINincludes your Vercel domain - Check URL: Verify
NEXT_PUBLIC_API_URLis correct - Check deployment: Ensure backend is deployed and healthy
Database Connection Errors
- Check Railway logs for connection errors
- Verify
DATABASE_URLis set correctly - Check PostgreSQL service is running in Railway
WebSocket Not Connecting
- WebSocket uses the same URL as API
- Verify backend is publicly accessible
- Check browser console for connection errors
Build Failures
Railway:
# Check build logs in Railway dashboard
# Common issues: missing dependencies, TypeScript errorsVercel:
# Check build logs in Vercel dashboard
# Ensure NEXT_PUBLIC_* variables are set