# sgnovice/disease-detection-using-chest-xrays architecture

> Architecture diagram of the GitHub repository sgnovice/disease-detection-using-chest-xrays, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sgnovice/disease-detection-using-chest-xrays
- Repository: https://github.com/sgnovice/disease-detection-using-chest-xrays

## Overview

##### Main Components
- User Interface / Frontend:
– This is represented by the HTML templates (index.html, result.html) and static assets (CSS in static/styles) that form the user-facing side of the application.
– The web pages allow users to upload chest X-ray images and view prediction results.

- Web Application / Backend:
– This is implemented in app.py and potentially supplemented by commons.py.
– It acts as the controller which receives requests (from the client's browser), handles routing, and interacts with the inference module.

- Inference / Deep Learning Engine:
– Encapsulated by inference.py, this module loads the deep learning model(s) (e.g., DenseNet161 with custom activations such as β-Mish, Mila, and others) and runs the image data through the model to obtain predictions.
– It handles pre-processing steps (like image resizing, random rotations, flips, and conversion to tensor format) before passing images to the model.

- Configuration & Deployment Components:
– Deployment configuration files like Procfile, app.json, runtime.txt, and requirements.txt indicate that the project is set up for deployment on platforms like Heroku or similar PaaS.
– These files and settings should be noted as part of the deployment and runtime environment.

##### Relationships and Data Flow
- The Web Server then interacts with the “Inference Engine” (inference.py), passing the preprocessed image data. The engine performs the prediction using the deep learning model.
- The response – including disease classification results – flows back through the web server to the front-end, which then renders the result on the web page.

##### Architectural Patterns & Design Principles
- The project follows a clear separation of concerns: the frontend (UI templates and styling) is distinct from the backend logic (Flask-based routing in app.py) and the deep learning inference (inference.py).
- Use of orchestration between components using client-server communication patterns.
- That deep learning preprocessing is integrated into the server pipeline—this is important given the care detailed in the README regarding data augmentation and preprocessing.

##### Relevant Technologies and Frameworks
- Python (Flask for the web server).
- PyTorch (for deep learning model implementation).
- HTML/CSS (for the frontend UI).
- Deployment technologies such as Heroku (indicated by Procfile and app.json).
- Libraries for image processing and pre-processing.

##### Emphasized Elements
- Clear Labels: Each module (UI, Backend, Inference Engine, Deployment Configurations) must be clearly labeled.

– The client-side (web browser with HTML/CSS).
– The application server using Flask (app.py, commons.py).
– The inference engine (inference.py with integrated deep learning model and processing logic).
– Configuration/deployment components (Procfile, app.json, runtime.txt, requirements.txt).

This design should serve as a comprehensive blueprint for understanding, deploying, and eventually extending the system (for example, to include federated learning on Raspberry Pi devices or mobile interfaces as mentioned in the README’s future work section).

## Diagram (Mermaid)

```mermaid
flowchart TD
    U["User (Client)"]:::client

    subgraph "User Interface / Frontend"
        T1["index.html"]:::frontend
        T2["result.html"]:::frontend
        S1["style.css"]:::frontend
    end

    subgraph "Web Application / Backend"
        A1["app.py (Flask Server)"]:::backend
        A2["commons.py"]:::backend
    end

    subgraph "Inference Engine"
        I1["inference.py"]:::inference
    end

    subgraph "Configuration & Deployment"
        D1["Procfile"]:::deployment
        D2["app.json"]:::deployment
        D3["runtime.txt"]:::deployment
        D4["requirements.txt"]:::deployment
    end

    U -->|"Accesses"| T1
    U -->|"Accesses"| T2
    U -->|"Accesses"| S1

    T1 -->|"HTTPRequest(ImageUpload)"| A1
    A1 -->|"PreprocessedImage/Inferences"| I1
    I1 -->|"PredictionResult"| A1
    A1 -->|"RendersPrediction"| T2

    A1 -->|"UsesConfiguration"| D1
    A1 -->|"UsesConfiguration"| D2
    A1 -->|"UsesConfiguration"| D3
    A1 -->|"UsesConfiguration"| D4

    A2 -.-> A1

    click T1 "https://github.com/sgnovice/disease-detection-using-chest-xrays/blob/master/templates/index.html"
    click T2 "https://github.com/sgnovice/disease-detection-using-chest-xrays/blob/master/templates/result.html"
    click S1 "https://github.com/sgnovice/disease-detection-using-chest-xrays/blob/master/static/styles/style.css"
    click A1 "https://github.com/sgnovice/disease-detection-using-chest-xrays/blob/master/app.py"
    click A2 "https://github.com/sgnovice/disease-detection-using-chest-xrays/blob/master/commons.py"
    click I1 "https://github.com/sgnovice/disease-detection-using-chest-xrays/blob/master/inference.py"
    click D1 "https://github.com/sgnovice/disease-detection-using-chest-xrays/tree/master/Procfile"
    click D2 "https://github.com/sgnovice/disease-detection-using-chest-xrays/blob/master/app.json"
    click D3 "https://github.com/sgnovice/disease-detection-using-chest-xrays/blob/master/runtime.txt"
    click D4 "https://github.com/sgnovice/disease-detection-using-chest-xrays/blob/master/requirements.txt"

    classDef client fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef frontend fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef backend fill:#87CEFA,stroke:#333,stroke-width:2px;
    classDef inference fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef deployment fill:#DDA0DD,stroke:#333,stroke-width:2px;
```
