Spaces:
Sleeping

microfunnel-api / DEPLOYMENT.md
MicroFunnel
Production-ready: Refactored codebase with Railway + Vercel config
cd61bf7
|
Raw History Blame Contribute Delete
5.2 kB

πŸ¦„ PRODUCTION DEPLOYMENT GUIDE

🎯 Stack Overview

  • Backend: Railway (Python/FastAPI)
  • Frontend: Vercel (Next.js)
  • Database: Supabase (PostgreSQL)
  • Code: GitHub

πŸ“‹ STEP 1: Push Code to GitHub

Create GitHub Repository:

# In your project root
git init
git add .
git commit -m "Initial commit - MicroFunnel AI Platform"

# Create repo on GitHub, then:
git remote add origin https://github.com/YOUR_USERNAME/microfunnel.git
git branch -M main
git push -u origin main

πŸ“‹ STEP 2: Deploy Backend to Railway

2.1. Create Railway Project:

  1. Go to https://railway.app
  2. Sign up with GitHub
  3. Click New Project β†’ Deploy from GitHub repo
  4. Select your microfunnel repository
  5. Railway will auto-detect Python project

2.2. Configure Environment Variables:

Railway Dashboard β†’ Your Project β†’ Variables β†’ Add these:

# Database (Supabase)
DATABASE_URL=postgresql://postgres.PROJECT_ID:PASSWORD@aws-0-eu-central-1.pooler.supabase.com:6543/postgres

# Supabase
SUPABASE_URL=https://kmdhrrkfzonbncxvjhjj.supabase.co
SUPABASE_KEY=<your-anon-key>
SUPABASE_SERVICE_KEY=<your-service-key>

# AI
GEMINI_API_KEY=<your-gemini-key>

# JWT Secret (generate new: openssl rand -hex 32)
SECRET_KEY=<generate-new-32-char-secret>
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=43200

# Environment
ENVIRONMENT=production
DEBUG=false

# CORS (will update after Vercel deployment)
ALLOWED_ORIGINS=https://your-app.vercel.app
FRONTEND_URL=https://your-app.vercel.app

# Optional: Redis (Railway Add-on)
# REDIS_URL=<auto-provided-by-railway>

2.3. Get Railway Domain:

After deployment, Railway will provide a domain like:

https://microfunnel-production.up.railway.app

Save this URL! You'll need it for Vercel.


πŸ“‹ STEP 3: Deploy Frontend to Vercel

3.1. Import Project:

  1. Go to https://vercel.com
  2. Sign up with GitHub
  3. Click Add New β†’ Project
  4. Import your microfunnel repository
  5. Vercel auto-detects Next.js

3.2. Configure Build Settings:

  • Framework Preset: Next.js
  • Root Directory: frontend
  • Build Command: npm run build
  • Output Directory: .next

3.3. Add Environment Variables:

Vercel Dashboard β†’ Settings β†’ Environment Variables:

# Backend API (Railway domain from Step 2.3)
NEXT_PUBLIC_API_URL=https://microfunnel-production.up.railway.app

# Webhook URL (same as backend)
NEXT_PUBLIC_WEBHOOK_URL=https://microfunnel-production.up.railway.app

# Supabase
NEXT_PUBLIC_SUPABASE_URL=https://kmdhrrkfzonbncxvjhjj.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=<your-anon-key>

3.4. Deploy:

Click Deploy β†’ Wait 2-3 minutes

Vercel will provide a domain like:

https://microfunnel.vercel.app

πŸ“‹ STEP 4: Update CORS in Railway

Now that you have Vercel domain, update Railway:

Railway β†’ Variables β†’ Update:

ALLOWED_ORIGINS=https://microfunnel.vercel.app,https://www.microfunnel.vercel.app
FRONTEND_URL=https://microfunnel.vercel.app

Click Redeploy (Railway auto-redeploys on variable change)


πŸ“‹ STEP 5: Run Database Migrations

Via Railway CLI:

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

# Login
railway login

# Link to your project
railway link

# Run migrations
railway run alembic upgrade head

Or manually via Supabase SQL Editor:

Run all migrations from backend/alembic/versions/*.py


πŸ“‹ STEP 6: Test Deployment

Backend Health Check:

curl https://microfunnel-production.up.railway.app/health

Expected:

{
  "status": "healthy",
  "database": "connected",
  "ai_engine": "ready"
}

Frontend:

Open: https://microfunnel.vercel.app

  • Login should work
  • Dashboard should load
  • Chats should connect

Webhooks (WhatsApp/Instagram):

Webhook URLs will now use Railway domain:

https://microfunnel-production.up.railway.app/api/v1/webhook/meta/whatsapp/{tenant_id}

Update these in Meta Developers β†’ Webhooks


πŸ”„ Continuous Deployment

Auto-deploy on Git Push:

# Make changes
git add .
git commit -m "Feature: Add X"
git push

# Railway auto-deploys backend
# Vercel auto-deploys frontend

πŸ’° Pricing Estimates

  • Railway: $5-20/month (based on usage)
  • Vercel: Free tier (Pro: $20/month)
  • Supabase: Free tier (Pro: $25/month)

Total: ~$0-50/month depending on traffic


πŸ› Troubleshooting

Railway Build Fails:

  • Check logs: Railway β†’ Deployments β†’ View Logs
  • Common issue: Missing env vars

Vercel Build Fails:

  • Check build logs in Vercel dashboard
  • Common issue: NEXT_PUBLIC_* vars not set

CORS Errors:

  • Verify ALLOWED_ORIGINS in Railway includes your Vercel domain
  • Check browser console for exact error

Database Connection Fails:

  • Verify DATABASE_URL in Railway
  • Check Supabase is not paused (free tier pauses after 7 days inactivity)

πŸŽ‰ You're Live!

Frontend: https://microfunnel.vercel.app Backend: https://microfunnel-production.up.railway.app Database: Supabase (always-on)

No more ngrok! Professional infrastructure! πŸ¦„