Spaces:
Build error
Build error
File size: 4,807 Bytes
a282d4b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | # BankBot AI β Deployment Guide
## Option 1: Local Development (Fastest)
```bash
# 1. Clone and setup backend
cd backend
python -m venv venv
venv\Scripts\activate # Windows
pip install -r requirements.txt
copy .env.example .env # Edit with your API keys
# 2. Seed demo data
python app/scripts/seed_demo.py
# 3. Start backend
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
# 4. In a new terminal β setup frontend
cd frontend
npm install --legacy-peer-deps
npm run dev
# Access: http://localhost:3000
# Login: alex@bankbot.dev / BankBot2026!
# API Docs: http://localhost:8000/docs
# Metrics: http://localhost:8000/api/metrics
```
---
## Option 2: Docker Compose (Recommended for Demo)
```bash
# 1. Configure environment
cp .env.example .env
# Edit .env β set OPENAI_API_KEY or GROQ_API_KEY
# 2. Start all services (PostgreSQL + Redis + Backend + Frontend)
docker compose up -d
# 3. Seed demo data
docker compose exec backend python app/scripts/seed_demo.py
# 4. Access
# Frontend: http://localhost:3000
# Backend: http://localhost:8000
# API Docs: http://localhost:8000/docs
# 5. View logs
docker compose logs -f backend
docker compose logs -f frontend
# 6. Stop
docker compose down
```
### With Nginx (Production mode)
```bash
docker compose --profile production up -d
# Access via http://localhost (port 80)
```
---
## Option 3: Cloud Deployment
### Frontend β Vercel
```bash
cd frontend
# Install Vercel CLI
npm i -g vercel
# Deploy
vercel --prod
# Set environment variable in Vercel dashboard:
# NEXT_PUBLIC_API_URL = https://your-backend.onrender.com
```
### Backend β Render
1. Push code to GitHub
2. Go to https://render.com β New β Web Service
3. Connect your GitHub repo
4. Render auto-detects `render.yaml` in `backend/`
5. Set environment variables in Render dashboard:
- `OPENAI_API_KEY` or `GROQ_API_KEY`
- `JWT_SECRET_KEY` (generate a strong random string)
6. Render provisions PostgreSQL and Redis automatically
### Backend β Railway
```bash
# Install Railway CLI
npm i -g @railway/cli
railway login
cd backend
railway init
railway up
# Add PostgreSQL and Redis plugins in Railway dashboard
# Set environment variables in Railway dashboard
```
### Backend β DigitalOcean App Platform
1. Create new App β GitHub repo
2. Set source directory: `backend`
3. Build command: `pip install -r requirements.txt`
4. Run command: `uvicorn app.main:app --host 0.0.0.0 --port $PORT`
5. Add PostgreSQL and Redis managed databases
6. Set environment variables
---
## Environment Variables Reference
### Backend (Required for Production)
```env
# REQUIRED
JWT_SECRET_KEY=<generate with: python -c "import secrets; print(secrets.token_hex(32))">
DATABASE_URL=postgresql://user:pass@host:5432/bankbot
# REQUIRED (at least one AI key)
OPENAI_API_KEY=sk-...
# OR
GROQ_API_KEY=gsk_...
# RECOMMENDED
REDIS_URL=redis://host:6379/0
BACKEND_CORS_ORIGINS=["https://your-frontend.vercel.app"]
ACCESS_TOKEN_EXPIRE_MINUTES=60
```
### Frontend (Required for Production)
```env
NEXT_PUBLIC_API_URL=https://your-backend.onrender.com
```
---
## Post-Deployment Checklist
```
[ ] Backend health check passes: GET /health β {"status": "healthy"}
[ ] API status shows correct backend: GET /api/status
[ ] Demo account works: POST /api/auth/login
[ ] Dashboard loads: GET /api/dashboard/overview
[ ] WebSocket connects: ws://your-backend/api/ai/chat/ws
[ ] Metrics endpoint works: GET /api/metrics
[ ] Frontend loads at production URL
[ ] CORS allows frontend origin
[ ] JWT tokens work end-to-end
[ ] Seed demo data: python app/scripts/seed_demo.py
```
---
## Troubleshooting
### Backend won't start
```bash
# Check Python version (needs 3.11+)
python --version
# Check if port is in use
netstat -ano | findstr :8000
# Check logs
uvicorn app.main:app --port 8000 --log-level debug
```
### Frontend can't reach backend
```bash
# Check NEXT_PUBLIC_API_URL in .env.local
cat frontend/.env.local
# Test backend directly
curl http://localhost:8000/health
# Check CORS β backend must allow frontend origin
# Edit BACKEND_CORS_ORIGINS in .env
```
### WebSocket not connecting
```bash
# Check browser console for WS errors
# Verify backend is running on correct port
# Check Nginx config if using reverse proxy (ws:// upgrade headers)
```
### AI responses not working
```bash
# Check which backend is active
curl http://localhost:8000/api/status
# If ai_available: false, check your API keys
# For Ollama: ensure it's running with: ollama serve
# For Groq: verify key at https://console.groq.com
```
### Database issues
```bash
# Force SQLite (no PostgreSQL needed)
# In .env: USE_SQLITE=true
# Re-seed database
python app/scripts/seed_demo.py
# Check DB type
curl http://localhost:8000/api/status | python -m json.tool
```
|