Inspiration
Pakistan has about 90,000 Lady Health Workers (LHWs). They walk from house to house in rural villages, visiting new mothers and newborns. Most newborn and maternal deaths happen in the first week after birth. Many of them follow danger signs that were visible at home: fever, heavy bleeding, fast breathing, a baby who stops feeding.
LHWs work with paper registers, often with no mobile signal, and they write everything up hours later. A sign that gets missed or written down late can cost a life. We wanted a tool that fits how they already work. They talk, the phone listens, the visit gets structured, and the right cases are flagged at the door, with or without internet.
What it does
Doorstep has two parts: an offline-first Android app for the health worker and a web dashboard for her supervisor.
Worker app (Android)
- Dictate the visit. On-device speech-to-text works in airplane mode once the offline language pack is installed. It downloads automatically.
- Redaction before any AI. Names and phone numbers are removed on the phone by deterministic rules. The AI only ever sees
[PATIENT]. - Hybrid AI form-filling. Firebase AI Logic turns the note into a structured visit form. It uses Gemini in the cloud when online and Gemini Nano on the device when available. The app shows which one was used ("Filled by Cloud AI" / "Filled by On-device AI").
- The rules decide the flag, not the AI. Fixed WHO checklist rules (IMNCI young-infant and postnatal maternal danger signs) map the facts to Routine, Follow up within 24h or Refer now, and give the reason.
- Voice assistant. It asks about any critical item the worker missed. Answers are understood on the phone in English, Roman Urdu and Urdu, so this also works offline.
- "Safe until seen." For referrals, the family gets reviewed WHO home-care guidance in Urdu for the journey. The worker can share the home's GPS location so transport can find the house.
- Document scan. Old medical reports are read with ML Kit OCR on the phone, redacted, and turned into a medical history and a rule-based "high-risk mother" check.
- Offline-first sync. SQLite on the phone is the source of truth. Only the redacted record syncs to Firestore when signal returns.
Supervisor dashboard (Web / Chrome)
- Live list and village map with Refer-now cases first, and the referral location for ambulance dispatch.
- AI referral letters, weekly summaries, "Ask Doorstep" and outbreak alert explanations. All of them run through the same Firebase AI Logic hybrid SDK.
- A one-click On-device AI switch runs these on Gemini Nano in Chrome: private, free, and no cloud round-trip.
How we built it
- Worker app: Expo (React Native, TypeScript), expo-sqlite, expo-speech-recognition, Zod schemas, and a custom Kotlin Expo module that wraps Firebase AI Logic (
firebase-ai+firebase-ai-ondevice). React Native has no binding for on-device AI Logic, so we wrote this bridge ourselves. It exposesgenerate(), the Nano status, model download with progress, andresponse.inferenceSource. - Dashboard: React 19, Vite, Tailwind, Firebase JS SDK with
getGenerativeModel(..., { mode: InferenceMode.PREFER_IN_CLOUD | ONLY_ON_DEVICE }), Leaflet/OpenStreetMap and Recharts. - Firebase: Auth with custom claims (
role,areaId), Firestore security rules that allow-list every synced field, App Check, Remote Config for the checklist and prompts, and Hosting. - The AI pipeline. Each model call follows the same strict path:
$$ \text{note} \xrightarrow{\text{redact}} \text{safe text} \xrightarrow{\text{PII guard}} \text{LLM (JSON schema)} \xrightarrow{\text{Zod}} \text{form} \xrightarrow{\text{WHO rules}} \text{flag} $$
Invalid output gets one strict retry, then one cloud attempt. The model never overwrites the worker's own answers, and an unclear answer becomes unknown, never no.
- The flag is a pure function of the facts. For example, a newborn is flagged Refer now when
$$ \text{RR} \ge 60\ \tfrac{\text{breaths}}{\text{min}} \;\lor\; T \ge 37.5^\circ\text{C} \;\lor\; \text{not feeding} \;\lor\; \dots $$
This logic lives in tested TypeScript, not in a prompt.
Challenges we ran into
- On-device AI on Android is very new. The hybrid API is in preview, and the docs only showed the web version. We read the AAR bytecode (
javap) to find the real Kotlin API. We also had to pin the rightfirebase-ai-ondevicebeta to matchfirebase-ai. - Gemini Nano only runs on a few flagship phones. Our own test phones had no AICore. We tested on Samsung Remote Test Lab devices, where AICore often reported the model as unavailable. So we built clear diagnostics into the app, and a "Force on-device" switch to prove which path ran.
- Build issues. We hit Kotlin metadata mismatches between Firebase BoM versions, Windows path-length limits in React Native's CMake builds, and memory crashes on a 16 GB laptop. We fixed them with config plugins, a pinned BoM and a newer CMake.
- Speech recognition in the field. Some Samsung recognisers never send an "end" event, so Stop needed a fallback. Clinical words get misheard ("fever" vs "Pfizer"), so we added a contextual vocabulary.
- App Check is enforced by Firebase AI Logic. It has to be set up separately on each platform and for each build type.
Accomplishments that we're proud of
- One hybrid SDK on two platforms. The same Firebase AI Logic routes between cloud and on-device on Android and in Chrome, with a visible label showing which one answered.
- It really works offline. Dictation, redaction, the danger-sign checklist, the voice assistant and saving the visit all work in airplane mode.
- Privacy by design. No raw name ever leaves the phone. Redaction is deterministic and tested, the PII guard blocks the call, and Firestore rules reject any field that isn't allow-listed.
- Safety by design. The AI extracts and writes; rules decide urgency. Home-care advice comes from a reviewed WHO library, and AI may only reword it into simpler Urdu under a validator that rejects medicines, doses or new numbers.
- A complete loop: from a spoken note in a village to a referral letter on a supervisor's screen.
What we learned
- Hybrid inference is a product decision, not only a technical one. Deciding what must run on the device (privacy, offline) and what may use the cloud (summaries, letters) shaped the whole architecture.
- On-device models can't be trusted to always return valid structured output. Schema validation, retries and fallbacks are essential.
- In health tools, the most important AI feature is often what the AI is not allowed to decide.
- Designing for low connectivity means designing for eventual sync: a local source of truth, an outbox, and clear "waiting to sync" states.
What's next for DoorStep
- Field pilot with LHWs and supervisors in one union council, with clinical review of the checklist and the Urdu content.
- Better Urdu and regional-language speech, and Urdu-script OCR for documents.
- Encryption at rest (SQLCipher) and production App Check (Play Integrity, reCAPTCHA Enterprise).
- More on-device AI as Gemini Nano reaches mid-range phones, so form-filling works offline on far more devices.
- Integration with Pakistan's LHW program reporting (the monthly register) and ambulance dispatch services.
- iOS and wider maternal care: antenatal visits, immunisation follow-up and child growth.
Built With
- ai
- android
- chrome-built-in-ai
- expo.io
- firebase
- firebase-ai-logic
- firebase-app-check
- firebase-auth
- firestore
- gemini
- gemini-nano
- kotlin
- openstreetmap
- react
- react-native
- sqlite
- vite
- web
- zod

