Deployment Guide

Deployment & Configuration

Complete guide for deploying ExportReady-Battery to production. Covers environment configuration, build commands, and hosting options.

Quick Deploy Checklist

Set up PostgreSQL database (Supabase recommended)
Configure environment variables
Run database migrations
Build frontend production bundle
Build backend binary
Configure reverse proxy (Nginx/Caddy)
Set up SSL certificates
Configure domain DNS

Environment Variables

Backend (.env)

DATABASE_URLRequired

PostgreSQL connection string. Use sslmode=require for production.

postgresql://user:pass@host:5432/database?sslmode=require
JWT_SECRETRequired

Secret key for signing JWT tokens. Use a cryptographically random string.

your-secure-random-secret-key-at-least-32-chars
PORT

Server port. Defaults to 8080 if not specified.

8080
FRONTEND_URLRequired

Frontend URL for CORS configuration.

https://app.exportready.com
QR_BASE_URLRequired

Base URL for QR code links. Points to public passport pages.

https://app.exportready.com
RAZORPAY_KEY_ID

Razorpay API key ID for payment processing.

rzp_live_xxxxxxxxxxxxx
RAZORPAY_KEY_SECRET

Razorpay API secret key.

xxxxxxxxxxxxxxxxxxxxx
.env
bash
# Backend .env example
DATABASE_URL=postgresql://postgres:password@db.supabase.co:5432/postgres
JWT_SECRET=your-super-secure-random-string-here
PORT=8080
FRONTEND_URL=https://app.exportready.com
QR_BASE_URL=https://app.exportready.com
RAZORPAY_KEY_ID=rzp_live_xxxx
RAZORPAY_KEY_SECRET=xxxx

Frontend (.env.local)

NEXT_PUBLIC_API_URLRequired

Backend API base URL.

https://api.exportready.com/api/v1
NEXT_PUBLIC_RAZORPAY_KEY_ID

Razorpay public key for checkout.

rzp_live_xxxxxxxxxxxxx
.env.local
bash
# Frontend .env.local example
NEXT_PUBLIC_API_URL=https://api.exportready.com/api/v1
NEXT_PUBLIC_RAZORPAY_KEY_ID=rzp_live_xxxx

Build Commands

Backend (Go)

Install dependencies:

go mod download

Run development server:

make run

Build production binary:

make build

Run migrations:

make migrate-up

Run tests:

make test

Frontend (Next.js)

Install dependencies:

npm install

Run development server:

npm run dev

Build production bundle:

npm run build

Start production server:

npm run start

Run linting:

npm run lint

Makefile Commands Reference

Makefile
makefile
# Development
make run              # Start backend server
make dev              # Start with hot reload (requires air)

# Build
make build            # Build binary to ./bin/server

# Testing
make test             # Run all tests
make test-coverage    # Run tests with coverage

# Database Migrations
make migrate-up       # Run pending migrations
make migrate-down     # Rollback last migration
make migrate-reset    # Rollback ALL migrations
make migrate-version  # Show current version
make migrate-create   # Create new migration file

# Utilities
make clean            # Remove build artifacts
make lint             # Run Go linter

Database Setup

Option 1: Supabase (Recommended)

  1. 1.Create a new project at supabase.com
  2. 2.Copy the connection string from Settings → Database
  3. 3.Set DATABASE_URL in your .env file
  4. 4.Run make migrate-up to create tables

Option 2: Local PostgreSQL

# Create database
createdb battery_db

# Set connection string
export DATABASE_URL="postgresql://postgres:password@localhost:5432/battery_db"

# Run migrations
cd backend
make migrate-up

Production Deployment

Railway

Deploy both frontend and backend to Railway with auto-scaling.

# Install Railway CLI
npm i -g @railway/cli

# Login
railway login

# Deploy backend
cd backend
railway up

# Deploy frontend
cd ../frontend
railway up

Vercel + Fly.io

Frontend on Vercel, backend on Fly.io.

# Deploy frontend to Vercel
cd frontend
vercel

# Deploy backend to Fly.io
cd ../backend
fly launch
fly deploy

Nginx Reverse Proxy

nginx.conf
nginx
# /etc/nginx/sites-available/exportready
server {
    listen 443 ssl http2;
    server_name app.exportready.com;

    ssl_certificate /etc/letsencrypt/live/app.exportready.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/app.exportready.com/privkey.pem;

    # Frontend
    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    # Backend API
    location /api/ {
        proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
    }
}

Health Check Endpoints

Use these endpoints to verify your deployment is working:

Backend Health
GET /api/v1/health
Frontend
GET /