# rakesh-myana/mental-health-predictor architecture

> Architecture diagram of the GitHub repository rakesh-myana/mental-health-predictor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rakesh-myana/mental-health-predictor
- Repository: https://github.com/rakesh-myana/mental-health-predictor

## Overview

##### Project type and purpose
- This is a full-stack, single-page Flask web application that exposes a machine-learning model for predicting the likelihood of depression.
- The user interacts with an HTML form (templates + CSS), submits data, and receives a prediction computed by Flask loading a pre-trained model (model.pkl).

##### File structure
- Top-level:
- app.py – Flask application entry point (routes, request handling, model invocation)
- model.pkl – serialized ML model
- requirements.txt – Python dependencies
- README.md – project description
- Directories:
- static/ – CSS and image assets
- templates/ – Jinja2 HTML templates
- training/ – Jupyter notebook and raw data for offline model training

##### README
- Confirms tech stack: Python + Flask + machine learning.
- Describes use case: web form → depression likelihood prediction.

##### Main components & relationships
a. Frontend (Client)
- Browser sends HTTP GET for landing page (templates/index.html + CSS)
- User fills form and submits via HTTP POST
b. Web Server / Backend (Flask in app.py)
- Route handlers parse input, invoke ML inference
- Loads model.pkl once or caches it in memory
- Returns JSON or rendered HTML with prediction
c. Machine Learning Model
- model.pkl lives on disk; loaded by Flask
d. (Offline) Training Pipeline
- training/training.ipynb reads mental_health_data.csv → preprocess → trains model → exports model.pkl
e. (Optional) External Infrastructure
- WSGI server (Gunicorn/uWSGI), load balancer, containerization (Docker), cloud hosting

##### Architectural patterns & design principles
- MVC-inspired separation: templates (View), app.py controllers (Controller), model.pkl (Model)
- Single-responsibility: training code is isolated in /training, web logic in app.py
- Stateless HTTP API for predictions
- Caching or lazy-loading of model for performance

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    Browser["Web Browser"]:::external

    %% Frontend Layer
    subgraph "Frontend Layer"
        Templates["Templates (index.html)"]:::frontend
        Style["style.css"]:::frontend
        Footer["footer.css"]:::frontend
        Images["images/"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        WSGI["WSGI Server (Gunicorn/uWSGI)"]:::backend
        App["Flask App (app.py)"]:::backend
    end

    %% Inference Tier
    subgraph "Inference Tier"
        Model["Model Store (model.pkl)"]:::data
    end

    %% Project Files
    subgraph "Project Files"
        Req["requirements.txt"]:::data
        Readme["README.md"]:::data
    end

    %% Training Tier (Offline)
    subgraph "Training Tier (Offline)"
        Notebook["Training Notebook (training.ipynb)"]:::offline
        CSV["Raw Data (mental_health_data.csv)"]:::offline
    end

    %% Connections
    Browser -->|"GET /"| WSGI
    WSGI -->|"invoke app"| App
    App -->|"renders"| Templates
    App -->|"serves"| Style
    App -->|"serves"| Footer
    App -->|"serves"| Images
    Browser -->|"POST /predict"| WSGI
    App -->|"loads model"| Model
    App -->|"returns prediction"| Browser
    Notebook -->|"reads data"| CSV
    Notebook -->|"trains and exports"| Model

    %% Click Events
    click Templates "https://github.com/rakesh-myana/mental-health-predictor/blob/main/templates/index.html"
    click Style "https://github.com/rakesh-myana/mental-health-predictor/blob/main/static/style.css"
    click Footer "https://github.com/rakesh-myana/mental-health-predictor/blob/main/static/footer.css"
    click Images "https://github.com/rakesh-myana/mental-health-predictor/tree/main/static/images/"
    click App "https://github.com/rakesh-myana/mental-health-predictor/blob/main/app.py"
    click Model "https://github.com/rakesh-myana/mental-health-predictor/blob/main/model.pkl"
    click Req "https://github.com/rakesh-myana/mental-health-predictor/blob/main/requirements.txt"
    click Readme "https://github.com/rakesh-myana/mental-health-predictor/blob/main/README.md"
    click Notebook "https://github.com/rakesh-myana/mental-health-predictor/blob/main/training/training.ipynb"
    click CSV "https://github.com/rakesh-myana/mental-health-predictor/blob/main/training/mental_health_data.csv"

    %% Styles
    classDef external fill:#ADD8E6,stroke:#333
    classDef frontend fill:#FFFFCC,stroke:#333
    classDef backend fill:#98FB98,stroke:#333
    classDef data fill:#FFA500,stroke:#333,color:#000
    classDef offline fill:#D3D3D3,stroke:#333
```
