# ashishchourasia17/ai-medical-diagnosis architecture

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

- Interactive diagram: https://gitdiagram.com/ashishchourasia17/ai-medical-diagnosis
- Repository: https://github.com/ashishchourasia17/ai-medical-diagnosis

## Overview

##### Main Components
- App Layer (User Interface/API):
- Folder: app
- Files: app.py and utils.py
- Role: Likely the entry point for user requests (e.g., a REST API or a web-based interface) that interact with the diagnosis service.
- Data Layer:
- Folder: data
- Files: Multiple CSV files representing raw datasets for different medical conditions.
- Role: Contain the raw data used for training the models and possibly for on-the-fly predictions.
- Model Management & Training:
- Folder: models
- Files: Saved model objects (with .sav extension) and training scripts for each disease (e.g., train_diabetes.py, train_heart_disease.py, etc.).
- Role: Manage the machine learning models, including training routines and storing the resulting models.
- Preprocessing & Training Pipeline:
- Folder: src
- Files: preprocess.py and train_model.py
- Role: Contain the core logic for data preprocessing and additional training routines that either support or complement the models in the models folder.

##### Understand the Interactions and Data Flow
- User requests enter via the App Layer (app/app.py), which calls utility functions (app/utils.py) to parse requests and possibly prepare data.
- The system accesses raw data from the Data Layer for either training or inference.
- Preprocessing is conducted by components in the src directory (e.g., preprocess.py) to clean and prepare the input data.
- Trained models are stored in the Models folder; during inference, the App Layer loads these models to make diagnoses.
- Training pipelines exist in both the models directory (individual training scripts) and in src/train_model.py for more general model training tasks, indicating a flexible modular training setup.

##### Key Architectural Patterns and Integration Points
- Separation of concerns: The project cleanly separates data handling, model training, and application logic.
- Modular design: Different modules are responsible for different diagnoses (each disease has its own model and training script).
- Pipeline pattern: Data flows from raw CSVs to preprocessing, then to training, and finally to inference via the loaded models.
- Possible API Gateway: The app might serve as an endpoint that abstracts the complexity of multiple models behind a unified service.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface / API Layer
    subgraph "User Interface / API Layer"
        A1["API Endpoint (app.py)"]:::ui
        A2["Utility Functions (utils.py)"]:::ui
    end

    %% Data Store (CSV Files)
    subgraph "Data Store (CSV Files)"
        D1["Diabetes Data (diabetes.csv)"]:::data
        D2["HeartDisease Data (heart_disease.csv)"]:::data
        D3["Hypothyroid Data (hypothyroid.csv)"]:::data
        D4["LungCancer Data (lung_cancer.csv)"]:::data
        D5["Parkinsons Data (parkinsons.csv)"]:::data
        D6["Thyroid Data (thyroid.csv)"]:::data
    end

    %% Processing Pipeline
    subgraph "Processing Pipeline"
        P1["Preprocessing Module (preprocess.py)"]:::process
        P2["Training Pipeline (train_model.py)"]:::process
    end

    %% Model Management & Training
    subgraph "Model Management & Training"
        subgraph "Disease-specific Training Scripts"
            T1["Train Diabetes (train_diabetes.py)"]:::model
            T2["Train HeartDisease (train_heart_disease.py)"]:::model
            T3["Train LungCancer (train_lung_cancer.py)"]:::model
            T4["Train Parkinsons (train_parkinsons.py)"]:::model
            T5["Train Thyroid (train_thyroid.py)"]:::model
        end
        subgraph "Saved Model Objects"
            S1["Diabetes Model (diabetes_model.sav)"]:::model
            S2["HeartDisease Model (heart_disease_model.sav)"]:::model
            S3["LungCancer Model (lung_cancer_model.sav)"]:::model
            S4["Parkinsons Model (parkinsons_model.sav)"]:::model
            S5["Thyroid Model (thyroid_model.sav)"]:::model
        end
        MI["Model Inference Engine"]:::model
    end

    %% Connections from UI and Data to Preprocessing
    A1 -->|"receivesRequest"| P1
    A2 --> P1
    D1 --> P1
    D2 --> P1
    D3 --> P1
    D4 --> P1
    D5 --> P1
    D6 --> P1

    %% Data flow from Preprocessing to Training Pipeline
    P1 -->|"preprocessedData"| P2
    D1 --> P2
    D2 --> P2
    D3 --> P2
    D4 --> P2
    D5 --> P2
    D6 --> P2

    %% Training Pipeline triggering training scripts
    P2 -->|"trainsModel"| T1
    P2 --> T2
    P2 --> T3
    P2 --> T4
    P2 --> T5

    %% Training Scripts produce Saved Models
    T1 --> S1
    T2 --> S2
    T3 --> S3
    T4 --> S4
    T5 --> S5

    %% Saved Models feed into the Model Inference Engine
    S1 --> MI
    S2 --> MI
    S3 --> MI
    S4 --> MI
    S5 --> MI

    %% UI calls Model Inference for predictions
    A1 -->|"inferenceCall"| MI
    MI -->|"returnsDiagnosis"| A1

    %% Click Events for App Layer
    click A1 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/app/app.py"
    click A2 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/app/utils.py"

    %% Click Events for Data Layer
    click D1 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/data/diabetes.csv"
    click D2 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/data/heart_disease.csv"
    click D3 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/data/hypothyroid.csv"
    click D4 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/data/lung_cancer.csv"
    click D5 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/data/parkinsons.csv"
    click D6 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/data/thyroid.csv"

    %% Click Events for Processing Pipeline
    click P1 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/src/preprocess.py"
    click P2 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/src/train_model.py"

    %% Click Events for Disease-specific Training Scripts
    click T1 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/models/train_diabetes.py"
    click T2 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/models/train_heart_disease.py"
    click T3 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/models/train_lung_cancer.py"
    click T4 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/models/train_parkinsons.py"
    click T5 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/models/train_thyroid.py"

    %% Click Events for Saved Model Objects
    click S1 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/models/diabetes_model.sav"
    click S2 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/models/heart_disease_model.sav"
    click S3 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/models/lung_cancer_model.sav"
    click S4 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/models/parkinsons_model.sav"
    click S5 "https://github.com/ashishchourasia17/ai-medical-diagnosis/blob/main/models/thyroid_model.sav"

    %% Styles
    classDef ui fill:#FCE4EC,stroke:#AD1457,stroke-width:2px;
    classDef data fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef process fill:#C8E6C9,stroke:#1B5E20,stroke-width:2px;
    classDef model fill:#FFE0B2,stroke:#E65100,stroke-width:2px;
```
