# ashumishrag/arogoai_mentalhealthmodel architecture

> Architecture diagram of the GitHub repository ashumishrag/arogoai_mentalhealthmodel, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ashumishrag/arogoai_mentalhealthmodel
- Repository: https://github.com/ashumishrag/arogoai_mentalhealthmodel

## Overview

##### Main Components
- Data Layer:
- A CSV file (data/mental_health_data.csv) that holds the dataset.
- Preprocessing logic in src/data_preprocessing.py.
- Model Training & Evaluation:
- Script for training (src/train_model.py) that cleans, engineers features, trains multiple models, evaluates them (using metrics like Accuracy, F1-score, ROC-AUC), and saves the best performing model as models/best_model.pkl.
- Integration of SHAP for model interpretability.
- Inference Modules:
- Command-Line Interface: src/predict_mental_health.py that handles user symptom input, prediction, and outputs a SHAP explanation as an HTML file.
- Web UI: mental_health_ui.py built with Streamlit, which offers interactive input, displays prediction probabilities, and embeds the SHAP explanation directly.
- Configuration & Dependencies:
- requirements.txt for the Python dependencies.
- README.md for overall context and reference.

##### Relationships and Interactions
- The data layer feeds into the data preprocessing module.
- Preprocessed data is used by the model training script to train and evaluate various models.
- The best model is serialized (as a .pkl file) and used by the inference modules.
- Both the CLI inference and the Streamlit UI load the model to predict outcomes based on new user inputs.
- SHAP is integrated post-prediction to generate explanations for the model decisions.

##### Architectural Patterns and Design Principles
- Clear separation of concerns: Data ingestion/preprocessing, model training, and inference/UI are modularized in different scripts.
- Reusability: The best model file (models/best_model.pkl) is shared across different inference implementations.
- Extensibility: Adding additional inference routes (e.g., RESTful APIs) or improving UI components can be done without disrupting the training pipeline.

##### Technologies and Frameworks
- Python is the primary language with packages such as scikit-learn.
- SHAP for model interpretability.
- Streamlit for the web UI.
- Pandas and possibly NumPy for data manipulation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration & Dependencies
    subgraph "Configuration & Dependencies"
        H1["requirements.txt"]:::config
        H2["README.md"]:::config
    end

    %% Machine Learning Pipeline
    subgraph "Machine Learning Pipeline"
        A["Data Source (CSV)"]:::data
        B["Data Preprocessing (src/data_preprocessing.py)"]:::ml
        C["Model Training & Evaluation (src/train_model.py)"]:::ml
        D["Best Model Storage (models/best_model.pkl)"]:::storage
    end

    %% Inference Modules
    subgraph "Inference Modules"
        E["Command-Line Inference (src/predict_mental_health.py)"]:::inference
        F["Web UI (Streamlit) (mental_health_ui.py)"]:::inference
    end

    %% SHAP Explanation
    G["SHAP Explanation Generation (HTML/Embedded)"]:::inference

    %% Data flow in Machine Learning Pipeline
    A -->|"RawData"| B
    B -->|"CleanedData"| C
    C -->|"TrainedModel"| D

    %% Model usage in Inference Modules
    D -->|"LoadModel"| E
    D -->|"LoadModel"| F

    %% Inference Flow to SHAP Explanation
    E -->|"PredictionOutput"| G
    F -->|"PredictionOutput"| G

    %% Configuration dependencies (dotted arrows)
    H1 -. "configures" .-> A
    H1 -. "configures" .-> B
    H1 -. "configures" .-> C
    H1 -. "configures" .-> E
    H1 -. "configures" .-> F

    H2 -. "provides info" .-> A
    H2 -. "provides info" .-> B
    H2 -. "provides info" .-> C
    H2 -. "provides info" .-> E
    H2 -. "provides info" .-> F

    %% Click Events for Component Mapping
    click A "https://github.com/ashumishrag/arogoai_mentalhealthmodel/blob/main/data/mental_health_data.csv"
    click B "https://github.com/ashumishrag/arogoai_mentalhealthmodel/blob/main/src/data_preprocessing.py"
    click C "https://github.com/ashumishrag/arogoai_mentalhealthmodel/blob/main/src/train_model.py"
    click D "https://github.com/ashumishrag/arogoai_mentalhealthmodel/blob/main/models/best_model.pkl"
    click E "https://github.com/ashumishrag/arogoai_mentalhealthmodel/blob/main/src/predict_mental_health.py"
    click F "https://github.com/ashumishrag/arogoai_mentalhealthmodel/blob/main/mental_health_ui.py"
    click H1 "https://github.com/ashumishrag/arogoai_mentalhealthmodel/blob/main/requirements.txt"
    click H2 "https://github.com/ashumishrag/arogoai_mentalhealthmodel/blob/main/README.md"

    %% Style Definitions
    classDef data fill:#A3C1DA,stroke:#333,stroke-width:2px;
    classDef ml fill:#B4E197,stroke:#333,stroke-width:2px;
    classDef storage fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef inference fill:#F7B2AD,stroke:#333,stroke-width:2px;
    classDef config fill:#D3D3D3,stroke:#333,stroke-width:2px;
```
