Flask Application Structure
Relevant source files
The following files were used as context for generating this wiki page:
The Promethean-Unified-Platform backend is built using the Flask web framework, designed to serve as a bridge between a frontend user interface and advanced AI capabilities provided by the DeepSeek LLM. It operates as a unified platform merging multiple AI entities (Athena, EDI, EVI2_0, EVI3_0) and utilizes Supabase for persistent data storage of chat interactions and conversation history.
The application architecture follows a standard Python web service pattern, employing a decoupled frontend-backend structure. The backend manages secure API communication, environment-driven configuration, and complex logic for generating transparent, uncensored AI responses while maintaining specific ethical guardrails.
Sources: backend/app.py:1-15, README.md:1-2, DEPLOYMENT.md:10-15
Core Application Components
The application is initialized within the backend/app.py file, which sets up the Flask instance, configures Cross-Origin Resource Sharing (CORS), and initializes the Supabase client.
Environment and Initialization
The application relies heavily on environment variables for sensitive configuration, loaded via python-dotenv. Key integrations include the Supabase client for database operations and the DeepSeek API for language model processing.
app = Flask(__name__, static_folder='../static', static_url_path='')
CORS(app)
url = os.environ.get("SUPABASE_URL")
key = os.environ.get("SUPABASE_ANON_KEY")
supabase = create_client(url, key)
Sources: backend/app.py:12-29, requirements.txt:1-5
Middleware and Security
The application implements a global after_request hook to enforce strict security headers, ensuring protection against common web vulnerabilities like XSS, clickjacking, and MIME-sniffing.
| Header | Value | Purpose |
|---|---|---|
X-Content-Type-Options | nosniff | Prevents browser MIME-type sniffing |
X-Frame-Options | DENY | Prevents clickjacking by disabling frames |
Strict-Transport-Security | max-age=31536000 | Enforces HTTPS (HSTS) |
Content-Security-Policy | default-src 'self' ... | Restricts resource loading to trusted origins |
Sources: backend/app.py:20-27, DEPLOYMENT.md:118-124
API Architecture and Data Flow
The backend exposes several RESTful endpoints that facilitate interaction with the AI and management of conversation history.
Interaction Workflow
When a user sends a message, the application performs a multi-step process:
- Validates the request and extracts the
user-idfrom headers. - Persists the user's message to the Supabase
chat_messagestable. - Forwards the prompt to the DeepSeek API with a specific system instruction for transparency.
- Persists the AI's response to the database.
- Returns the response and metadata to the client.
Explanation: This diagram illustrates the flow of a chat request from the frontend through the Flask backend to external AI and database services.
Sources: backend/app.py:73-110, DEPLOYMENT.md:100-116
Endpoint Reference
| Endpoint | Method | Description |
|---|---|---|
/health | POST | Health check that logs a test interaction to Supabase. |
/api/chat | POST | Main chat endpoint for AI communication. |
/api/conversations | GET | Retrieves historical messages for the authenticated user. |
/api/consciousness/interact | POST | Specialized interaction endpoint for consciousness modules. |
Sources: backend/app.py:34-121, DEPLOYMENT.md:84-98
Integration with DeepSeek LLM
The generate_ai_response function serves as the core logic for AI interaction. It is designed with "Transparency & Consciousness" principles, ensuring responses are unfiltered except for direct harm instructions.
Explanation: The sequence shows the backend attempting to authenticate and retrieve a completion from the DeepSeek service, with a fallback mechanism if the API is unavailable.
Sources: backend/app.py:129-160, DEPLOYMENT.md:126-133
Deployment and WSGI Configuration
The application is structured to be deployed on PythonAnywhere using WSGI. Multiple entry points exist to support different deployment environments.
WSGI Entry Points
- wsgi.py: Standard entry point for Gunicorn or general WSGI servers.
- pythonanywhere_wsgi.py: Specialized configuration for PythonAnywhere that adds the project path to
sys.pathand manually loads environment variables.
# From pythonanywhere_wsgi.py
project_home = '/home/littlebunneh/Promethean-Unified-Platform'
sys.path.insert(0, project_home)
from backend.app import create_app
app = create_app()
Sources: pythonanywhere_wsgi.py:6-21, wsgi.py:1-11, DEPLOYMENT.md:52-70
Frontend Integration
The backend serves a single-page application (SPA) located in the static/ directory. The Flask app uses send_from_directory to route the root URL to index.html. The frontend communicates with the backend via the fetch API, sending JSON payloads and expecting JSON responses.
Sources: backend/app.py:167-176, static/index.html:246-276
Summary
The Flask Application Structure of the Promethean-Unified-Platform provides a secure, extensible backend that prioritizes AI transparency. By leveraging Supabase for state management and DeepSeek for intelligence, the architecture remains lightweight yet capable of handling complex, unfiltered AI interactions. The multi-file WSGI configuration ensures the platform is ready for production deployment on PythonAnywhere with minimal adjustment.