# nourgaida/smartcare architecture

> Architecture diagram of the GitHub repository nourgaida/smartcare, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nourgaida/smartcare
- Repository: https://github.com/nourgaida/smartcare

## Overview

SmartCare is an experimental patient-monitoring platform. Its implemented data workflow runs from simulated readings through MQTT gateway validation, backend revalidation and deduplicated MongoDB persistence; separate branches provide rule-based anomaly detection, offline ML experimentation, and patient and supervision portals. Backend authentication and sessions support server-backed sign-in, while the portals also retain demo behavior. The README documents some gateway and broker components whose source is absent from the supplied tree; those are shown as external services. Live ML scoring and portal measurement integration are not established as connected.

Main entry points: [`frontends/frontoffice/app.js`](https://github.com/nourgaida/smartcare/blob/main/frontends/frontoffice/app.js) (Patient portal), [`frontends/backoffice/app.mjs`](https://github.com/nourgaida/smartcare/blob/main/frontends/backoffice/app.mjs) (Supervision portal), [`iot/detection/duration_detector.py`](https://github.com/nourgaida/smartcare/blob/main/iot/detection/duration_detector.py) (Duration detector), [`iot/simulator/simulator.py`](https://github.com/nourgaida/smartcare/blob/main/iot/simulator/simulator.py) (Simulator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sensing["Sensing and MQTT"]
  node_simulator["Simulator<br/>[simulator.py]"]
  node_broker["Mosquitto MQTT"]
  node_gateway["Node-RED gateway"]
end

subgraph group_middleware["Ingestion and storage"]
  node_receiver["MQTT receiver<br/>[MqttReceiver.java]"]
  node_handler["Measurement handler"]
  node_measurements["Measurement repository"]
  node_mongo[("MongoDB")]
  node_counters["Ingestion counters"]
end

subgraph group_analysis["Anomaly and ML"]
  node_detector["Duration detector"]
  node_event_manager["Detection events<br/>[event_manager.py]"]
  node_ml_training["ML training<br/>[train_real.py]"]
  node_ml_api["Inference API<br/>[main.py]"]
end

subgraph group_identity["Identity and sessions"]
  node_auth_resource["Authentication API<br/>[AuthResource.java]"]
  node_auth_service["Authentication service<br/>[AuthService.java]"]
  node_session_service["Session service"]
  node_session_repo["Session repository"]
end

subgraph group_portals["Care portals"]
  node_patient_app["Patient portal<br/>[app.js]"]
  node_patient_adapter["Patient adapter"]
  node_history["Reading history<br/>[history.mjs]"]
  node_backoffice_app["Supervision portal<br/>[app.mjs]"]
  node_backoffice_adapter["Care adapter<br/>[adapter.mjs]"]
  node_backoffice_views["Supervision views<br/>[views.mjs]"]
  node_shared_auth["Demo authentication<br/>[auth.mjs]"]
end

node_patient(("Patient"))
node_professional(("Care professional"))

node_simulator -->|"publishes readings"| node_broker
node_broker -->|"routes raw readings"| node_gateway
node_gateway -->|"publishes validated"| node_broker
node_broker -->|"delivers validated"| node_receiver
node_receiver -.->|"dispatches messages"| node_handler
node_handler -->|"saves readings"| node_measurements
node_measurements -->|"writes and reads"| node_mongo
node_patient -->|"starts scenarios"| node_simulator
node_broker -->|"delivers readings"| node_detector
node_detector -.->|"emits detections"| node_event_manager
node_detector -->|"publishes events"| node_broker
node_ml_training -.->|"provides trained model"| node_ml_api
node_patient -->|"views readings"| node_patient_app
node_patient_app -->|"loads measurements"| node_patient_adapter
node_patient_app -->|"mounts history"| node_history
node_professional -->|"reviews care data"| node_backoffice_app
node_backoffice_app -->|"loads care data"| node_backoffice_adapter
node_backoffice_app -->|"renders views"| node_backoffice_views
node_patient_app -->|"uses demo login"| node_shared_auth
node_backoffice_app -->|"uses demo login"| node_shared_auth
node_auth_resource -->|"delegates authentication"| node_auth_service
node_auth_service -->|"creates sessions"| node_session_service
node_session_service -->|"stores sessions"| node_session_repo
node_session_repo -->|"persists sessions"| node_mongo

click node_simulator "https://github.com/nourgaida/smartcare/blob/main/iot/simulator/simulator.py"
click node_receiver "https://github.com/nourgaida/smartcare/blob/main/middleware/core/src/main/java/com/smartcare/ingestion/MqttReceiver.java"
click node_handler "https://github.com/nourgaida/smartcare/blob/main/middleware/core/src/main/java/com/smartcare/ingestion/MeasurementMessageHandler.java"
click node_measurements "https://github.com/nourgaida/smartcare/blob/main/middleware/core/src/main/java/com/smartcare/persistence/MeasurementRepository.java"
click node_counters "https://github.com/nourgaida/smartcare/blob/main/middleware/core/src/main/java/com/smartcare/ingestion/IngestionCounters.java"
click node_detector "https://github.com/nourgaida/smartcare/blob/main/iot/detection/duration_detector.py"
click node_event_manager "https://github.com/nourgaida/smartcare/blob/main/iot/detection/event_manager.py"
click node_ml_training "https://github.com/nourgaida/smartcare/blob/main/iot/mlops/src/train_real.py"
click node_ml_api "https://github.com/nourgaida/smartcare/blob/main/iot/mlops/api/main.py"
click node_patient_app "https://github.com/nourgaida/smartcare/blob/main/frontends/frontoffice/app.js"
click node_patient_adapter "https://github.com/nourgaida/smartcare/blob/main/frontends/frontoffice/measurements-adapter.mjs"
click node_history "https://github.com/nourgaida/smartcare/blob/main/frontends/frontoffice/history.mjs"
click node_backoffice_app "https://github.com/nourgaida/smartcare/blob/main/frontends/backoffice/app.mjs"
click node_backoffice_adapter "https://github.com/nourgaida/smartcare/blob/main/frontends/backoffice/adapter.mjs"
click node_backoffice_views "https://github.com/nourgaida/smartcare/blob/main/frontends/backoffice/views.mjs"
click node_auth_resource "https://github.com/nourgaida/smartcare/blob/main/middleware/api/src/main/java/com/smartcare/api/auth/AuthResource.java"
click node_auth_service "https://github.com/nourgaida/smartcare/blob/main/middleware/iam/src/main/java/com/smartcare/iam/auth/AuthService.java"
click node_session_service "https://github.com/nourgaida/smartcare/blob/main/middleware/iam/src/main/java/com/smartcare/iam/session/SessionService.java"
click node_session_repo "https://github.com/nourgaida/smartcare/blob/main/middleware/core/src/main/java/com/smartcare/persistence/SessionRepository.java"
click node_shared_auth "https://github.com/nourgaida/smartcare/blob/main/frontends/shared/auth.mjs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_simulator,node_broker,node_gateway toneBlue
class node_receiver,node_handler,node_measurements,node_mongo,node_counters toneAmber
class node_detector,node_event_manager,node_ml_training,node_ml_api toneMint
class node_auth_resource,node_auth_service,node_session_service,node_session_repo toneRose
class node_patient_app,node_patient_adapter,node_history,node_backoffice_app,node_backoffice_adapter,node_backoffice_views,node_shared_auth,node_patient,node_professional toneIndigo
```

## Components

### Sensing and MQTT

- [Simulator](https://github.com/nourgaida/smartcare/blob/main/iot/simulator/simulator.py): `iot/simulator/simulator.py`
- **Mosquitto MQTT**
- **Node-RED gateway**

### Ingestion and storage

- [MQTT receiver](https://github.com/nourgaida/smartcare/blob/main/middleware/core/src/main/java/com/smartcare/ingestion/MqttReceiver.java): `middleware/core/src/main/java/com/smartcare/ingestion/MqttReceiver.java`
- [Measurement handler](https://github.com/nourgaida/smartcare/blob/main/middleware/core/src/main/java/com/smartcare/ingestion/MeasurementMessageHandler.java): `middleware/core/src/main/java/com/smartcare/ingestion/MeasurementMessageHandler.java`
- [Measurement repository](https://github.com/nourgaida/smartcare/blob/main/middleware/core/src/main/java/com/smartcare/persistence/MeasurementRepository.java): `middleware/core/src/main/java/com/smartcare/persistence/MeasurementRepository.java`
- **MongoDB**
- [Ingestion counters](https://github.com/nourgaida/smartcare/blob/main/middleware/core/src/main/java/com/smartcare/ingestion/IngestionCounters.java): `middleware/core/src/main/java/com/smartcare/ingestion/IngestionCounters.java`

### Anomaly and ML

- [Duration detector](https://github.com/nourgaida/smartcare/blob/main/iot/detection/duration_detector.py): `iot/detection/duration_detector.py`
- [Detection events](https://github.com/nourgaida/smartcare/blob/main/iot/detection/event_manager.py): `iot/detection/event_manager.py`
- [ML training](https://github.com/nourgaida/smartcare/blob/main/iot/mlops/src/train_real.py): `iot/mlops/src/train_real.py`
- [Inference API](https://github.com/nourgaida/smartcare/blob/main/iot/mlops/api/main.py): `iot/mlops/api/main.py`

### Identity and sessions

- [Authentication API](https://github.com/nourgaida/smartcare/blob/main/middleware/api/src/main/java/com/smartcare/api/auth/AuthResource.java): `middleware/api/src/main/java/com/smartcare/api/auth/AuthResource.java`
- [Authentication service](https://github.com/nourgaida/smartcare/blob/main/middleware/iam/src/main/java/com/smartcare/iam/auth/AuthService.java): `middleware/iam/src/main/java/com/smartcare/iam/auth/AuthService.java`
- [Session service](https://github.com/nourgaida/smartcare/blob/main/middleware/iam/src/main/java/com/smartcare/iam/session/SessionService.java): `middleware/iam/src/main/java/com/smartcare/iam/session/SessionService.java`
- [Session repository](https://github.com/nourgaida/smartcare/blob/main/middleware/core/src/main/java/com/smartcare/persistence/SessionRepository.java): `middleware/core/src/main/java/com/smartcare/persistence/SessionRepository.java`

### Care portals

- [Patient portal](https://github.com/nourgaida/smartcare/blob/main/frontends/frontoffice/app.js): `frontends/frontoffice/app.js`
- [Patient adapter](https://github.com/nourgaida/smartcare/blob/main/frontends/frontoffice/measurements-adapter.mjs): `frontends/frontoffice/measurements-adapter.mjs`
- [Reading history](https://github.com/nourgaida/smartcare/blob/main/frontends/frontoffice/history.mjs): `frontends/frontoffice/history.mjs`
- [Supervision portal](https://github.com/nourgaida/smartcare/blob/main/frontends/backoffice/app.mjs): `frontends/backoffice/app.mjs`
- [Care adapter](https://github.com/nourgaida/smartcare/blob/main/frontends/backoffice/adapter.mjs): `frontends/backoffice/adapter.mjs`
- [Supervision views](https://github.com/nourgaida/smartcare/blob/main/frontends/backoffice/views.mjs): `frontends/backoffice/views.mjs`
- [Demo authentication](https://github.com/nourgaida/smartcare/blob/main/frontends/shared/auth.mjs): `frontends/shared/auth.mjs`

### Other components

- **Patient**
- **Care professional**

## Connections

- Simulator → Mosquitto MQTT: publishes readings
- Mosquitto MQTT → Node-RED gateway: routes raw readings
- Node-RED gateway → Mosquitto MQTT: publishes validated
- Mosquitto MQTT → MQTT receiver: delivers validated
- MQTT receiver → Measurement handler: dispatches messages
- Measurement handler → Measurement repository: saves readings (evidence: `middleware/core/src/main/java/com/smartcare/ingestion/MeasurementMessageHandler.java`)
- Measurement repository → MongoDB: writes and reads (evidence: `middleware/core/src/main/java/com/smartcare/persistence/MeasurementRepository.java`)
- Patient → Simulator: starts scenarios
- Mosquitto MQTT → Duration detector: delivers readings
- Duration detector → Detection events: emits detections
- Duration detector → Mosquitto MQTT: publishes events
- ML training → Inference API: provides trained model
- Patient → Patient portal: views readings
- Patient portal → Patient adapter: loads measurements (evidence: `frontends/frontoffice/app.js`)
- Patient portal → Reading history: mounts history (evidence: `frontends/frontoffice/app.js`)
- Care professional → Supervision portal: reviews care data
- Supervision portal → Care adapter: loads care data (evidence: `frontends/backoffice/app.mjs`)
- Supervision portal → Supervision views: renders views (evidence: `frontends/backoffice/app.mjs`)
- Patient portal → Demo authentication: uses demo login (evidence: `frontends/frontoffice/app.js`)
- Supervision portal → Demo authentication: uses demo login (evidence: `frontends/backoffice/app.mjs`)
- Authentication API → Authentication service: delegates authentication (evidence: `middleware/api/src/main/java/com/smartcare/api/auth/AuthResource.java`)
- Authentication service → Session service: creates sessions (evidence: `middleware/iam/src/main/java/com/smartcare/iam/auth/AuthService.java`)
- Session service → Session repository: stores sessions (evidence: `middleware/iam/src/main/java/com/smartcare/iam/session/SessionService.java`)
- Session repository → MongoDB: persists sessions (evidence: `middleware/core/src/main/java/com/smartcare/persistence/SessionRepository.java`)
