# 🦄 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: ```bash # 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: ```env # 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= SUPABASE_SERVICE_KEY= # AI GEMINI_API_KEY= # JWT Secret (generate new: openssl rand -hex 32) SECRET_KEY= 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= ``` ### 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: ```env # 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= ``` ### 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: ```env 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: ```bash # 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: ```bash curl https://microfunnel-production.up.railway.app/health ``` Expected: ```json { "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: ```bash # 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! 🦄**