# praneetb2929/ai-medical-diagnosis-system architecture

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

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

## Overview

This repository is a chest-X-ray pneumonia classifier with a FastAPI prediction API and separate model-training and evaluation workflows. The documented dataset is the Kaggle Chest X-Ray Images (Pneumonia) dataset. The README does not describe a user interface; links to one are omitted. Training weights are loaded and saved by the code but are not present in the tree, so they are represented as external artifacts.

Main entry points: [`app/main.py`](https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/app/main.py) (FastAPI endpoints), [`data-pipeline/preprocessing.py`](https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/data-pipeline/preprocessing.py) (Load and transform data), [`models/baseline_cnn.py`](https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/models/baseline_cnn.py) (Train baseline CNN), [`models/transfer_learning.py`](https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/models/transfer_learning.py) (Train DenseNet)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_preprocessing["Load and transform data<br/>[preprocessing.py]"]
  node_split["Validation split utility<br/>[fix_val_split.py]"]
end

subgraph group_training["Model training"]
  node_baseline_train["Train baseline CNN<br/>[baseline_cnn.py]"]
  node_densenet_train["Train DenseNet"]
  node_baseline_model["Baseline CNN<br/>[baseline_cnn.py]"]
  node_densenet_model["DenseNet121"]
end

subgraph group_analysis["Evaluation and explanation"]
  node_evaluation["Metrics and ROC evaluation<br/>[evaluate_model.py]"]
  node_offline_cam["Grad-CAM visualization<br/>[gradcam_viz.py]"]
end

subgraph group_serving["Prediction API"]
  node_api["FastAPI endpoints<br/>[main.py]"]
  node_image_prep["Inference image transform<br/>[main.py]"]
  node_inference["Dual-model inference<br/>[main.py]"]
  node_cam_overlay["Prediction heatmaps<br/>[main.py]"]
  node_metrics["Reported metrics<br/>[main.py]"]
end

node_user(("Image user"))
node_dataset[("Chest X-ray dataset")]
node_weights["Saved model weights"]
node_result["Predictions and overlays"]

node_dataset -->|"provides images"| node_preprocessing
node_dataset -.->|"source split"| node_split
node_split -->|"moves validation images"| node_dataset
node_preprocessing -->|"provides loaders"| node_baseline_train
node_preprocessing -->|"provides loaders"| node_densenet_train
node_baseline_train -->|"trains"| node_baseline_model
node_densenet_train -->|"trains"| node_densenet_model
node_baseline_train -->|"saves baseline weights"| node_weights
node_densenet_train -->|"saves DenseNet weights"| node_weights
node_preprocessing -->|"provides test loader"| node_evaluation
node_weights -->|"loads DenseNet weights"| node_evaluation
node_preprocessing -->|"provides test loader"| node_offline_cam
node_weights -->|"loads DenseNet weights"| node_offline_cam
node_user -->|"uploads X-ray"| node_api
node_api -->|"decodes image"| node_image_prep
node_image_prep -->|"supplies tensor"| node_inference
node_weights -->|"loads both models"| node_api
node_api -->|"runs prediction"| node_inference
node_inference -->|"generates heatmaps"| node_cam_overlay
node_api -->|"serves metrics"| node_metrics
node_api -->|"returns response"| node_result
node_inference -->|"supplies predictions"| node_result
node_cam_overlay -->|"supplies overlays"| node_result
node_user -->|"receives response"| node_result

click node_preprocessing "https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/data-pipeline/preprocessing.py"
click node_split "https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/data-pipeline/fix_val_split.py"
click node_baseline_train "https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/models/baseline_cnn.py"
click node_densenet_train "https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/models/transfer_learning.py"
click node_baseline_model "https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/models/baseline_cnn.py"
click node_densenet_model "https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/models/transfer_learning.py"
click node_evaluation "https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/models/evaluate_model.py"
click node_offline_cam "https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/models/gradcam_viz.py"
click node_api "https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/app/main.py"
click node_image_prep "https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/app/main.py"
click node_inference "https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/app/main.py"
click node_cam_overlay "https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/app/main.py"
click node_metrics "https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/app/main.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_preprocessing,node_split,node_user toneBlue
class node_baseline_train,node_densenet_train,node_baseline_model,node_densenet_model,node_dataset toneAmber
class node_evaluation,node_offline_cam toneMint
class node_api,node_image_prep,node_inference,node_cam_overlay,node_metrics toneRose
class node_weights,node_result toneIndigo
```

## Components

### Data preparation

- [Load and transform data](https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/data-pipeline/preprocessing.py): `data-pipeline/preprocessing.py`
- [Validation split utility](https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/data-pipeline/fix_val_split.py): `data-pipeline/fix_val_split.py`

### Model training

- [Train baseline CNN](https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/models/baseline_cnn.py): `models/baseline_cnn.py`
- [Train DenseNet](https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/models/transfer_learning.py): `models/transfer_learning.py`
- [Baseline CNN](https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/models/baseline_cnn.py): `models/baseline_cnn.py`
- [DenseNet121](https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/models/transfer_learning.py): `models/transfer_learning.py`

### Evaluation and explanation

- [Metrics and ROC evaluation](https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/models/evaluate_model.py): `models/evaluate_model.py`
- [Grad-CAM visualization](https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/models/gradcam_viz.py): `models/gradcam_viz.py`

### Prediction API

- [FastAPI endpoints](https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/app/main.py): `app/main.py`
- [Inference image transform](https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/app/main.py): `app/main.py`
- [Dual-model inference](https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/app/main.py): `app/main.py`
- [Prediction heatmaps](https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/app/main.py): `app/main.py`
- [Reported metrics](https://github.com/praneetb2929/ai-medical-diagnosis-system/blob/main/app/main.py): `app/main.py`

### Other components

- **Image user**
- **Chest X-ray dataset**
- **Saved model weights**
- **Predictions and overlays**

## Connections

- Chest X-ray dataset → Load and transform data: provides images
- Chest X-ray dataset → Validation split utility: source split
- Validation split utility → Chest X-ray dataset: moves validation images
- Load and transform data → Train baseline CNN: provides loaders
- Load and transform data → Train DenseNet: provides loaders
- Train baseline CNN → Baseline CNN: trains
- Train DenseNet → DenseNet121: trains
- Train baseline CNN → Saved model weights: saves baseline weights
- Train DenseNet → Saved model weights: saves DenseNet weights
- Load and transform data → Metrics and ROC evaluation: provides test loader
- Saved model weights → Metrics and ROC evaluation: loads DenseNet weights
- Load and transform data → Grad-CAM visualization: provides test loader
- Saved model weights → Grad-CAM visualization: loads DenseNet weights
- Image user → FastAPI endpoints: uploads X-ray
- FastAPI endpoints → Inference image transform: decodes image
- Inference image transform → Dual-model inference: supplies tensor
- Saved model weights → FastAPI endpoints: loads both models
- FastAPI endpoints → Dual-model inference: runs prediction
- Dual-model inference → Prediction heatmaps: generates heatmaps
- FastAPI endpoints → Reported metrics: serves metrics
- FastAPI endpoints → Predictions and overlays: returns response
- Dual-model inference → Predictions and overlays: supplies predictions
- Prediction heatmaps → Predictions and overlays: supplies overlays
- Image user → Predictions and overlays: receives response
