# mateusrondon/monitoramento-cardiaco architecture

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

- Interactive diagram: https://gitdiagram.com/mateusrondon/monitoramento-cardiaco
- Repository: https://github.com/mateusrondon/monitoramento-cardiaco

## Overview

##### Project type and purpose
- This is an IoT + web‐based full-stack monitoring system (“SystemBPM”) that uses an ESP32 + MAX30100/30102 sensor to measure heart rate (BPM) and SpO2, presenting results via a responsive web UI and persisting data in Firebase.

##### File structure
- /back-end: Arduino/ESP32 sketches ( `.ino` and `.cpp` ) that initialize Wi-Fi, read sensor, run an internal WebServer, define HTTP routes (`/bpm`, `/spo2`), and push data to Firebase.
- /Integracao-Web/project: A modern web client (Vite + React + TypeScript + Tailwind) containing components (Dashboard, VitalChart, Login, etc.), contexts (AuthContext, SensorContext), and build/config files.
- README.md: high-level description, flowchart of the ESP32 logic, tech stack.

##### Key insights from README
- ESP32 runs a WebServer exposing sensor data as JSON on HTTP routes.
- The web client consumes those JSON endpoints and also writes to Firebase for long-term storage.
- System flow: sensor → ESP32 → serve JSON → React UI → Firebase.

- IoT Device (ESP32 + MAX30100/30102 sensor)
- Internal WebServer on ESP32 (routes `/`, `/bpm`, `/spo2`)
- React Frontend (Vite app)
- Authentication Context (AuthContext)
- Sensor Context (SensorContext)
- Firebase (Realtime DB or Firestore)
- (Optional) Serial Monitor for local logging

1. Hardware sensor → ESP32 (I²C data reads)
2. ESP32 WebServer → serves static UI (index.html + JS) over Wi-Fi
3. React UI → polls `/bpm`, `/spo2` endpoints on ESP32
4. SensorContext → distributes fetched data through React component tree
5. UI Components (Dashboard, VitalChart) → render real-time metrics
6. ESP32 → pushes measurement JSON to Firebase (HTTP POST)
7. AuthContext → manages user sessions if any backend auth layer exists
8. Firebase → serves as historical data store for future retrieval

c. Architectural patterns & design principles:
- IoT edge computing: sensor data processed on-device
- Client-server: ESP32 as minimal HTTP API provider
- React Context for state management (separate Auth & Sensor concerns)
- Single Page Application served as static assets
- External service integration (Firebase) for persistence

d. Key technologies & frameworks:
- ESP32 C++ (WebServer.h)
- Arduino-CLI
- MAX30100/30102 sensor library
- React + TypeScript + Vite + Tailwind CSS
- Firebase (Realtime Database or Firestore)
- Optional: ESLint, PostCSS, tsconfig

## Diagram (Mermaid)

```mermaid
flowchart LR
    %% Hardware/IoT Device
    subgraph "Hardware/IoT Device"
        style Hardware fill:#e0f7e9,stroke:#2e7d32,stroke-width:2px
        Sensor["MAX30100/30102 Sensor"]:::hardware
        ESP32["ESP32 WebServer\n(ESP32 Firmware)"]:::hardware
        Sensor -->|I2C Data Reads| ESP32
    end

    %% Legacy Sketches
    subgraph "Alternative Arduino Sketches"
        style LegacySketches fill:#f1f8e9,stroke:#558b2f,stroke-width:1px
        Legacy1["sensor_batimentos.ino"]:::hardware
        Legacy2["Monitoramento_Web.cpp"]:::hardware
    end
    ESP32 --> Legacy1
    ESP32 --> Legacy2

    %% Assets
    Assets["Hardware Diagrams & Assets"]:::hardware
    ESP32 --> Assets

    %% Network Layer
    subgraph "Network (Wi-Fi)"
        style Network fill:#e3f2fd,stroke:#1565c0,stroke-width:2px
        WiFi["Wi-Fi Network"]:::network
    end
    ESP32 -->|Serves Static UI & JSON APIs| WiFi

    %% Web Client & External Service
    subgraph "Web Client & External Service"
        direction TB
        %% Frontend
        subgraph "React App" 
            style Frontend fill:#e3f2fd,stroke:#1e88e5,stroke-width:2px
            Entry["main.tsx"]:::frontend
            App["App.tsx"]:::frontend
            AuthCtx["AuthContext.tsx"]:::frontend
            SensorCtx["SensorContext.tsx"]:::frontend
            Layout["Layout.tsx"]:::frontend
            Dashboard["Dashboard.tsx"]:::frontend
            VitalChart["VitalChart.tsx"]:::frontend
            Login["Login.tsx"]:::frontend
            Patients["Patients.tsx"]:::frontend
            Settings["Settings.tsx"]:::frontend
            Button["Button.tsx"]:::frontend
            Card["Card.tsx"]:::frontend
            Input["Input.tsx"]:::frontend
        end

        %% Firebase
        Firebase["Firebase (Realtime DB)"]:::external
    end

    %% Data Flows
    WiFi -->|HTTP GET /bpm, /spo2| SensorCtx
    SensorCtx -->|Provides Data| Dashboard
    SensorCtx -->|Provides Data| VitalChart
    AuthCtx -->|Manages Sessions| Login
    AuthCtx -->|Manages Sessions| Patients
    AuthCtx -->|Manages Sessions| Settings
    WiFi -->|Serves SPA Assets| Entry
    Entry --> App
    App --> AuthCtx
    App --> SensorCtx
    ESP32 -->|HTTP POST JSON| Firebase
    Firebase -->|Historical Data| SensorCtx

    %% Click Events
    click ESP32 "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/esp32/max30102_wifi.ino"
    click Legacy1 "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/back-end/sensor_batimentos.ino"
    click Legacy2 "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/back-end/Site_Batimento/Monitoramento_Web.cpp"
    click Assets "https://github.com/mateusrondon/monitoramento-cardiaco/tree/main/assets/Esp32"
    click Entry "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/src/main.tsx"
    click App "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/src/App.tsx"
    click AuthCtx "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/src/contexts/AuthContext.tsx"
    click SensorCtx "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/src/contexts/SensorContext.tsx"
    click Layout "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/src/components/Layout.tsx"
    click Dashboard "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/src/components/Dashboard.tsx"
    click VitalChart "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/src/components/VitalChart.tsx"
    click Login "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/src/components/Login.tsx"
    click Patients "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/src/components/Patients.tsx"
    click Settings "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/src/components/Settings.tsx"
    click Button "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/src/components/ui/Button.tsx"
    click Card "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/src/components/ui/Card.tsx"
    click Input "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/src/components/ui/Input.tsx"
    click WiFi "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/index.html"
    click WiFi "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/package.json"
    click WiFi "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/vite.config.ts"
    click WiFi "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/postcss.config.js"
    click WiFi "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/tailwind.config.js"
    click WiFi "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/tsconfig.json"
    click WiFi "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/tsconfig.app.json"
    click WiFi "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/tsconfig.node.json"
    click WiFi "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/Integracao-Web/project/eslint.config.js"
    click bin "https://github.com/mateusrondon/monitoramento-cardiaco/tree/main/bin/arduino-cli"
    click README "https://github.com/mateusrondon/monitoramento-cardiaco/blob/main/README.md"

    %% Styles
    classDef hardware fill:#e0f7e9,stroke:#2e7d32,stroke-width:1px
    classDef network fill:#e3f2fd,stroke:#1565c0,stroke-width:1px
    classDef frontend fill:#e3f2fd,stroke:#1e88e5,stroke-width:1px
    classDef external fill:#fff3e0,stroke:#ef6c00,stroke-width:2px
    class WiFi,LegacySketches,bin,README network
    class Firebase external
```
