# vanshtyagi-01/mentalhealth architecture

> Architecture diagram of the GitHub repository vanshtyagi-01/mentalhealth, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vanshtyagi-01/mentalhealth
- Repository: https://github.com/vanshtyagi-01/mentalhealth

## Overview

MentalHealth is a browser-based mental-health score estimator backed by a FastAPI prediction service. The main workflow is user input, client-side validation and payload construction, API validation and country grouping, model inference, then score and insight rendering. The model artifact is present in the tree and loaded by the service. Evidence is limited to the README, file tree, and excerpts; the HTML, styling, model internals, and portions of the JavaScript were not inspected.

Main entry points: [`main.py`](https://github.com/vanshtyagi-01/mentalhealth/blob/main/main.py) (FastAPI service), [`script.js`](https://github.com/vanshtyagi-01/mentalhealth/blob/main/script.js) (Prediction request), [`index.html`](https://github.com/vanshtyagi-01/mentalhealth/blob/main/index.html) (Input form), [`style.css`](https://github.com/vanshtyagi-01/mentalhealth/blob/main/style.css) (Visual styling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Browser experience"]
  node_form["Input form<br/>[index.html]"]
  node_interaction["Form interaction<br/>[script.js]"]
  node_validation["Input validation<br/>[script.js]"]
  node_payload["Payload collection<br/>[script.js]"]
  node_api_call["Prediction request<br/>[script.js]"]
  node_result["Score and insights<br/>[script.js]"]
  node_presentation["Visual styling<br/>[style.css]"]
end

subgraph group_api["Prediction service"]
  node_service["FastAPI service<br/>[main.py]"]
  node_schema["Request schema<br/>[main.py]"]
  node_country["Country grouping<br/>[main.py]"]
  node_frame["Feature frame<br/>[main.py]"]
  node_score["Score response<br/>[main.py]"]
end

subgraph group_ml["Scoring"]
  node_model["Prediction model"]
end

node_person(("User"))

node_person -->|"enters data"| node_form
node_form -->|"drives controls"| node_interaction
node_interaction -->|"validates input"| node_validation
node_validation -->|"collects fields"| node_payload
node_payload -->|"submits payload"| node_api_call
node_api_call -->|"POST /predict"| node_service
node_service -->|"validates request"| node_schema
node_service -->|"groups country"| node_country
node_service -->|"builds features"| node_frame
node_service -->|"predicts score"| node_model
node_service -->|"returns score"| node_score
node_api_call -->|"renders response"| node_result
node_result -.->|"uses styles"| node_presentation

click node_form "https://github.com/vanshtyagi-01/mentalhealth/blob/main/index.html"
click node_interaction "https://github.com/vanshtyagi-01/mentalhealth/blob/main/script.js"
click node_validation "https://github.com/vanshtyagi-01/mentalhealth/blob/main/script.js"
click node_payload "https://github.com/vanshtyagi-01/mentalhealth/blob/main/script.js"
click node_api_call "https://github.com/vanshtyagi-01/mentalhealth/blob/main/script.js"
click node_result "https://github.com/vanshtyagi-01/mentalhealth/blob/main/script.js"
click node_presentation "https://github.com/vanshtyagi-01/mentalhealth/blob/main/style.css"
click node_service "https://github.com/vanshtyagi-01/mentalhealth/blob/main/main.py"
click node_schema "https://github.com/vanshtyagi-01/mentalhealth/blob/main/main.py"
click node_country "https://github.com/vanshtyagi-01/mentalhealth/blob/main/main.py"
click node_frame "https://github.com/vanshtyagi-01/mentalhealth/blob/main/main.py"
click node_model "https://github.com/vanshtyagi-01/mentalhealth/blob/main/Mental_Health_Model.pkl"
click node_score "https://github.com/vanshtyagi-01/mentalhealth/blob/main/main.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_form,node_interaction,node_validation,node_payload,node_api_call,node_result,node_presentation,node_person toneBlue
class node_service,node_schema,node_country,node_frame,node_score toneAmber
class node_model toneMint
```

## Components

### Browser experience

- [Input form](https://github.com/vanshtyagi-01/mentalhealth/blob/main/index.html): `index.html`
- [Form interaction](https://github.com/vanshtyagi-01/mentalhealth/blob/main/script.js): `script.js`
- [Input validation](https://github.com/vanshtyagi-01/mentalhealth/blob/main/script.js): `script.js`
- [Payload collection](https://github.com/vanshtyagi-01/mentalhealth/blob/main/script.js): `script.js`
- [Prediction request](https://github.com/vanshtyagi-01/mentalhealth/blob/main/script.js): `script.js`
- [Score and insights](https://github.com/vanshtyagi-01/mentalhealth/blob/main/script.js): `script.js`
- [Visual styling](https://github.com/vanshtyagi-01/mentalhealth/blob/main/style.css): `style.css`

### Prediction service

- [FastAPI service](https://github.com/vanshtyagi-01/mentalhealth/blob/main/main.py): `main.py`
- [Request schema](https://github.com/vanshtyagi-01/mentalhealth/blob/main/main.py): `main.py`
- [Country grouping](https://github.com/vanshtyagi-01/mentalhealth/blob/main/main.py): `main.py`
- [Feature frame](https://github.com/vanshtyagi-01/mentalhealth/blob/main/main.py): `main.py`
- [Score response](https://github.com/vanshtyagi-01/mentalhealth/blob/main/main.py): `main.py`

### Scoring

- [Prediction model](https://github.com/vanshtyagi-01/mentalhealth/blob/main/Mental_Health_Model.pkl): `Mental_Health_Model.pkl`

### Other components

- **User**

## Connections

- User → Input form: enters data
- Input form → Form interaction: drives controls
- Form interaction → Input validation: validates input (evidence: `script.js`)
- Input validation → Payload collection: collects fields (evidence: `script.js`)
- Payload collection → Prediction request: submits payload (evidence: `script.js`)
- Prediction request → FastAPI service: POST /predict (evidence: `script.js`)
- FastAPI service → Request schema: validates request (evidence: `main.py`)
- FastAPI service → Country grouping: groups country (evidence: `main.py`)
- FastAPI service → Feature frame: builds features (evidence: `main.py`)
- FastAPI service → Prediction model: predicts score (evidence: `main.py`)
- FastAPI service → Score response: returns score (evidence: `main.py`)
- Prediction request → Score and insights: renders response (evidence: `script.js`)
- Score and insights → Visual styling: uses styles
