Prerequisites
Required Software
- Python: 3.12 or higher
- uv: Package manager (installation guide)
- Database: SQLite (development) or PostgreSQL (production recommended)
Optional
- Docker: For containerized deployment (coming soon)
- Nginx: For reverse proxy in production
- systemd: For service management on Linux
Development Deployment
Quick Start
1. Clone the repository:- API: http://localhost:8000
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Development Configuration
Create a.env file in the project root:
Development Server Options
Initialize Database
The database is automatically initialized on first run. To manually initialize:Development Tools
Production Deployment
Deployment Checklist
- Set strong
SNACKBASE_SECRET_KEY - Use PostgreSQL database
- Set
SNACKBASE_ENVIRONMENT=production - Set
SNACKBASE_DEBUG=false - Configure proper CORS origins
- Set up reverse proxy (Nginx)
- Enable HTTPS/TLS
- Configure log aggregation
- Set up monitoring and alerts
- Configure automated backups
- Test health check endpoints
Option 1: Direct Deployment (systemd)
1. Prepare the Server
2. Deploy Application
3. Production Environment Configuration
4. Set Up PostgreSQL
5. Create systemd Service
Create/etc/systemd/system/snackbase.service:
6. Start and Enable Service
Option 2: Nginx Reverse Proxy
1. Install Nginx
2. Configure Nginx
Create/etc/nginx/sites-available/snackbase:
3. Enable Site and Restart Nginx
4. Set Up SSL with Let’s Encrypt
Option 3: Docker Deployment
You can deploy SnackBase using the includedDockerfile and docker-compose.yml (optional).
1. Build the Image
2. Run the Container
3. Access Application
The application will be available at http://localhost:8000.Database Configuration
SQLite (Development Only)
- Zero configuration
- Perfect for development
- File-based, easy to backup
- Not suitable for production
- Limited concurrency
- No network access
PostgreSQL (Recommended for Production)
.env:
Environment Variables
Complete Reference
Health Checks
SnackBase provides three health check endpoints:/health - Basic Health Check
Returns 200 if the service is running.
/ready - Readiness Check
Returns 200 if the service is ready to accept requests (includes database connectivity).
/live - Liveness Check
Returns 200 if the service is alive (simple ping).
Using Health Checks
systemd:Troubleshooting
Service Won’t Start
Check logs:- Database connection failure
- Port already in use
- Missing environment variables
- File permission issues
Database Connection Errors
PostgreSQL:Permission Denied Errors
High Memory Usage
Reduce worker count:Slow API Responses
Check database:CORS Errors
Update CORS origins:Monitoring and Maintenance
Log Management
View logs:/etc/logrotate.d/snackbase:
Performance Monitoring
System resources:- Prometheus integration
- Grafana dashboards
- Custom metrics endpoint
Backup Strategy
Database backup (PostgreSQL):Automated backup/restore commands will be added in Phase 5 (F5.10)
Security Best Practices
- Use strong secret keys: Generate with
secrets.token_urlsafe(64) - Enable HTTPS: Use Let’s Encrypt for free SSL certificates
- Restrict CORS: Only allow trusted domains
- Use PostgreSQL: SQLite is not suitable for production
- Regular updates: Keep dependencies up to date
- Monitor logs: Set up log aggregation and alerts
- Firewall: Only expose necessary ports (80, 443)
- Database security: Use strong passwords, restrict network access
- File permissions: Ensure proper ownership and permissions
- Rate limiting: Add Nginx rate limiting (future enhancement)
Security Headers
SnackBase automatically sets security headers on all HTTP responses to protect against common web vulnerabilities:- X-Content-Type-Options: Prevents MIME type sniffing
- X-Frame-Options: Prevents clickjacking attacks
- X-XSS-Protection: Enables browser XSS protection
- Strict-Transport-Security (production only): Enforces HTTPS
- Content-Security-Policy: Prevents XSS and injection attacks
- Permissions-Policy: Restricts browser features
- Referrer-Policy: Controls referrer information
Customizing Security Headers
You can customize security headers via environment variables:Troubleshooting CSP Issues
If your frontend is blocked by CSP:- Check browser console: Look for CSP violation errors
- Identify blocked resources: Note the source and type (script, style, image, etc.)
- Update CSP policy: Add the necessary sources to the appropriate directive
- Test thoroughly: Ensure all functionality works after CSP changes
Authentication Flow
In single-tenant mode, the account is resolved server-side:The default CSP policy is designed to work with the SnackBase Admin UI. If
you’re using a custom frontend with external CDNs or inline scripts, you may
need to adjust the CSP policy.
Troubleshooting CSP Issues
If your frontend is blocked by CSP:- Check browser console: Look for CSP violation errors
- Identify blocked resources: Note the source and type (script, style, image, etc.)
- Update CSP policy: Add the necessary sources to the appropriate directive
- Test thoroughly: Ensure all functionality works after CSP changes
Next Steps
After deployment:- Create first account: Use the
/api/v1/auth/registerendpoint - Test API: Use Swagger UI at
/docs - Create collections: Use the
/api/v1/collectionsendpoint - Set up monitoring: Configure log aggregation and alerts
- Configure backups: Set up automated database backups
- Review security: Follow security best practices checklist