Inspiration
In Indonesia, the first report after a disaster is rarely written in a form. It is a voice note, a WhatsApp message, a line in a notebook: "30 families at the Sukamaju village hall need water and blankets, the road is blocked by a landslide, two infants have fever."
That sentence contains six structured fields. By the time it is retyped at a coordination post, the network is gone, the detail has drifted, and nobody can tell which version is true. We watched relays work this way: information degrades exactly when decisions become urgent.
LENTERA exists to close that gap. It turns the raw note into a validated report on the device, keeps it alive with no connection, and only escalates to the cloud when a human consents and the task genuinely needs cross-report context.
What it does
A volunteer writes the note exactly as it arrived and optionally attaches one photo. LENTERA returns an editable extraction card — summary, category, urgency, location, people affected, urgent needs — and the volunteer is the final validator. Nothing is saved until a human confirms it.
From there:
- Queue — the report is written to a local-first queue with a client-generated ID. Status is always visible:
queued,sent,needs review, orconflict. There is no spinner that hides a failed write. - Survives reload — cut the network, reload the app, and the report is still there with its full history.
- Map — Indonesian province geometry is bundled with the app, so density shading and province drill-down work in airplane mode.
- SITREP — for decisions across posts, a consent-gated cloud task deduplicates reports describing the same incident and writes a ≤250-word daily brief in the chosen language. Every claim carries a source-report ID that opens the original record.
- Bilingual by design — Indonesian is the default, one tap switches every label and the language the model writes in. ## How we built it LENTERA is a mobile-first PWA: Vite + React 19 + TypeScript (strict) + Tailwind, with shadcn-style primitives.
Hybrid inference, with an explicit policy. Firebase AI Logic is the only AI runtime. Nothing calls a model endpoint directly. Routing is decided by declared policy, never by navigator.onLine:
| Path | Work | Why |
|---|---|---|
| Gemini Nano (on device) | note + photo → structured JSON | frequent, private, must work with zero connectivity |
| Gemini 3.5 Flash Lite (cloud) | dedupe, cross-report clustering, daily SITREP | needs context a single note cannot provide |
The app reports the path the SDK actually used, and that path is persisted on every report.
The model is treated as untrusted. Every response is validated with a strict Zod schema before it can reach the UI or storage. Invalid on-device output triggers exactly one cloud retry; if the cloud is unavailable, the local result is kept and flagged needs review instead of being silently promoted.
Privacy before egress. Reporter names and phone numbers are replaced with tokens before any cloud call; the token map never leaves the device. Victim and casualty details stay as product data because coordinators need them.
Offline that is honest. Firestore's persistent cache backs a local-first queue. Saves use a client-generated ID and an upsert, so a reconnect can never duplicate a report. If a remote copy is newer, the app raises conflict for a human decision instead of applying last-write-wins.
SITREP you can audit. Deduplication clusters below 0.6 confidence are never applied — they are surfaced for review. The narrative is capped at 250 words and every claim links back to its source reports.
Boundaries enforced by CI. Only src/modules/inference may import firebase/ai. Only src/modules/queue may import firebase/firestore. The reports module is pure — no Firebase, no React, no DOM. dependency-cruiser fails the build on a violation.
Verification. 53 unit tests, 11 Firestore emulator rules tests, App Check (reCAPTCHA Enterprise in production), and a guarded deploy script.
Challenges we ran into
Path is not connectivity. Our first routing attempt keyed off navigator.onLine, which lies constantly on field devices. We replaced it with declared policy plus the SDK's real inferenceSource, so the UI can say "cloud fallback" truthfully.
Unvalidated model output is a data-loss bug. The first extraction we recorded returned an empty summary while claiming success. That forced a guard: validate, retry once, and if the second attempt fails, keep the local result and mark it for review rather than shipping an empty report.
Offline reload is not a checkbox. A service worker only helps once it controls the page, and auth restoration can take several seconds on a cold offline start. We made that state visible — "stored on this device" — instead of faking instant recovery.
Duplicates after reconnect. Retrying a write is the natural instinct, and it is also how you create two copies of the same emergency. Client-generated IDs plus upsert plus a conflict state solved it.
Bilingual output, not just bilingual labels. Translating the UI was easy. Making the model answer in the same language, including cluster reasons and the SITREP, required threading the language choice through every prompt and schema.
Accomplishments that we're proud of
What we learned
The model call is the easy part. The product is the state machine around it: what happens when the model is wrong, when the network disappears mid-write, when two devices disagree, and when a coordinator has to trust a sentence they did not write. Designing for those states — and making them visible rather than hiding them — is what makes an offline-first AI tool usable in the field.
What's next for LENTERA: Offline-First Field Reports
- A coordinator console for assigning posts and reviewing conflicts in bulk.
- Intake from WhatsApp and SMS, so a note does not have to be retyped at all.
- A device matrix that verifies the on-device path across real field hardware.
- Field trials with posyandu health workers and village logistics couriers.
Built With
- cloud-firestore
- dependency-cruiser
- firebase
- firebase-ai-logic
- firebase-app-check
- firebase-authentication
- firebase-hosting
- gemini
- gemini-nano
- geoboundaries
- google-cloud
- lucide
- pwa
- react
- react-router
- tailwind-css
- testing-library
- typescript
- vite
- vite-pwa
- vitest
- zod