# royan04/respirex architecture

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

- Interactive diagram: https://gitdiagram.com/royan04/respirex
- Repository: https://github.com/royan04/respirex

## Overview

Respirx is a Flask web app for classifying uploaded chest X-rays as COVID-19, Normal, Pneumonia, or Tuberculosis. The main workflow accepts an image, preprocesses it, runs the loaded model, stores the prediction, and returns the result; users can later view predictions and download a generated medical report. Login routes doctors and patients to different pages. The README also mentions training controls and visualizations, but the available source shows no implementation for them, so they are not mapped here.

Main entry points: [`app.py`](https://github.com/royan04/respirex/blob/main/app.py) (Flask routes), [`instance/predictions.db`](https://github.com/royan04/respirex/blob/main/instance/predictions.db) (Prediction records), [`templates/login.html`](https://github.com/royan04/respirex/blob/main/templates/login.html) (Login page), [`templates/doctors.html`](https://github.com/royan04/respirex/blob/main/templates/doctors.html) (Doctor page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_flask["Flask routes<br/>[app.py]"]
  node_login_page["Login page<br/>[login.html]"]
  node_doctor_page["Doctor page<br/>[doctors.html]"]
  node_report_page["Report page<br/>[report.html]"]
  node_result_page["Result page<br/>[result.html]"]
end

subgraph group_inference["Image inference"]
  node_image_prep["Image preprocessing<br/>[app.py]"]
  node_classifier["Classifier inference<br/>[app.py]"]
  node_weights["Trained weights<br/>[best_weight.h5]"]
end

subgraph group_records["Accounts and records"]
  node_prediction_store[("Prediction records<br/>[predictions.db]")]
  node_user_store[("User records<br/>[predictions.db]")]
end

subgraph group_reports["Medical reports"]
  node_report_generator["Report generation<br/>[app.py]"]
  node_pdf["PDF report"]
end

node_patient(("Patient"))
node_doctor(("Doctor"))

node_patient -->|"uploads X-ray"| node_flask
node_doctor -->|"uses web app"| node_flask
node_flask -->|"processes image"| node_image_prep
node_image_prep -->|"passes tensor"| node_classifier
node_classifier -->|"loads model"| node_weights
node_classifier -->|"saves prediction"| node_prediction_store
node_flask -->|"renders page"| node_result_page
node_patient -->|"requests login"| node_flask
node_doctor -->|"requests login"| node_flask
node_flask -->|"renders page"| node_login_page
node_flask -->|"checks account"| node_user_store
node_flask -->|"redirects doctor"| node_doctor_page
node_flask -->|"renders records"| node_report_page
node_flask -->|"queries records"| node_prediction_store
node_flask -->|"generates report"| node_report_generator
node_report_generator -->|"writes PDF"| node_pdf
node_patient -->|"downloads report"| node_flask

click node_flask "https://github.com/royan04/respirex/blob/main/app.py"
click node_login_page "https://github.com/royan04/respirex/blob/main/templates/login.html"
click node_doctor_page "https://github.com/royan04/respirex/blob/main/templates/doctors.html"
click node_report_page "https://github.com/royan04/respirex/blob/main/templates/report.html"
click node_result_page "https://github.com/royan04/respirex/blob/main/templates/result.html"
click node_image_prep "https://github.com/royan04/respirex/blob/main/app.py"
click node_classifier "https://github.com/royan04/respirex/blob/main/app.py"
click node_weights "https://github.com/royan04/respirex/blob/main/best_weight.h5"
click node_prediction_store "https://github.com/royan04/respirex/blob/main/instance/predictions.db"
click node_user_store "https://github.com/royan04/respirex/blob/main/instance/predictions.db"
click node_report_generator "https://github.com/royan04/respirex/blob/main/app.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_flask,node_login_page,node_doctor_page,node_report_page,node_result_page toneBlue
class node_image_prep,node_classifier,node_weights toneAmber
class node_prediction_store,node_user_store toneMint
class node_report_generator,node_pdf toneRose
class node_patient,node_doctor toneIndigo
```

## Components

### Web application

- [Flask routes](https://github.com/royan04/respirex/blob/main/app.py): `app.py`
- [Login page](https://github.com/royan04/respirex/blob/main/templates/login.html): `templates/login.html`
- [Doctor page](https://github.com/royan04/respirex/blob/main/templates/doctors.html): `templates/doctors.html`
- [Report page](https://github.com/royan04/respirex/blob/main/templates/report.html): `templates/report.html`
- [Result page](https://github.com/royan04/respirex/blob/main/templates/result.html): `templates/result.html`

### Image inference

- [Image preprocessing](https://github.com/royan04/respirex/blob/main/app.py): `app.py`
- [Classifier inference](https://github.com/royan04/respirex/blob/main/app.py): `app.py`
- [Trained weights](https://github.com/royan04/respirex/blob/main/best_weight.h5): `best_weight.h5`

### Accounts and records

- [Prediction records](https://github.com/royan04/respirex/blob/main/instance/predictions.db): `instance/predictions.db`
- [User records](https://github.com/royan04/respirex/blob/main/instance/predictions.db): `instance/predictions.db`

### Medical reports

- [Report generation](https://github.com/royan04/respirex/blob/main/app.py): `app.py`
- **PDF report**

### Other components

- **Patient**
- **Doctor**

## Connections

- Patient → Flask routes: uploads X-ray (evidence: `README.md`)
- Doctor → Flask routes: uses web app (evidence: `README.md`)
- Flask routes → Image preprocessing: processes image (evidence: `app.py`)
- Image preprocessing → Classifier inference: passes tensor (evidence: `app.py`)
- Classifier inference → Trained weights: loads model (evidence: `app.py`)
- Classifier inference → Prediction records: saves prediction (evidence: `app.py`)
- Flask routes → Result page: renders page (evidence: `app.py`)
- Patient → Flask routes: requests login (evidence: `app.py`)
- Doctor → Flask routes: requests login (evidence: `app.py`)
- Flask routes → Login page: renders page (evidence: `app.py`)
- Flask routes → User records: checks account (evidence: `app.py`)
- Flask routes → Doctor page: redirects doctor (evidence: `app.py`)
- Flask routes → Report page: renders records (evidence: `app.py`)
- Flask routes → Prediction records: queries records (evidence: `app.py`)
- Flask routes → Report generation: generates report (evidence: `app.py`)
- Report generation → PDF report: writes PDF (evidence: `app.py`)
- Patient → Flask routes: downloads report (evidence: `app.py`)
