# heuscartist/uraanai-medical-platform architecture

> Architecture diagram of the GitHub repository heuscartist/uraanai-medical-platform, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/heuscartist/uraanai-medical-platform
- Repository: https://github.com/heuscartist/uraanai-medical-platform

## Overview

##### Project type and purpose
- This is a full-stack, Python-based web application built on Streamlit.
- Purpose: Assist doctors with patient management and AI-driven medical tools (X-ray disease detection, chatbot, OCR prescription parsing, heart risk prediction).

##### File structure
Top-level files
- app.py / run.py – Streamlit entrypoints
- healthcare.db – SQLite patient database
- requirements.txt – Python dependencies
Directories
- models/ – serialized ML artifacts (Keras models, pickled scalers, logistic-regression model)
- pages/ – Streamlit “multi-page” modules (auth, dashboard, disease_detection, chatbot, heart_risk, prescription_ocr)
- rag/ – static PDF resources used for Retrieval-Augmented Generation or explainability

##### Pull additional insights from README
- Frontend & App: Streamlit multi-page interface
- Database: SQLite3 for secure patient data
- ML: Keras (TensorFlow) for image models, scikit-learn for tabular models
- NLP/chatbot: Calls Gemini API for explanations
- OCR: Tesseract/EasyOCR for prescription parsing

a. Main components
1. Streamlit Application
– Pages Router (auth.py → dashboard.py → feature pages)
2. Data Storage
– SQLite database (healthcare.db)
3. ML Inference Layer
– Disease Detection Service
- Loads Keras models (pneumonia.h5, pneumonia.keras, etc.) and scaler.pkl
– Heart Risk Service
- Loads log_reg_model.pkl
4. NLP Chatbot Service
– Gemini API (external)
– RAG storage (PDFs in rag/)
5. OCR Service
– Tesseract/EasyOCR library
6. Static Assets & Reporting
– Heatmaps, Grad-CAM visualizations, Plotly charts

b. Relationships and data flows
- User → Streamlit Frontend
- Frontend → Auth module → SQLite
- Dashboard & Feature Pages → Database (CRUD)
- Disease Detection Page → ML Inference → returns prediction + explainability → Frontend
- Chatbot Page → pulls context from DB or free text → calls Gemini API → renders answer
- Prescription OCR Page → sends image to OCR Service → returns structured text → optional DB write
- Heart Risk Page → sends vitals data to Heart Risk Service → returns risk score & insights

c. Architectural patterns and principles
- Single-code-base, multi-page architecture (Streamlit’s page router)
- Separation of concerns: pages (UI) vs. models (inference) vs. data (SQLite) vs. external APIs
- Modular ML services: each feature page loads only its required model
- Externalization of heavy compute: calls out to Gemini, OCR libraries

d. Key technologies and frameworks
- Streamlit (UI & routing)
- SQLite3 (persistent storage)
- TensorFlow/Keras (image classification)
- scikit-learn (heart risk model)
- Gemini API (NLP & explainability)
- Tesseract/EasyOCR (OCR)
- Python libraries: NumPy, Pandas, OpenCV, Plotly

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        User["User"]:::client
    end

    %% Application Layer
    subgraph "Application Layer"
        subgraph "Entrypoints"
            AppPY["app.py"]:::infra
            RunPY["run.py"]:::infra
        end
        subgraph "Streamlit Application"
            Auth["Authentication Page"]:::frontend
            Dashboard["Dashboard Page"]:::frontend
            XRay["X-Ray Disease Detection Page"]:::frontend
            Chatbot["Chatbot Page"]:::frontend
            HeartRiskPage["Heart Risk Page"]:::frontend
            PrescriptionOCR["Prescription OCR Page"]:::frontend
        end
    end

    %% Service Layer
    subgraph "Service Layer"
        subgraph "ML Inference Services"
            DiseaseService["DiseaseDetectionService"]:::ml
            HeartService["HeartRiskService"]:::ml
            Pneum1["pneumonia.h5"]:::artifact
            Pneum2["pneumonia.keras"]:::artifact
            Pneum3["pneumonia_v2.keras"]:::artifact
            Scaler["scaler.pkl"]:::artifact
            LogReg["log_reg_model.pkl"]:::artifact
        end
        subgraph "External APIs"
            Gemini["Gemini API"]:::external
            OCREngine["OCR Engine (Tesseract/EasyOCR)"]:::external
        end
        subgraph "RAG Storage"
            PDFs["Pneumonia_ADULT.pdf"]:::rag
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        DB["SQLite Database"]:::db
    end

    %% Connections
    User --> AppPY
    User --> RunPY
    AppPY --> Auth
    RunPY --> Auth
    Auth -->|SELECT/INSERT| DB
    Auth --> Dashboard
    Dashboard -->|SELECT/INSERT| DB
    Dashboard --> XRay
    XRay -->|POST /predict| DiseaseService
    DiseaseService --> Pneum1
    DiseaseService --> Pneum2
    DiseaseService --> Pneum3
    DiseaseService --> Scaler
    DiseaseService -->|prediction + explainability| XRay
    Dashboard --> Chatbot
    Chatbot -->|SELECT context| DB
    Chatbot -->|API call| Gemini
    Gemini -->|response| Chatbot
    Chatbot -->|RAG retrieval| PDFs
    Dashboard --> PrescriptionOCR
    PrescriptionOCR -->|image input| OCREngine
    OCREngine -->|structured text| PrescriptionOCR
    PrescriptionOCR -->|optional INSERT| DB
    Dashboard --> HeartRiskPage
    HeartRiskPage -->|POST data| HeartService
    HeartService --> LogReg
    HeartService -->|risk score| HeartRiskPage

    %% Click Events
    click AppPY "https://github.com/heuscartist/uraanai-medical-platform/blob/main/app.py"
    click RunPY "https://github.com/heuscartist/uraanai-medical-platform/blob/main/run.py"
    click Auth "https://github.com/heuscartist/uraanai-medical-platform/blob/main/pages/auth.py"
    click Dashboard "https://github.com/heuscartist/uraanai-medical-platform/blob/main/pages/dashboard.py"
    click XRay "https://github.com/heuscartist/uraanai-medical-platform/blob/main/pages/disease_detection.py"
    click Chatbot "https://github.com/heuscartist/uraanai-medical-platform/blob/main/pages/chatbot.py"
    click HeartRiskPage "https://github.com/heuscartist/uraanai-medical-platform/blob/main/pages/heart_risk.py"
    click PrescriptionOCR "https://github.com/heuscartist/uraanai-medical-platform/blob/main/pages/prescription_ocr.py"
    click DB "https://github.com/heuscartist/uraanai-medical-platform/blob/main/healthcare.db"
    click Pneum1 "https://github.com/heuscartist/uraanai-medical-platform/blob/main/models/pneumonia.h5"
    click Pneum2 "https://github.com/heuscartist/uraanai-medical-platform/blob/main/models/pneumonia.keras"
    click Pneum3 "https://github.com/heuscartist/uraanai-medical-platform/blob/main/models/pneumonia_v2.keras"
    click Scaler "https://github.com/heuscartist/uraanai-medical-platform/blob/main/models/scaler.pkl"
    click LogReg "https://github.com/heuscartist/uraanai-medical-platform/blob/main/models/log_reg_model.pkl"
    click PDFs "https://github.com/heuscartist/uraanai-medical-platform/blob/main/rag/Pneumonia_ADULT.pdf"
    click Requirements "https://github.com/heuscartist/uraanai-medical-platform/blob/main/requirements.txt"
    click Readme "https://github.com/heuscartist/uraanai-medical-platform/blob/main/readme.md"

    %% Styles
    classDef frontend fill:#B3CDE3,stroke:#03396C,color:#03396C
    classDef ml fill:#C7E9C0,stroke:#006400,color:#006400
    classDef db fill:#FED976,stroke:#B35600,color:#B35600
    classDef external fill:#FDBB84,stroke:#D95F02,color:#D95F02
    classDef rag fill:#DECBE4,stroke:#6A3D9A,color:#6A3D9A
    classDef artifact fill:#A1D99B,stroke:#238B45,color:#238B45
    classDef client fill:#f0f0f0,stroke:#666666,color:#333333
    classDef infra fill:#d9d9d9,stroke:#666666,color:#333333
```
