# adourian/diabetes-prediction-tool architecture

> Architecture diagram of the GitHub repository adourian/diabetes-prediction-tool, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adourian/diabetes-prediction-tool
- Repository: https://github.com/adourian/diabetes-prediction-tool

## Overview

##### Project Type and Purpose
- This is a monolithic, Python-based web application built with Streamlit.
- It serves a single purpose: real-time inference—loading pre-trained ML models, accepting user inputs, and returning a probability of diabetes.

##### High-Level Architecture Layers
a. Presentation Layer
– Component: Streamlit App (src/main.py)
– Role: Render UI, capture user inputs, display output.
b. Business Logic Layer
– Component: Preprocessing Module (src/preprocessing_data.py)
– Component: Prediction Engine (src/make_predictions.py)
– Component: Helpers (src/helpers.py)
– Role: Clean & transform inputs, invoke ML models, aggregate results.
c. Data & Artifact Layer
– Component: Model Artifacts (models/*.pkl)
– Component: Training Data (data/diabetes.csv) – used offline in notebook.ipynb
– Role: Persist serialized models, scalers, clustering centroids, ensemble weights.

##### Main Components and Their Interactions
1. User Browser
└─ Sends HTTP request (via Streamlit) with feature values.
2. Streamlit App (main.py)
├─ Calls preprocessing_data.clean_and_transform(user_inputs)
├─ Passes transformed features to make_predictions.predict(features)
└─ Renders returned probability back to UI.
3. Preprocessing Module
├─ Loads scaler.pkl, fitted_kmeans.pkl (cluster centroids)
├─ Scales inputs, computes cluster-based features.
└─ Returns feature vector.
4. Prediction Engine
├─ Loads xgb_model.pkl, lgb_model.pkl, lr_model.pkl
├─ Retrieves xgb_params.pkl, lgb_params.pkl, lr_features.pkl, lgb_features.pkl, xgb_features.pkl
├─ Calls each model’s predict_proba(), multiplies by ensemble_weights.pkl
└─ Aggregates weighted predictions → single probability.
5. Model Artifacts Store
└─ Local filesystem folder `models/` containing all .pkl files.
6. (Offline) Notebook
└─ Uses data/diabetes.csv to train models & generate artifacts (not part of runtime).

##### Architectural Patterns and Design Principles
- Layered (Presentation → Logic → Data)
- Separation of concerns:
– UI code (main.py) contains no heavy logic.
– Preprocessing and prediction concerns isolated in their own modules.
- Single-process, single-container deployment (Streamlit server hosting both UI and logic).

##### Essential Details to Capture
- All .pkl files grouped under “Model Artifacts”—show they are loaded at runtime.
- user→UI→preprocessing→models→prediction→UI→user flow must be obvious.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["Streamlit App<br/>src/main.py"]:::ui
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        Pre["Preprocessing Module<br/>src/preprocessing_data.py"]:::logic
        Pred["Prediction Engine<br/>src/make_predictions.py"]:::logic
        Helper["Helpers<br/>src/helpers.py"]:::logic
    end

    %% Data & Artifact Layer
    subgraph "Data & Artifact Layer"
        Artifacts["Model Artifacts<br/>models/"]:::data
        CSV["Training Data<br/>data/diabetes.csv"]:::data
    end

    %% Offline Notebook
    subgraph "Offline Training Notebook" 
        direction TB
        Notebook["notebook.ipynb"]:::offline
    end

    %% User
    User["User Browser"]:::ui

    %% Connections
    User -->|"HTTP Request with features"| UI
    UI -->|"raw inputs"| Pre
    Pre -->|"feature vector"| Pred
    Pred -->|"probability"| UI
    UI -->|"HTTP Response"| User

    %% Dashed artifact loads
    Pre -.->|"load scaler.pkl & fitted_kmeans.pkl"| Artifacts
    Pred -.->|"load models & params"| Artifacts

    %% Offline flows
    Notebook -->|"uses diabetes.csv to train"| CSV
    Notebook -->|"generates .pkl artifacts"| Artifacts

    %% Click Events
    click UI "https://github.com/adourian/diabetes-prediction-tool/blob/main/src/main.py"
    click Pre "https://github.com/adourian/diabetes-prediction-tool/blob/main/src/preprocessing_data.py"
    click Pred "https://github.com/adourian/diabetes-prediction-tool/blob/main/src/make_predictions.py"
    click Helper "https://github.com/adourian/diabetes-prediction-tool/blob/main/src/helpers.py"
    click Artifacts "https://github.com/adourian/diabetes-prediction-tool/tree/main/models/"
    click CSV "https://github.com/adourian/diabetes-prediction-tool/blob/main/data/diabetes.csv"
    click Notebook "https://github.com/adourian/diabetes-prediction-tool/blob/main/notebook.ipynb"

    %% Styles
    classDef ui fill:#D0E7FF,stroke:#0366d6,color:#0366d6;
    classDef logic fill:#DFF5D0,stroke:#228B22,color:#228B22;
    classDef data fill:#FFE7C0,stroke:#FF8C00,color:#FF8C00;
    classDef offline fill:#F0F0F0,stroke:#888888,color:#888888;
```
