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:

  1. 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).
  2. Firebase AI Logic Hybrid Router: Shopkeepers and judges can switch live between PREFER_ON_DEVICE, ONLY_ON_DEVICE, PREFER_IN_CLOUD, and ONLY_IN_CLOUD (InferenceMode) while watching response.inferenceSource, modelUsed, latency in milliseconds, and tokens kept local update in real time.
  3. 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 calls initializeDeviceModel with live progress percentage. If Chrome Nano is unavailable on a device offline, SokoMind degrades cleanly to deterministic local parsing and queues sanitized entries locally.
  4. 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 to gemini-3.5-flash-lite on transient high-demand errors).
  5. 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.
  6. 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_CLOUD for practical restock advice, inspectable in the Anonymized Cloud Payload panel. A built-in Run Benchmark button measures PREFER_ON_DEVICE vs ONLY_IN_CLOUD timing on the same masked note.

How we built it

  • Firebase SDK & Hybrid Inference (firebase >= 13.4.0): Configured getAI(app, { backend: new GoogleAIBackend() }) with getGenerativeModel across all four InferenceMode policies and inspected result.response.inferenceSource (InferenceSource.ON_DEVICE vs InferenceSource.IN_CLOUD).
  • Firebase App Check: Initialized in src/lib/firebaseClient.ts supporting browser attestation providers and host-scoped debug token inspection (localhost or ?appcheck_debug=1).
  • Offline-Capable Persistence & Security Rules: Configured Firestore persistentLocalCache with persistentMultipleTabManager alongside sanitizeEntryForCloud() (which strips rawInput before persistence) and strict rules in firestore.rules rejecting 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 .env credentials were provisioned locally, solved by isolating cached Firebase instances and stubbing environment config cleanly during offline/preview Vitest suites.
  • Handling transient 500 capacity spikes during initial cloud inference testing, solved by adding withCloudResilience to fail over smoothly from gemini-3.8-flash to gemini-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=1 testing 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 InferenceMode routing turns hybrid inference from a novelty toggle into a concrete compliance and cost advantage for emerging-market commerce.
  • Explicitly inspecting response.inferenceSource makes 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
Share this project:

Updates

Submission history