Inspiration

Depression affects an estimated 332 million people worldwide, and for many it comes back. People who have been through it often know their own early signs: they go to bed later, skip the gym, stop answering messages. With a therapist they write those signs down in a relapse-prevention plan, together with what helps them.

Then the plan goes into a drawer. Appointments are weeks apart, and the drift happens in between, at exactly the moment it is hardest to notice yourself. A plan on paper doesn't notice anything.

I wanted to build the part that's missing: something that quietly watches for your own signs, compares you only with yourself, and brings back your plan, in your own words, when your days start to drift. Because that data is about as personal as it gets, it had to work without sending your words anywhere.

What it does

Hearth watches the signals research links to depression: sleep, physical activity, daily rhythm, resting heart rate, time at home and the places you go. The Science page lists the sources for every signal. Heart learns your own usual days and compares it to yourself, never with anyone else, and the signs you named in your plan weigh more. When your days drift from your own pattern for a few days, it:

  • checks in gently: three taps for how you feel, your own questions, and one line in your own words;
  • shows why it asked: each signal against your own usual range on the "Why?" screen;
  • opens your plan: the signs you named, what helped last time (recalled by meaning, on the device), and your people one tap away;
  • sets context aside: a holiday you confirm doesn't count as a change;
  • hands over to your clinician only when you say so: a one-page plan for your GP, a FHIR export, or a private 7-day link.

How we built it

Every model call goes through one router built on Firebase AI Logic, and the route depends on how personal the data is:

Data Where it runs
Your own words and places (plan text, notes, check-in text) ONLY_ON_DEVICE: Gemini Nano in Chrome. No model? A plain fallback in code. Never the cloud.
Single numbers about you On the device, or with consent PREFER_ON_DEVICE
Weekly summaries you approved With consent, Gemini in the cloud, after a readable preview of what will be sent

Gemini Nano turns a plan written in plain language into cards, reads context from notes ("I'm in Spain this week"), recognises signs in a check-in, and drafts a text to a friend. With consent, cloud Gemini writes the weekly reflection and the clinician overview from weekly numbers. A privacy ledger in the app lists every model call, where it ran and exactly what was sent, and a strict Content-Security-Policy means the page can only reach the listed Firebase services.

The model never decides on its own. Every output is validated against a JSON schema, and every quote is checked against the user's own text in code: if the model invents a sign you never wrote, it is dropped. You confirm every card before it is saved.

The maths is deterministic quality control. Each feature $j$ gets a robust score against your last 56 eligible days $R_j$:

$$z_j = \operatorname{clip}\left(\frac{x_j - \operatorname{median}(R_j)}{1.4826\,\operatorname{MAD}(R_j) + \epsilon_j},\ -4,\ 4\right)$$

The scores (signs you named weigh more) combine into a daily drift score $D_d$, which goes through two classic trend tests:

$$S_d = \lambda D_d + (1-\lambda)\,S_{d-1}, \qquad \lambda = 0.3$$

$$C_d = \max\left(0,\ C_{d-1} + \frac{D_d - \mu_0}{\sigma_0} - k\right), \qquad k = 0.5$$

A day counts as changed when $S_d > \mu_0 + L\,\sigma_0\sqrt{\lambda/(2-\lambda)}$ with $L = 2.5$, or when $C_d > 4$. One bad day doesn't trigger anything; a trend does. Changed days never join the baseline, so a slow decline can't quietly become the new normal.

Over time Hearth also learns, per person, which kinds of signal go with their low days, from answers to random check-ins. It uses a ridge regression pulled towards equal weights, so it stays linear and "Why?" can still explain every alert:

$$\hat\beta = \arg\min_\beta\ \lVert y - X\beta\rVert^2 + \gamma\,\lVert \beta - \bar\beta\,\mathbf{1}\rVert^2$$

To learn more: https://hearth-9de01.web.app/#/science

Stack. A TypeScript monorepo: a deterministic engine with no I/O and golden-fixture tests; a React/Vite web app with Dexie for local storage; Firebase AI Logic (all four inference modes), App Check, anonymous Auth, Firestore and Remote Config. The same engine also runs on iOS inside JavaScriptCore, in a SwiftUI app on HealthKit data, with Apple's on-device model and Gemini through Firebase AI Logic for consented cloud tasks. Everything was built during the submission period, starting 16 November.

Challenges we ran into

  • A small model on a hard task. Turning free text into the right sensor rules is where Gemini Nano struggles most. It proposes too many signals. I had to do many tuning rounds.
  • Schema order matters. Nano fills a structured answer in order. With rules before questions, it turned every sign into a rule, even signs no sensor can see. Asking for the questions first brought the missing questions back.
  • Rare hangs. About 1 in 200 calls, Nano kept writing whitespace forever. On-device calls have no timeout by default, so I added a 30-second one with a fallback.
  • Crisis flags that are too eager. "I could murder a pizza right now" got a "possible" flag. I kept recall at 20 of 20 and made a "possible" flag add a support card, not a full-screen takeover.
  • Not letting a decline become normal. The hardest design question was keeping the baseline honest. Changed and masked days never become reference days.

Accomplishments that we're proud of

I didn't want to build a mental-health tool only on my own assumptions. I made a short overview video for clinicians and emailed 14 research groups and professional bodies in 7 countries (the Netherlands, Belgium, the UK, Germany, the US, Canada and Australia), working on depression relapse, digital phenotyping and mental-health apps. Two researchers replied with written feedback, and I also asked a mental-health practice nurse in a Dutch GP practice. None of this is an endorsement, but it changed the product:

  • Self-report deserves more weight. One researcher noted that Hearth leaned heavily on sensor data, while self-report is one of the strongest sources. Hearth already asked short check-ins on random days, independent of any signal, but barely used the answers. Now it learns from them which signals go with that person's low days (the personal weights above).
  • False alarms, sensing in practice, and a safety plan. A US researcher in digital mental health liked the within-person baseline, but wouldn't recommend it to patients without prospective evidence that the drift precedes relapse. Those worries are now at the top of my evaluation: the false-alarm rate on stable people, holiday masking, the sensing limits listed openly, and a crisis flow that works offline.
  • A clinician who would use it, within limits. A mental-health practice nurse in a Dutch GP practice (POH GGZ, the person many patients see between GP appointments) said she could recommend Hearth to some of her patients, mainly those under about 50 because of the digital skills it needs. She had no concerns and asked for a direct link to 113 and De Luisterlijn. 113 was already on the crisis screen, which works offline; De Luisterlijn is now there too, as someone to talk to on a hard day that is not a crisis.

Thinking about self-report also showed me a blind spot: Hearth used to ask less when someone stopped answering, while going quiet can itself be an early sign. Now a run of unanswered check-ins gets two short questions instead of silence.

What we learned

  • An on-device model is powerful for private text, but it needs code around it. Schemas, quote checks and a deterministic engine let a small model help without letting it decide.
  • Privacy is easiest to explain when it is visible. The ledger and the "What would be shared" preview do more than any policy text.
  • Measure everything, report the misses, and ask experts early. The two replies I got changed the product more than any feature I came up with myself.

What's next for Hearth

A retrospective test on real longitudinal data, then a small prospective study after ethics approval, the only real answer to whether the drift comes before relapse. Testing the iOS app on real iPhones.

Built With

  • chrome-prompt-api
  • cloud-firestore
  • dexie
  • firebase-ai-logic
  • firebase-app-check
  • firebase-authentication
  • firebase-hosting
  • firebase-remote-config
  • gemini
  • gemini-nano
  • healthkit
  • react
  • swift
  • swiftui
  • typescript
  • vite
Share this project:

Updates

Submission history