Added comprehensive migration documentation and configuration files for restructuring the application to split frontend/backend: New Documentation: - MIGRATION_GUIDE.md: Complete step-by-step migration instructions - MIGRATION_SUMMARY.md: Quick reference guide for deployment - MIGRATION_CHECKLIST.md: Printable checklist for migration day - DEPLOYMENT_RESTRUCTURE.md: Architecture overview and benefits New Configuration Files: - run_api_server.py: Production WSGI server wrapper using Waitress - ai_qc.service: Systemd service configuration for backend - apache_config.conf: Apache virtual host configuration template Updated Files: - requirements.txt: Added waitress>=2.1.2 for production WSGI server - README.md: Added deployment documentation section Migration Overview: - Split current monolithic structure into separate frontend/backend - Move backend to /opt/ai_qc/ (following server standards) - Keep frontend in /var/www/html/ai_qc/ (single index.html) - Use Apache reverse proxy to connect frontend to backend API - Implement systemd service for reliable backend process management Benefits: - Improved security (backend code not in web root) - Better separation of concerns - Follows industry best practices - Matches existing server app patterns (/opt/veo3, /opt/voice2text) - Easier independent updates of frontend/backend 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
5.6 KiB
5.6 KiB
Visual AI QC Migration - Quick Summary
What You Need to Know
Why Split Frontend/Backend?
Your server already follows this pattern with other apps:
/opt/veo3/backend/- Backend in opt/opt/voice2text/- Backend in opt/opt/justeight/- Backend in opt
This structure provides:
- ✅ Better Security - Backend code not in web root
- ✅ Cleaner Separation - Frontend and backend updates independent
- ✅ Standard Practice - Industry standard for web applications
- ✅ Better Permissions - Granular access control
Current vs. New Structure
Current:
/var/www/html/ai_qc/ ← Everything here
├── web_ui.html (frontend)
├── api_server.py (backend)
├── visual_qc_apps/ (backend)
└── ... (all files mixed together)
After Migration:
/var/www/html/ai_qc/ ← Frontend only
└── index.html (renamed from web_ui.html)
/opt/ai_qc/ ← Backend only
├── api_server.py
├── run_api_server.py
├── visual_qc_apps/
├── profiles/
├── brand_guidelines/
├── uploads/
├── output/
└── ... (all Python code and data)
Files Created for Migration
run_api_server.py- Production server wrapper (uses Waitress WSGI)ai_qc.service- Systemd service configurationapache_config.conf- Apache virtual host configurationMIGRATION_GUIDE.md- Complete step-by-step instructionsrequirements.txt- Updated with Waitress dependency
Frontend Changes Required
NONE! Your web_ui.html already has smart base path detection:
function getBasePath() {
const path = window.location.pathname;
if (path.includes('/ai_qc/')) {
return path.substring(0, path.indexOf('/ai_qc/') + 7);
}
return '/';
}
This automatically detects if running at root (/) or subdirectory (/ai_qc/) and adjusts API calls accordingly.
Backend Changes Required
Minimal! Just update file paths in api_server.py to use absolute paths:
UPLOAD_FOLDER = '/opt/ai_qc/uploads'
OUTPUT_FOLDER = '/opt/ai_qc/output'
# etc.
Migration Timeline
- Preparation: 10 minutes (backup, read guide)
- Migration: 15-20 minutes (follow MIGRATION_GUIDE.md)
- Testing: 10 minutes (verify all features work)
- Total Downtime: ~20-30 minutes
Quick Migration Checklist
- ✅ Read
MIGRATION_GUIDE.mdcompletely - ✅ Schedule maintenance window
- ✅ Backup current deployment
- ✅ Stop current service
- ✅ Copy backend files to
/opt/ai_qc/ - ✅ Copy frontend to
/var/www/html/ai_qc/(rename to index.html) - ✅ Update systemd service file
- ✅ Update Apache configuration
- ✅ Install waitress dependency
- ✅ Test backend standalone
- ✅ Start services
- ✅ Test in browser
- ✅ Enable service on boot
Rollback Plan
If issues occur, rollback is simple:
- Stop new service
- Restore old Apache config
- Rename old directory back
- Start old service
Full instructions in MIGRATION_GUIDE.md → "Rollback Plan" section.
What to Test After Migration
- Frontend loads (http://your-domain.com/)
- Authentication works (Microsoft sign-in)
- File upload works
- Analysis runs successfully
- Results display correctly
- Saved files list updates
- PDF downloads work
- All profiles load
- Brand guidelines work
Need Help During Migration?
Before Migration:
- Read
MIGRATION_GUIDE.mdcompletely - Test commands in Step 0 to understand current setup
- Verify backup is created successfully
During Migration:
- Follow steps sequentially - don't skip
- Test each step before moving to next
- Check logs if something fails:
sudo journalctl -u ai_qc -n 50 --no-pager sudo tail -100 /var/log/apache2/ai_qc_error.log
After Migration:
- Monitor logs for first hour
- Test all major features
- Keep backup for 48 hours before deleting
Common Issues and Solutions
| Issue | Cause | Solution |
|---|---|---|
| Backend won't start | Permission denied | sudo chown -R www-data:www-data /opt/ai_qc |
| Module not found | Wrong Python environment | Check service file uses /opt/ai_qc/venv/bin/python |
| API not responding | Service not running | sudo systemctl status ai_qc |
| Frontend shows 404 | Apache config wrong | Check DocumentRoot path in Apache config |
| Uploads fail | Directory permissions | sudo chmod 770 /opt/ai_qc/uploads |
Key Commands
# Check service status
sudo systemctl status ai_qc
# View logs (live)
sudo journalctl -u ai_qc -f
# Check Apache logs
sudo tail -f /var/log/apache2/ai_qc_error.log
# Test backend directly
curl http://localhost:7183/api/profiles
# Test through Apache
curl http://your-domain.com/api/profiles
# Restart service
sudo systemctl restart ai_qc
# Reload Apache
sudo systemctl reload apache2
Files to Review Before Migration
- Read completely:
MIGRATION_GUIDE.md - Understand:
apache_config.conf(your Apache setup) - Review:
ai_qc.service(systemd service) - Check:
run_api_server.py(server wrapper)
Next Steps
- Read
MIGRATION_GUIDE.md- Complete step-by-step instructions - Schedule maintenance window - 30 minutes recommended
- Test in development - If you have a dev server, test there first
- Execute migration - Follow guide exactly
- Monitor and verify - Test all features thoroughly
Questions?
- Where's the detailed guide? →
MIGRATION_GUIDE.md - What Apache config do I use? →
apache_config.conf - How do I start the service? → See
ai_qc.service - Need to rollback? →
MIGRATION_GUIDE.md→ "Rollback Plan"