# 🚀 LuckyChit Deployment Guide Complete production deployment guide. --- ## 📍 Production Setup **Server IP**: 192.168.8.148 **Domain**: chitfund.deepteklabs.com **User**: luckychit **Project**: /home/luckychit/apps/chitfund **Branch**: prodnew --- ## 🏗️ Architecture ``` Internet ↓ Cloudflare (SSL, CDN) ↓ Nginx Proxy (LXC 1) ↓ Application Server (LXC 2: 192.168.8.148) ├── PM2: luckychit-api (Port 3000) ├── PM2: luckychit-frontend (Port 8080) └── PostgreSQL (Port 5432) ``` --- ## ⚡ Quick Deploy ```bash ssh luckychit@192.168.8.148 cd /home/luckychit/apps/chitfund ./scripts/deploy.sh ``` ### Deploy Options: ```bash ./scripts/deploy.sh # Deploy both backend + frontend ./scripts/deploy.sh backend # Backend only ./scripts/deploy.sh frontend # Frontend only ``` --- ## 🔧 Manual Deployment ### Backend ```bash cd /home/luckychit/apps/chitfund git pull origin prodnew cd backend npm install pm2 restart luckychit-api pm2 logs luckychit-api --lines 20 ``` ### Frontend ```bash cd /home/luckychit/apps/chitfund git pull origin prodnew cd luckychit flutter pub get flutter build web --release --pwa-strategy=none pm2 restart luckychit-frontend pm2 logs luckychit-frontend --lines 20 ``` --- ## 📊 PM2 Commands ```bash pm2 status # Show all processes pm2 logs # Live logs pm2 logs luckychit-api # Backend logs pm2 logs luckychit-frontend # Frontend logs pm2 restart all # Restart everything pm2 monit # Real-time monitoring ``` --- ## 🗑️ Clear Caches (After Deployment) ### 1. Server Cache ```bash pm2 restart all ``` ### 2. Nginx Proxy Cache (if using separate LXC) ```bash ssh root@ sudo rm -rf /var/cache/nginx/* sudo systemctl reload nginx ``` ### 3. Cloudflare Cache - Login to Cloudflare dashboard - Caching → Purge Everything ### 4. Browser Cache ``` Hard Refresh: Ctrl + Shift + R (Windows) or Cmd + Shift + R (Mac) Or test in Incognito: Ctrl + Shift + N ``` --- ## 🔥 Emergency: Complete Cache Clear ```bash cd /home/luckychit/apps/chitfund ./scripts/deploy.sh --force ``` This will: 1. Clean all build caches 2. Rebuild from scratch 3. Restart all services 4. Clear nginx cache (if configured) --- ## 🗄️ Database Backup ### Manual Backup ```bash ./scripts/backup-db.sh ``` ### Automated Daily Backup ```bash # Add to crontab crontab -e # Add: 0 2 * * * /home/luckychit/apps/chitfund/scripts/backup-db.sh ``` ### Restore from Backup ```bash ./scripts/restore-db.sh ``` --- ## 🔍 Initial Server Setup (One-Time) ### 1. Install Dependencies ```bash # Node.js, Flutter, PM2, PostgreSQL # See PM2_PRODUCTION_GUIDE.md for details ``` ### 2. Setup PM2 ```bash cd /home/luckychit/apps/chitfund/backend pm2 start src/server.js --name luckychit-api cd ../luckychit pm2 serve build/web 8080 --name luckychit-frontend --spa pm2 save pm2 startup systemd -u luckychit --hp /home/luckychit ``` ### 3. Configure Auto-start ```bash pm2 startup # Run the command it outputs pm2 save ``` --- ## 🔐 Security Checklist - [ ] Firewall configured (ports 3000, 8080) - [ ] Strong database password - [ ] JWT secret set (32+ characters) - [ ] SSL/TLS enabled (via Cloudflare) - [ ] Database backups automated - [ ] PM2 auto-start configured --- ## 📋 Pre-Deployment Checklist - [ ] Changes tested locally - [ ] Committed to git - [ ] Pushed to `prodnew` branch - [ ] Database migrations ready (if any) - [ ] Backup recent (< 24 hours) --- ## 📋 Post-Deployment Checklist - [ ] `pm2 status` shows all online - [ ] No errors in `pm2 logs` - [ ] Backend health check works: `curl http://localhost:3000/health` - [ ] Frontend loads: `curl http://localhost:8080` - [ ] Domain works: https://chitfund.deepteklabs.com - [ ] Login works - [ ] Clear browser cache tested --- ## 🆘 Troubleshooting See [TROUBLESHOOTING.md](TROUBLESHOOTING.md) for common issues and fixes. Quick diagnostics: ```bash ./scripts/diagnose.sh ``` --- ## 📞 Emergency Contacts **If everything is broken:** ```bash ./scripts/diagnose.sh # See what's wrong ./scripts/fix-502.sh # Fix 502 errors pm2 restart all # Restart everything ``` --- ## 📚 Additional Resources - **PM2 Production Guide**: [PM2_PRODUCTION_GUIDE.md](PM2_PRODUCTION_GUIDE.md) - **Quick Reference**: [QUICK_REFERENCE.md](QUICK_REFERENCE.md) - **Backend API Docs**: [backend/API_DOCUMENTATION.md](backend/API_DOCUMENTATION.md) --- **Last Updated**: November 2025