How nextgen-limited/ios-stress-app works
1. This repository is a multi-target Apple platform product, centered on an iOS app plus a standalone watchOS app, with a WidgetKit extension and a separate VitePress documentation site. The iOS/watch code lives under StressMonitor/, while docs-site/ is an independently deployable site.
2. The core app architecture is MVVM with protocol-oriented service boundaries. SwiftUI views sit on top of @Observable view models, which coordinate with service objects through protocols rather than calling frameworks directly. The main app entry points are StressMonitorApp.swift and StressMonitorWatchApp.swift.
3. The primary product flow is health-data ingestion to stress computation to local persistence and display. HealthKit managers read HRV, heart rate, sleep, activity, and recovery data, then the algorithm layer computes a StressResult using multiple stress factors and baseline calibration, and the repository layer persists the measurement history.
4. The stress calculation subsystem is split into reusable factor modules: HRV, heart rate, sleep, recovery, and activity factors feed a multi-factor calculator, with baseline and calibration services shaping the final score. This is the core business logic boundary and is independent of the UI layer.
5. Persistence and sync are separated into local storage, synchronization, and export/delete management. The repository abstraction sits over SwiftData-like local storage, CloudKit sync services push/pull records, and data-management services handle CSV/JSON export, deletion, local wipe, and CloudKit reset. This is the main data-governance boundary in the system.
6. The iOS UI is organized into feature screens: dashboard, history, trends, breathing, journal/chat, settings, onboarding, and shared design-system components. The dashboard is the main landing surface for current stress state and quick actions; history and trends consume the same measurement store for timeline and analytics views; onboarding handles HealthKit permission and baseline calibration before normal use.
7. There is a dedicated AI/chat subsystem in the iOS app. LLM services build chat context from stress and health data, then route to either Apple Intelligence or a cloud LLM service depending on configuration. Chat UI is presented as a bottom sheet and is fed by quick-action prompts, so it is a feature-layer integration rather than part of the core stress algorithm.
8. Background and notification support is a separate operational subsystem. The app includes a health background scheduler and notification manager for periodic refresh and user prompts, while the watch app has its own lighter-weight data-fetch and sync path tuned for battery and watch constraints.
9. The watchOS target is not just a thin client; it has its own HealthKit manager, stress algorithm stack, CloudKit manager, and WatchConnectivity bridge. It can compute and show stress locally, sync to iCloud directly, and optionally exchange updates with the phone for near-real-time coordination. The watch complications are built as a separate WidgetKit-style submodule with circular, rectangular, and inline views.
10. Home-screen widgets form another read-only presentation boundary. The widget extension consumes shared widget data and renders compact stress summaries in small, medium, and large configurations; it is updated through an intent/provider flow rather than direct UI state from the app.
11. Cross-cutting concerns are handled by shared utility and design-system layers. Theme tokens, fonts, gradients, accessibility modifiers, haptics, animation presets, and asset catalogs are reused across screens to keep the visual system consistent, while the app remains privacy-first by relying only on Apple frameworks: SwiftUI, HealthKit, SwiftData, CloudKit, WidgetKit, and WatchConnectivity.
12. Build and validation are split by target and automation. Xcode schemes exist for iOS and watchOS, unit/UI tests cover the main app and watch app, and GitHub Actions CI builds/tests the project. The docs site is deployed separately and serves product, architecture, and user guidance outside the runtime app stack.
Main entry points: MainTabView.swift Main flow · WatchHealthKitManager.swift Watch stack · StressRepository.swift Persistence · HealthKitManager.swift Health ingest
Components 19
iOS app
Main iPhone/iPad application under StressMonitor/
- iOS app · Primary mobile application entrypoint and feature shell
StressMonitor/StressMonitor/StressMonitorApp.swift - Main flow · Dashboard-centric iOS feature shell and navigation
StressMonitor/StressMonitor/Views/MainTabView.swift - Dashboard · Landing surface for current stress state and quick actions
StressMonitor/StressMonitor/Views/DashboardView.swift - History & trends · Timeline, detail, and trend views over stored measurements
StressMonitor/StressMonitor/Views/HistoryView.swift - Onboarding · Permission, baseline calibration, and first-run setup
StressMonitor/StressMonitor/Views/Onboarding/OnboardingWelcomeView.swift - AI chat · Bottom-sheet chat and prompt experience for stress guidance
StressMonitor/StressMonitor/Views/Chat/ChatBottomSheetView.swift
watchOS app
Standalone watch target and complication stack
- Watch app · Standalone watch application entrypoint
StressMonitor/StressMonitorWatch Watch App/StressMonitorWatchApp.swift - Watch stack · Watch-side health, algorithm, connectivity, and cloud coordination
StressMonitor/StressMonitorWatch Watch App/Services/WatchHealthKitManager.swift - Complications · Circular, rectangular, and inline complication rendering
StressMonitor/StressMonitorWatch Watch App/Complications/ComplicationBundle.swift
Widget extension
Home-screen widget target
- Widget ext · Home-screen widget extension entrypoint
StressMonitor/StressMonitorWidget/StressMonitorWidget.swift - Widget data · Shared compact data consumed by the widget extension
StressMonitor/StressMonitor/Models/WidgetSharedData.swift
Docs site
Independently deployable VitePress documentation site
- Docs site · Separate documentation deployment
docs-site/.vitepress/config.ts
Shared layers
Cross-cutting models, services, UI system, and utilities
- Stress engine · Multi-factor scoring, calibration, and result generation
StressMonitor/StressMonitor/Services/Algorithm/MultiFactorStressCalculator.swift - Health ingest · HealthKit reads for HRV, heart rate, sleep, recovery, and activity
StressMonitor/StressMonitor/Services/HealthKit/HealthKitManager.swift - Persistence · Local measurement repository behind protocol boundaries
StressMonitor/StressMonitor/Services/Repository/StressRepository.swift - Sync & ops · CloudKit sync plus export, delete, wipe, and reset operations
StressMonitor/StressMonitor/Services/Sync/SyncManager.swift - LLM stack · Chat context building and routing to Apple Intelligence or cloud LLM
StressMonitor/StressMonitor/Services/LLM/ChatContextBuilder.swift - Background ops · Periodic refresh scheduling and user prompts
StressMonitor/StressMonitor/Services/Background/HealthBackgroundScheduler.swift - UI system · Theme tokens, typography, spacing, accessibility, and reusable components
StressMonitor/StressMonitor/Theme/DesignTokens.swift
Connections 25
- iOS app → Main flow: launches · App entrypoint hosts primary navigation
- Main flow → Dashboard: shows · Main tab shell exposes dashboard as the primary surface
- Main flow → History & trends: routes to · Navigation includes history and trend analysis screens
- Main flow → Onboarding: routes to · First-run setup gates normal use
- Main flow → AI chat: opens · Feature navigation presents bottom-sheet AI chat
- Dashboard → Health ingest: reads · Dashboard reflects latest health data and permissions state
- History & trends → Persistence: reads · Timeline and analytics consume stored measurements
- Onboarding → Health ingest: requests · Onboarding handles HealthKit access and calibration input
- Health ingest → Stress engine: feeds · Collected health signals are passed into scoring
- Stress engine → Persistence: writes · Computed stress results are persisted as measurement history
- Sync & ops → Persistence: syncs · Cloud sync operates over locally stored records
- Sync & ops → Watch stack: coordinates · Data can be exchanged across phone and watch
- Background ops → Health ingest: refreshes · Background scheduler supports periodic health refresh
- AI chat → LLM stack: uses · Chat UI depends on context building and LLM routing
- LLM stack → Persistence: reads · Chat context is built from stored stress and health history
- Watch app → Watch stack: launches · Watch app hosts its own runtime stack
- Watch stack → Stress engine: computes · Watch can score stress locally on-device
- Watch stack → Sync & ops: syncs · Watch target can push/pull via CloudKit and coordination paths
- Watch stack → Complications: renders · Watch complications are powered by watch-side data
- Widget ext → Widget data: reads · Widget extension consumes shared widget payloads
- Widget data → Persistence: derived from · Widget content is sourced from the stored measurement state
- UI system → Dashboard: styles · Shared design system shapes the main app surfaces
- UI system → History & trends: styles · Analytics screens reuse shared visual primitives
- UI system → Complications: styles · Watch complication views reuse watch-specific tokens
- Docs site → iOS app: documents · Docs site explains product and usage outside runtime app code