# aries0d0f/web-ble-heart-rate-zone-monitor architecture

> Architecture diagram of the GitHub repository aries0d0f/web-ble-heart-rate-zone-monitor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aries0d0f/web-ble-heart-rate-zone-monitor
- Repository: https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor

## Overview

##### Main Components
- User Interface (Frontend): Represented by the Vue components (e.g., App.vue, Controller.vue, Monitor.vue, HeartRateZone.vue, Preference.vue). This layer is responsible for displaying data and user interactions.
- Bluetooth Module: Found under src/modules/bluetooth (bluetooth.model.ts and bluetooth.service.ts). This component handles communication with the Bluetooth hardware using the Web Bluetooth API.
- PWA Module: Under src/modules/pwa (pwa.service.ts) which manages offline capabilities, caching, and service worker-related functionalities for offline support.
- Utility & Shared Modules: Includes src/modules/utils (context, context service, module-factory.ts) and src/shared (signal.ts, timer.ts). These handle contextual data, cross-cutting utilities, and timing functions that support the core functionalities.
- Data Models: For example, src/model/preference.model.ts defines the structure for user preferences which are used to preserve settings locally.
- Assets & Styling: While not “logical” components, the assets (CSS/SCSS files) support the UI presentation, enhancing user experience.
- Build & Configuration Infrastructure: Shown via several configuration files (vite.config.ts, package.json, various tsconfig.*) and CI/CD pipelines (.github/workflows) that ensure continuous integration and deployment.

##### Relationships and Interactions
- The UI interacts directly with various modules:
- It retrieves heart rate and zone data by interacting with the Bluetooth service.
- It saves and retrieves user preferences via the model and related context services.
- The PWA module ensures service workers are active for offline capabilities.
- The UI layer (Vue components) makes calls to the Bluetooth and PWA services, which in turn might use shared utilities (signals, timers) to process and propagate data.
- Configuration and build files support the entire application lifecycle but are not part of runtime interactions.

##### Architectural Patterns and Design Principles
- Layered Architecture: The system is well-organized into distinct layers—presentation (UI components), business logic (Bluetooth/PWA modules, utilities), and data (models, shared resources).
- Modularity: Functionality is split into modules (bluetooth, pwa, utils), making the app extensible and maintainable.
- Separation of Concerns: UI components, BLE communication, and service worker management are isolated, allowing for easier modifications and testing.

##### Relevant Technologies and Frameworks
- Vue.js: Building the user interface (components are .vue files).
- TypeScript: All source code files (with .ts extensions) indicate a strongly typed implementation.
- Vite: Used as a build tool (vite.config.ts), which is geared towards modern web development.
- Web Bluetooth API: Central to interacting with BLE devices.
- Progressive Web App (PWA) Techniques: For offline support and caching.
- SCSS: For styling, with modular and library styles under the assets folder.
- GitHub Actions: For CI/CD automation (see .github/workflows).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        UI_App["App.vue"]:::ui
        UI_Controller["Controller.vue"]:::ui
        UI_Monitor["Monitor.vue"]:::ui
        UI_HeartRate["HeartRateZone.vue"]:::ui
        UI_Preference["Preference.vue"]:::ui
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        subgraph "Bluetooth Module"
            BT_Model["Bluetooth Model"]:::service
            BT_Service["Bluetooth Service"]:::service
        end
        subgraph "PWA Module"
            PWA_Service["PWA Service"]:::service
        end
    end

    %% Utilities & Data Models
    subgraph "Utilities & Data Models"
        Context_Model["Context Model"]:::utility
        Context_Service["Context Service"]:::utility
        Module_Factory["Module Factory"]:::utility
        Signal["Signal"]:::utility
        Timer["Timer"]:::utility
        Pref_Model["Preference Model"]:::utility
    end

    %% Build & Configuration Infrastructure (side component)
    subgraph "Build & Configuration"
        Package_Config["Package & Lock"]:::config
        Vite_Config["Vite & TS Config"]:::config
        CI_CD["CI/CD Pipeline"]:::config
    end

    %% External Dependency
    External_BT["Web Bluetooth API"]:::external

    %% Connections from UI to Business Logic
    UI_App -->|"calls"| BT_Service
    UI_Controller -->|"triggers"| BT_Service
    UI_Monitor -->|"receives data from"| BT_Service
    UI_HeartRate -->|"displays zone via"| BT_Service
    UI_Preference -->|"saves preferences to"| Pref_Model

    %% Connections from UI to PWA Module
    UI_App -->|"activates"| PWA_Service
    UI_Preference -->|"updates settings via"| PWA_Service

    %% Bluetooth Module interactions
    BT_Service -->|"uses"| BT_Model
    BT_Service -->|"communicates with"| External_BT

    %% Utilities interactions (shared among modules)
    UI_App -->|"leverages"| Context_Service
    BT_Service -->|"utilizes"| Module_Factory
    PWA_Service -->|"utilizes"| Module_Factory
    Context_Service -->|"manages"| Context_Model
    UI_Controller -->|"triggers events via"| Signal
    UI_Monitor -->|"updated with"| Timer

    %% Build & Configuration supports overall system
    Package_Config ---|"builds"| UI_App
    Vite_Config ---|"configures"| PWA_Service
    CI_CD ---|"deploys"| UI_App

    %% Styling for layers
    classDef ui fill:#FFD700,stroke:#B8860B,stroke-width:2px;
    classDef service fill:#87CEFA,stroke:#4682B4,stroke-width:2px;
    classDef utility fill:#FFB6C1,stroke:#CD5C5C,stroke-width:2px;
    classDef config fill:#98FB98,stroke:#2E8B57,stroke-width:2px;
    classDef external fill:#DDA0DD,stroke:#9932CC,stroke-width:2px;

    %% Click Events for User Interface (Frontend)
    click UI_App "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/src/App.vue"
    click UI_Controller "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/src/components/Controller.vue"
    click UI_Monitor "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/src/components/Monitor.vue"
    click UI_HeartRate "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/src/components/HeartRateZone.vue"
    click UI_Preference "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/src/components/Preference.vue"

    %% Click Events for Bluetooth Module
    click BT_Model "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/src/modules/bluetooth/bluetooth.model.ts"
    click BT_Service "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/src/modules/bluetooth/bluetooth.service.ts"

    %% Click Events for PWA Module
    click PWA_Service "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/src/modules/pwa/pwa.service.ts"

    %% Click Events for Utility & Shared Modules
    click Context_Model "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/src/modules/utils/context/context.model.ts"
    click Context_Service "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/src/modules/utils/context/context.service.ts"
    click Module_Factory "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/src/modules/utils/module-factory.ts"
    click Signal "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/src/shared/signal.ts"
    click Timer "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/src/shared/timer.ts"
    click Pref_Model "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/src/model/preference.model.ts"

    %% Click Events for Assets & Styling
    click Package_Config "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/package.json"
    click Package_Config "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/pnpm-lock.yaml"
    click Vite_Config "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/vite.config.ts"
    click Vite_Config "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/tsconfig.app.json"
    click Vite_Config "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/tsconfig.json"
    click Vite_Config "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/tsconfig.node.json"
    click CI_CD "https://github.com/aries0d0f/web-ble-heart-rate-zone-monitor/blob/main/.github/workflows/ci-cd.yaml"
```
