# sayamkhatri/kidney-disease-detection-ml-application architecture

> Architecture diagram of the GitHub repository sayamkhatri/kidney-disease-detection-ml-application, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sayamkhatri/kidney-disease-detection-ml-application
- Repository: https://github.com/sayamkhatri/kidney-disease-detection-ml-application

## Overview

##### Project Type and Purpose
- This is an end-to-end machine learning (ML) application focused on predicting kidney disease. It covers the complete ML lifecycle—from data ingestion and preprocessing, through model training/evaluation, to deployment.
- The application is built with modularity in mind and integrates MLOps practices using tools like DVC for data version control, MLflow for experiment tracking, and Docker & GitHub Actions for deployment and CI/CD.

##### File Structure
- Key top-level directories:
- .dvc, dvc.yaml, params.yaml: Indicate the use of DVC for managing data and ML pipelines.
- mlruns: Contains MLflow experiment logs (tracking model runs, metrics, and parameters).
- config: Contains configuration files (static and dynamic settings).
- model: Where the serialized trained model (model.h5) is stored.
- research: Jupyter notebooks documenting data ingestion, model preparation, and experiments.
- src/mypackage: Contains the application’s core logic including subdirectories for components (data ingestion, model training/evaluation), configuration, constants, entities, pipelines which suggest a well-structured pipeline-based architecture.
- templates and app.py: Define the web front-end using Flask for serving results or providing UI.
- Other files like dockerfile and GitHub Actions workflows indicate containerization and CI/CD integration.

##### Components and Their Interactions
- Frontend / Deployment Layer:
- Component: Flask Web Application (app.py) and HTML templates (templates/)
- Role: Exposes the ML results and possibly user interactions.
- ML Pipeline Core:
- Data Ingestion Component (src/mypackage/components/data_ingestion.py and corresponding pipeline stage in stage_01_data_ingestion.py)
- Base Model Preparation (src/mypackage/components/prepare_base_model.py and stage_02_base_model.py)
- Model Training (src/mypackage/components/model_training.py and stage_03_model_training.py)
- Model Evaluation (src/mypackage/components/model_eval.py and stage_04_model_eval.py)
- Experiment and Model Management:
- MLflow (directory: mlruns) for logging experiments, metrics, parameter values, and run information.
- Model Storage (model/model.h5) for saving the trained model.
- Configuration and Control:
- Configurations stored in config folder and src/mypackage/config help manage environment settings, hyperparameters, and pipeline configurations.
- DVC (files: .dvc, dvc.yaml, params.yaml) used to track data versions and manage ML pipeline stages.
- Infrastructure and DevOps:
- CI/CD via GitHub Actions located in .github/workflows (automating testing/build, etc.).
- Containerization with Docker (dockerfile) ensuring the application is portable and easily deployable.

##### Architectural Patterns and Design Principles
- Modular Pipeline Architecture: The separation of components under src/mypackage (components, pipeline, config) underlines a clean separation of concerns for data ingestion, training, and evaluation stages.
- MLOps Best Practices: Integration of MLflow and DVC for reproducibility, experiment tracking, and managing data/model versions.
- Containerization and CI/CD: Use of Docker and GitHub Actions enable continuous integration, deployment, and consistent deployment environments.

##### Final Assembly
- Data and Configuration (DVC, params.yaml, config/)
- ML Pipeline (Broken into clear stages/components)
- Experiment Logging (MLflow and model storage)
- Web Service (Flask app)
- Infrastructure and Automation (Docker, GitHub Actions)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration & Data Management
    subgraph "Configuration & Data Management"
        A1("DVC Pipeline (.dvc, dvc.yaml, params.yaml)"):::dvc
        A2("Configuration (config/)"):::config
        A3("App Config (src/mypackage/config)"):::config
    end

    %% ML Pipeline: Data Ingestion
    subgraph "Data Ingestion"
        DI1("Component: data_ingestion.py"):::ml
        DI2("Pipeline: stage_01_data_ingestion.py"):::ml
        DI3("Research: data_ingestion.ipynb"):::research
    end

    %% ML Pipeline: Base Model Preparation
    subgraph "Base Model Preparation"
        BM1("Component: prepare_base_model.py"):::ml
        BM2("Pipeline: stage_02_base_model.py"):::ml
        BM3("Research: prepare_base_model.ipynb"):::research
    end

    %% ML Pipeline: Model Training
    subgraph "Model Training"
        MT1("Component: model_training.py"):::ml
        MT2("Pipeline: stage_03_model_training.py"):::ml
    end

    %% ML Pipeline: Model Evaluation
    subgraph "Model Evaluation"
        ME1("Component: model_eval.py"):::ml
        ME2("Pipeline: stage_04_model_eval.py"):::ml
    end

    %% Experiment Tracking & Model Storage
    subgraph "Experiment Tracking & Model Storage"
        C1("MLflow (mlruns)"):::mlflow
        C2("Model Storage (model/model.h5)"):::modelstorage
    end

    %% Frontend Deployment
    subgraph "Frontend Deployment"
        D1("Flask Application (app.py)"):::frontend
        D2("Templates (templates/)"):::frontend
    end

    %% CI/CD & Containerization
    subgraph "CI/CD & Containerization"
        E1("GitHub Actions (.github/workflows)"):::cicd
        E2("Docker (dockerfile)"):::cicd
    end

    %% Connections from Configuration to ML Pipeline
    A1 -->|"feeds"| DI1
    A2 -->|"configures"| DI1
    A3 -->|"configures"| DI1

    %% ML Pipeline Flow
    DI1 --> DI2
    DI2 --> DI3
    DI3 --> BM1
    BM1 --> BM2
    BM2 --> BM3
    BM3 --> MT1
    MT1 --> MT2
    MT2 --> ME1
    ME1 --> ME2

    %% Flow to Experiment Tracking and Frontend
    ME2 -->|"logs output"| C1
    ME2 -->|"saves model"| C2
    ME2 -->|"serves predictions"| D1

    %% CI/CD & Containerization influences Frontend Deployment
    E1 -->|"deploys"| D1
    E2 -->|"containers"| D1

    %% Class Definitions
    classDef dvc fill:#FFCCCC,stroke:#AA0000,stroke-width:2px;
    classDef config fill:#CCFFCC,stroke:#006600,stroke-width:2px;
    classDef ml fill:#CCE5FF,stroke:#004080,stroke-width:2px;
    classDef research fill:#FFFFCC,stroke:#CCCC00,stroke-width:2px;
    classDef mlflow fill:#E6CCFF,stroke:#660099,stroke-width:2px;
    classDef modelstorage fill:#FFEBCC,stroke:#B8860B,stroke-width:2px;
    classDef frontend fill:#CCFFFF,stroke:#008B8B,stroke-width:2px;
    classDef cicd fill:#D3D3D3,stroke:#696969,stroke-width:2px;

    %% Click Events
    click A1 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/blob/main/.dvc"
    click A2 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/tree/main/config/"
    click A3 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/tree/main/src/mypackage/config/"
    click DI1 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/blob/main/src/mypackage/components/data_ingestion.py"
    click DI2 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/blob/main/src/mypackage/pipeline/stage_01_data_ingestion.py"
    click DI3 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/blob/main/research/data_ingestion.ipynb"
    click BM1 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/blob/main/src/mypackage/components/prepare_base_model.py"
    click BM2 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/blob/main/src/mypackage/pipeline/stage_02_base_model.py"
    click BM3 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/blob/main/research/prepare_base_model.ipynb"
    click MT1 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/blob/main/src/mypackage/components/model_training.py"
    click MT2 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/blob/main/src/mypackage/pipeline/stage_03_model_training.py"
    click ME1 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/blob/main/src/mypackage/components/model_eval.py"
    click ME2 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/blob/main/src/mypackage/pipeline/stage_04_model_eval.py"
    click C1 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/tree/main/mlruns/"
    click C2 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/blob/main/model/model.h5"
    click D1 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/blob/main/app.py"
    click D2 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/tree/main/templates/"
    click E1 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/tree/main/.github/workflows/"
    click E2 "https://github.com/sayamkhatri/kidney-disease-detection-ml-application/tree/main/dockerfile"
```
