# nextgen-limited/ios-stress-app architecture

> Architecture diagram of the GitHub repository nextgen-limited/ios-stress-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nextgen-limited/ios-stress-app
- Repository: https://github.com/nextgen-limited/ios-stress-app

## Overview

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: [`StressMonitor/StressMonitor/Views/MainTabView.swift`](https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Views/MainTabView.swift) (Main flow), [`StressMonitor/StressMonitorWatch Watch App/Services/WatchHealthKitManager.swift`](https://github.com/nextgen-limited/ios-stress-app/blob/HEAD/StressMonitor/StressMonitorWatch%20Watch%20App/Services/WatchHealthKitManager.swift) (Watch stack), [`StressMonitor/StressMonitor/Services/Repository/StressRepository.swift`](https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Services/Repository/StressRepository.swift) (Persistence), [`StressMonitor/StressMonitor/Services/HealthKit/HealthKitManager.swift`](https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Services/HealthKit/HealthKitManager.swift) (Health ingest)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_root["Repo"]
end

subgraph group_ios["iOS app"]
  node_ios_app["iOS app<br/>SwiftUI app target"]
  node_main_flow["Main flow<br/>app navigation<br/>[MainTabView.swift]"]
  node_dashboard["Dashboard<br/>feature screen"]
  node_history_trends["History & trends<br/>analytics screens<br/>[HistoryView.swift]"]
  node_onboarding["Onboarding<br/>setup flow"]
  node_chat_ai["AI chat<br/>feature integration"]
end

subgraph group_watch["watchOS app"]
  node_watch_app["Watch app<br/>watchOS target"]
  node_watch_stack{{"Watch stack<br/>watch services"}}
  node_watch_complications["Complications<br/>watch complication UI"]
end

subgraph group_widget["Widget extension"]
  node_widget_ext["Widget ext<br/>WidgetKit target"]
  node_widget_data[("Widget data<br/>shared widget model")]
end

subgraph group_docs["Docs site"]
  node_docs_site["Docs site<br/>VitePress site<br/>[config.ts]"]
end

subgraph group_shared["Shared layers"]
  node_stress_algo{{"Stress engine<br/>domain logic"}}
  node_health_ingest[("Health ingest<br/>data acquisition")]
  node_persistence[("Persistence<br/>storage repository")]
  node_sync_ops[("Sync & ops<br/>cloud/data governance<br/>[SyncManager.swift]")]
  node_llm_stack{{"LLM stack<br/>chat services"}}
  node_background_ops["Background ops<br/>scheduler and notifications"]
  node_ui_system["UI system<br/>design system<br/>[DesignTokens.swift]"]
end

node_ios_app -->|"launches"| node_main_flow
node_main_flow -->|"shows"| node_dashboard
node_main_flow -->|"routes to"| node_history_trends
node_main_flow -->|"routes to"| node_onboarding
node_main_flow -->|"opens"| node_chat_ai
node_dashboard -->|"reads"| node_health_ingest
node_history_trends -->|"reads"| node_persistence
node_onboarding -->|"requests"| node_health_ingest
node_health_ingest -->|"feeds"| node_stress_algo
node_stress_algo -->|"writes"| node_persistence
node_sync_ops -->|"syncs"| node_persistence
node_sync_ops -->|"coordinates"| node_watch_stack
node_background_ops -->|"refreshes"| node_health_ingest
node_chat_ai -->|"uses"| node_llm_stack
node_llm_stack -->|"reads"| node_persistence
node_watch_app -->|"launches"| node_watch_stack
node_watch_stack -->|"computes"| node_stress_algo
node_watch_stack -->|"syncs"| node_sync_ops
node_watch_stack -->|"renders"| node_watch_complications
node_widget_ext -->|"reads"| node_widget_data
node_widget_data -->|"derived from"| node_persistence
node_ui_system -->|"styles"| node_dashboard
node_ui_system -->|"styles"| node_history_trends
node_ui_system -->|"styles"| node_watch_complications
node_docs_site -.->|"documents"| node_ios_app

click node_ios_app "https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/StressMonitorApp.swift"
click node_watch_app "https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitorWatch Watch App/StressMonitorWatchApp.swift"
click node_widget_ext "https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitorWidget/StressMonitorWidget.swift"
click node_docs_site "https://github.com/nextgen-limited/ios-stress-app/blob/main/docs-site/.vitepress/config.ts"
click node_main_flow "https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Views/MainTabView.swift"
click node_dashboard "https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Views/DashboardView.swift"
click node_history_trends "https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Views/HistoryView.swift"
click node_onboarding "https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Views/Onboarding/OnboardingWelcomeView.swift"
click node_chat_ai "https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Views/Chat/ChatBottomSheetView.swift"
click node_stress_algo "https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Services/Algorithm/MultiFactorStressCalculator.swift"
click node_health_ingest "https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Services/HealthKit/HealthKitManager.swift"
click node_persistence "https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Services/Repository/StressRepository.swift"
click node_sync_ops "https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Services/Sync/SyncManager.swift"
click node_llm_stack "https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Services/LLM/ChatContextBuilder.swift"
click node_background_ops "https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Services/Background/HealthBackgroundScheduler.swift"
click node_watch_stack "https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitorWatch Watch App/Services/WatchHealthKitManager.swift"
click node_watch_complications "https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitorWatch Watch App/Complications/ComplicationBundle.swift"
click node_widget_data "https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Models/WidgetSharedData.swift"
click node_ui_system "https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Theme/DesignTokens.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_ios_app,node_main_flow,node_dashboard,node_history_trends,node_onboarding,node_chat_ai toneAmber
class node_watch_app,node_watch_stack,node_watch_complications toneMint
class node_widget_ext,node_widget_data toneRose
class node_docs_site toneIndigo
class node_stress_algo,node_health_ingest,node_persistence,node_sync_ops,node_llm_stack,node_background_ops,node_ui_system toneTeal
```

## Components

### iOS app

Main iPhone/iPad application under StressMonitor/

- [iOS app](https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/StressMonitorApp.swift): SwiftUI app target · Primary mobile application entrypoint and feature shell · `StressMonitor/StressMonitor/StressMonitorApp.swift`
- [Main flow](https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Views/MainTabView.swift): app navigation · Dashboard-centric iOS feature shell and navigation · `StressMonitor/StressMonitor/Views/MainTabView.swift`
- [Dashboard](https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Views/DashboardView.swift): feature screen · Landing surface for current stress state and quick actions · `StressMonitor/StressMonitor/Views/DashboardView.swift`
- [History & trends](https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Views/HistoryView.swift): analytics screens · Timeline, detail, and trend views over stored measurements · `StressMonitor/StressMonitor/Views/HistoryView.swift`
- [Onboarding](https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Views/Onboarding/OnboardingWelcomeView.swift): setup flow · Permission, baseline calibration, and first-run setup · `StressMonitor/StressMonitor/Views/Onboarding/OnboardingWelcomeView.swift`
- [AI chat](https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Views/Chat/ChatBottomSheetView.swift): feature integration · 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](https://github.com/nextgen-limited/ios-stress-app/blob/HEAD/StressMonitor/StressMonitorWatch%20Watch%20App/StressMonitorWatchApp.swift): watchOS target · Standalone watch application entrypoint · `StressMonitor/StressMonitorWatch Watch App/StressMonitorWatchApp.swift`
- [Watch stack](https://github.com/nextgen-limited/ios-stress-app/blob/HEAD/StressMonitor/StressMonitorWatch%20Watch%20App/Services/WatchHealthKitManager.swift): watch services · Watch-side health, algorithm, connectivity, and cloud coordination · `StressMonitor/StressMonitorWatch Watch App/Services/WatchHealthKitManager.swift`
- [Complications](https://github.com/nextgen-limited/ios-stress-app/blob/HEAD/StressMonitor/StressMonitorWatch%20Watch%20App/Complications/ComplicationBundle.swift): watch complication UI · Circular, rectangular, and inline complication rendering · `StressMonitor/StressMonitorWatch Watch App/Complications/ComplicationBundle.swift`

### Widget extension

Home-screen widget target

- [Widget ext](https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitorWidget/StressMonitorWidget.swift): WidgetKit target · Home-screen widget extension entrypoint · `StressMonitor/StressMonitorWidget/StressMonitorWidget.swift`
- [Widget data](https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Models/WidgetSharedData.swift): shared widget model · Shared compact data consumed by the widget extension · `StressMonitor/StressMonitor/Models/WidgetSharedData.swift`

### Docs site

Independently deployable VitePress documentation site

- [Docs site](https://github.com/nextgen-limited/ios-stress-app/blob/main/docs-site/.vitepress/config.ts): VitePress site · Separate documentation deployment · `docs-site/.vitepress/config.ts`

### Shared layers

Cross-cutting models, services, UI system, and utilities

- [Stress engine](https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Services/Algorithm/MultiFactorStressCalculator.swift): domain logic · Multi-factor scoring, calibration, and result generation · `StressMonitor/StressMonitor/Services/Algorithm/MultiFactorStressCalculator.swift`
- [Health ingest](https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Services/HealthKit/HealthKitManager.swift): data acquisition · HealthKit reads for HRV, heart rate, sleep, recovery, and activity · `StressMonitor/StressMonitor/Services/HealthKit/HealthKitManager.swift`
- [Persistence](https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Services/Repository/StressRepository.swift): storage repository · Local measurement repository behind protocol boundaries · `StressMonitor/StressMonitor/Services/Repository/StressRepository.swift`
- [Sync & ops](https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Services/Sync/SyncManager.swift): cloud/data governance · CloudKit sync plus export, delete, wipe, and reset operations · `StressMonitor/StressMonitor/Services/Sync/SyncManager.swift`
- [LLM stack](https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Services/LLM/ChatContextBuilder.swift): chat services · Chat context building and routing to Apple Intelligence or cloud LLM · `StressMonitor/StressMonitor/Services/LLM/ChatContextBuilder.swift`
- [Background ops](https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Services/Background/HealthBackgroundScheduler.swift): scheduler and notifications · Periodic refresh scheduling and user prompts · `StressMonitor/StressMonitor/Services/Background/HealthBackgroundScheduler.swift`
- [UI system](https://github.com/nextgen-limited/ios-stress-app/blob/main/StressMonitor/StressMonitor/Theme/DesignTokens.swift): design system · Theme tokens, typography, spacing, accessibility, and reusable components · `StressMonitor/StressMonitor/Theme/DesignTokens.swift`

## Connections

- 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
