-
-
The explained letter: deadline quoted from the letter, what to bring, what to do
-
iPhone with Apple Intelligence: the letter is read entirely on the phone
-
What stays on the device and what the cloud sees
-
A follow-up question answered on the device by Gemini Nano
-
The review screen: exactly what leaves the device, with personal details hidden
Inspiration
My husband owns a Relocation Agency and handles the usual hassle of people wanting or needing to move to a country that is completely unfamiliar to them and, very often, where they do not speak the native language! So I completely understand their pain points, including the usual suspicion of whether they're handing over more personal details than they need to.
If you move to Portugal or Spain (or many other countries, for that matter), official letters arrive in formal, bureaucratic language: a fine, a residence appointment, a tax assessment. Miss the deadline and you can be fined or have a residence application closed. Pasting the letter into a chatbot is the obvious shortcut, and it hands over your name, tax number, address and process number. Decifra is for people who need to understand the letter without doing that.
What it does
- Reads a photo, scan or PDF with OCR on the device. Covers 9 kinds of Portuguese sender (Finanças, AIMA, Segurança Social, road-traffic fines, courts, IMT, town councils, SNS, IRN) and four Spanish ones.
- Explains the letter in plain English: what it is, how urgent, the deadline, the amount, what to do and what to bring, with official links.
- Hides names, tax and ID numbers, addresses and other identifiers on the device, then shows you exactly what would be sent. Tap any word to hide it.
- Never invents a deadline or an amount: each must quote the letter, or the app says it wasn't found. Working days are shown only when the letter says so, and dates worked out from "15 working days" are labelled as estimates.
- Answers follow-up questions, on device when possible, and drafts a formal reply with an English translation.
- Labels where each answer ran, and keeps a receipt of each cloud call with the text that was sent.
Letters and receipts stay in the browser or on the phone; no user data is written to Firestore. Decifra is not legal advice, and a Portuguese court letter always starts with talking to a lawyer or asking for legal aid.
How we used Firebase AI Logic
Hybrid inference is the privacy boundary.
- Web:
getGenerativeModelruns inONLY_ON_DEVICEorONLY_IN_CLOUD, never aPREFER_*mode, because a silent fallback could send unredacted text to the cloud. Our own router picks the model from device status, language and length, andinferenceSourcedrives the label on each answer. Portuguese letters go to cloud Gemini with details hidden, after the review screen; follow-up questions run on Gemini Nano over the English case file. Spanish letters can be read on device when Nano is ready. - Structured output on both sides:
responseJsonSchemain the cloud andresponseConstrainton device. - iPhone: Apple's on-device model reads Portuguese, so with Apple Intelligence on, a letter that fits the length limit is read entirely on the phone, with no cloud call. Otherwise it takes the same gated, redacted cloud path and says why. Redaction, routing and validation are ported to Swift and checked against the web on shared golden files.
- No on-device model? The cloud path still works in other browsers: letters and replies go through the review screen first, and follow-up questions send only the question and the case file, with known details hidden.
Also used: App Check (reCAPTCHA Enterprise on the web, App Attest on iPhone), Remote Config (one shared "brain" with prompts, redaction rules, routing thresholds and the cloud model name, tunable without a release), Anonymous Authentication, Firestore (a read-only public catalogue of letter types) and Hosting.
Challenges
Chrome rejects Portuguese as a declared input language for its built-in model, which is why Portuguese letters on the web need the redacted cloud path while the iPhone can read them locally. OCR was the harder privacy problem: photos produce broken lines and misread digits, and testing every sample after OCR exposed identifiers our rules missed. We fixed the redactor rather than loosening the tests.
Accomplishments
219 web tests and 93 Swift core tests pass. Among them, every sample photo and scan is read by the real OCR engine and the personal details listed for it are checked after redaction, including misread number plates and emails. Testing the live site before submitting turned up a misread plate, misread emails and a wrongly detected name; we fixed them and made the tests stricter. The tests cover 16 fictional letters. OCR of a real letter can still miss something, which is why the review screen comes before any letter is sent.
What we learned
Hybrid inference is most useful when the app decides explicitly what each model may see, instead of treating the cloud as a backup. Making that boundary visible, with the review screen and receipts, makes it something people can check.
What's next
More countries, starting with Germany, and testing how well on-device models read each new language.
Built during the contest
Everything in the repository was written between 18 and 30 November 2026, starting from an empty folder, with AI coding assistance. Third-party libraries are listed in the README.
Built With
- apple-foundation-models
- firebase
- firebase-ai-logic
- firebase-app-check
- firebase-authentication
- firebase-hosting
- firebase-remote-config
- firestore
- gemini
- gemini-nano
- pdf.js
- react
- swift
- swiftui
- tesseract.js
- typescript
- vision
- vite
