# madhursatija/whoof architecture

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

- Interactive diagram: https://gitdiagram.com/madhursatija/whoof
- Repository: https://github.com/madhursatija/whoof

## Overview

1. This repository is a local-first iOS app plus a separate Rust core and a small Live Activity extension. The main product is the SwiftUI app; the Rust crate is compiled into a platform-specific static library and linked through a C bridge. Most device data stays on-device.

2. The app entry path is `GooseSwiftApp` → `RootView` → `AppShellView` / `AppRouter`. `GooseAppModel` is the central state owner: it coordinates lifecycle, onboarding gates, BLE ownership, sync status, and the high-level health summaries that drive the tabs.

3. The primary navigation split is Home, Health, Coach, and More. Each tab is implemented as a cluster of SwiftUI views around a shared app/store model rather than as isolated screens, so the architecture is “shared state + feature surfaces” instead of per-tab subapps.

4. Bluetooth ingestion is the core runtime boundary. `GooseBLEClient` handles CoreBluetooth scanning, connection, command dispatch, historical sync, parsing, and delegate callbacks. The various `+Commands`, `+Parsing`, `+Historical*`, and `+Peripheral/CentralDelegate` files show that BLE is intentionally split into protocol, transport, and user-action layers.

5. Incoming BLE data is normalized into packet/state aggregators and then published into the app model. Files like `BLEUIStateAggregator`, `PacketUIStateAggregator`, `GooseAppModel+PacketPublishing`, and the overnight spool/mirror queues indicate a pipeline that turns raw frames into UI-ready state while preserving raw capture for debugging and replay.

6. The Rust core is the algorithmic boundary. `GooseRustBridge` calls into `Rust/core` via `goose_core_bridge.h`, and the Rust crate owns protocol details, historical-sync logic, metrics, validation, export, storage checks, sleep/step/recovery algorithms, and reference comparisons. Swift depends on Rust for parsing/derivation, not just for convenience wrappers.

7. Persistent local data is split by concern. `HealthDataStore` and its extensions hold the user-facing metric history and derived datasets; `MoreDataStore` and `GooseMessageStore` support operational/debug messaging and settings; onboarding and coach API key state are stored separately. The architecture keeps raw packet capture, derived health records, and UI state in different stores.

8. The health experience is built from the shared store rather than directly from live sensors. `HealthView`, `HomeView`, and the many `Health*`, `Home*`, `Sleep*`, `Fitness*`, and `Recovery*` view files render dashboards, trends, sheets, and cards for sleep, recovery, strain, stress, cardio, energy, and core vitals. These surfaces consume derived metrics from the store, so missing-data states are first-class.

9. There are two distinct data acquisition modes. Live BLE streaming feeds heart rate, HRV, respiratory rate, and other real-time values; historical sync pulls stored band history and populates sleep, steps, temperature trend, and deeper recovery data. The README’s “live stream vs history sync” split is reflected in the model names and in the Rust `health_sync` / `historical_sync` tooling.

10. The overnight and activity pipelines are separate subdomains inside the app model. Files such as `ActivityLocationTracker`, `PassiveActivityDetector`, `ActivitySessionModel`, `OvernightRawNotificationSpool`, `OvernightSQLiteMirrorQueue`, and the `GooseAppModel+Overnight*` extensions suggest dedicated logic for detecting sessions, capturing overnight notifications, and rolling those into recovery/sleep state.

11. Apple Health is an integration boundary, not the primary source of truth. `HealthKitMetricExporter` pushes selected local metrics outward, while `HealthKitSleepImporter` brings in sleep-related data. This means the app can both consume and emit health data, but the app’s own local store remains the canonical layer.

12. The Coach subsystem is a separate feature stack with its own state, UI, and optional remote dependency. `CoachView`, `CoachChatModel`, `CoachComposer`, `CoachToolDefinitions`, `CoachLocalToolContext`, and `GeminiCoachClient` indicate a chat-style assistant that summarizes local metrics, explains missing data, and may call an external Gemini-backed service when enabled. API key storage is isolated in `CoachAPIKeyStore`.

13. `MoreView` is the operational and developer surface. It contains connection lab, capture/import/export, raw data inspection, algorithm/debug tools, and profile/settings-like screens. This is the place where raw packets and internal diagnostics are intentionally exposed without cluttering the consumer tabs.

14. The app has a separate Workout Live Activity extension in `GooseWorkoutLiveActivityExtension`. It uses shared activity attributes/controller types from the main target, so workout presentation is an external system boundary rather than part of the main SwiftUI navigation stack.

15. The Rust tree is also a development and validation platform, not just a library. `Rust/core` includes many CLI binaries, fixtures, benchmarks, property tests, and reference-algo comparisons, which means the processing pipeline is heavily validated outside the iOS app. That testing/fixture ecosystem is part of the architecture because it defines the contract Swift relies on.

Main entry points: [`GooseSwift/GooseAppModel.swift`](https://github.com/madhursatija/whoof/blob/main/GooseSwift/GooseAppModel.swift) (App Model), [`GooseSwift/HealthDataStore.swift`](https://github.com/madhursatija/whoof/blob/main/GooseSwift/HealthDataStore.swift) (Health Store), [`GooseSwift/RootView.swift`](https://github.com/madhursatija/whoof/blob/main/GooseSwift/RootView.swift) (Root View), [`GooseSwift/GooseBLEClient.swift`](https://github.com/madhursatija/whoof/blob/main/GooseSwift/GooseBLEClient.swift) (BLE Client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ios_app["iOS App"]
  node_goose_swift_app["App Entry<br/>SwiftUI app bootstrap"]
  node_root_view["Root View<br/>navigation root<br/>[RootView.swift]"]
  node_app_shell_router["App Shell<br/>tab router<br/>[AppShellView.swift]"]
  node_goose_app_model["App Model<br/>state coordinator"]
  node_ble_client["BLE Client<br/>CoreBluetooth pipeline"]
  node_packet_aggregators["Packet State<br/>ui state pipeline"]
  node_health_store[("Health Store<br/>derived metrics store")]
  node_more_store[("More Store<br/>ops/debug store")]
  node_coach_stack["Coach Stack<br/>assistant feature<br/>[CoachView.swift]"]
  node_health_surfaces["Health Views<br/>dashboard UI<br/>[HealthView.swift]"]
  node_home_surfaces["Home Views<br/>dashboard UI"]
  node_more_surfaces["More Views<br/>ops/debug UI<br/>[MoreView.swift]"]
  node_onboarding_flow["Onboarding<br/>setup flow"]
  node_activity_pipeline["Activity Pipeline<br/>session detection"]
  node_rust_bridge["Rust Bridge<br/>FFI bridge"]
end

subgraph group_rust_core["Rust Core"]
  node_protocol_core["Protocol Core<br/>rust protocol/parsing<br/>[protocol.rs]"]
  node_sync_core["Sync & Metrics<br/>rust derivation<br/>[health_sync.rs]"]
  node_validation_core["Validation Tools<br/>rust tooling<br/>[reference.rs]"]
  node_storage_core["Storage & Export<br/>rust persistence<br/>[store.rs]"]
end

subgraph group_live_activity["Live Activity"]
  node_live_activity_ext["Workout Live Activity<br/>extension target"]
  node_activity_attributes["Activity Types<br/>shared activity model"]
end

node_goose_swift_app -->|"launches"| node_root_view
node_root_view -->|"enters shell"| node_app_shell_router
node_root_view -->|"gates setup"| node_onboarding_flow
node_app_shell_router -->|"binds state"| node_goose_app_model
node_goose_app_model -->|"owns BLE"| node_ble_client
node_goose_app_model -->|"publishes health"| node_health_store
node_goose_app_model -->|"publishes ops"| node_more_store
node_goose_app_model -->|"feeds coach"| node_coach_stack
node_goose_app_model -->|"tracks activity"| node_activity_pipeline
node_ble_client -->|"normalizes data"| node_packet_aggregators
node_ble_client -->|"delegates parsing"| node_rust_bridge
node_rust_bridge -->|"calls protocol"| node_protocol_core
node_rust_bridge -->|"calls derivation"| node_sync_core
node_sync_core -->|"produces metrics"| node_health_store
node_packet_aggregators -->|"updates state"| node_health_store
node_health_store -->|"drives views"| node_health_surfaces
node_health_store -->|"drives home"| node_home_surfaces
node_more_store -->|"drives ops UI"| node_more_surfaces
node_coach_stack -->|"reads summaries"| node_health_store
node_validation_core -.->|"guards contract"| node_protocol_core
node_validation_core -.->|"checks algorithms"| node_sync_core
node_storage_core -.->|"feeds export"| node_more_store
node_activity_pipeline -->|"rolls up recovery"| node_health_store
node_live_activity_ext -->|"shares models"| node_activity_attributes
node_goose_app_model -.->|"coordinates"| node_live_activity_ext

click node_goose_swift_app "https://github.com/madhursatija/whoof/blob/main/GooseSwift/GooseSwiftApp.swift"
click node_root_view "https://github.com/madhursatija/whoof/blob/main/GooseSwift/RootView.swift"
click node_app_shell_router "https://github.com/madhursatija/whoof/blob/main/GooseSwift/AppShellView.swift"
click node_goose_app_model "https://github.com/madhursatija/whoof/blob/main/GooseSwift/GooseAppModel.swift"
click node_ble_client "https://github.com/madhursatija/whoof/blob/main/GooseSwift/GooseBLEClient.swift"
click node_packet_aggregators "https://github.com/madhursatija/whoof/blob/main/GooseSwift/PacketUIStateAggregator.swift"
click node_health_store "https://github.com/madhursatija/whoof/blob/main/GooseSwift/HealthDataStore.swift"
click node_more_store "https://github.com/madhursatija/whoof/blob/main/GooseSwift/MoreDataStore.swift"
click node_coach_stack "https://github.com/madhursatija/whoof/blob/main/GooseSwift/CoachView.swift"
click node_health_surfaces "https://github.com/madhursatija/whoof/blob/main/GooseSwift/HealthView.swift"
click node_home_surfaces "https://github.com/madhursatija/whoof/blob/main/GooseSwift/HomeDashboardView.swift"
click node_more_surfaces "https://github.com/madhursatija/whoof/blob/main/GooseSwift/MoreView.swift"
click node_onboarding_flow "https://github.com/madhursatija/whoof/blob/main/GooseSwift/OnboardingView.swift"
click node_activity_pipeline "https://github.com/madhursatija/whoof/blob/main/GooseSwift/ActivitySessionModel.swift"
click node_rust_bridge "https://github.com/madhursatija/whoof/blob/main/GooseSwift/GooseRustBridge.swift"
click node_protocol_core "https://github.com/madhursatija/whoof/blob/main/Rust/core/src/protocol.rs"
click node_sync_core "https://github.com/madhursatija/whoof/blob/main/Rust/core/src/health_sync.rs"
click node_validation_core "https://github.com/madhursatija/whoof/blob/main/Rust/core/src/reference.rs"
click node_storage_core "https://github.com/madhursatija/whoof/blob/main/Rust/core/src/store.rs"
click node_live_activity_ext "https://github.com/madhursatija/whoof/blob/main/GooseWorkoutLiveActivityExtension/GooseWorkoutLiveActivityWidget.swift"
click node_activity_attributes "https://github.com/madhursatija/whoof/blob/main/GooseSwift/WorkoutLiveActivityAttributes.swift"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_goose_swift_app,node_root_view,node_app_shell_router,node_goose_app_model,node_ble_client,node_packet_aggregators,node_health_store,node_more_store,node_coach_stack,node_health_surfaces,node_home_surfaces,node_more_surfaces,node_onboarding_flow,node_activity_pipeline,node_rust_bridge toneBlue
class node_protocol_core,node_sync_core,node_validation_core,node_storage_core toneAmber
class node_live_activity_ext,node_activity_attributes toneMint
```

## Components

### iOS App

SwiftUI application, local stores, BLE ingestion, and feature surfaces

- [App Entry](https://github.com/madhursatija/whoof/blob/main/GooseSwift/GooseSwiftApp.swift): SwiftUI app bootstrap · Starts the app and hands off to the root shell · `GooseSwift/GooseSwiftApp.swift`
- [Root View](https://github.com/madhursatija/whoof/blob/main/GooseSwift/RootView.swift): navigation root · Top-level view that chooses onboarding, shell, and app flow · `GooseSwift/RootView.swift`
- [App Shell](https://github.com/madhursatija/whoof/blob/main/GooseSwift/AppShellView.swift): tab router · Coordinates the main navigation surfaces and shared app state · `GooseSwift/AppShellView.swift`
- [App Model](https://github.com/madhursatija/whoof/blob/main/GooseSwift/GooseAppModel.swift): state coordinator · Central owner for lifecycle, onboarding gates, BLE ownership, sync status, and summary state · `GooseSwift/GooseAppModel.swift`
- [BLE Client](https://github.com/madhursatija/whoof/blob/main/GooseSwift/GooseBLEClient.swift): CoreBluetooth pipeline · Handles scanning, connection, commands, parsing, sync, and delegate callbacks · `GooseSwift/GooseBLEClient.swift`
- [Packet State](https://github.com/madhursatija/whoof/blob/main/GooseSwift/PacketUIStateAggregator.swift): ui state pipeline · Normalizes raw BLE frames into UI-ready packet and connection state · `GooseSwift/PacketUIStateAggregator.swift`
- [Health Store](https://github.com/madhursatija/whoof/blob/main/GooseSwift/HealthDataStore.swift): derived metrics store · Stores user-facing metric history, snapshots, trends, and derived health datasets · `GooseSwift/HealthDataStore.swift`
- [More Store](https://github.com/madhursatija/whoof/blob/main/GooseSwift/MoreDataStore.swift): ops/debug store · Holds operational, validation, and settings-oriented state for the More surface · `GooseSwift/MoreDataStore.swift`
- [Coach Stack](https://github.com/madhursatija/whoof/blob/main/GooseSwift/CoachView.swift): assistant feature · Chat-based coach UI and local tool context for metric summaries and guidance · `GooseSwift/CoachView.swift`
- [Health Views](https://github.com/madhursatija/whoof/blob/main/GooseSwift/HealthView.swift): dashboard UI · Sleep, recovery, cardio, stress, and trend dashboards driven from shared store data · `GooseSwift/HealthView.swift`
- [Home Views](https://github.com/madhursatija/whoof/blob/main/GooseSwift/HomeDashboardView.swift): dashboard UI · Home tab views for summary, timeline, and health monitor surfaces · `GooseSwift/HomeDashboardView.swift`
- [More Views](https://github.com/madhursatija/whoof/blob/main/GooseSwift/MoreView.swift): ops/debug UI · Connection lab, capture/import/export, raw inspection, and developer tools · `GooseSwift/MoreView.swift`
- [Onboarding](https://github.com/madhursatija/whoof/blob/main/GooseSwift/OnboardingView.swift): setup flow · Permissions, persistence, and step-based onboarding screens · `GooseSwift/OnboardingView.swift`
- [Activity Pipeline](https://github.com/madhursatija/whoof/blob/main/GooseSwift/ActivitySessionModel.swift): session detection · Tracks activity, location, passive detection, and overnight recovery inputs · `GooseSwift/ActivitySessionModel.swift`
- [Rust Bridge](https://github.com/madhursatija/whoof/blob/main/GooseSwift/GooseRustBridge.swift): FFI bridge · Swift bridge into the Rust crate through the C header boundary · `GooseSwift/GooseRustBridge.swift`

### Rust Core

Algorithmic and validation boundary compiled as a static library

- [Protocol Core](https://github.com/madhursatija/whoof/blob/main/Rust/core/src/protocol.rs): rust protocol/parsing · Owns frame protocol, commands, historical sync, and parsing logic · `Rust/core/src/protocol.rs`
- [Sync & Metrics](https://github.com/madhursatija/whoof/blob/main/Rust/core/src/health_sync.rs): rust derivation · Implements health sync, historical sync, metrics, energy, recovery, sleep, and step derivation · `Rust/core/src/health_sync.rs`
- [Validation Tools](https://github.com/madhursatija/whoof/blob/main/Rust/core/src/reference.rs): rust tooling · CLI runners, fixtures, property tests, and comparison tools that lock the contract with Swift · `Rust/core/src/reference.rs`
- [Storage & Export](https://github.com/madhursatija/whoof/blob/main/Rust/core/src/store.rs): rust persistence · Local health validation, storage checks, export, and capture/import tooling · `Rust/core/src/store.rs`

### Live Activity

Workout Live Activity extension

- [Workout Live Activity](https://github.com/madhursatija/whoof/blob/main/GooseWorkoutLiveActivityExtension/GooseWorkoutLiveActivityWidget.swift): extension target · Separate Live Activity UI for workout presentation · `GooseWorkoutLiveActivityExtension/GooseWorkoutLiveActivityWidget.swift`
- [Activity Types](https://github.com/madhursatija/whoof/blob/main/GooseSwift/WorkoutLiveActivityAttributes.swift): shared activity model · Shared attributes and controller types used by the extension and main app · `GooseSwift/WorkoutLiveActivityAttributes.swift`

## Connections

- App Entry → Root View: launches · App bootstrap enters the root navigation view
- Root View → App Shell: enters shell · Routes into the main shell after onboarding and gating
- Root View → Onboarding: gates setup · Shows onboarding when permissions or setup are incomplete
- App Shell → App Model: binds state · Main tabs read from the shared application model
- App Model → BLE Client: owns BLE · Coordinates device lifecycle and data acquisition
- App Model → Health Store: publishes health · Receives normalized packets and derived metrics
- App Model → More Store: publishes ops · Feeds debug, validation, and operational state
- App Model → Coach Stack: feeds coach · Provides summaries and local context for assistant flows
- App Model → Activity Pipeline: tracks activity · Maintains session, overnight, and recovery-related pipelines
- BLE Client → Packet State: normalizes data · Raw BLE frames become UI-ready state and packet summaries
- BLE Client → Rust Bridge: delegates parsing · Uses Rust for protocol and derivation boundaries
- Rust Bridge → Protocol Core: calls protocol · FFI boundary into frame parsing and command handling
- Rust Bridge → Sync & Metrics: calls derivation · FFI boundary into historical sync and metric computation
- Sync & Metrics → Health Store: produces metrics · Derived sleep, recovery, stress, and vitals data flows into the store
- Packet State → Health Store: updates state · Packet-level inputs are folded into user-facing health history
- Health Store → Health Views: drives views · Health dashboards render from stored metrics and missing-data states
- Health Store → Home Views: drives home · Home summary surfaces consume the shared health store
- More Store → More Views: drives ops UI · Operational screens read validation and capture state
- Coach Stack → Health Store: reads summaries · Coach chats reference local metrics and trends
- Validation Tools → Protocol Core: guards contract · Fixtures and tests lock the parsing and sync behavior
- Validation Tools → Sync & Metrics: checks algorithms · Comparisons and benchmarks verify derived metric behavior
- Storage & Export → More Store: feeds export · Validation and export tooling back the developer surface
- Activity Pipeline → Health Store: rolls up recovery · Activity and overnight signals contribute to derived health state
- Workout Live Activity → Activity Types: shares models · Extension uses shared activity attributes and controller types
- App Model → Workout Live Activity: coordinates · Main app and extension share workout presentation boundaries
