
DreamTune AI
Sleep Tracker · Smart Alarm · Coaching
DreamTune AI is an iOS sleep app that reads eight HealthKit signals — sleep, heart rate, HRV, respiratory rate, SpO2 and more — to compute a 0–100 sleep score, then helps you sleep better with a heart-rate-reactive soundscape and a smart alarm. All analysis runs on-device through deterministic pure functions, extending to Lock Screen widgets, an Apple Watch complication, and a Live Activity.
People may have sleep data but struggle to know what it means or what to change. DreamTune AI turns that data into an actionable routine through 8-factor scoring, sleep-debt tracking, pattern prediction, and CBT-I coaching.
App preview
What it does
8-Factor Sleep Score
Weights eight factors into a 0–100 score — duration (0.22), efficiency (0.18), deep sleep (0.18), REM (0.13), heart rate (0.09), HRV (0.08), respiratory rate (0.06), and SpO2 (0.06). Weights auto-redistribute when biometric data is missing, and it is a deterministic pure function driven only by its inputs.
Biometric-Reactive Soundscape
An AVAudioEngine multi-layer mixer plays file-based and procedural nodes together, while live heart rate from HKAnchoredObjectQuery is classified into four stages — active (75+), relaxing (65–75), sleeping (55–65), deep (<55) — to crossfade layer volumes smoothly.
Procedural Sound Synthesis
To keep playing even without bundled files, AVAudioSourceNode synthesizes five noise types — pink, brown (deep/warm variants), and white — plus four nature sounds (rain, ocean, forest, wind) in real time, shaping organic texture with state such as wave phase, raindrop timing, and a wind LFO.
Smart Alarm & Wind-Down
Schedules a smart alarm within a 30-minute window around the optimal wake time, plus a wind-down routine that starts 60 minutes before bed (including 4-7-8 breathing), via UNUserNotifications — orchestrated by an actor NotificationManager.
Sleep Debt & Pattern Prediction
Calculates accumulated sleep debt against a daily target and proposes a recovery plan — recovery days, nightly added sleep, naps — then analyzes the last 14 days to predict an optimal bedtime, wake time, and expected score with a rule-based model, visualized through Swift Charts.
CBT-I Coaching Program
Tracks a CBT-I (cognitive behavioral therapy for insomnia) program with weekly sessions and a sleep-restriction window in SwiftData @Model, deriving progress from session completion, and reinforcing consistency with streaks and 7/30/100/365-day badges.
Apple Watch · Widgets · Live Activity
Ships a watchOS app with a sleep-score complication, Lock Screen gauge widgets (circular, rectangular, inline), and an ActivityKit Live Activity showing elapsed time, heart rate, and playback state during sleep — sharing data via an App Group and syncing through WatchConnectivity.
Siri Shortcuts Integration
Exposes three App Shortcuts via AppIntents — Start Bedtime Routine, Get Sleep Score, Stop Sounds — so core actions run from Siri and the Shortcuts app without opening the app.
How it's built
Language
UI
Persistence
Health
Audio
System
Commerce
Platforms
A multi-target SwiftUI app that runs on-device with no third-party dependencies. Swift 6 strict concurrency (complete) is enforced — services are actors, ViewModels are @MainActor @Observable, and the analysis logic is implemented as deterministic pure functions.
- 1
Concurrency split: I/O services such as HealthKitService and NotificationManager are actors for thread safety, while ViewModels are @MainActor @Observable injected via .environment().
- 2
Deterministic pure-function engine: SleepScoreCalculator, SleepDebtCalculator, SleepPatternPredictor, and SleepStreakCalculator are static pure functions defined solely by inputs, maximizing testability.
- 3
Adaptive scoring weights: eight factors carry fixed weights, but when biometric inputs like respiratory rate or SpO2 are missing, the remaining weight is redistributed so scores stay robust under partial data.
- 4
Real-time audio graph: SoundscapeEngine builds a layered graph of file PlayerNodes and procedural SourceNodes atop AVAudioEngine, interpolating layer volumes gradually as heart-rate stages change.
- 5
Multi-surface reach: beyond the main app, it spans Lock Screen widgets (WidgetKit), a Live Activity (ActivityKit), and an Apple Watch app + complication, sharing data through an App Group and syncing via WatchConnectivity.
- 6
Design-token system: DTColors, DTTypography, and DTSpacing tokens keep the dark sleep theme consistent, with a convention that forbids raw values in favor of tokens.
- 7
XcodeGen multi-target setup: project.yml is the single source of truth declaratively managing the iOS app, Widget extension, watchOS app, and test targets, while AppIntents provide Siri/Shortcuts entry points.
108
Swift files
40
Unit/UI tests
8
HealthKit signals
8
Sleep score factors
iPhone · Watch · Widget · Live Activity
Surfaces



