# 📚 LuckyChit Deployment Documentation Complete guide to deploying and updating your LuckyChit application. --- ## 📖 Available Guides ### 🎯 Quick Start - **`PRODUCTION_UPDATE_GUIDE.md`** ⭐ **START HERE** - Quick reference for updates - **`PM2_QUICK_START.md`** - Get backend running in 5 minutes ### 📘 Detailed Guides - **`PM2_PRODUCTION_GUIDE.md`** - Complete PM2 backend deployment - **`FLUTTER_DEPLOYMENT_GUIDE.md`** - Complete Flutter frontend deployment - **`DEPLOYMENT_TROUBLESHOOTING.md`** - Common issues and solutions --- ## 🚀 Quick Commands ### Update Backend ```bash # On production server cd backend git pull origin main npm install pm2 reload luckychit-api ``` ### Update Frontend (Web) ```bash # On your machine cd luckychit ./deploy-web.sh # Then upload build/web/* to server ``` --- ## 🛠️ Available Scripts ### Backend Scripts (`backend/`) - **`deploy.sh`** - Full backend deployment - **`fix-bcrypt.sh`** - Fix native module issues - **`ecosystem.config.js`** - PM2 configuration ### Frontend Scripts (`luckychit/`) - **`deploy-web.sh`** - Build Flutter web (local) - **`deploy-web-auto.sh`** - Build & upload to server - **`build-android.sh`** - Build Android APK/AAB - **`web-server.js`** - Express server for Flutter web - **`ecosystem.config.js`** - PM2 configuration for web --- ## 📋 Common Scenarios ### Scenario 1: UI Changes Only ```bash cd luckychit flutter build web --release # Upload to server ``` **Time:** 2-3 minutes | **Downtime:** None ### Scenario 2: Backend Changes Only ```bash cd backend pm2 reload luckychit-api ``` **Time:** 30 seconds | **Downtime:** None ### Scenario 3: Both UI and Backend 1. Update backend first 2. Then update frontend **Time:** 5 minutes | **Downtime:** None ### Scenario 4: Database Changes 1. Backup database first 2. Update backend with migrations 3. Test thoroughly **Time:** 10-15 minutes | **Downtime:** Possible --- ## 🎯 First Time Setup ### Backend ```bash # Install PM2 npm install -g pm2 # Deploy backend cd backend ./deploy.sh production pm2 startup pm2 save ``` ### Frontend Web ```bash # Build cd luckychit flutter build web --release # Deploy to nginx sudo cp -r build/web/* /var/www/luckychit/ # Or use PM2 npm install express pm2 start ecosystem.config.js --env production ``` --- ## ⚠️ Common Issues ### Backend: bcrypt Error ```bash cd backend ./fix-bcrypt.sh ``` ### Frontend: Old UI Still Showing - Hard refresh browser: Ctrl+Shift+R - Clear browser cache - Check files updated on server ### PM2 Not Starting ```bash pm2 logs luckychit-api --lines 100 ``` --- ## 📞 Getting Help 1. Check relevant guide in the list above 2. Check `DEPLOYMENT_TROUBLESHOOTING.md` 3. View logs: `pm2 logs` 4. Check server logs: `/var/log/nginx/error.log` --- ## 📁 File Structure ``` chitfund/ ├── backend/ │ ├── deploy.sh # Backend deployment │ ├── fix-bcrypt.sh # Fix bcrypt issues │ ├── ecosystem.config.js # PM2 config │ └── server.js # Main server file │ ├── luckychit/ │ ├── deploy-web.sh # Build web (local) │ ├── deploy-web-auto.sh # Build & upload │ ├── build-android.sh # Build Android │ ├── web-server.js # Express server │ ├── ecosystem.config.js # PM2 web config │ └── build/web/ # Build output │ ├── PM2_PRODUCTION_GUIDE.md # Backend guide ├── PM2_QUICK_START.md # Quick backend start ├── FLUTTER_DEPLOYMENT_GUIDE.md # Frontend guide ├── PRODUCTION_UPDATE_GUIDE.md # Update guide ⭐ ├── DEPLOYMENT_TROUBLESHOOTING.md # Troubleshooting └── DEPLOYMENT_README.md # This file ``` --- ## ✅ Deployment Checklist ### Pre-Deployment - [ ] Code tested locally - [ ] Version updated (if applicable) - [ ] Database backup (if DB changes) - [ ] Environment variables checked ### Deployment - [ ] Backend updated (if needed) - [ ] Frontend rebuilt (if needed) - [ ] Files uploaded to server - [ ] Services restarted ### Post-Deployment - [ ] App loads successfully - [ ] No errors in logs - [ ] Critical features tested - [ ] Monitoring for 15 minutes --- ## 🎓 Learn More ### PM2 (Backend) - Official Docs: https://pm2.keymetrics.io/docs/ - Commands: `PM2_PRODUCTION_GUIDE.md` → PM2 Commands section ### Flutter (Frontend) - Official Docs: https://docs.flutter.dev/deployment - Web Deploy: https://docs.flutter.dev/deployment/web ### nginx (Web Server) - Official Docs: https://nginx.org/en/docs/ - Configuration: `FLUTTER_DEPLOYMENT_GUIDE.md` → nginx section --- ## 🔐 Security Notes ### Never Commit - `.env` files (backend credentials) - `node_modules/` (backend) - `build/` directories (frontend) - `*.jks`, `*.keystore` (Android signing keys) - Database backups ### Always Use - Strong passwords in production - SSL certificates (HTTPS) - Firewall rules - Regular backups - Monitoring --- ## 📊 Version History Keep track of your deployments: ```bash # Add to deployment.log echo "$(date): v1.0.2 - Fixed payment UI bug" >> deployment.log ``` --- ## 💡 Pro Tips 1. **Test in staging first** if possible 2. **Deploy during low traffic** hours 3. **Keep deployments small** (easier to rollback) 4. **Monitor after deployment** for 15+ minutes 5. **Document changes** in deployment.log 6. **Have a rollback plan** ready 7. **Communicate with users** about updates --- ## 🆘 Emergency Contacts **For Production Issues:** - PM2 Logs: `pm2 logs luckychit-api` - nginx Logs: `sudo tail -f /var/log/nginx/error.log` - Database Logs: `sudo tail -f /var/log/postgresql/postgresql-*.log` **Rollback:** ```bash git checkout pm2 reload luckychit-api ``` --- **🎉 Your deployment documentation is complete and production-ready!** _Last updated: November 2025_