# prakashutoledo/msbandwearableuwp architecture

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

- Interactive diagram: https://gitdiagram.com/prakashutoledo/msbandwearableuwp
- Repository: https://github.com/prakashutoledo/msbandwearableuwp

## Overview

##### Main Components
- UWP Application (UI): Represented by the main application in “MSBandWearable/IDEASLabUT.MSBandWearable.Application”. It includes XAML pages (MSBandPage.xaml, etc.) and resources such as styles.
- MVVM Components: Model, View, and ViewModel layers reside in different projects (for example, the UWP Core project “MSBandWearable/IDEASLabUT.MSBandWearable.UWPCore” which contains ViewModel classes and converters).
- Business Logic Services:
- Band Client Service (in the “Client” project) for Bluetooth communication.
- Properties Service (in ApplicationProperties) to manage configuration and AWS resource endpoints.
- NTPSync, Notification, and other sensor services present in respective service folders (e.g., NTPSync, Notification, and WearableCore) handle data synchronization, sensor management, and notifications.
- Logging and External Integration:
- Elasticsearch Client and Logger (in “ElasticsearchClient” and “ElasticsearchLogger”) manage log formatting and HTTP communications. These handle batching sensor data via Serilog and pushing logs every 8 seconds to Elasticsearch.
- WebSocket Service (in the Notification project) which manages the communication with the AWS WebSocket API that connects with the iOS component and AWS Lambda.
- External Dependencies:
- AWS Resources such as Lambda functions, WebSocket API, and an Elasticsearch domain.
- Related external projects like EmpaticaE4WearableIOS and ideaslabut-aws-lambda, which are mentioned as dependencies in the README.

##### Relationships and Interactions
- The UWP Application (the View and ViewModel layers) interacts with business logic services to read sensor data and control sessions (start/stop).
- Sensor data from the Band is captured through the Band Client Service and then processed by various sensor modules (in WearableCore) before being passed into the logging pipeline.
- The Logging component uses a file-based Serilog queue to batch sensor events, and the HTTP sink makes periodic bulk API calls to the AWS-hosted Elasticsearch domain.
- Notification components communicate over WebSocket (via the WebSocketService) to send or receive connection messages, possibly in response to input from the iOS application.
- Configuration is managed centrally using properties defined in ApplicationProperties (local and default JSON files).

##### Architectural Patterns and Design Principles
- MVVM (Model-View-ViewModel) is a core design pattern used to separate UI logic from business logic.
- The thread-safe lazy singleton design pattern is used to manage global access to certain service instances.
- Modularization is evident with separate projects for services, logging, extension methods, and testing, showcasing a micro-modular architecture within the solution.
- Dependency on external AWS resources indicates a hybrid system where local processing and cloud-based logging/notification are integrated.

##### Technologies and Frameworks
- UWP (Universal Windows Platform) and XAML for the client application.
- C# (.NET) for the business logic, services, and MVVM implementation.
- Serilog for logging with a file-based blocking queue.
- AWS services (Lambda, WebSocket API, Elasticsearch domain) for remote logging and notifications.
- REST/HTTP communication via custom Elasticsearch REST clients and WebSocket communication services.

## Diagram (Mermaid)

```mermaid
graph TD
    %% UI Layer
    subgraph "UI Layer"
        AppUI["UWP App (UI & XAML)"]:::ui
        MVVM["MVVM Components"]:::ui
    end
    AppUI -->|"binds"| MVVM

    %% Business Logic Services
    subgraph "Business Logic Services"
        BandService["Band Client Service"]:::service
        PropertiesService["Properties Service"]:::service
        NtpSync["NTPSync Service"]:::service
        SensorModule["Sensor Modules"]:::sensor
    end
    MVVM -->|"controls"| PropertiesService
    MVVM -->|"initiates"| BandService
    BandService -->|"sends-sensor-data"| SensorModule
    NtpSync -->|"syncs-time"| SensorModule

    %% Logging Pipeline
    subgraph "Logging Pipeline"
        ESLogger["Elasticsearch Logger"]:::service
        ESClient["Elasticsearch Client"]:::service
    end
    SensorModule -->|"logs-data"| ESLogger
    ESLogger -->|"http-logging"| ESClient

    %% Notification Pipeline
    subgraph "Notification Pipeline"
        NotificationService["Notification Service"]:::service
    end
    SensorModule -->|"triggers-notification"| NotificationService

    %% External Integrations
    subgraph "External Integrations"
        AWSWS["AWS WebSocket API"]:::external
        AWSLambda["AWS Lambda"]:::external
        AWSElasticsearch["AWS Elasticsearch Domain"]:::external
        EmpaticaIOS["EmpaticaE4 iOS App"]:::external
    end
    PropertiesService -->|"configures-AWS"| AWSLambda
    NotificationService -->|"sends-message"| AWSWS
    AWSWS -->|"invokes"| AWSLambda
    NotificationService ---|"communicates"| EmpaticaIOS
    ESClient -->|"sends-logs"| AWSElasticsearch

    %% Click Events
    click AppUI "https://github.com/prakashutoledo/msbandwearableuwp/blob/story/create-new-msband2-uwp-application/MSBandWearable/IDEASLabUT.MSBandWearable.Application"
    click MVVM "https://github.com/prakashutoledo/msbandwearableuwp/blob/story/create-new-msband2-uwp-application/MSBandWearable/IDEASLabUT.MSBandWearable.UWPCore"
    click BandService "https://github.com/prakashutoledo/msbandwearableuwp/blob/story/create-new-msband2-uwp-application/MSBandWearable/IDEASLabUT.MSBandWearable.Client/Service/MSBandClientService.cs"
    click PropertiesService "https://github.com/prakashutoledo/msbandwearableuwp/blob/story/create-new-msband2-uwp-application/MSBandWearable/IDEASLabUT.MSBandWearable.ApplicationProperties/Service/PropertiesService.cs"
    click NtpSync "https://github.com/prakashutoledo/msbandwearableuwp/blob/story/create-new-msband2-uwp-application/MSBandWearable/IDEASLabUT.MSBandWearable.NTPSync/Service/NtpSyncService.cs"
    click NotificationService "https://github.com/prakashutoledo/msbandwearableuwp/blob/story/create-new-msband2-uwp-application/MSBandWearable/IDEASLabUT.MSBandWearable.Notification/Service/WebSocketService.cs"
    click ESClient "https://github.com/prakashutoledo/msbandwearableuwp/blob/story/create-new-msband2-uwp-application/MSBandWearable/IDEASLabUT.MSBandWearable.ElasticsearchClient/Service/ElasticsearchRestClient.cs"
    click ESLogger "https://github.com/prakashutoledo/msbandwearableuwp/blob/story/create-new-msband2-uwp-application/MSBandWearable/IDEASLabUT.MSBandWearable.ElasticsearchLogger/Service/ElasticsearchLoggerHttpClient.cs"
    click SensorModule "https://github.com/prakashutoledo/msbandwearableuwp/tree/story/create-new-msband2-uwp-application/MSBandWearable/IDEASLabUT.MSBandWearable.WearableCore/Sensor"

    %% Styles
    classDef ui fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef service fill:#ABEBC6,stroke:#27AE60,stroke-width:2px;
    classDef sensor fill:#FADBD8,stroke:#C0392B,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
```
