# t-k-234/eyedis-using-ensemle-learning architecture

> Architecture diagram of the GitHub repository t-k-234/eyedis-using-ensemle-learning, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-03-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/t-k-234/eyedis-using-ensemle-learning
- Repository: https://github.com/t-k-234/eyedis-using-ensemle-learning

## Overview

##### What this project is (type + purpose)
This repo is a **Flask-based web application** that:
- Serves HTML pages (Jinja templates in `templates/`, assets in `static/`)
- Accepts **file uploads** (retinal images and/or PDFs) into `uploads/`
- Runs **ML inference** using pre-trained model artifacts (`main_model.h5`, `model_eye.h5`) to classify eye disease
- Produces a **human-readable summary/report** and stores outputs in `summaries/`
- Uses a local **SQLite database** (`users.db`, `db.py`) for user/auth or basic persistence

The README describes an ensemble (CNN/ResNet/Swin) trained with PyTorch/TensorFlow; the repo structure indicates that **training is mostly offline** (e.g., `pytorch_resnet18.ipynb`), while the deployed web app loads **ready-to-serve model files** (`.h5`) for runtime inference.

- **Runtime web system** (Flask + DB + inference + storage)
- **Offline ML training pipeline** (notebook → model artifacts → deployed to app)

##### File tree to architectural building blocks
Use the tree to drive the decomposition into as many components as possible (don’t overthink—split by responsibility):

##### Runtime / Serving
- **Web Server / App**
- `app.py` → Flask routes, request handling, page rendering, upload endpoints, inference trigger
- **Database Layer**
- `db.py` + `users.db` → SQLite access, likely users/login/register state
- **Model Artifacts**
- `main_model.h5`, `model_eye.h5` → TensorFlow/Keras models loaded by the Flask app at startup or per request
- **HTML Views (UI)**
- `templates/*.html` → pages like login/register/home, disease detection pages (`dect.html`, `indexeye.html`), summarization page (`sum.html`)
- **Static Assets**
- `static/css/*`, `static/js/*`, `static/img/*` → styling and client-side behavior
- **File Storage**
- `uploads/*` → raw user uploaded files
- `summaries/*` → generated summaries / result PDFs

##### Offline / Training (should be shown as separate “pipeline”)
- `pytorch_resnet18.ipynb` → training/experiments; produces a model that is eventually exported/converted to deployment format (represented as `.h5` in this repo)

##### Flask Web App (Python)
- Route/controller layer (in `app.py`)
- Template rendering (Jinja + `templates/`)
##### Auth/User Data Store
- SQLite (`users.db`) accessed via `db.py`
##### ML Inference Subsystem
- Model loader (loads `.h5`)
- Preprocessing (OpenCV/NumPy; implied by README)
- Predictor (classification)
- Post-processing (label mapping, confidence)
##### Report/Summary Generator
- Generates short text explanation
- Writes output artifact(s) into `summaries/`
##### File Storage
- Upload directory (`uploads/`) for inputs
- Summaries directory (`summaries/`) for outputs

Optional but accurate to include (since it’s in repo/README):
##### Offline Training Environment
- Notebook (`pytorch_resnet18.ipynb`) + dataset (external Kaggle)
- Outputs: trained weights → exported `.h5` → copied into runtime

**(1) Authentication flow**
- Browser → Flask: `GET /login`, `POST /login`, `GET/POST /register`
- Flask ↔ SQLite: create user / validate credentials
- Flask → Browser: rendered HTML (`templates/login.html`, `templates/register.html`)

**(2) Inference flow (retinal image classification)**
- Browser → Flask: `POST` upload retinal image (multipart form)
- Flask → File Storage: write file to `uploads/`
- Flask → ML Inference: preprocess image → run model(s) (`main_model.h5` / `model_eye.h5`)
- ML Inference → Flask: predicted class (+ optional probabilities)
- Flask → Report/Summary Generator: build explanation text (disease info)
- Report/Summary Generator → File Storage: write summary artifact to `summaries/`
- Flask → Browser: render results page (`templates/dect.html` / `templates/sum.html` / `templates/indexeye.html` depending on routing)

**(3) Static content flow**
- Browser → Flask (or direct static serving): `static/css`, `static/js`

**(4) Offline training → deployment flow**
- Kaggle Dataset → Training Notebook (`pytorch_resnet18.ipynb`)
- Notebook → Model Artifact(s): exported weights (represented as `.h5` files here)
- Model Artifact(s) → Flask runtime: loaded at startup for inference

##### Architectural patterns to highlight (specific to this repo)
- **Monolithic Flask app**: all runtime logic (routing + inference + summary + persistence) is in one deployable unit (`app.py` + local assets)
- **Server-side rendered UI**: Jinja templates, not a SPA
- **Local persistence**: SQLite file DB (`users.db`)
- **File-system backed object storage**: uploads and summaries stored on disk (`uploads/`, `summaries/`)
- **ML inference as an internal library/module**: not separated into a microservice (so show it as a component inside the Flask container)

##### Concrete labeling based on THIS repository (use these names)

- “Flask App (`app.py`)"
- “DB Access Layer (`db.py`)"
- “SQLite DB (`users.db`)"
- “Templates (`templates/*.html`)"
- “Static Assets (`static/`)"
- “Uploaded Inputs (`uploads/`)"
- “Generated Summaries (`summaries/`)"
- “Model Artifacts (`main_model.h5`, `model_eye.h5`)"
- “Training Notebook (`pytorch_resnet18.ipynb`)" + “External Dataset (Kaggle)”

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% =========================
    %% System Context
    %% =========================
    subgraph "System Context"
        U["User (Patient/Clinician)\nBrowser"]:::runtime
        APP_SYS["Eye Disease Classification + Report Web App\n(Flask + ML Inference + SQLite)"]:::runtime
        KAG["External Dataset\n(Kaggle)"]:::external
    end

    U -->|"HTTP(S) requests\n(login/upload/results)"| APP_SYS

    %% =========================
    %% Runtime / Serving (Monolith)
    %% =========================
    subgraph "Runtime / Serving"
        direction TB

        subgraph "Flask Web App (Python)"
            direction TB

            ROUTES["Flask App\nRoutes/Controllers\n(app.py)"]:::runtime

            subgraph "UI Delivery (Server-side Rendered)"
                direction TB
                TEMPL["Templates\n(templates/*.html)"]:::ui
                LOGIN["login.html"]:::ui
                REG["register.html"]:::ui
                HOME["home/index/main.html"]:::ui
                DETECT["dect/indexeye.html"]:::ui
                SUMUI["sum.html"]:::ui

                STATIC["Static Assets\n(static/)"]:::ui
                CSS["CSS\n(static/css/)"]:::ui
                JS["JavaScript\n(static/js/)"]:::ui
            end

            subgraph "Persistence"
                direction TB
                DBL["DB Access Layer\n(db.py)"]:::service
                SQLITE[("SQLite DB\n(users.db)")]:::datastore
            end

            subgraph "File Storage (Local FS)"
                direction TB
                UPLOADS[("Uploaded Inputs\n(uploads/)")]:::datastore
                SUMMARIES[("Generated Summaries\n(summaries/)")]:::datastore
            end

            subgraph "ML Inference Subsystem (Internal)"
                direction TB
                PRE["Preprocessing\n(OpenCV/NumPy)"]:::ml
                LOADER["Model Loader\n(TensorFlow/Keras)"]:::ml
                PRED["Predictor\n(Classification)"]:::ml
                POST["Post-processing\n(Label+Confidence)"]:::ml

                MODELS["Model Artifacts\n(.h5 files)"]:::artifact
                MAINH5["main_model.h5"]:::artifact
                EYEH5["model_eye.h5"]:::artifact
            end

            subgraph "Report/Summary Generator"
                direction TB
                REPORT["Generate Summary/Report\n(human-readable)"]:::service
            end
        end
    end

    %% Tie context app to concrete runtime entry
    APP_SYS -->|"handles requests"| ROUTES

    %% Authentication flow
    ROUTES -->|"GET/POST /login\nrender template"| LOGIN
    ROUTES -->|"GET/POST /register\nrender template"| REG
    ROUTES -->|"validate credentials\nSQL queries"| DBL
    DBL -->|"Read/Write user record\n(SQL)"| SQLITE

    %% Main UI rendering
    ROUTES -->|"render pages"| TEMPL
    TEMPL -->|"includes"| HOME
    TEMPL -->|"includes"| DETECT
    TEMPL -->|"includes"| SUMUI

    %% Static content flow
    U -->|"GET /static/*"| STATIC
    STATIC -->|"serve"| CSS
    STATIC -->|"serve"| JS

    %% Inference flow (upload -> predict -> summary -> result)
    U -->|"HTTP POST /upload\n(multipart image/PDF)"| ROUTES
    ROUTES -->|"write file"| UPLOADS
    ROUTES -->|"trigger inference\n(file path/bytes)"| PRE
    PRE -->|"image tensor"| LOADER
    LOADER -->|"load weights\n(.h5)"| MODELS
    MODELS -->|"contains"| MAINH5
    MODELS -->|"contains"| EYEH5
    LOADER -->|"model session"| PRED
    PRED -->|"raw prediction"| POST
    POST -->|"predicted class\n+confidence"| ROUTES
    ROUTES -->|"build explanation request\n(prediction+metadata)"| REPORT
    REPORT -->|"write summary artifact\n(text/PDF)"| SUMMARIES
    ROUTES -->|"render results page\n(dect/sum/indexeye)"| DETECT
    ROUTES -->|"render report page\n(sum)"| SUMUI
    ROUTES -->|"HTTP response\n(HTML)"| U

    %% =========================
    %% Offline / Training Pipeline
    %% =========================
    subgraph "Offline / Training Pipeline (Not in runtime request path)"
        direction TB
        NB["Training Notebook\n(pytorch_resnet18.ipynb)"]:::offline
        EXPORT["Export/Convert Trained Weights\n(to deployment format)"]:::offline
    end

    KAG -.->|"download dataset"| NB
    NB -.->|"train/experiment"| EXPORT
    EXPORT -.->|"produce model artifacts\n(.h5)"| MAINH5
    EXPORT -.->|"produce model artifacts\n(.h5)"| EYEH5

    %% =========================
    %% Click Events (from component mapping)
    %% =========================
    click ROUTES "https://github.com/t-k-234/eyedis-using-ensemle-learning/blob/main/app.py"
    click DBL "https://github.com/t-k-234/eyedis-using-ensemle-learning/blob/main/db.py"
    click SQLITE "https://github.com/t-k-234/eyedis-using-ensemle-learning/blob/main/users.db"
    click MAINH5 "https://github.com/t-k-234/eyedis-using-ensemle-learning/blob/main/main_model.h5"
    click EYEH5 "https://github.com/t-k-234/eyedis-using-ensemle-learning/blob/main/model_eye.h5"
    click TEMPL "https://github.com/t-k-234/eyedis-using-ensemle-learning/tree/main/templates/"
    click LOGIN "https://github.com/t-k-234/eyedis-using-ensemle-learning/blob/main/templates/login.html"
    click REG "https://github.com/t-k-234/eyedis-using-ensemle-learning/blob/main/templates/register.html"
    click HOME "https://github.com/t-k-234/eyedis-using-ensemle-learning/blob/main/templates/home.html"
    click DETECT "https://github.com/t-k-234/eyedis-using-ensemle-learning/blob/main/templates/dect.html"
    click SUMUI "https://github.com/t-k-234/eyedis-using-ensemle-learning/blob/main/templates/sum.html"
    click STATIC "https://github.com/t-k-234/eyedis-using-ensemle-learning/tree/main/static/"
    click CSS "https://github.com/t-k-234/eyedis-using-ensemle-learning/tree/main/static/css/"
    click JS "https://github.com/t-k-234/eyedis-using-ensemle-learning/tree/main/static/js/"
    click UPLOADS "https://github.com/t-k-234/eyedis-using-ensemle-learning/tree/main/uploads/"
    click SUMMARIES "https://github.com/t-k-234/eyedis-using-ensemle-learning/tree/main/summaries/"
    click NB "https://github.com/t-k-234/eyedis-using-ensemle-learning/blob/main/pytorch_resnet18.ipynb"

    %% =========================
    %% Styles
    %% =========================
    classDef runtime fill:#1f77b4,stroke:#0b3d91,color:#ffffff,stroke-width:1.5px
    classDef service fill:#2c3e50,stroke:#1b2836,color:#ffffff,stroke-width:1.2px
    classDef ui fill:#4aa3df,stroke:#1b6a99,color:#ffffff,stroke-width:1.2px
    classDef datastore fill:#2ecc71,stroke:#1f8f4d,color:#053b1a,stroke-width:1.5px
    classDef ml fill:#f39c12,stroke:#b36b00,color:#3a2400,stroke-width:1.5px
    classDef artifact fill:#f8c471,stroke:#b9770e,color:#3a2400,stroke-width:1.2px
    classDef offline fill:#95a5a6,stroke:#5f6a6a,color:#1f2d2d,stroke-width:1.2px,stroke-dasharray: 6 4
    classDef external fill:#7f8c8d,stroke:#4d5656,color:#ffffff,stroke-width:1.2px,stroke-dasharray: 4 3
```
