# eldrago12/restorease architecture

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

- Interactive diagram: https://gitdiagram.com/eldrago12/restorease
- Repository: https://github.com/eldrago12/restorease

## Overview

##### Project Type and Purpose
- This is a machine learning deployment project that integrates a Neural Network, a Random Forest model (for feature selection and probabilities), and a LightGBM meta-model. Its aim is to predict sleep disorders (e.g., Insomnia, Sleep Apnea, or Healthy status) with high accuracy.
- The project supports both model training/testing and deployment via two options: a Flask web application and an AWS Lambda-based solution using a converted tflite model.

##### File Structure
- Top-level files like LICENSE, README.md, app.py, and HTML pages (assessment.html, homepage.html) indicate that the repository holds both documentation and user interfaces.
- The existence of multiple Python scripts (final.py, h5_test.py, tflite_test.py, and model_conversion.py) shows that the project includes testing and conversion utilities.
- The “model” directory contains all artifact models (TensorFlow neural network in .h5 and .tflite formats, Random Forest, scaler, and meta-model artifacts in .pkl files) used in the prediction pipeline.

##### Key Architectural Components
a. User / Client Interface:
- Static web pages (assessment.html, homepage.html) and API clients that send prediction requests.
b. Web Server / API Layer:
- Flask application (app.py) that receives HTTP POST requests on the “/predict” endpoint.
c. Model Loading & Preprocessing:
- Code that loads all the model artifacts (neural.h5, rf_model.pkl, scaler.pkl, sleep_disorder_encoder.pkl, top_feature_names.pkl).
- Data preprocessing (using StandardScaler and label encoding) and feature selection steps.
d. Prediction Pipeline:
- Neural Network component running predictions (with probability output for each class).
- Random Forest component generating feature selection probabilities.
- A meta-model (LightGBM) that integrates outputs from the Neural Network, Random Forest, and selected top features.
- A decision logic that compares the NN prediction confidence to determine whether to use the neural or meta-model output.
e. Deployment Options:
- Option 1: Flask-based REST API for real-time predictions.
- Option 2: AWS Lambda deployment with model conversion to tflite for a lightweight execution environment.
f. Model Conversion & Testing Utilities:
- Scripts like model_conversion.py for converting to tflite and separate testing scripts (h5_test.py, tflite_test.py) to validate model performance.

- Clear labels for every component or module.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User / Client Interface"
        A1["Assessment Page"]:::client
        A2["Homepage"]:::client
    end

    subgraph "Prediction Pipeline"
        B["Flask API"]:::api
        C["Model Loading & Preprocessing"]:::preprocessing

        subgraph "Neural Network Module"
            D1["NN Model (.h5)"]:::inference
            D2["NN Model (tflite)"]:::inference
        end

        E["Random Forest Module"]:::inference
        F["Meta-Model Integration"]:::inference
    end

    subgraph "Deployment Options"
        G["AWS Lambda Deployment"]:::deployment
    end

    subgraph "Model Conversion & Testing"
        H1["Model Conversion"]:::utilities
        H2["H5 Test"]:::utilities
        H3["TFLite Test"]:::utilities
    end

    %% Data Flow Arrows
    A1 -->|"HTTP_POST"| B
    A2 -->|"HTTP_POST"| B
    B --> C
    C -- "Preprocessed_Data" --> D1
    C -- "Preprocessed_Data" --> D2
    C -- "Preprocessed_Data" --> E
    D1 --> F
    E --> F
    F -->|"Final_Prediction"| B
    B -->|"Response"| A1
    B -->|"Response"| A2

    %% AWS Lambda Branch
    D2 --> G
    H1 --> G

    %% Class Definitions for Color Coding
    classDef client fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef api fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef preprocessing fill:#FFFACD,stroke:#000,stroke-width:1px;
    classDef inference fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef deployment fill:#DDA0DD,stroke:#000,stroke-width:1px;
    classDef utilities fill:#E6E6FA,stroke:#000,stroke-width:1px;

    %% Click Events
    click A1 "https://github.com/eldrago12/restorease/blob/main/assessment.html"
    click A2 "https://github.com/eldrago12/restorease/blob/main/homepage.html"
    click B "https://github.com/eldrago12/restorease/blob/main/app.py"
    click C "https://github.com/eldrago12/restorease/blob/main/final.py"
    click D1 "https://github.com/eldrago12/restorease/blob/main/model/neural.h5"
    click D2 "https://github.com/eldrago12/restorease/blob/main/model/neural.tflite"
    click E "https://github.com/eldrago12/restorease/blob/main/model/rf_model.pkl"
    click F "https://github.com/eldrago12/restorease/blob/main/model/optim.pkl"
    click G "https://github.com/eldrago12/restorease/blob/main/model/neural.tflite"
    click H1 "https://github.com/eldrago12/restorease/blob/main/model_conversion.py"
    click H2 "https://github.com/eldrago12/restorease/blob/main/h5_test.py"
    click H3 "https://github.com/eldrago12/restorease/blob/main/tflite_test.py"
```
