# zayedu/polycare architecture

> Architecture diagram of the GitHub repository zayedu/polycare, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zayedu/polycare
- Repository: https://github.com/zayedu/polycare

## Overview

##### Project Type and Purpose
- PolyCare is a full-stack health application combining a React Native/Expo mobile client (Android/iOS) with a Python backend.
- Purpose: aggregate three independent analyses (symptoms via LLM chat, blood‐test algorithm, ultrasound image ML) under a blackboard architecture to compute and display a PCOS likelihood score and recommendations.

##### File Structure
- Top-level folders:
- backend – Python microservices and modules
‑ UltrasoundAnalyzer (ML model, data folders, training script)
‑ account_system (CSV data, auth, CRUD account operations)
‑ calculateResults (modular calculators + blackboard logic)
‑ uploadResults (services to formulate discussion/narratives)
‑ api.py (entry point/REST API server)
‑ results_viewer_service.py
‑ data (Excel DB, CSV, prompt templates)
- pcos-app – React Native/Expo mobile application
‑ app (UI screens: Login, Home, data‐upload screens, results screen)
‑ android/ios folders (native project files)
‑ package.json, tsconfig.json

##### README for Architectural Insights
- Confirms use of a blackboard architectural pattern:
- Agents (LLM symptom chat, blood test analyzer, ultrasound analyzer) post partial results to a central “blackboard.”
- A controller/aggregator (overall_calculation) computes a weighted average.
- Key services: Account Management, Symptom & Result Upload, Likelihood Calculation, Result Viewer.
- External dependencies: TensorFlow/Keras for ML, a large language model (LLM) API (e.g., OpenAI), openpyxl for Excel, Expo/React Native.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Mobile Client
    subgraph "Mobile Client"
        direction TB
        MobileClient["📱 React Native/Expo App"]:::frontend
    end

    %% External Services
    ExternalLLM["☁️ LLM API (OpenAI)"]:::external

    %% Backend API Layer
    API["🛣️ API Layer (Flask/FastAPI)"]:::api

    %% Account Management
    subgraph "Account Service"
        direction TB
        AccountService["🔐 Account Management Service"]:::service
        AccountCSV1["📄 Data.csv"]:::db
        AccountCSV2["📄 GovtIDs.csv"]:::db
    end

    %% Analysis Agents
    subgraph "Analysis Agents"
        direction TB
        SymptomAgent["💬 Symptom Chat Agent (LLM)"]:::service
        BloodAgent["🩸 Blood Test Analyzer"]:::service
        UltrasoundAgent["🖼️ Ultrasound Analyzer (Keras)"]:::ml
    end

    %% Blackboard Core
    subgraph "Blackboard Core"
        direction TB
        BlackboardRepo["🗄️ Blackboard Repository"]:::service
        LikelihoodService["⚙️ likelihood_calculation_service"]:::service
    end

    %% Aggregator and Results Viewer
    subgraph "Results Processing"
        direction TB
        Aggregator["📊 Aggregator/Controller"]:::service
        ResultsViewer["📝 Results Viewer Service"]:::service
    end

    %% Data Storage
    subgraph "Data Storage"
        direction TB
        DBExcel["📊 PCOSLikelihoodDB.xlsx"]:::db
        UploadedCSV["📄 uploadedData.csv"]:::db
    end

    %% Narrative Modules
    subgraph "Narrative Generators"
        direction TB
        DiscussBlood["discussBloodTest.py"]:::service
        DiscussSymptoms["discussSymptoms.py"]:::service
        DiscussUltrasound["discussUltrasound.py"]:::service
    end

    %% Connections
    MobileClient -->|"REST API Calls"| API
    API -->|"Auth & CRUD"| AccountService
    API -->|"POST /upload-symptoms"| SymptomAgent
    API -->|"POST /upload-blood"| BloodAgent
    API -->|"POST /upload-ultrasound"| UltrasoundAgent

    SymptomAgent -->|writes partial results| BlackboardRepo
    BloodAgent -->|writes partial results| BlackboardRepo
    UltrasoundAgent -->|writes partial results| BlackboardRepo

    BlackboardRepo -->|stores data| LikelihoodService
    LikelihoodService -->|partial scores| Aggregator
    Aggregator -->|computes weighted score| ResultsViewer

    ResultsViewer -->|narrative| DiscussBlood
    ResultsViewer -->|narrative| DiscussSymptoms
    ResultsViewer -->|narrative| DiscussUltrasound
    ResultsViewer -->|reads| DBExcel
    ResultsViewer -->|reads| UploadedCSV

    Aggregator -->|GET /results| API
    ResultsViewer -->|GET /results| API
    API -->|response| MobileClient

    SymptomAgent -->|calls| ExternalLLM

    %% Click Events
    click MobileClient "https://github.com/zayedu/polycare/tree/main/pcos-app/app"
    click API "https://github.com/zayedu/polycare/blob/main/backend/api.py"
    click AccountService "https://github.com/zayedu/polycare/tree/main/backend/account_system"
    click AccountCSV1 "https://github.com/zayedu/polycare/blob/main/backend/account_system/Data.csv"
    click AccountCSV2 "https://github.com/zayedu/polycare/blob/main/backend/account_system/GovtIDs.csv"
    click SymptomAgent "https://github.com/zayedu/polycare/blob/main/backend/calculateResults/symptomCalculation.py"
    click ExternalLLM "https://github.com/zayedu/polycare/blob/main/backend/data/promptTemplate.txt"
    click BloodAgent "https://github.com/zayedu/polycare/blob/main/backend/calculateResults/bloodCalculation.py"
    click UltrasoundAgent "https://github.com/zayedu/polycare/blob/main/backend/UltrasoundAnalyzer/train_model.py"
    click UltrasoundAgent "https://github.com/zayedu/polycare/blob/main/backend/UltrasoundAnalyzer/ultrasound_pcos_model.h5"
    click UltrasoundAgent "https://github.com/zayedu/polycare/blob/main/backend/UltrasoundAnalyzer/ultrasound_pcos_model.keras"
    click UltrasoundAgent "https://github.com/zayedu/polycare/blob/main/backend/calculateResults/UltrasoundCalculation.py"
    click LikelihoodService "https://github.com/zayedu/polycare/blob/main/backend/calculateResults/likelihood_calculation_service.py"
    click Aggregator "https://github.com/zayedu/polycare/blob/main/backend/calculateResults/overall_calculation.py"
    click ResultsViewer "https://github.com/zayedu/polycare/blob/main/backend/results_viewer_service.py"
    click DiscussBlood "https://github.com/zayedu/polycare/blob/main/backend/uploadResults/discussBloodTest.py"
    click DiscussSymptoms "https://github.com/zayedu/polycare/blob/main/backend/uploadResults/discussSymptoms.py"
    click DiscussUltrasound "https://github.com/zayedu/polycare/blob/main/backend/uploadResults/discussUltrasound.py"
    click DBExcel "https://github.com/zayedu/polycare/blob/main/backend/data/PCOSLikelihoodDB.xlsx"
    click UploadedCSV "https://github.com/zayedu/polycare/blob/main/backend/data/uploadedData.csv"

    %% Styles
    classDef frontend fill:#E8F0FE,stroke:#4285F4,stroke-width:2px
    classDef api fill:#E8F0FE,stroke:#DB4437,stroke-width:2px
    classDef service fill:#F1F8E9,stroke:#0F9D58,stroke-width:2px
    classDef ml fill:#FFF3E0,stroke:#FB8C00,stroke-width:2px
    classDef db fill:#ECEFF1,stroke:#607D8B,stroke-width:2px
    classDef external fill:#F3E5F5,stroke:#9C27B0,stroke-width:2px
```
