# shushilshah/student-depression-prediction-system architecture

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

- Interactive diagram: https://gitdiagram.com/shushilshah/student-depression-prediction-system
- Repository: https://github.com/shushilshah/student-depression-prediction-system

## Overview

##### Major Components
- Frontend/UI: Represented by the Streamlit app (app.py), which acts as the user interface where users enter information.
- Machine Learning Pipeline:
- Data Ingestion (src/components/data_ingestion.py) to load and structure data (with dependencies on the dataset in the data/ folder).
- Data Transformation (src/components/data_transformation.py) that processes the raw data.
- Data Validation (src/components/data_validation.py) ensuring consistency and quality.
- Model Trainer (src/components/model_trainer.py) that trains the prediction model.
- Model Evaluation (src/components/model_evaluation.py) which assesses model performance.
- Pipeline Orchestration: The training pipeline (src/pipeline/training_pipeline.py) that strings together these components in sequence.
- Database Integration: MongoDB Atlas used to both fetch whole data for training dynamically and to save prediction history.
- Utility and Support Modules: Including configurations (src/configuration/ db_connection.py for database settings), logging (src/logger/ for standardized logging), and utilities (src/utils/main_utils.py) that support various operations.
- Exception Handling: Modules under src/exception help capture and manage errors.
- Testing: Several “test” files in the components folder (e.g., test_data_ingestion.py) showcase the emphasis on validation and unit testing of the components.

##### Relationships and Data Flow
- The Streamlit UI (app.py) collects user input. Once the user submits data, the application calls the prediction module which makes use of the pre-trained model (model.pkl) or triggers the training pipeline (via src/pipeline/training_pipeline.py).
- The ML pipeline components form a sequential flow: starting with data ingestion, then transformation, validation, model training, and finally evaluation. Each stage feeds its output to the next.
- MongoDB Atlas is integrated for:
- Reading the entire dataset for training (dynamic due to each new user input).
- Storing each prediction result.
- Utility modules provide supporting functions while configuration files set up connections (e.g., db_connection.py in src/configuration).

##### Architectural Patterns and Design Principles
- Modular Design: The code is broken up into multiple components (e.g., ingestion, transformation, training), following a microservices-like approach within the same project.
- Separation of Concerns: There is a clear boundary between the UI (app.py), backend processing (ML pipeline), and database operations (MongoDB integration).
- Reusability & Testability: With dedicated test modules for each main component, the design supports robust testing and reliability.
- Configuration Management: Database connectivity and potentially other environment settings are handled through specific modules and a .env file.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Vertical Flow
    UI["UI: Streamlit (app.py)"]:::frontend
    PO["Pipeline Orchestration (training_pipeline.py)"]:::orchestration
    DI["Data Ingestion (data_ingestion.py)"]:::ml_pipeline
    DT["Data Transformation (data_transformation.py)"]:::ml_pipeline
    DV["Data Validation (data_validation.py)"]:::ml_pipeline
    MT["Model Trainer (model_trainer.py)"]:::ml_pipeline
    ME["Model Evaluation (model_evaluation.py)"]:::ml_pipeline
    DB["MongoDB Atlas"]:::database

    %% Main Flow Connections
    UI -->|"submits"| PO
    PO -->|"runs"| DI
    DI -->|"feeds"| DT
    DT -->|"feeds"| DV
    DV -->|"feeds"| MT
    MT -->|"feeds"| ME
    ME -->|"stores_prediction"| DB
    PO -->|"fetches_training_data"| DB

    %% Support Modules Subgraph
    subgraph "Support Modules"
        CONF["Configuration (db_connection.py)"]:::support
        LOG["Logging (logger)"]:::support
        UTIL["Utility Functions (main_utils.py)"]:::support
        EXCEP["Exception Handling (exception)"]:::support
    end

    %% Connections from Support Modules
    CONF -->|"configures"| PO
    CONF -->|"configures"| DB
    LOG --> PO
    UTIL --> PO
    EXCEP --> PO

    %% Testing Modules Subgraph
    subgraph "Testing Modules"
        TDI["Test: Data Ingestion (test_data_ingestion.py)"]:::support
        TDT["Test: Data Transformation (test_data_transformation.py)"]:::support
        TDV["Test: Data Validation (test_data_validation.py)"]:::support
        TMT["Test: Model Trainer (test_model_trainer.py)"]:::support
        TME["Test: Model Evaluation (test_model_evaluation.py)"]:::support
    end

    %% Dashed connections from Testing Modules to corresponding ML Pipeline components
    TDI -.-> DI
    TDT -.-> DT
    TDV -.-> DV
    TMT -.-> MT
    TME -.-> ME

    %% Click Events
    click UI "https://github.com/shushilshah/student-depression-prediction-system/blob/main/app.py"
    click PO "https://github.com/shushilshah/student-depression-prediction-system/blob/main/src/pipeline/training_pipeline.py"
    click DI "https://github.com/shushilshah/student-depression-prediction-system/blob/main/src/components/data_ingestion.py"
    click DT "https://github.com/shushilshah/student-depression-prediction-system/blob/main/src/components/data_transformation.py"
    click DV "https://github.com/shushilshah/student-depression-prediction-system/blob/main/src/components/data_validation.py"
    click MT "https://github.com/shushilshah/student-depression-prediction-system/blob/main/src/components/model_trainer.py"
    click ME "https://github.com/shushilshah/student-depression-prediction-system/blob/main/src/components/model_evaluation.py"
    click CONF "https://github.com/shushilshah/student-depression-prediction-system/blob/main/src/configuration/db_connection.py"
    click LOG "https://github.com/shushilshah/student-depression-prediction-system/tree/main/src/logger/"
    click UTIL "https://github.com/shushilshah/student-depression-prediction-system/blob/main/src/utils/main_utils.py"
    click EXCEP "https://github.com/shushilshah/student-depression-prediction-system/tree/main/src/exception"
    click TDI "https://github.com/shushilshah/student-depression-prediction-system/blob/main/src/components/test_data_ingestion.py"
    click TDT "https://github.com/shushilshah/student-depression-prediction-system/blob/main/src/components/test_data_transformation.py"
    click TDV "https://github.com/shushilshah/student-depression-prediction-system/blob/main/src/components/test_data_validation.py"
    click TMT "https://github.com/shushilshah/student-depression-prediction-system/blob/main/src/components/test_model_trainer.py"
    click TME "https://github.com/shushilshah/student-depression-prediction-system/blob/main/src/components/test_model_evaluation.py"

    %% Styles
    classDef frontend fill:#fceabb,stroke:#e48b0d,stroke-width:2px;
    classDef ml_pipeline fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef orchestration fill:#d1c4e9,stroke:#5e35b1,stroke-width:2px;
    classDef database fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
    classDef support fill:#ffcdd2,stroke:#c62828,stroke-width:2px;
```
