Inspiration
Walk into any kiryana store, tailor shop, or neighborhood business in Pakistan, and you will see a paper udhaar-khata register on the counter. At rush hour, shopkeepers do not have time to tap through multi-column accounting forms; mental-math mistakes cause disputes, and asking regular customers for overdue balances in person feels awkward.
We built Khata Saathi (کھاتہ ساتھی) — "Bolo. Khata likh jaye." — so a shopkeeper can update their khata at the speed of a sentence, verify every rupee in one tap, and follow up politely on WhatsApp.
What it does
- Voice & Text Entry (Urdu & Roman Urdu): Say or type natural sentences like "Ali ko 500 ka udhaar likh do", "Sara ne dhai sau wapis kiye", or
"بلال کو ۵۰۰ کا سامان دیا"using the browser Web Speech API (ur-PK/en-IN) or typed fallback. - Always-Confirm Read-Back: Nothing is saved until the shopkeeper taps Confirm. The read-back card shows Customer, Type (
udhaar/wapis), Amount, and the newly computed balance, with Edit and Cancel options. - Deterministic Integer Ledger & Audit-Safe Undo: Every transaction is stored as a positive integer rupee amount in an append-only
transactionstable (no floats). Undoing an entry appends a reversingadjustmentevent so history is never deleted. - Reminder-Sorted Customer List & Payment Pattern: Customers are sorted by who needs a reminder first. Once a customer has at least 3 settled credit cycles, FIFO matching estimates their average payment lateness.
- Polite Draft-Only Reminders: Generates messages in Roman Urdu, Urdu (Nastaliq), and English across Friendly, Polite, and Firm tones with one-tap Open in WhatsApp (
wa.me) and Copy text. Nothing is ever sent automatically. - KhataBot & Custom Slang Trainer: Answers shopkeeper questions ("Total kitna lena hai?", "Ali ka kitna baqi hai?", "Kis ko reminder bhejna hai?") from code-computed totals, and lets shopkeepers teach custom local slang (e.g.
"chukta"→wapis). - Offline-Capable PWA & Exports: Installable on phones (390px mobile-first layout), caches the ledger for offline reading, and supports CSV export, printable statements, and full JSON backup.
How we built it
- Monorepo (
pnpmworkspaces):packages/core: Pure TypeScript deterministic Roman Urdu / Urdu parser, integer-only ledger maths,KhataBot, and 7 typed port interfaces (SpeechToText,LanguageUnderstanding,Storage,FileStore,Notifier,Translator,Ocr) with offline local defaults and env-swappable AWS adapter stubs.apps/api: Node.js + Fastify + Zod + SQLite (better-sqlite3), with CORS allowlisting,/api/*rate limiting, structured error handling, andGET /health/providers.apps/web: React 19 + Vite 6 + TypeScript + React Router 7 + Service Worker PWA, styled with a warm paper-ledger aesthetic (Young Serif,Figtree,IBM Plex Mono,Noto Nastaliq Urdu).
- Live & Tested: Deployed to Vercel (
https://khata-saathi-five.vercel.app) and backed by 70 Vitest unit tests inpackages/core, 3 API integration tests inapps/api, and a Playwright E2E smoke test covering desktop + 390px mobile with zero console errors.
Challenges we ran into
- Mixed-script & fractional Urdu parsing without a cloud LLM: Handling Urdu digits (
۰-۹), Roman Urdu number words (dhai sau, dedh hazaar, saade teen sau), Unicode word boundaries on Urdu postpositions (کو/نے), and typo-tolerant fuzzy customer matching deterministically. - Keeping money math 100% deterministic: Enforcing integer-only arithmetic and append-only reversing events so no AI or UI bug can silently corrupt a balance.
- Mobile-first counter ergonomics: Designing a 390px phone view with
>= 48pxtap targets, RTL-safe Nastaliq Urdu rendering, and zero horizontal scroll.
Accomplishments that we're proud of
- 60 / 60 accuracy on our curated 60-sentence Roman Urdu, Urdu script, mixed, typo, and number-word parser benchmark, running completely offline.
- Clean Ports & Adapters architecture with
/health/providersand 20-minute integration checklists (docs/AWS_ADAPTERS.md) so any of the 7 slots can be swapped to an AWS service via environment variables. - Full-stack live deployment with zero production source maps, route-level code splitting, and passing unit + E2E tests.
What we learned
- Deterministic rule-based NLU paired with a mandatory human Confirm step is faster, cheaper, and far safer for neighborhood commerce than letting an LLM write directly to a database.
- Separating domain logic into a runtime-agnostic
packages/corepackage made both local SQLite execution and serverless deployment straightforward.
What's next for Khata Saathi
- Plugging in live AWS adapters behind our existing ports — e.g., Amazon Bedrock fallback for complex multi-item sentences, AWS Transcribe for noisy counter audio, and Amazon Textract to import photos of existing paper khata pages.
- Multi-user shop sync and role-based access for shops with multiple counter staff.
Built With
- css
- fastify
- node.js
- playwright
- pnpm
- pwa
- react
- react-router
- remotion
- sqlite
- typescript
- vercel
- vite
- vitest
- web-speech-api
- zod
