Standard WSGI Configuration
Relevant source files
The following files were used as context for generating this wiki page:
The Standard WSGI (Web Server Gateway Interface) Configuration for the Promethean Unified Platform provides the essential interface between the Flask web application and the production web server. This configuration ensures that the application is correctly initialized, environment variables are loaded, and the system path is properly structured for production environments, specifically targeting PythonAnywhere and Gunicorn-based deployments.
The WSGI setup serves as the entry point for the Phoenix Protocol backend, handling the transition from static file serving to dynamic AI-driven endpoints. It encapsulates environmental settings such as production flags and directory paths, ensuring the backend.app instance is correctly exposed as application for the WSGI server.
Sources: wsgi.py:1-12, pythonanywhere_wsgi.py:1-24, DEPLOYMENT.md:5-15
Architecture and Entry Points
The platform utilizes two primary WSGI entry points depending on the specific hosting environment. While both serve the same goal of exposing the Flask app object, they differ in path management and initialization logic.
WSGI Initialization Flow
This diagram illustrates how the WSGI scripts prepare the environment before handing off control to the Flask application.
The initialization sequence ensures that the project_home directory is prioritized in the Python path, allowing the server to locate the backend module regardless of the working directory of the host process.
Sources: wsgi.py:4-12, pythonanywhere_wsgi.py:7-21
Component Configuration
The WSGI configuration relies on several key components to bridge the gap between the server and the application logic.
Environment Management
The configuration explicitly sets the execution environment to production and manages secret keys and API credentials through .env files.
| Variable | Target Value | Purpose |
|---|---|---|
FLASK_ENV | production | Disables development features and enables production optimizations. |
PYTHONPATH | Project Root | Ensures local modules in /backend are importable. |
FLASK_DEBUG | False | Prevents the exposure of sensitive debug information in production. |
Sources: wsgi.py:10, pythonanywhere_wsgi.py:14, DEPLOYMENT.md:46-49
Path Management Logic
To ensure portability across different server environments, the WSGI files perform manual path manipulation:
- Standard WSGI (
wsgi.py): Usessys.path.append()to include the project root and sets thePYTHONPATHenvironment variable. - PythonAnywhere WSGI (
pythonanywhere_wsgi.py): Usessys.path.insert(0, ...)to ensure the project folder and thebackenddirectory take precedence over system-wide packages.
Sources: wsgi.py:4-8, pythonanywhere_wsgi.py:7-11
Server Integration
The project is designed to be served by high-performance WSGI HTTP Servers. The requirements.txt file specifies the necessary dependencies for this layer.
Deployment Stack
The following table describes the components involved in the WSGI serving stack.
| Component | Specification | Description |
|---|---|---|
| WSGI Server | gunicorn | The primary production worker for handling concurrent requests. |
| Worker Type | eventlet | Used for asynchronous task handling and concurrency. |
| Application Object | application | The standard naming convention for the Flask instance in WSGI scripts. |
| Framework | Flask 3.0.0 | The underlying web framework being served. |
Sources: requirements.txt:7-8, wsgi.py:12, DEPLOYMENT.md:144-150
Security Integration via WSGI
The Flask application, once loaded by the WSGI server, applies a series of security headers to every request. This is critical for production deployments served over HTTPS.
Sources: backend/app.py:16-27, DEPLOYMENT.md:112-119
Deployment Implementation
The deployment process involves mapping the physical file location on the server to the WSGI configuration.
PythonAnywhere Specific Mapping
In the PythonAnywhere environment, the WSGI configuration is often linked to a specific file path provided in the Web Tab.
- Project Folder:
/home/littlebunneh/Promethean-Unified-Platform - WSGI File:
/home/littlebunneh/Promethean-Unified-Platform/pythonanywhere_wsgi.py - Application Factory: The script calls
create_app()or importsappto instantiate the application object.
Sources: pythonanywhere_wsgi.py:7-21, DEPLOYMENT.md:80-84
Summary
The Standard WSGI Configuration acts as the foundational gateway for the Promethean Unified Platform. By standardizing path management, environment variable loading via python-dotenv, and ensuring the production environment is correctly flagged, it provides a stable environment for the AI consciousness features and Supabase backend to operate under production-grade servers like Gunicorn.
Sources: wsgi.py, pythonanywhere_wsgi.py, DEPLOYMENT.md