# manas8114/shmt architecture

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

- Interactive diagram: https://gitdiagram.com/manas8114/shmt
- Repository: https://github.com/manas8114/shmt

## Overview

Step 1: Identify Project Type and Purpose
- This is a multi-module Android project comprising two Gradle modules:
- “hanheld” – the phone (handheld) app
- “wearable” – the Wear OS app
- Purpose: Fitness tracking (“FitWatch”) on a wearable device, synchronizing data to a companion phone app.

Step 2: Analyze the File Structure
- Top-level folders:
- hanheld/ – Android phone application
- wearable/ – Wear OS application
- Each module follows standard Android project layout:
- src/main/java/.../presentation or ui (UI layer)
- src/main/java/.../ViewModel (MVVM)
- src/main/java/.../service (DataLayerListenerService in hanheld)
- src/main/res – drawables, themes, strings
- Gradle build scripts at root and per-module define dependencies and packaging.

Step 3: Examine README (empty)
- No additional architecture details, so we infer from code:
- Both apps use MVVM (ViewModel + Compose-based UI/theme packages).
- Data synchronization uses Google’s Wearable Data Layer API (DataLayerListenerService in the phone module and ClientDataViewModel in both).

a. Main Components
1. Wearable App
– Presentation Layer (Jetpack Compose UI, navigation host, screens/components)
– Wearable ViewModel (ClientDataViewModel)
– Device Sensor Inputs (heart rate, steps, etc.)
– Wear OS Tile (FitWatchTile)
2. Handheld App
– UI Layer (Compose-based MainActivity/ViewModel-driven UI)
– Handheld ViewModel (ClientDataViewModel)
– DataLayerListenerService (listens for data events from wearable)
3. Wearable Data Layer API
– Communication channel between wearable & phone
4. Device Hardware
– Wearable sensors (accelerometer, heart-rate sensor, etc.)

b. Relationships & Interactions
1. Sensors → Wearable ViewModel
- ViewModel collects sensor data
2. Wearable ViewModel → Wearable Data Layer API
- DataItems or Messages sent to phone
3. Wearable Data Layer API ↔ Handheld DataLayerListenerService
- Data layer sync
4. DataLayerListenerService → Handheld ViewModel
- Forwards received data to UI
5. Handheld ViewModel → Handheld UI
- Renders data in phone app

c. Architectural Patterns
- MVVM in both modules
- Single Responsibility: Services for comms, ViewModels for state, Compose for UI
- Decoupled communication via Wearable Data Layer

d. Key Technologies
- Kotlin
- Android Jetpack Compose (ui/theme packages)
- Wear OS Tile API
- Google Play Services Wearable Data Layer
- Gradle multi-module build

Step 5: Tailoring to This Project
- Dual-app nature: two frontends (wearable & handheld) + shared comms layer.
- Sensor → UI flow on the watch, and comms → UI flow on the phone.
- No remote server—system is entirely peer-to-peer via Wearable Data Layer.

- Rectangles (components): Wearable App, Handheld App, Data Layer API, Sensors
– Sensor data flow → Wearable ViewModel → Data Layer
– Data Layer → Handheld Service → ViewModel → UI
– Blue for Wearable components
– Green for Handheld components
– Orange for shared comms layer
- Labels:
– Component names, interface/API names (e.g., DataClient.sendDataItem)
– Data types (heart rate, step count)

Step 7: Level of Detail
- Break apps into:
- UI (screens, tiles)
- ViewModel
- Communication/service
- Hardware/sensors
- Data flow and dependencies clearly.
- Avoid unnecessary detail—focus on runtime interactions and module boundaries.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Sensors
    Sensors["Sensors\n(Heart Rate, Steps, Accelerometer)"]:::hw

    %% Wearable App Module
    subgraph "Wearable App" 
        direction TB
        FitWatchNavHost["Navigation Host\n(FitWatchNavHost)"]:::wearable
        FitWatchTile["Wear OS Tile\n(FitWatchTile)"]:::wearable
        subgraph "UI Screens"
            direction TB
            HeartRate["Heart Rate Screen"]:::wearable
            StepTracker["Step Tracker Screen"]:::wearable
            SPO2["SPO2 Screen"]:::wearable
            Calories["Calories Screen"]:::wearable
            Summary["Summary Screen"]:::wearable
            WaterTracking["Water Tracking Screen"]:::wearable
            Meals["Meals Screen"]:::wearable
            Nutrients["Nutrients Screen"]:::wearable
        end
        WVM["Wearable ViewModel\n(ClientDataViewModel)"]:::wearable
    end

    %% Shared Communication Layer
    DataLayer["Wearable Data Layer API"]:::shared

    %% Handheld App Module
    subgraph "Handheld App"
        direction TB
        DLS["DataLayerListenerService"]:::handheld
        HVM["Handheld ViewModel\n(ClientDataViewModel)"]:::handheld
        MainUI["MainActivity / UI Layer"]:::handheld
        Theme["UI Theme & Resources"]:::handheld
    end

    %% Data Flow
    Sensors -->|"collects data"| WVM
    WVM -->|"DataClient.sendDataItem"| DataLayer
    DataLayer -->|"DataEvents"| DLS
    DLS -->|"forwards data"| HVM
    HVM -->|"updates state"| MainUI

    %% Click Events
    click WVM "https://github.com/manas8114/shmt/blob/main/wearable/src/main/java/com/example/fitwatch/presentation/ClientDataViewModel.kt"
    click FitWatchTile "https://github.com/manas8114/shmt/blob/main/wearable/src/main/java/com/example/fitwatch/presentation/tiles/FitWatchTile.kt"
    click FitWatchNavHost "https://github.com/manas8114/shmt/blob/main/wearable/src/main/java/com/example/fitwatch/presentation/navigation/FitWatchNavHost.kt"
    click HeartRate "https://github.com/manas8114/shmt/blob/main/wearable/src/main/java/com/example/fitwatch/presentation/screens/Heart_Rate/Heart_Rate.kt"
    click StepTracker "https://github.com/manas8114/shmt/blob/main/wearable/src/main/java/com/example/fitwatch/presentation/screens/StepTrackerScreen/StepTrackerScreen.kt"
    click SPO2 "https://github.com/manas8114/shmt/blob/main/wearable/src/main/java/com/example/fitwatch/presentation/screens/SPO2/SPO2.kt"
    click Calories "https://github.com/manas8114/shmt/blob/main/wearable/src/main/java/com/example/fitwatch/presentation/screens/caloriestracking/CaloriesScreen.kt"
    click Summary "https://github.com/manas8114/shmt/blob/main/wearable/src/main/java/com/example/fitwatch/presentation/screens/summarylist/SummaryScreen.kt"
    click WaterTracking "https://github.com/manas8114/shmt/blob/main/wearable/src/main/java/com/example/fitwatch/presentation/screens/watertracking/WaterTrackingScreen.kt"
    click Meals "https://github.com/manas8114/shmt/blob/main/wearable/src/main/java/com/example/fitwatch/presentation/screens/meals/MealsScreen.kt"
    click Nutrients "https://github.com/manas8114/shmt/blob/main/wearable/src/main/java/com/example/fitwatch/presentation/screens/nutrients/NutrientsScreen.kt"
    click MainUI "https://github.com/manas8114/shmt/blob/main/hanheld/src/main/java/com/example/fitwatch/MainActivity.kt"
    click HVM "https://github.com/manas8114/shmt/blob/main/hanheld/src/main/java/com/example/fitwatch/ClientDataViewModel.kt"
    click DLS "https://github.com/manas8114/shmt/blob/main/hanheld/src/main/java/com/example/fitwatch/DataLayerListenerService.kt"
    click Theme "https://github.com/manas8114/shmt/blob/main/hanheld/src/main/java/com/example/fitwatch/ui/theme/Theme.kt"

    %% Styles
    classDef wearable fill:#ddeeff,stroke:#0000ff,color:#000033;
    classDef handheld fill:#ddffdd,stroke:#008000,color:#003300;
    classDef shared fill:#ffe5cc,stroke:#ff6600,color:#663300;
    classDef hw fill:#f0f0f0,stroke:#888888,color:#333333;
```
