Deployment Guide
Learn how to deploy Coach to production environments
Frontend Deployment
The Coach frontend is built with Next.js 14 and can be deployed to various hosting platforms.
Vercel (Recommended)
As Next.js is developed by Vercel, deploying to their platform offers the best performance and developer experience.
# Install Vercel CLI
npm install -g vercel
# Login to Vercel
vercel login
# Deploy from your project directory
cd frontend
vercel
Environment Variables
Set these in the Vercel dashboard or using the CLI:
NEXT_PUBLIC_API_URL=https://your-backend-url.com/api
NEXT_PUBLIC_GITHUB_CLIENT_ID=your_github_client_id
Netlify
Netlify offers great integration with GitHub and continuous deployment.
# netlify.toml
[build]
command = "npm run build"
publish = ".next"
[[plugins]]
package = "@netlify/plugin-nextjs"
[build.environment]
NEXT_PUBLIC_API_URL = "https://your-backend-url.com/api"
Self-Hosting with Docker
For complete control over your deployment, use Docker:
# Dockerfile
FROM node:18-alpine AS base
# Install dependencies
FROM base AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
# Build the app
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
# Production image
FROM base AS runner
WORKDIR /app
ENV NODE_ENV production
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
EXPOSE 3000
CMD ["node", "server.js"]
# Build and run the Docker container
docker build -t coach-frontend .
docker run -p 3000:3000 coach-frontend
Backend Deployment
The Coach FastAPI backend can be deployed on various platforms that support Python applications.
Render
Render provides simple Python application hosting with automatic deployment from GitHub.
# render.yaml
services:
- type: web
name: coach-api
env: python
buildCommand: pip install -r requirements.txt
startCommand: uvicorn app.main:app --host 0.0.0.0 --port $PORT
envVars:
- key: GITHUB_CLIENT_ID
sync: false
- key: GITHUB_CLIENT_SECRET
sync: false
- key: GEMINI_API_KEY
sync: false
- key: DATABASE_URL
sync: false
Fly.io
Fly.io offers global deployment with servers close to your users.
# fly.toml
app = "coach-api"
primary_region = "iad"
[build]
builder = "paketobuildpacks/builder:base"
[env]
PORT = "8080"
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
# Deploy to Fly.io
fly auth login
fly launch
fly secrets set GITHUB_CLIENT_ID=your_github_client_id
fly secrets set GITHUB_CLIENT_SECRET=your_github_client_secret
fly secrets set GEMINI_API_KEY=your_gemini_api_key
fly deploy
Docker + AWS/GCP/Azure
For maximum scalability, deploy using containers on major cloud providers.
# Dockerfile for FastAPI backend
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
Docker Compose for Local Testing
# docker-compose.yml
version: '3.8'
services:
api:
build: ./backend
ports:
- "8000:8000"
environment:
- GITHUB_CLIENT_ID=your_github_client_id
- GITHUB_CLIENT_SECRET=your_github_client_secret
- GEMINI_API_KEY=your_gemini_api_key
- DATABASE_URL=postgresql://postgres:postgres@db:5432/coach
depends_on:
- db
db:
image: postgres:15
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
- POSTGRES_DB=coach
volumes:
postgres_data:
Database Setup
Coach requires a database to store scan results and user data.
PostgreSQL (Recommended)
We recommend using PostgreSQL for production environments.
-- Initial database setup
CREATE DATABASE coach;
CREATE USER coach_user WITH PASSWORD 'secure_password';
GRANT ALL PRIVILEGES ON DATABASE coach TO coach_user;
Database Migration
Coach uses Alembic for database migrations:
# Run migrations
cd backend
export DATABASE_URL=postgresql://coach_user:secure_password@localhost/coach
alembic upgrade head
CORS and Security
Ensure proper CORS settings to allow communication between frontend and backend:
# FastAPI CORS configuration
from fastapi.middleware.cors import CORSMiddleware
app.add_middleware(
CORSMiddleware,
allow_origins=["https://your-frontend-domain.com"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
Security Note
Always use HTTPS in production environments, and ensure your API keys and secrets are properly secured using environment variables or a secrets management system.