How madhursatija/whoof works
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: GooseAppModel.swift App Model · HealthDataStore.swift Health Store · RootView.swift Root View · GooseBLEClient.swift BLE Client
Components 21
iOS App
SwiftUI application, local stores, BLE ingestion, and feature surfaces
- App Entry · Starts the app and hands off to the root shell
GooseSwift/GooseSwiftApp.swift - Root View · Top-level view that chooses onboarding, shell, and app flow
GooseSwift/RootView.swift - App Shell · Coordinates the main navigation surfaces and shared app state
GooseSwift/AppShellView.swift - App Model · Central owner for lifecycle, onboarding gates, BLE ownership, sync status, and summary state
GooseSwift/GooseAppModel.swift - BLE Client · Handles scanning, connection, commands, parsing, sync, and delegate callbacks
GooseSwift/GooseBLEClient.swift - Packet State · Normalizes raw BLE frames into UI-ready packet and connection state
GooseSwift/PacketUIStateAggregator.swift - Health Store · Stores user-facing metric history, snapshots, trends, and derived health datasets
GooseSwift/HealthDataStore.swift - More Store · Holds operational, validation, and settings-oriented state for the More surface
GooseSwift/MoreDataStore.swift - Coach Stack · Chat-based coach UI and local tool context for metric summaries and guidance
GooseSwift/CoachView.swift - Health Views · Sleep, recovery, cardio, stress, and trend dashboards driven from shared store data
GooseSwift/HealthView.swift - Home Views · Home tab views for summary, timeline, and health monitor surfaces
GooseSwift/HomeDashboardView.swift - More Views · Connection lab, capture/import/export, raw inspection, and developer tools
GooseSwift/MoreView.swift - Onboarding · Permissions, persistence, and step-based onboarding screens
GooseSwift/OnboardingView.swift - Activity Pipeline · Tracks activity, location, passive detection, and overnight recovery inputs
GooseSwift/ActivitySessionModel.swift - Rust 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 · Owns frame protocol, commands, historical sync, and parsing logic
Rust/core/src/protocol.rs - Sync & Metrics · Implements health sync, historical sync, metrics, energy, recovery, sleep, and step derivation
Rust/core/src/health_sync.rs - Validation Tools · CLI runners, fixtures, property tests, and comparison tools that lock the contract with Swift
Rust/core/src/reference.rs - Storage & Export · Local health validation, storage checks, export, and capture/import tooling
Rust/core/src/store.rs
Live Activity
Workout Live Activity extension
- Workout Live Activity · Separate Live Activity UI for workout presentation
GooseWorkoutLiveActivityExtension/GooseWorkoutLiveActivityWidget.swift - Activity Types · Shared attributes and controller types used by the extension and main app
GooseSwift/WorkoutLiveActivityAttributes.swift
Connections 25
- 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