# ali-119/pulmoscope architecture

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

- Interactive diagram: https://gitdiagram.com/ali-119/pulmoscope
- Repository: https://github.com/ali-119/pulmoscope

## Overview

PulmoScope is an educational pulmonary CT analysis application. A user submits questionnaire answers and one CT slice through its self-contained web page; the FastAPI endpoint validates the upload, computes questionnaire risk, runs classification and segmentation, fuses the outputs, and returns a decision with localization and an overlay. The runtime is concentrated in main.py; model-training notebooks and saved artifacts are represented as separate capability branches. Several runtime details are documented in the README but omitted from the source excerpt, so those relationships cite the README.

Main entry points: [`main.py`](https://github.com/ali-119/pulmoscope/blob/main/main.py) (FastAPI endpoint), [`Models/ml_model.pkl`](https://github.com/ali-119/pulmoscope/blob/main/Models/ml_model.pkl) (Risk model artifact), [`Models/dl_classification_model.keras`](https://github.com/ali-119/pulmoscope/blob/main/Models/dl_classification_model.keras) (Classifier artifact), [`Models/dl_segmentation_model.keras`](https://github.com/ali-119/pulmoscope/blob/main/Models/dl_segmentation_model.keras) (Segmentation artifact)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_serving["Web serving"]
  node_web_ui["Questionnaire UI<br/>[main.py]"]
  node_api["FastAPI endpoint<br/>[main.py]"]
end

subgraph group_risk["Questionnaire risk"]
  node_risk_score["Weighted risk<br/>[main.py]"]
  node_risk_model["Risk probability<br/>[main.py]"]
  node_risk_asset[("Risk model artifact<br/>[ml_model.pkl]")]
end

subgraph group_imaging["CT analysis"]
  node_validation["Image validation<br/>[main.py]"]
  node_classifier["CT classifier<br/>[main.py]"]
  node_classifier_asset[("Classifier artifact")]
  node_segmenter["Nodule segmenter<br/>[main.py]"]
  node_segmenter_asset[("Segmentation artifact")]
end

subgraph group_decision["Decision output"]
  node_fusion["Decision fusion<br/>[main.py]"]
  node_localization["Region localization<br/>[main.py]"]
  node_overlay["Overlay rendering<br/>[main.py]"]
  node_result["Decision response<br/>[main.py]"]
end

subgraph group_training["Model development"]
  node_risk_training["Risk model training<br/>[ml_model.ipynb]"]
  node_classification_training["Classifier training"]
  node_segmentation_training["Segmenter training"]
end

node_patient(("Patient"))
node_ct_slice["CT slice"]

node_patient -->|"enters answers"| node_web_ui
node_ct_slice -->|"uploads slice"| node_web_ui
node_web_ui -->|"submits form"| node_api
node_api -->|"validates image"| node_validation
node_api -->|"scores answers"| node_risk_score
node_api -->|"estimates probability"| node_risk_model
node_api -->|"classifies slice"| node_classifier
node_api -->|"segments slice"| node_segmenter
node_risk_score -->|"sets threshold"| node_classifier
node_classifier -->|"supplies probability"| node_fusion
node_segmenter -->|"supplies mask"| node_fusion
node_segmenter -->|"extracts regions"| node_localization
node_fusion -->|"sets decision"| node_result
node_localization -->|"adds region boxes"| node_result
node_fusion -->|"renders findings"| node_overlay
node_overlay -->|"adds overlay"| node_result
node_api -->|"loads artifact"| node_risk_asset
node_api -->|"loads artifact"| node_classifier_asset
node_api -->|"loads artifact"| node_segmenter_asset
node_risk_training -.->|"produces model"| node_risk_asset
node_classification_training -.->|"produces model"| node_classifier_asset
node_segmentation_training -.->|"produces model"| node_segmenter_asset

click node_web_ui "https://github.com/ali-119/pulmoscope/blob/main/main.py"
click node_api "https://github.com/ali-119/pulmoscope/blob/main/main.py"
click node_validation "https://github.com/ali-119/pulmoscope/blob/main/main.py"
click node_risk_score "https://github.com/ali-119/pulmoscope/blob/main/main.py"
click node_risk_model "https://github.com/ali-119/pulmoscope/blob/main/main.py"
click node_risk_asset "https://github.com/ali-119/pulmoscope/blob/main/Models/ml_model.pkl"
click node_classifier "https://github.com/ali-119/pulmoscope/blob/main/main.py"
click node_classifier_asset "https://github.com/ali-119/pulmoscope/blob/main/Models/dl_classification_model.keras"
click node_segmenter "https://github.com/ali-119/pulmoscope/blob/main/main.py"
click node_segmenter_asset "https://github.com/ali-119/pulmoscope/blob/main/Models/dl_segmentation_model.keras"
click node_fusion "https://github.com/ali-119/pulmoscope/blob/main/main.py"
click node_localization "https://github.com/ali-119/pulmoscope/blob/main/main.py"
click node_overlay "https://github.com/ali-119/pulmoscope/blob/main/main.py"
click node_result "https://github.com/ali-119/pulmoscope/blob/main/main.py"
click node_risk_training "https://github.com/ali-119/pulmoscope/blob/main/Algorithms/machine%20learning/ml_model.ipynb"
click node_classification_training "https://github.com/ali-119/pulmoscope/blob/main/Algorithms/classification/dl_classification_model.ipynb"
click node_segmentation_training "https://github.com/ali-119/pulmoscope/blob/main/Algorithms/segmentation/dl_segmentation_model.ipynb"

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_web_ui,node_api toneBlue
class node_risk_score,node_risk_model,node_risk_asset toneAmber
class node_validation,node_classifier,node_classifier_asset,node_segmenter,node_segmenter_asset toneMint
class node_fusion,node_localization,node_overlay,node_result toneRose
class node_risk_training,node_classification_training,node_segmentation_training,node_patient,node_ct_slice toneIndigo
```

## Components

### Web serving

- [Questionnaire UI](https://github.com/ali-119/pulmoscope/blob/main/main.py): `main.py`
- [FastAPI endpoint](https://github.com/ali-119/pulmoscope/blob/main/main.py): `main.py`

### Questionnaire risk

- [Weighted risk](https://github.com/ali-119/pulmoscope/blob/main/main.py): `main.py`
- [Risk probability](https://github.com/ali-119/pulmoscope/blob/main/main.py): `main.py`
- [Risk model artifact](https://github.com/ali-119/pulmoscope/blob/main/Models/ml_model.pkl): `Models/ml_model.pkl`

### CT analysis

- [Image validation](https://github.com/ali-119/pulmoscope/blob/main/main.py): `main.py`
- [CT classifier](https://github.com/ali-119/pulmoscope/blob/main/main.py): `main.py`
- [Classifier artifact](https://github.com/ali-119/pulmoscope/blob/main/Models/dl_classification_model.keras): `Models/dl_classification_model.keras`
- [Nodule segmenter](https://github.com/ali-119/pulmoscope/blob/main/main.py): `main.py`
- [Segmentation artifact](https://github.com/ali-119/pulmoscope/blob/main/Models/dl_segmentation_model.keras): `Models/dl_segmentation_model.keras`

### Decision output

- [Decision fusion](https://github.com/ali-119/pulmoscope/blob/main/main.py): `main.py`
- [Region localization](https://github.com/ali-119/pulmoscope/blob/main/main.py): `main.py`
- [Overlay rendering](https://github.com/ali-119/pulmoscope/blob/main/main.py): `main.py`
- [Decision response](https://github.com/ali-119/pulmoscope/blob/main/main.py): `main.py`

### Model development

- [Risk model training](https://github.com/ali-119/pulmoscope/blob/main/Algorithms/machine%20learning/ml_model.ipynb): `Algorithms/machine learning/ml_model.ipynb`
- [Classifier training](https://github.com/ali-119/pulmoscope/blob/main/Algorithms/classification/dl_classification_model.ipynb): `Algorithms/classification/dl_classification_model.ipynb`
- [Segmenter training](https://github.com/ali-119/pulmoscope/blob/main/Algorithms/segmentation/dl_segmentation_model.ipynb): `Algorithms/segmentation/dl_segmentation_model.ipynb`

### Other components

- **Patient**
- **CT slice**

## Connections

- Patient → Questionnaire UI: enters answers (evidence: `README.md`)
- CT slice → Questionnaire UI: uploads slice (evidence: `README.md`)
- Questionnaire UI → FastAPI endpoint: submits form (evidence: `README.md`)
- FastAPI endpoint → Image validation: validates image (evidence: `README.md`)
- FastAPI endpoint → Weighted risk: scores answers (evidence: `main.py`)
- FastAPI endpoint → Risk probability: estimates probability (evidence: `main.py`)
- FastAPI endpoint → CT classifier: classifies slice (evidence: `README.md`)
- FastAPI endpoint → Nodule segmenter: segments slice (evidence: `README.md`)
- Weighted risk → CT classifier: sets threshold (evidence: `README.md`)
- CT classifier → Decision fusion: supplies probability (evidence: `README.md`)
- Nodule segmenter → Decision fusion: supplies mask (evidence: `README.md`)
- Nodule segmenter → Region localization: extracts regions (evidence: `README.md`)
- Decision fusion → Decision response: sets decision (evidence: `README.md`)
- Region localization → Decision response: adds region boxes (evidence: `README.md`)
- Decision fusion → Overlay rendering: renders findings (evidence: `README.md`)
- Overlay rendering → Decision response: adds overlay (evidence: `README.md`)
- FastAPI endpoint → Risk model artifact: loads artifact (evidence: `main.py`)
- FastAPI endpoint → Classifier artifact: loads artifact (evidence: `main.py`)
- FastAPI endpoint → Segmentation artifact: loads artifact (evidence: `main.py`)
- Risk model training → Risk model artifact: produces model
- Classifier training → Classifier artifact: produces model
- Segmenter training → Segmentation artifact: produces model
