# sheethhassan/ai-based-pneumonia-detection architecture

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

- Interactive diagram: https://gitdiagram.com/sheethhassan/ai-based-pneumonia-detection
- Repository: https://github.com/sheethhassan/ai-based-pneumonia-detection

## Overview

This is a cross-platform Flutter prototype for pneumonia screening and X-ray explainability. The principal workflow is selecting an X-ray, running app-side classification, and presenting a result; users can also review history and export results. Separate capabilities include Firebase-backed authentication, an optional FastAPI Grad-CAM service, and a Python model-training pipeline. The README documents these capabilities, but Dart sources were not sampled, so detailed app-to-service calls and internal sequencing are not verified.

Main entry points: [`lib/services/classifier_service.dart`](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/services/classifier_service.dart) (On-device classifier), [`lib/screens/home_screen.dart`](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/screens/home_screen.dart) (Screening home), [`lib/services/auth_service.dart`](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/services/auth_service.dart) (Authentication service), [`lib/screens/result_screen.dart`](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/screens/result_screen.dart) (Result screen)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Flutter application"]
  node_entry["App entry<br/>[main.dart]"]
  node_home["Screening home<br/>[home_screen.dart]"]
  node_resultscreen["Result screen<br/>[result_screen.dart]"]
  node_login["Login and recovery<br/>[login_screen.dart]"]
  node_forgot["Password recovery"]
  node_history["Scan history"]
  node_admin["Admin dashboard"]
end

subgraph group_inference["Inference and explanation"]
  node_image["Image selection<br/>[image_service.dart]"]
  node_validation["Image validation"]
  node_preprocess["Image preprocessing"]
  node_classifier["On-device classifier"]
  node_result["Classification result"]
  node_gradcam["Grad-CAM API<br/>[main.py]"]
  node_modelasset["Bundled model assets"]
end

subgraph group_platform["Accounts and records"]
  node_auth["Authentication service<br/>[auth_service.dart]"]
  node_firebase[("Firebase services")]
  node_scanrecord["Scan record<br/>[scan_record.dart]"]
  node_export["Result export"]
end

subgraph group_modeling["Model development"]
  node_training["Model training<br/>[train_model.py]"]
  node_trainedmodel["Trained Keras model"]
end

node_user(("Clinician or researcher"))

node_user -->|"opens app"| node_entry
node_entry -.->|"presents screening"| node_home
node_user -->|"selects X-ray"| node_home
node_home -.->|"chooses image"| node_image
node_image -.->|"validates image"| node_validation
node_validation -.->|"prepares image"| node_preprocess
node_preprocess -.->|"supplies image"| node_classifier
node_classifier -.->|"uses model"| node_modelasset
node_classifier -.->|"produces prediction"| node_result
node_resultscreen -.->|"displays result"| node_result
node_user -->|"signs in"| node_login
node_login -.->|"authenticates"| node_auth
node_forgot -.->|"recovers account"| node_auth
node_auth -->|"uses Firebase"| node_firebase
node_user -.->|"reviews scans"| node_history
node_history -.->|"shows records"| node_scanrecord
node_resultscreen -.->|"exports result"| node_export
node_user -.->|"manages app"| node_admin
node_user -->|"uploads X-ray"| node_gradcam
node_gradcam -->|"returns heatmap"| node_user
node_user -->|"trains model"| node_training
node_training -.->|"produces model"| node_trainedmodel

click node_entry "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/main.dart"
click node_home "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/screens/home_screen.dart"
click node_image "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/services/image_service.dart"
click node_validation "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/services/image_validation.dart"
click node_preprocess "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/services/image_preprocessor.dart"
click node_classifier "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/services/classifier_service.dart"
click node_result "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/models/classification_result.dart"
click node_resultscreen "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/screens/result_screen.dart"
click node_gradcam "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/server/main.py"
click node_modelasset "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/assets/model/MULTI_OUTPUT_MODEL_flutter.tflite"
click node_auth "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/services/auth_service.dart"
click node_login "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/screens/login_screen.dart"
click node_forgot "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/screens/forgot_password_screen.dart"
click node_firebase "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/firebase_options.dart"
click node_history "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/screens/scan_history_screen.dart"
click node_scanrecord "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/models/scan_record.dart"
click node_export "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/services/result_export_service.dart"
click node_admin "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/screens/admin/admin_dashboard.dart"
click node_training "https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/model/train_model.py"
click node_trainedmodel "https://github.com/sheethhassan/ai-based-pneumonia-detection/tree/master/model"

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_entry,node_home,node_resultscreen,node_login,node_forgot,node_history,node_admin toneBlue
class node_image,node_validation,node_preprocess,node_classifier,node_result,node_gradcam,node_modelasset toneAmber
class node_auth,node_firebase,node_scanrecord,node_export toneMint
class node_training,node_trainedmodel toneRose
class node_user toneIndigo
```

## Components

### Flutter application

- [App entry](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/main.dart): `lib/main.dart`
- [Screening home](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/screens/home_screen.dart): `lib/screens/home_screen.dart`
- [Result screen](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/screens/result_screen.dart): `lib/screens/result_screen.dart`
- [Login and recovery](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/screens/login_screen.dart): `lib/screens/login_screen.dart`
- [Password recovery](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/screens/forgot_password_screen.dart): `lib/screens/forgot_password_screen.dart`
- [Scan history](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/screens/scan_history_screen.dart): `lib/screens/scan_history_screen.dart`
- [Admin dashboard](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/screens/admin/admin_dashboard.dart): `lib/screens/admin/admin_dashboard.dart`

### Inference and explanation

- [Image selection](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/services/image_service.dart): `lib/services/image_service.dart`
- [Image validation](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/services/image_validation.dart): `lib/services/image_validation.dart`
- [Image preprocessing](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/services/image_preprocessor.dart): `lib/services/image_preprocessor.dart`
- [On-device classifier](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/services/classifier_service.dart): `lib/services/classifier_service.dart`
- [Classification result](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/models/classification_result.dart): `lib/models/classification_result.dart`
- [Grad-CAM API](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/server/main.py): `server/main.py`
- [Bundled model assets](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/assets/model/MULTI_OUTPUT_MODEL_flutter.tflite): `assets/model/MULTI_OUTPUT_MODEL_flutter.tflite`

### Accounts and records

- [Authentication service](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/services/auth_service.dart): `lib/services/auth_service.dart`
- [Firebase services](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/firebase_options.dart): `lib/firebase_options.dart`
- [Scan record](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/models/scan_record.dart): `lib/models/scan_record.dart`
- [Result export](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/lib/services/result_export_service.dart): `lib/services/result_export_service.dart`

### Model development

- [Model training](https://github.com/sheethhassan/ai-based-pneumonia-detection/blob/master/model/train_model.py): `model/train_model.py`
- [Trained Keras model](https://github.com/sheethhassan/ai-based-pneumonia-detection/tree/master/model): `model`

### Other components

- **Clinician or researcher**

## Connections

- Clinician or researcher → App entry: opens app (evidence: `README.md`)
- App entry → Screening home: presents screening
- Clinician or researcher → Screening home: selects X-ray (evidence: `README.md`)
- Screening home → Image selection: chooses image
- Image selection → Image validation: validates image
- Image validation → Image preprocessing: prepares image
- Image preprocessing → On-device classifier: supplies image
- On-device classifier → Bundled model assets: uses model
- On-device classifier → Classification result: produces prediction
- Result screen → Classification result: displays result
- Clinician or researcher → Login and recovery: signs in (evidence: `README.md`)
- Login and recovery → Authentication service: authenticates
- Password recovery → Authentication service: recovers account
- Authentication service → Firebase services: uses Firebase (evidence: `README.md`)
- Clinician or researcher → Scan history: reviews scans
- Scan history → Scan record: shows records
- Result screen → Result export: exports result
- Clinician or researcher → Admin dashboard: manages app
- Clinician or researcher → Grad-CAM API: uploads X-ray (evidence: `README.md`)
- Grad-CAM API → Clinician or researcher: returns heatmap (evidence: `README.md`)
- Clinician or researcher → Model training: trains model (evidence: `README.md`)
- Model training → Trained Keras model: produces model
