Inspiration
Across Kenya and East Africa, neighborhood retail shops (dukas) track hundreds of daily transactions on paper notebooks: Swahili and Sheng notes covering M-PESA confirmation codes, partial cash payments, and customer credit tabs (madeni). Shopkeepers hesitate to upload raw ledger pages to cloud AI tools because those notes contain customer names, mobile phone numbers, national IDs, and mobile money transaction IDs, while rural and peri-urban cellular connections drop frequently during busy trading hours.
SokoMind solves both problems using Firebase AI Logic Hybrid Inference: private routine entry parsing runs locally on Chrome Gemini Nano with an on-device PII firewall scrubbing identifiers first, while complex multimodal supplier invoices and anonymized daily restock analytics route to Cloud Gemini when connected.
What it does
SokoMind turns messy Swahili, Sheng, and English shopkeeper notes and wholesale supplier receipts into a structured, searchable retail ledger with margin analytics:
- On-Device PII Firewall: Before any prompt touches an AI model,
redactShopNote()masks Kenyan phone numbers (07...,01...,+254...), M-PESA reference codes, National ID numbers, emails, and customer names, replacing names with deterministic hashed aliases (Customer #A1B2). - Firebase AI Logic Hybrid Router: Shopkeepers and judges can switch live between
PREFER_ON_DEVICE,ONLY_ON_DEVICE,PREFER_IN_CLOUD, andONLY_IN_CLOUD(InferenceMode) while watchingresponse.inferenceSource,modelUsed, latency in milliseconds, and tokens kept local update in real time. - Offline Continuity & One-Click Nano Warmup: When offline with Chrome Gemini Nano ready, routine notes parse locally (
gemini-nano). When Gemini Nano is still downloadable, a header trigger callsinitializeDeviceModelwith live progress percentage. If Chrome Nano is unavailable on a device offline, SokoMind degrades cleanly to deterministic local parsing and queues sanitized entries locally. - Multimodal Wholesale Receipt Scanner: Upload a JPEG/PNG invoice or click Try Sample Receipt to generate a realistic Kenyan wholesale receipt on HTML5 Canvas and extract itemized SKUs and totals via Cloud Gemini (
gemini-3.8-flash, with automatic fallback togemini-3.5-flash-liteon transient high-demand errors). - Madeni Credit Tab Ledger & Settlement: Aggregates net open credit balances per hashed customer alias (
aggregateOpenCreditTabs), provides one-click Settle Tab repayments, searchable category filters, and anonymized CSV export. - Anonymized Cloud Margin & Restock Advisor + Side-by-Side Benchmark: Sends only scrubbed SKU quantities and margin totals (never customer identities or phone numbers) via
ONLY_IN_CLOUDfor practical restock advice, inspectable in the Anonymized Cloud Payload panel. A built-in Run Benchmark button measuresPREFER_ON_DEVICEvsONLY_IN_CLOUDtiming on the same masked note.
How we built it
- Firebase SDK & Hybrid Inference (
firebase>= 13.4.0): ConfiguredgetAI(app, { backend: new GoogleAIBackend() })withgetGenerativeModelacross all fourInferenceModepolicies and inspectedresult.response.inferenceSource(InferenceSource.ON_DEVICEvsInferenceSource.IN_CLOUD). - Firebase App Check: Initialized in src/lib/firebaseClient.ts supporting browser attestation providers and host-scoped debug token inspection (
localhostor?appcheck_debug=1). - Offline-Capable Persistence & Security Rules: Configured Firestore
persistentLocalCachewithpersistentMultipleTabManageralongsidesanitizeEntryForCloud()(which stripsrawInputbefore persistence) and strict rules infirestore.rulesrejecting any document containing raw unredacted text. - PWA Shell & Frontend: Built with React 19, TypeScript, Tailwind CSS v4, Vite, Vitest, and a custom Service Worker (
public/sw.js) + Web App Manifest.
Challenges we ran into
- Ensuring automated unit tests stayed completely hermetic once live
.envcredentials were provisioned locally, solved by isolating cached Firebase instances and stubbing environment config cleanly during offline/preview Vitest suites. - Handling transient
500capacity spikes during initial cloud inference testing, solved by addingwithCloudResilienceto fail over smoothly fromgemini-3.8-flashtogemini-3.5-flash-lite. - Avoiding unconfigured App Check debug token console 403 errors on public Firebase Hosting URLs for external judges while keeping
?appcheck_debug=1testing instant.
Accomplishments that we're proud of
- Strict privacy architecture backed by automated tests: raw customer phones, names, IDs, emails, and M-PESA codes never appear in cloud prompts or anonymized strategy payloads.
- Genuine hybrid utility even on hardware without Chrome Nano flags enabled, giving every judge instant sample receipts, voice note capture, credit tab settlement, CSV export, and real-time latency telemetry.
What we learned
- Combining deterministic pre-model PII scrubbing with
InferenceModerouting turns hybrid inference from a novelty toggle into a concrete compliance and cost advantage for emerging-market commerce. - Explicitly inspecting
response.inferenceSourcemakes hybrid savings auditable rather than guesswork.
What's next for SokoMind
- Enable native Android Gemini Nano integration alongside the Web/Chrome PWA so shopkeepers on mid-range Android handsets sync the same masked ledger across counter tablet and phone.
- Add automated M-PESA Till webhook reconciliation with zero plain-text phone storage.
Built With
- firebase
- firebase-ai-logic
- firebase-app-check
- firestore
- gemini-3.5-flash-lite
- gemini-3.8-flash
- gemini-nano
- pwa
- react
- tailwindcss
- typescript
- vite