How qnity001/coffee-break works
Project type and purpose
• This is a full-stack mental-health companion for students:
• A static informational site (HTML/CSS/JS) hosting landing pages (“about”, “resources”, “coffee”)
• A Flask backend under the AI/ folder providing the “Milo” chat interface
• An external dependency on the OpenAI API to generate empathetic chatbot responses
File structure
• Top-level directories and files:
• index.html, about/, resources/, coffee/, plus global script.js and style.css → static site
• AI/ → Flask application
– app.py (controller/routes)
– system_instruction.txt (prompt template)
– data.json (resource metadata)
– requirements.txt
– templates/ (Jinja2 views: bot.html)
– static/ (chat-UI assets: app.js, stylebot.css)
• Patterns: MVC‐style in Flask (templates = views, static assets = public, app.py = controller), static content served separately (via GitHub Pages or CDN)
Key insights from README
• Backend “handshake” between front end and Flask
• Rate-limit handling (delay logic) around OpenAI API
• Single-session memory stored in process (no persistent DB yet)
Main components
A. Web Client (Browser)
• Renders static pages (index.html, about/…, resources/…)
• Loads script.js/style.css
• On “Coffee” page, initializes chat widget (app.js)
B. Static-Site Host
• GitHub Pages or Nginx serving the entire index.html, /about, /resources, /coffee folder
C. Flask Backend
• app.py
• Route GET /chat → serves templates/bot.html
• Route POST /api/message → reads user message, loads system_instruction.txt, data.json, calls OpenAI API, returns response
• templates/ + static/ within AI/
D. Data Store (file‐based)
• data.json (resource metadata for in-chat suggestions)
• Future: relational/NoSQL DB for user sessions
E. External Service
• OpenAI API (GPT-based model)
Relationships & interactions
1. User’s browser requests GET /coffee/index.html from static host
2. Browser loads chat widget (AI/static/app.js) via script tag (could be proxied or fetched directly from backend host)
3. Client JS sends POST /api/message to Flask server with the user’s input
4. Flask server:
a. Reads system_instruction.txt + data.json
b. Calls OpenAI API over HTTPS
c. Receives chatbot reply
d. Returns JSON response to client
5. Browser receives JSON, updates DOM, displays chatbot message
Architectural patterns & design principles
• Separation of concerns: static site vs. API service
• MVC in backend (views, controllers)
• Single‐page mini-app for chat widget (modular JS)
• External dependency isolation (all OpenAI calls in one module)