# krishkrosh/trackweight architecture

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

- Interactive diagram: https://gitdiagram.com/krishkrosh/trackweight
- Repository: https://github.com/krishkrosh/trackweight

## Overview

##### Project Type and Purpose
- This is a native macOS desktop application (built in Swift 6+/Xcode 16) that uses Force Touch trackpad sensors for weight measurement.
- It follows an MVVM-style pattern with a SwiftUI frontend, Combine for reactive data flow, and a low-level touch library (OpenMultitouchSupport) for sensor access.

##### File Structure
Top-level modules:
- Sources/OpenMultitouchSupport (OMS library)
- OMSManager.swift – Touch event capture and publisher
- OMSTouchData.swift – Touch data model (pressure, position, etc.)
- TrackWeight (app code)
- TrackWeightApp.swift – App entry point
- *.swift views (ContentView, ScaleView, WeighingView, DebugView, etc.)
- *ViewModel.swift (ContentViewModel, ScaleViewModel, WeighingViewModel)
- WeighingState.swift – Domain state model
- Assets & entitlements

##### Main Components
a. User Interface Layer (SwiftUI Views)
- ContentView, HomeView, ScaleView, TrackWeightView, DebugView
b. Presentation / ViewModel Layer (Combine publishers/subscribers)
- ContentViewModel, ScaleViewModel, WeighingViewModel
c. Core Logic / Domain Model
- WeighingState, calibration logic, pressure-to-weight conversion
d. Sensor Integration Library
- OpenMultitouchSupport (OMSManager + OMSTouchData)
e. Operating System & Hardware
- macOS event system, Force Touch trackpad hardware
f. Build & Deployment
- Xcode project, Package.swift, Homebrew cask workflow

##### Relationships & Data Flow
1. User taps/places finger on trackpad → SwiftUI View reacts to ViewModel state
2. ViewModel subscribes to OMSManager pressure data publisher
3. OMSManager captures raw touch events via private macOS APIs → emits OMSTouchData streams
4. ViewModel receives pressure readings → applies calibration logic in WeighingState → computes weight
5. ViewModel publishes weight updates → SwiftUI View displays updated measurement
6. DebugView optionally subscribes to raw OMSTouchData for logging
7. Build pipeline: GitHub Actions updates Homebrew formula for distribution

##### Architectural Patterns & Principles
- MVVM (Model-View-ViewModel) separation
- Reactive data flow via Combine (Publishers & Subscribers)
- Single responsibility per ViewModel (each view has its own)
- Modular dependency on an external library (OpenMultitouchSupport)
- Sandbox disabled for low-level hardware access

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Hardware & OS"
        HW["Force Touch Trackpad & macOS Event System"]:::hardware
    end

    subgraph "Sensor Integration Library"
        OMSManager["OMSManager"]:::external
        OMSTouchData["OMSTouchData"]:::external
    end

    subgraph "Domain Logic"
        WeighingState["WeighingState (Calibration & Conversion)"]:::domain
    end

    subgraph "Presentation Layer (ViewModels)"
        ContentVM["ContentViewModel"]:::viewmodel
        ScaleVM["ScaleViewModel"]:::viewmodel
        WeighingVM["WeighingViewModel"]:::viewmodel
    end

    subgraph "UI Layer (SwiftUI Views)"
        ContentV["ContentView"]:::ui
        HomeV["HomeView"]:::ui
        ScaleV["ScaleView"]:::ui
        TrackWeightV["TrackWeightView"]:::ui
        DebugV["DebugView"]:::ui
    end

    subgraph "Build & Deployment"
        GH["GitHub Actions: update-homebrew.yml"]:::build
        PKG["Package.swift"]:::build
    end

    HW -->|"raw touch events"| OMSManager
    OMSManager -->|"OMSTouchData streams"| OMSTouchData
    OMSTouchData -->|"pressure readings"| WeighingState
    WeighingState -->|"state updates"| ContentVM
    WeighingState -->|"state updates"| ScaleVM
    WeighingState -->|"state updates"| WeighingVM

    ContentVM -->|"binds"| ContentV
    ScaleVM -->|"binds"| ScaleV
    WeighingVM -->|"binds"| TrackWeightV

    OMSTouchData -->|"raw events"| DebugV

    PKG -.-> GH

    click ContentV "https://github.com/krishkrosh/trackweight/blob/main/TrackWeight/ContentView.swift"
    click HomeV "https://github.com/krishkrosh/trackweight/blob/main/TrackWeight/HomeView.swift"
    click ScaleV "https://github.com/krishkrosh/trackweight/blob/main/TrackWeight/ScaleView.swift"
    click TrackWeightV "https://github.com/krishkrosh/trackweight/blob/main/TrackWeight/TrackWeightView.swift"
    click DebugV "https://github.com/krishkrosh/trackweight/blob/main/TrackWeight/DebugView.swift"
    click ContentVM "https://github.com/krishkrosh/trackweight/blob/main/TrackWeight/ContentViewModel.swift"
    click ScaleVM "https://github.com/krishkrosh/trackweight/blob/main/TrackWeight/ScaleViewModel.swift"
    click WeighingVM "https://github.com/krishkrosh/trackweight/blob/main/TrackWeight/WeighingViewModel.swift"
    click WeighingState "https://github.com/krishkrosh/trackweight/blob/main/TrackWeight/WeighingState.swift"
    click OMSManager "https://github.com/krishkrosh/trackweight/blob/main/Sources/OpenMultitouchSupport/OMSManager.swift"
    click OMSTouchData "https://github.com/krishkrosh/trackweight/blob/main/Sources/OpenMultitouchSupport/OMSTouchData.swift"
    click GH "https://github.com/krishkrosh/trackweight/blob/main/.github/workflows/update-homebrew.yml"
    click PKG "https://github.com/krishkrosh/trackweight/blob/main/Package.swift"

    classDef ui fill:#D0E6FF,stroke:#0366D6,color:#0366D6
    classDef viewmodel fill:#E6FFEB,stroke:#28A745,color:#28A745
    classDef domain fill:#FFF5CC,stroke:#D4A017,color:#D4A017
    classDef external fill:#FFDADA,stroke:#D73A49,color:#D73A49
    classDef hardware fill:#F0F0F0,stroke:#6A737D,color:#6A737D
    classDef build fill:#EEEEEE,stroke-dasharray: 5 5,stroke:#444444,color:#444444
```
