# fog-3/cloudcare architecture

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

- Interactive diagram: https://gitdiagram.com/fog-3/cloudcare
- Repository: https://github.com/fog-3/cloudcare

## Overview

##### Project type and purpose
- CloudCare is a full-stack, data-driven clinical assistant for hospitals.
- Frontend: Angular SPA/SSR providing UI for patient search, charts, and chat.
- Backend: Java Spring Boot REST API for CRUD (patients, labs, notes, meds, procedures).
- AI layer: Python Lambda functions (deployed via API Gateway) to run LLM prompts and generate summaries/plots.
- Data/ML: Python ETL scripts to load and clean data; CSV backups and SQL scripts; test harness for OpenAI integration.

##### File structure
- Top-level modules:
- ai/ — Python code for local examples and AWS Lambda (lambda_project).
- backend/CloudCareSpring — Spring Boot microservice (pom.xml, main/java, repositories, services).
- backend/api — tests for OpenAI-based endpoints (invokes Lambda?).
- backend/data_processing — ETL scripts ingesting raw data into the database.
- backend/prompts — JSON templates for LLM prompts.
- frontend/ — Angular project (app components, routes, services/types, assets, SSR entry points).
- ml/ — synthetic and real CSV datasets, SQL import scripts.
- docs/ — architecture.md (reference), presentation materials.
- Key patterns:
- Layered design in Spring Boot (Controller → Service → Repository → DB).
- Angular module/component hierarchy (pages, services).
- Serverless functions behind API Gateway for AI tasks.
- Separate ETL/ML pipelines feeding the main database.

##### Extract additional insights from README
- Purpose: Automate generation of “evolutive summaries” for hospitalized patients.
- Main flows: patient lookup → view clinical history and labs → generate interactive graphics → ask chatbot for summary or custom chart.
- Tech stack: Angular, TypeScript, Spring Boot, Java, Maven, Python, AWS Lambda, API Gateway, OpenAI APIs.

a. Main components
1. User & Browser (Patient/Doctor UI).
2. Angular Frontend (deployed on static host or Node SSR).
3. API Gateway (REST endpoints for chat/summary).
4. AWS Lambda Functions (lambda_function1.py, lambda_function2.py).
5. Spring Boot Backend (PacientesResource & other controllers).
6. Relational Database (e.g., RDS/Postgres) holding patients, labs, notes, meds, procedures.
7. ETL/Data Processing module (data_check.py) loading CSV/SQL into DB.
8. ML/Data Store (csv files, insertarDatos.SQL) for offline analytics.
9. OpenAI Service (external LLM).
10. Prompts Store (JSON templates).

b. Relationships & interactions
- Browser ↔ Angular Frontend via HTTP/HTTPS.
- Frontend ↔ Spring Boot API for CRUD operations on patient data.
- Frontend ↔ API Gateway → Lambda → OpenAI for chat & summaries.
- Spring Boot ↔ Database via JPA repositories.
- ETL scripts (cron or manual) load raw/clean CSVs into Database.
- ML/data folder serves as source for ETL or bulk imports.
- Lambda functions may also read/write to test_db.py or directly to the DB for caching.
- Prompts JSON are consumed by Lambda when composing LLM requests.

c. Architectural patterns
- Layered MVC in Spring Boot.
- Component-based in Angular.
- Serverless micro-functions for AI workloads.
- Batch ETL pipeline separate from real-time services.
- Clear separation of concerns: UI, business logic, data, and AI.

d. Key technologies/frameworks
- Angular (components, services, routing, SSR).
- Spring Boot (REST controllers, services, JPA, Maven).
- AWS Lambda + API Gateway (Python 3.x functions).
- OpenAI SDK (invoked inside Lambda).
- ETL scripts in Python (pandas/sqlalchemy).
- Relational DB (MySQL/Postgres via JPA).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        User["User / Browser"]:::external
        Angular["Angular Frontend"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        APIGateway["API Gateway"]:::core
        subgraph "AWS Lambda Functions"
            Lambda1["Lambda Function 1"]:::core
            Lambda2["Lambda Function 2"]:::core
            TestDBStub["Lambda Test DB Stub"]:::core
            HTMLOutputs["Supporting HTML Outputs"]:::core
        end
        subgraph "Spring Boot Backend"
            Pom["pom.xml"]:::core
            AppEntry["CloudCareSpringApplication.java"]:::core
            Controller["PacientesResource.java"]:::core
            Services["Services Package"]:::core
            Repos["Repositories Package"]:::core
            Entities["Entities Package"]:::core
        end
        subgraph "Prompts Store"
            Prompt1["Prompt1.json"]:::core
            Prompt2["Prompt2.json"]:::core
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        DB["Relational Database (RDS/Postgres)"]:::data
        ETL["ETL Scripts"]:::data
        subgraph "ML / Data Store"
            CSVs["CSV Datasets"]:::data
            SQLScript["SQL Import Script"]:::data
            MLCheck["Data Check Script"]:::data
        end
    end

    %% External Services
    subgraph "External"
        OpenAI["OpenAI Service"]:::external
    end

    %% Connections
    User -->|"HTTPS"| Angular
    Angular -->|"REST API Calls"| SpringBootBackend[Spring Boot Backend]
    Angular -->|"Invoke Chat API"| APIGateway
    APIGateway -->|"Invoke"| Lambda1
    APIGateway -->|"Invoke"| Lambda2
    Lambda1 -->|"Use Prompts"| Prompt1
    Lambda2 -->|"Use Prompts"| Prompt2
    Lambda1 -->|"Query/Cache"| DB
    SpringBootBackend -->|"JPA (JDBC)"| DB
    ETL -->|"Cron / Manual"| DB
    MLCheck -->|"Source Data"| CSVs
    SQLScript -->|"Bulk Import"| DB
    Lambda1 -->|"LLM Request"| OpenAI
    Lambda2 -->|"LLM Request"| OpenAI

    %% Click Events
    click Angular "https://github.com/fog-3/cloudcare/tree/main/frontend/"
    click Pom "https://github.com/fog-3/cloudcare/blob/main/backend/CloudCareSpring/pom.xml"
    click AppEntry "https://github.com/fog-3/cloudcare/blob/main/backend/CloudCareSpring/src/main/java/com/CloudCare/CloudCareSpring/CloudCareSpringApplication.java"
    click Controller "https://github.com/fog-3/cloudcare/blob/main/backend/CloudCareSpring/src/main/java/com/CloudCare/CloudCareSpring/PacientesResource.java"
    click Services "https://github.com/fog-3/cloudcare/tree/main/backend/CloudCareSpring/src/main/java/com/CloudCare/CloudCareSpring/service/"
    click Repos "https://github.com/fog-3/cloudcare/tree/main/backend/CloudCareSpring/src/main/java/com/CloudCare/CloudCareSpring/repository/"
    click Entities "https://github.com/fog-3/cloudcare/tree/main/backend/CloudCareSpring/src/main/java/com/CloudCare/CloudCareSpring/entities/"
    click Lambda1 "https://github.com/fog-3/cloudcare/blob/main/ai/lambda_project/lambda_function1.py"
    click Lambda2 "https://github.com/fog-3/cloudcare/blob/main/ai/lambda_project/lambda_function2.py"
    click TestDBStub "https://github.com/fog-3/cloudcare/blob/main/ai/lambda_project/test_db.py"
    click HTMLOutputs "https://github.com/fog-3/cloudcare/tree/main/ai/lambda_project/html/"
    click ETL "https://github.com/fog-3/cloudcare/blob/main/backend/data_processing/data_check.py"
    click Prompt1 "https://github.com/fog-3/cloudcare/blob/main/backend/prompts/Prompt1.json"
    click Prompt2 "https://github.com/fog-3/cloudcare/blob/main/backend/prompts/Prompt2.json"
    click CSVs "https://github.com/fog-3/cloudcare/blob/main/ml/data/resumen_pacientes.csv"
    click SQLScript "https://github.com/fog-3/cloudcare/blob/main/ml/data/insertarDatos.SQL"
    click MLCheck "https://github.com/fog-3/cloudcare/blob/main/ml/data/data_check.py"

    %% Styles
    classDef frontend fill:#AEDFFF,stroke:#000,stroke-width:1px;
    classDef core fill:#C1FFC1,stroke:#000,stroke-width:1px;
    classDef data fill:#FFD580,stroke:#000,stroke-width:1px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px;
```
