# tbachu/pneumoniadetection architecture

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

- Interactive diagram: https://gitdiagram.com/tbachu/pneumoniadetection
- Repository: https://github.com/tbachu/pneumoniadetection

## Overview

PneumoniaDetection combines dataset acquisition and binary or multi-label model training with image inference, Grad-CAM explanations, and a clinical analysis API/dashboard. The principal user workflow is to upload a chest X-ray, receive model findings and visual explanations, and review clinical context in the dashboard. Training, calibration, and evaluation form supporting model-development stages. The API and clinical engine excerpts are partial, so links are limited to documented behavior and visible calls; unsampled endpoint wiring is not expanded.

Main entry points: [`app.py`](https://github.com/tbachu/pneumoniadetection/blob/main/app.py) (FastAPI service), [`modeling.py`](https://github.com/tbachu/pneumoniadetection/blob/main/modeling.py) (Modeling runtime), [`dashboard/app.js`](https://github.com/tbachu/pneumoniadetection/blob/main/dashboard/app.js) (Dashboard logic), [`artifacts`](https://github.com/tbachu/pneumoniadetection/tree/main/artifacts) (Model checkpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_development["Model Development"]
  node_dataset_download["Dataset download<br/>[data_loader.py]"]
  node_binary_training["Binary training<br/>[train.py]"]
  node_multilabel_training["14-label training"]
  node_modeling["Modeling runtime<br/>[modeling.py]"]
  node_checkpoint["Model checkpoint"]
end

subgraph group_clinical["Clinical Analysis"]
  node_calibration["Calibration<br/>[calibrate.py]"]
  node_clinical_eval["Clinical evaluation<br/>[clinical_eval.py]"]
  node_calibration_state["Calibration state"]
  node_clinical_engine["Clinical analysis<br/>[clinical_engine.py]"]
  node_report["Clinical report"]
  node_gradcam_cli["Grad-CAM tool<br/>[gradcam.py]"]
end

subgraph group_service["Prediction Service"]
  node_api["FastAPI service<br/>[app.py]"]
end

subgraph group_interface["Clinician Interface"]
  node_dashboard["Dashboard logic<br/>[app.js]"]
  node_dashboard_page["Dashboard page<br/>[index.html]"]
  node_dashboard_style["Dashboard styling<br/>[styles.css]"]
end

node_clinician(("Clinician"))
node_dataset_provider(("Kaggle dataset"))
node_xray["Chest X-ray"]
node_analysis_result["Analysis response"]

node_dataset_provider -.->|"provides dataset"| node_dataset_download
node_dataset_download -->|"makes data available"| node_binary_training
node_binary_training -->|"trains through"| node_modeling
node_binary_training -->|"saves checkpoint"| node_checkpoint
node_multilabel_training -->|"saves checkpoint"| node_checkpoint
node_calibration -->|"loads model"| node_modeling
node_calibration -->|"writes calibration"| node_calibration_state
node_clinical_eval -->|"loads model"| node_modeling
node_api -->|"loads checkpoint"| node_modeling
node_api -->|"reads checkpoint"| node_checkpoint
node_api -->|"loads calibration"| node_calibration_state
node_api -->|"initializes analyzer"| node_clinical_engine
node_api -->|"analyzes image"| node_clinical_engine
node_clinical_engine -->|"preprocesses and explains"| node_modeling
node_api -->|"formats report"| node_report
node_gradcam_cli -->|"predicts and explains"| node_modeling
node_gradcam_cli -->|"loads checkpoint"| node_checkpoint
node_clinician -->|"uploads image"| node_dashboard
node_dashboard_page -->|"hosts interface"| node_dashboard
node_dashboard -->|"requests analysis"| node_api
node_api -->|"returns findings"| node_analysis_result
node_analysis_result -->|"renders results"| node_dashboard
node_xray -->|"uploaded for analysis"| node_api

click node_dataset_download "https://github.com/tbachu/pneumoniadetection/blob/main/data_loader.py"
click node_binary_training "https://github.com/tbachu/pneumoniadetection/blob/main/train.py"
click node_multilabel_training "https://github.com/tbachu/pneumoniadetection/blob/main/kaggle_multilabel_train.py"
click node_modeling "https://github.com/tbachu/pneumoniadetection/blob/main/modeling.py"
click node_checkpoint "https://github.com/tbachu/pneumoniadetection/tree/main/artifacts"
click node_calibration "https://github.com/tbachu/pneumoniadetection/blob/main/calibrate.py"
click node_clinical_eval "https://github.com/tbachu/pneumoniadetection/blob/main/clinical_eval.py"
click node_calibration_state "https://github.com/tbachu/pneumoniadetection/tree/main/artifacts"
click node_clinical_engine "https://github.com/tbachu/pneumoniadetection/blob/main/clinical_engine.py"
click node_report "https://github.com/tbachu/pneumoniadetection/blob/main/report_generator.py"
click node_gradcam_cli "https://github.com/tbachu/pneumoniadetection/blob/main/gradcam.py"
click node_api "https://github.com/tbachu/pneumoniadetection/blob/main/app.py"
click node_dashboard "https://github.com/tbachu/pneumoniadetection/blob/main/dashboard/app.js"
click node_dashboard_page "https://github.com/tbachu/pneumoniadetection/blob/main/dashboard/index.html"
click node_dashboard_style "https://github.com/tbachu/pneumoniadetection/blob/main/dashboard/styles.css"

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_dataset_download,node_binary_training,node_multilabel_training,node_modeling,node_checkpoint toneBlue
class node_calibration,node_clinical_eval,node_calibration_state,node_clinical_engine,node_report,node_gradcam_cli toneAmber
class node_api toneMint
class node_dashboard,node_dashboard_page,node_dashboard_style toneRose
class node_clinician,node_dataset_provider,node_xray,node_analysis_result toneIndigo
```

## Components

### Model Development

- [Dataset download](https://github.com/tbachu/pneumoniadetection/blob/main/data_loader.py): `data_loader.py`
- [Binary training](https://github.com/tbachu/pneumoniadetection/blob/main/train.py): `train.py`
- [14-label training](https://github.com/tbachu/pneumoniadetection/blob/main/kaggle_multilabel_train.py): `kaggle_multilabel_train.py`
- [Modeling runtime](https://github.com/tbachu/pneumoniadetection/blob/main/modeling.py): `modeling.py`
- [Model checkpoint](https://github.com/tbachu/pneumoniadetection/tree/main/artifacts): `artifacts`

### Clinical Analysis

- [Calibration](https://github.com/tbachu/pneumoniadetection/blob/main/calibrate.py): `calibrate.py`
- [Clinical evaluation](https://github.com/tbachu/pneumoniadetection/blob/main/clinical_eval.py): `clinical_eval.py`
- [Calibration state](https://github.com/tbachu/pneumoniadetection/tree/main/artifacts): `artifacts`
- [Clinical analysis](https://github.com/tbachu/pneumoniadetection/blob/main/clinical_engine.py): `clinical_engine.py`
- [Clinical report](https://github.com/tbachu/pneumoniadetection/blob/main/report_generator.py): `report_generator.py`
- [Grad-CAM tool](https://github.com/tbachu/pneumoniadetection/blob/main/gradcam.py): `gradcam.py`

### Prediction Service

- [FastAPI service](https://github.com/tbachu/pneumoniadetection/blob/main/app.py): `app.py`

### Clinician Interface

- [Dashboard logic](https://github.com/tbachu/pneumoniadetection/blob/main/dashboard/app.js): `dashboard/app.js`
- [Dashboard page](https://github.com/tbachu/pneumoniadetection/blob/main/dashboard/index.html): `dashboard/index.html`
- [Dashboard styling](https://github.com/tbachu/pneumoniadetection/blob/main/dashboard/styles.css): `dashboard/styles.css`

### Other components

- **Clinician**
- **Kaggle dataset**
- **Chest X-ray**
- **Analysis response**

## Connections

- Kaggle dataset → Dataset download: provides dataset
- Dataset download → Binary training: makes data available
- Binary training → Modeling runtime: trains through
- Binary training → Model checkpoint: saves checkpoint
- 14-label training → Model checkpoint: saves checkpoint
- Calibration → Modeling runtime: loads model
- Calibration → Calibration state: writes calibration
- Clinical evaluation → Modeling runtime: loads model
- FastAPI service → Modeling runtime: loads checkpoint
- FastAPI service → Model checkpoint: reads checkpoint
- FastAPI service → Calibration state: loads calibration
- FastAPI service → Clinical analysis: initializes analyzer
- FastAPI service → Clinical analysis: analyzes image
- Clinical analysis → Modeling runtime: preprocesses and explains
- FastAPI service → Clinical report: formats report
- Grad-CAM tool → Modeling runtime: predicts and explains
- Grad-CAM tool → Model checkpoint: loads checkpoint
- Clinician → Dashboard logic: uploads image
- Dashboard page → Dashboard logic: hosts interface
- Dashboard logic → FastAPI service: requests analysis
- FastAPI service → Analysis response: returns findings
- Analysis response → Dashboard logic: renders results
- Chest X-ray → FastAPI service: uploaded for analysis
