# mohamedelsayadd/al-shefaa-hospital-v1 architecture

> Architecture diagram of the GitHub repository mohamedelsayadd/al-shefaa-hospital-v1, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mohamedelsayadd/al-shefaa-hospital-v1
- Repository: https://github.com/mohamedelsayadd/al-shefaa-hospital-v1

## Overview

##### Project type and purpose
- This is a full-stack, AI-powered disease-diagnosis web application built with Python (Flask), HTML/CSS/JavaScript on the front end, persisting results to a SQL Server database, and exposing endpoints that load pre-trained ML/DL models (.pkl and .h5 files) for inference.
- It offers four diagnostic services: diabetes, breast cancer, liver disease, and Alzheimer’s.

##### File structure
Top-level:
- app.py                ← Flask entrypoint for diabetes, breast-cancer, liver routes
- breast_cancer.pkl
- diabetes.pkl
- hepatitis_c.pkl
- alzh_model1.h5        ← Alzheimer’s model artifact
- static/               ← shared CSS/JS/images
- templates/            ← shared HTML templates (index.html, result pages)
- uploads/              ← user-uploaded files (e.g., MRI scans)
- Alzheimer Diagnosis/  ← mini-Flask app for Alzheimer’s (alzh.py, separate static & templates, train/test datasets)
Configuration & docs:
- README.md

##### README for additional insights
- Confirms Flask/JS/CSS stack, SQL Server persistence, and four diagnosis features.
- Emphasizes user-friendly web interface.

a. Main components
1. Client Browser (UI)
2. Web Server (Flask app.py + Alzheimer’s alzh.py)
3. Model Service Layer
- DiabetesService (loads diabetes.pkl)
- CancerService (loads breast_cancer.pkl)
- LiverService (loads hepatitis_c.pkl)
- AlzheimerService (loads alzh_model1.h5, image-processing)
4. File System
- uploads/ (MRI scans for Alzheimer’s)
- static/ & Alzheimer Diagnosis/static/
- offline train/test data (under Alzheimer Diagnosis/)
5. Database (SQL Server)
6. Offline Training (datasets under Alzheimer Diagnosis/train & /test)
b. Relationships & interactions
- Browser ↔ HTTP(S) ↔ Flask routing
- Flask route handlers call respective ModelService
- ModelService loads artifact, runs inference
- Inference result → persisted to SQL Server
- Template renderer returns HTML with prediction
- For Alzheimer’s: client uploads image → AlzheimerService preprocesses image → inference
c. Architectural patterns & principles
- Monolithic MVC (views in templates/, controllers in app.py & alzh.py, models as ML artifacts)
- Separation of concerns: distinct service modules for each disease
- Layering: Presentation (HTML/CSS/JS), Application (Flask routes), Domain (ML models), Persistence (SQL Server)
d. Key technologies
- Python & Flask, HTML/CSS, JavaScript
- ML frameworks: scikit-learn (.pkl) and TensorFlow/Keras (.h5)
- SQL Server (via pyodbc or similar)
- File I/O for uploads & model artifacts

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Browser["Client Browser"]:::frontend

    %% Web Server
    FlaskAPI["Flask API\n(app.py, alzh.py)"]:::service

    %% Model Service Layer
    subgraph "Model Service Layer"
        direction TB
        DiabetesService["DiabetesService"]:::service
        CancerService["CancerService"]:::service
        LiverService["LiverService"]:::service
        AlzheimerService["AlzheimerService"]:::service
    end

    %% Artifacts
    DiabetesArtifact["diabetes.pkl"]:::fs
    CancerArtifact["breast_cancer.pkl"]:::fs
    HepArtifact["hepatitis_c.pkl"]:::fs
    AlzArtifact["alzh_model1.h5"]:::fs

    %% Persistence
    DB["SQL Server"]:::db

    %% File System
    subgraph "File System"
        direction TB
        SharedStatic["static/"]:::fs
        SharedTemplates["templates/"]:::fs
        FSUploads["uploads/"]:::fs
        subgraph "Alzheimer Mini-App Files"
            direction TB
            AlzAppDir["Alzheimer Diagnosis/app.py"]:::fs
            AlzHandler["Alzheimer Diagnosis/alzh.py"]:::fs
            AlzStatic["Alzheimer Diagnosis/static/"]:::fs
            AlzTemplates["Alzheimer Diagnosis/templates/"]:::fs
            AlzUploads["Alzheimer Diagnosis/uploads/"]:::fs
            OfflineTrain["Alzheimer Diagnosis/train/"]:::offline
            OfflineTest["Alzheimer Diagnosis/test/"]:::offline
        end
    end

    %% Interactions
    Browser -->|HTTP POST /diagnose| FlaskAPI
    FlaskAPI -->|"call"| DiabetesService
    FlaskAPI -->|"call"| CancerService
    FlaskAPI -->|"call"| LiverService
    FlaskAPI -->|"delegate MRI upload"| AlzheimerService
    Browser -->|"upload MRI"| AlzheimerService

    DiabetesService -->|"load"| DiabetesArtifact
    CancerService -->|"load"| CancerArtifact
    LiverService -->|"load"| HepArtifact
    AlzheimerService -->|"load & preprocess"| AlzArtifact
    AlzheimerService -->|"access uploads"| AlzUploads

    DiabetesService -->|"INSERT prediction"| DB
    CancerService -->|"INSERT prediction"| DB
    LiverService -->|"INSERT prediction"| DB
    AlzheimerService -->|"INSERT prediction"| DB

    FlaskAPI -->|"serve static"| SharedStatic
    FlaskAPI -->|"render templates"| SharedTemplates
    AlzheimerService -->|"serve static"| AlzStatic
    AlzheimerService -->|"render templates"| AlzTemplates

    %% Click Events
    click FlaskAPI "https://github.com/mohamedelsayadd/al-shefaa-hospital-v1/blob/main/app.py"
    click DiabetesArtifact "https://github.com/mohamedelsayadd/al-shefaa-hospital-v1/blob/main/diabetes.pkl"
    click CancerArtifact "https://github.com/mohamedelsayadd/al-shefaa-hospital-v1/blob/main/breast_cancer.pkl"
    click HepArtifact "https://github.com/mohamedelsayadd/al-shefaa-hospital-v1/blob/main/hepatitis_c.pkl"
    click AlzAppDir "https://github.com/mohamedelsayadd/al-shefaa-hospital-v1/blob/main/Alzheimer Diagnosis/app.py"
    click AlzHandler "https://github.com/mohamedelsayadd/al-shefaa-hospital-v1/blob/main/Alzheimer Diagnosis/alzh.py"
    click AlzArtifact "https://github.com/mohamedelsayadd/al-shefaa-hospital-v1/blob/main/Alzheimer Diagnosis/alzh_model1.h5"
    click SharedStatic "https://github.com/mohamedelsayadd/al-shefaa-hospital-v1/tree/main/static/"
    click SharedTemplates "https://github.com/mohamedelsayadd/al-shefaa-hospital-v1/tree/main/templates/"
    click AlzStatic "https://github.com/mohamedelsayadd/al-shefaa-hospital-v1/tree/main/Alzheimer Diagnosis/static/"
    click AlzTemplates "https://github.com/mohamedelsayadd/al-shefaa-hospital-v1/tree/main/Alzheimer Diagnosis/templates/"
    click FSUploads "https://github.com/mohamedelsayadd/al-shefaa-hospital-v1/tree/main/uploads/"
    click AlzUploads "https://github.com/mohamedelsayadd/al-shefaa-hospital-v1/tree/main/Alzheimer Diagnosis/uploads/"
    click OfflineTrain "https://github.com/mohamedelsayadd/al-shefaa-hospital-v1/tree/main/Alzheimer Diagnosis/train/"
    click OfflineTest "https://github.com/mohamedelsayadd/al-shefaa-hospital-v1/tree/main/Alzheimer Diagnosis/test/"

    %% Styles
    classDef frontend fill:#D6EAFE,stroke:#2B6CB0
    classDef service fill:#C6F6D5,stroke:#2F855A
    classDef db fill:#FAF089,stroke:#D69E2E,shape:cylinder
    classDef fs fill:#E2E8F0,stroke:#4A5568
    classDef offline fill:#EDF2F7,stroke:#718096,stroke-dasharray:5 5
```
