Overview
Deploying Framefox applications to production requires careful configuration and optimization. This guide covers best practices for running Framefox in production environments.Production Checklist
Before deploying to production, ensure you’ve completed these critical steps:Security
- Set a strong
SECRET_KEYin your environment variables - Configure secure session management
- Enable HTTPS and set
cookie.securetotrue - Review and configure CORS settings appropriately
- Disable debug mode by setting
APP_ENV=prod - Configure proper firewall rules
Performance
- Configure production-grade database connection pooling
- Enable appropriate caching strategies
- Optimize static file serving
- Configure proper logging levels
- Set up monitoring and error tracking (e.g., Sentry)
Environment
- Use environment variables for sensitive configuration
- Set
APP_ENV=prodin your.envfile - Configure production database credentials
- Set up proper backup strategies
Running with Uvicorn
Framefox is built on FastAPI and runs on Uvicorn, a lightning-fast ASGI server.Basic Production Command
Recommended Production Configuration
--host 0.0.0.0: Bind to all network interfaces--port 8000: Port to listen on--workers 4: Number of worker processes (typically 2-4 per CPU core)--proxy-headers: Trust X-Forwarded headers from reverse proxy--forwarded-allow-ips='*': Allow forwarded IPs from any source (adjust for security)--no-access-log: Disable access logs (use reverse proxy logs instead)
Worker Count Calculation
A good starting point for worker count:Process Management with Gunicorn
For production, use Gunicorn with Uvicorn workers:Install Gunicorn
Systemd Service
Create a systemd service for automatic startup and management.Service File: /etc/systemd/system/framefox.service
Enable and Start Service
Reverse Proxy Configuration
Nginx
Recommended Nginx configuration:Apache
Performance Tuning
Database Connection Pooling
Configure proper connection pooling in yourconfig/orm.yaml:
Logging Configuration
Optimize logging for production inconfig/debug.yaml:
Session Storage
Use Redis for session storage in production:Monitoring and Error Tracking
Sentry Integration
Configure Sentry for error tracking inconfig/debug.yaml:
SENTRY_DSN environment variable:
Application Monitoring
Monitor key metrics:- Response times: Track endpoint performance
- Error rates: Monitor failed requests
- Database performance: Query times and connection pool usage
- Resource usage: CPU, memory, disk I/O
- Worker health: Process status and restarts
Health Check Endpoint
Implement a health check endpoint:Security Best Practices
Environment Variables
Never commit sensitive data. Use environment variables:Cookie Security
Configure secure cookies inconfig/application.yaml:
CSRF Protection
Framefox includes built-in CSRF protection. Ensure it’s enabled for state-changing operations.HTTPS Only
Always use HTTPS in production:- Obtain SSL certificates (Let’s Encrypt is free)
- Configure your reverse proxy for HTTPS
- Set
cookie.secure: true - Enable HSTS headers
Deployment Strategies
Blue-Green Deployment
- Deploy new version to separate environment
- Run tests on new environment
- Switch traffic to new environment
- Keep old environment for quick rollback
Rolling Updates
- Deploy to one server at a time
- Verify each server before proceeding
- Minimize downtime with load balancer
Database Migrations
Run migrations before deploying new code:- Make migrations backward-compatible
- Deploy code that works with old and new schema
- Run migration
- Deploy code optimized for new schema
Backup and Recovery
Database Backups
Automated Backups
Set up cron jobs for regular backups:Session Data
If using Redis, enable RDB or AOF persistence:Scaling Considerations
Horizontal Scaling
- Use a load balancer (Nginx, HAProxy, AWS ALB)
- Ensure session storage is shared (Redis)
- Use external database, not SQLite
- Stateless application design
Vertical Scaling
- Increase worker count based on CPU cores
- Allocate more memory for caching
- Optimize database queries
- Use connection pooling
Troubleshooting
High Memory Usage
- Reduce worker count
- Check for memory leaks
- Optimize database queries
- Review application code for inefficiencies
Slow Response Times
- Check database query performance
- Review Sentry traces
- Optimize template rendering
- Enable caching where appropriate
- Use database query profiling
Worker Crashes
- Check logs:
journalctl -u framefox -n 100 - Review Sentry for exceptions
- Verify database connectivity
- Check resource limits (ulimit)
Next Steps
Docker Deployment
Containerize your Framefox application
Environment Variables
Manage configuration and secrets