Prerequisites
Before configuring your environment, ensure you have:- Python 3.8 or higher installed
- MySQL database server running
- Access to external services (Cloudinary, API Ninjas)
- A text editor for creating
.envfiles
Environment Variables
The ExpireEye Backend requires several environment variables for database connectivity, authentication, and external service integrations.Creating Your Environment File
Database Configuration
The application uses MySQL with PyMySQL driver. Configure these variables for your database connection:.env
The database connection is configured in
app/db/session.py using the format:
mysql+pymysql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}| Variable | Description | Example |
|---|---|---|
DB_USER | MySQL database username | expireeye_user |
DB_PASSWORD | MySQL database password | SecureP@ssw0rd |
DB_HOST | Database host address | localhost or mysql.example.com |
DB_PORT | MySQL port number | 3306 (default) |
DB_NAME | Target database name | expireeye_db |
JWT Authentication
The application uses JWT tokens for API authentication. Configure a strong secret key:.env
- Use a cryptographically strong random string (minimum 32 characters)
- Never commit your actual secret key to version control
- Rotate keys periodically in production environments
The JWT configuration in
app/utils/jwt.py sets tokens to expire after 4000 minutes. Access tokens are validated via the Authorization: Bearer <token> header on all protected endpoints.Cloudinary Integration
ExpireEye uses Cloudinary for image storage and management. Configure your Cloudinary credentials:.env
Create a Cloudinary account
Sign up at https://cloudinary.com if you don’t have an account.
External API Keys
The application integrates with API Ninjas for nutrition data:.env
- Creating a free account
- Navigating to the API dashboard
- Generating a new API key for the Nutrition API
Connection Pool Settings
The database connection pool is configured inapp/db/session.py with the following settings:
app/db/session.py
For development environments, you can set
echo=True to log all SQL queries for debugging purposes.Verifying Your Configuration
After setting up your environment variables, verify the configuration:Environment-Specific Configurations
Development
.env
Production
.env
Troubleshooting
Database Connection Issues
If you encounter database connection errors:- Verify MySQL is running:
systemctl status mysqlorbrew services list - Check credentials: Ensure DB_USER has proper permissions
- Test connectivity: Use
mysql -u {DB_USER} -p -h {DB_HOST}to test manually - Check firewall: Ensure port 3306 is accessible
JWT Token Issues
If authentication fails:- Verify
SECRET_KEYis set and non-empty - Check token expiration settings in
app/utils/jwt.py - Ensure the
Authorizationheader format is correct:Bearer <token>
Import Errors
If you see module import errors:Next Steps
After configuring your environment:- Run database migrations to set up your schema
- Deploy to production when ready