JunSoft
DreamTune AI
Health · Wellness

DreamTune AI

Sleep Tracker · Smart Alarm · Coaching

View on App Store
Overview

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.

The Problem

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.

Screenshots

App preview

  • DreamTune AI screenshot 1
  • DreamTune AI screenshot 2
  • DreamTune AI screenshot 3
  • DreamTune AI screenshot 4
Key Features

What it does

01

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.

02

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.

03

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.

04

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.

05

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.

06

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.

07

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.

08

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.

Tech Stack

How it's built

Language

Swift 6.0Strict Concurrency (complete)

UI

SwiftUISwift Charts

Persistence

SwiftData (@Model)App GroupUserDefaults

Health

HealthKitHKAnchoredObjectQuery

Audio

AVFoundationAVAudioEngineAVAudioSourceNode

System

WidgetKitActivityKitAppIntentsUserNotificationsWatchConnectivity

Commerce

StoreKit 2

Platforms

iOS 17+watchOS 10+
Architecture

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. 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. 2

    Deterministic pure-function engine: SleepScoreCalculator, SleepDebtCalculator, SleepPatternPredictor, and SleepStreakCalculator are static pure functions defined solely by inputs, maximizing testability.

  3. 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. 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. 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. 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. 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.

By the Numbers

108

Swift files

40

Unit/UI tests

8

HealthKit signals

8

Sleep score factors

iPhone · Watch · Widget · Live Activity

Surfaces