DEV Community

Areen Agrawal
Areen Agrawal

Posted on AI-assisted

Solving India's Biggest SMB Problem That 99% of People Don't Know About: Meet Quatern

Hacktoberfest Open-Source AI Challenge Week 2: Side Hustle Submission 💸

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 2: Side Hustle

What I Built

The Illusion of Digitization: 94% UPI vs. 74% Paper Ledgers

Walk down any street in India and you will see QR codes and soundboxes at every storefront. According to the Ministry of Finance's Socio-Economic Impact Analysis of BHIM-UPI Transactions, 94% of small businesses in India have adopted UPI. With annual volumes exceeding 241 billion transactions, Indian retail appears fully digitized from the outside.

Under the surface, it isn't. Digital payments are merely the payment rail—not operational digitization.

Across India's 7.47 crore MSMEs and 12–13 million neighborhood retail stores, roughly 74% still rely on handwritten paper ledgers (bahi-khata) and manual cash memos (Zoho POS Survey). Because three out of four neighborhood shops operate on paper:

  • Zero Repeat-Customer Visibility: A customer pays ₹250 via a static QR code, but the shopkeeper captures no SKU metadata and no customer profile. Regular households quietly defect to 10-minute quick-commerce delivery without the owner ever knowing.
  • Cash Leaks on Untracked Udhaar (Credit): The Confederation of Indian Industry estimates small retailers lose an average of ₹18,000 per month due to forgotten credit entries, torn ledger pages, and disputed balances, waiting an average of 45 days to collect dues.
  • Uncalculated Margins: Owners routinely confuse markup on cost with gross margin on selling price, overlook transport in landed costs, and mix collected GST with daily cash flow.
  • Passive Word-of-Mouth: Without customer CRM or purchase interval tracking, stores have no mechanism to send automated restock reminders, festival greetings, or clearance offers over WhatsApp.

The Math: Why Small Retailers Reject Legacy POS

Why haven't these stores adopted POS software? In the Zoho survey, 95% wanted software, ranking "ease of use (like WhatsApp)" and cost-effectiveness as their top priorities.

They reject legacy systems because the unit economics are unsustainable for a neighborhood shop. A typical store generates ₹2,00,000 to ₹5,00,000 in monthly sales at 12%–15% gross margin, leaving the owner with a median net profit of ₹30,000/month (₹3,60,000/year) (SuperK Retail Benchmarks).

Traditional POS solutions demand:

  • Upfront Hardware: Touch terminal, printer, scanner, and UPS cost ₹28,000 to ₹45,000+ ($350–$500).
  • Dedicated Billing Operator: Complex legacy software requires a dedicated data entry operator averaging ₹14,500 to ₹16,800/month ($200/mo), totaling over ₹2,00,000/year (Indeed India).
  • SaaS Renewals & AMC: Annual software licenses and maintenance add another ₹15,000+/year.

In Year 1, legacy POS consumes over 70% of the shopkeeper's entire annual income.

Metric Legacy Enterprise POS Handwritten Bahi-Khata Quatern (Local AI POS)
Upfront Hardware ₹42,000 (~$500) ₹0 ₹0 (Runs on existing PC/laptop + mobile browser)
Operator Labor ₹16,800/mo (~$200/mo) ₹0 ₹0 (3-click UI + Hinglish AI Copilot)
Software & AI Cost ₹12,000–₹25,000/yr ₹0 ₹0 Core (FOSS) / ₹149/mo optional Cloud Backup
Year-1 TCO Burden ₹2,59,200 (72% of profit) Bleeds ~₹2.16L/yr in leaks ₹0 to ₹1,788/yr (<0.5% of profit — 145x cheaper)
Analytics & Retention Complex tabular menus 0% visibility Real-time SQLite telemetry + Gemma 4 E2B Copilot

Enter Quatern: Local POS + On-Device Gemma 4 E2B Copilot

Quatern is an offline-first, single-node retail POS, inventory ledger, udhaar tracker, consent-guarded WhatsApp CRM, and on-device Gemma 4 E2B AI Business Copilot built with PyWebView + FastAPI + SQLite + React 19 + Tailwind CSS v4.

  • Zero-Operator Desktop & Mobile UI: Packages into a standalone Windows executable (Quatern.exe) that runs on standard shop hardware without requiring Python or Node installed. It also serves a responsive interface over the local network so owners can bill and inspect metrics directly from their phone.
  • Deterministic Integer-Paise Billing: Barcode/SKU checkout powered by integer-paise arithmetic (src/lib/money.ts), automated CGST/SGST splits, native 58mm/80mm ESC/POS thermal printing, and 1-click WhatsApp receipts.
  • Offline Gemma 4 E2B AI Copilot: Shopkeepers ask questions in Hinglish, Hindi, or English ("Aaj ki bikri aur payment breakdown dikhao", "Kaunse product par sabse zyada margin hai?", "Kitna udhaar baaki hai?") and receive verified answers computed from their local SQLite database.
  • Autonomous Retention Engine: Scans customer purchase cycles to identify three high-value cohorts: Monthly Ration Refill Overdue, Inactive Customers (20–60 days), and Slow-Moving Stock, drafting ready-to-send WhatsApp messages.

The Side-Hustle Business Model (Who Pays For It)

While the core Quatern desktop app and local Gemma 4 E2B inference are 100% free and open-source, local shopkeepers gladly pay for three high-utility value-added services:

  1. Cloud Backup & Remote Sync (₹149/month or ₹1,499/year — ~₹4/day): Automated encrypted offsite backups of quatern.db with remote mobile dashboard access when away from the counter.
  2. White-Glove Ledger Migration (₹999 one-time): Digitizing existing rate sheets and customer ledgers using Quatern's fuzzy-header Excel importer (src/lib/importer.ts) and local invoice OCR (backend/ocr.py).
  3. Managed WhatsApp & SMS Gateway Bundle (₹299/month): Pre-configured Meta Cloud API and Indian DLT SMS credits for automated campaign broadcasts.

Demo

The Workflow in Action

  1. 60-Second Setup & Catalog Import: Set store name, GSTIN, and an optional 4-digit SHA-256 Owner PIN (locking cost prices and audit logs from cashiers). Drop any Excel/CSV price list into the fuzzy importer or scan paper supplier bills with local OCR.
  2. 3-Click Checkout & WhatsApp Bill: Search or scan items, select payment mode (Cash, UPI, Card, or Udhaar credit), print thermal receipts, and share formatted WhatsApp invoices with an instant UPI payment link.
  3. Consulting the Local Gemma 4 E2B Copilot: Download the quantized google_gemma-4-E2B-it-Q4_K_M.gguf model directly within the app, select Hinglish/Hindi/English, and ask about top margins, month-on-month growth, or overdue debtors.
  4. 1-Click Retention Campaigns: Review automated cohorts (e.g. 14 households overdue for grocery refill) and dispatch personalized, consent-compliant WhatsApp messages.

Code

Quatern

Quatern Logo

Modern, Offline-First Desktop POS & Retail Management System

PyWebView (WebView2) · FastAPI · SQLite · React 19 · Tailwind CSS v4

GitHub Release Platform License Architecture

Download Latest Release (Windows x64) · Features · Quick Start · Architecture


Overview

Quatern is a modern, high-speed retail desktop application designed for retail shops, grocery stores, boutiques, chemists, and general merchants.

Unlike traditional bulky cloud POS systems that require costly subscriptions, continuous internet connectivity, and external servers, Quatern is 100% offline-first. All store data — products, transactions, customer records, and credit ledgers — resides securely on the local computer in an encrypted SQLite database.


Highlights

  • ⚡ High-Speed Checkout: Lightning-fast barcode/SKU scanning, keyboard-first navigation, and real-time total calculations.
  • 💰 Paise-Accurate Accounting: Zero floating-point drift. All financial arithmetic is performed in integer paise with automatic rounding.
  • 🧾 Flexible Receipt Generation
    • ESC/POS thermal printing (58mm and 80mm format toggle).
    • Canvas-based visual bill images for direct clipboard…

Repository Architecture

quatern/
├── backend/
│   ├── main.py        # FastAPI endpoints for POS, sync, AI, and messaging
│   ├── ai.py          # Gemma 4 E2B runner (llama-cpp-python) & SQLite BI grounding
│   ├── db.py          # WAL-mode SQLite schema, migrations & SHA-256 PIN guard
│   ├── escpos.py      # 58mm & 80mm ESC/POS thermal receipt byte-stream driver
│   ├── messaging.py   # WhatsApp (wa.me, Meta Cloud) & Indian SMS dispatch
│   └── ocr.py         # Local Tesseract supplier bill invoice parser
├── src/
│   ├── lib/
│   │   ├── money.ts   # Deterministic integer-paise GST & discount arithmetic
│   │   ├── forecast.ts# Moving average & exponential smoothing engine
│   │   ├── importer.ts# Fuzzy-header Excel/CSV catalog & ledger mapper
│   │   └── store.ts   # Offline-first state hydrated from local SQLite
│   └── views/         # Billing, Invoices, Udhaar Ledger, Inventory, AI Assistant, Forecast
├── desktop.py         # Native PyWebView container + background FastAPI daemon
└── build_desktop.py   # PyInstaller bundler -> standalone Quatern.exe
Enter fullscreen mode Exit fullscreen mode

Grounding Gemma 4 E2B on Live SQLite Telemetry

To eliminate financial hallucinations, backend/ai.py never asks the LLM to do mental arithmetic. Instead, get_business_intelligence_snapshot() queries the local SQLite database in real time—calculating exact DoD/WoW/MoM growth, product margins, low-stock warnings, and aged debts—and injects this verified snapshot into the local Gemma 4 E2B context window:

# backend/ai.py: Local Gemma 4 E2B GGUF Inference via llama-cpp-python
DEFAULT_MODEL_FILENAME = "google_gemma-4-E2B-it-Q4_K_M.gguf"
DEFAULT_MODEL_URL = (
    "https://huggingface.co/bartowski/google_gemma-4-E2B-it-GGUF/"
    "resolve/main/google_gemma-4-E2B-it-Q4_K_M.gguf"
)

def get_local_llm():
    global _cached_local_llm, _cached_local_llm_path
    cfg = db.get_ai_config()
    model_path = Path(cfg.model_path) if cfg.model_path else get_default_model_path()
    if not model_path.exists() or model_path.stat().st_size < 100_000_000:
        return None

    with _local_llm_lock:
        if _cached_local_llm is not None and _cached_local_llm_path == str(model_path):
            return _cached_local_llm
        from llama_cpp import Llama
        _cached_local_llm = Llama(
            model_path=str(model_path),
            n_ctx=2048,
            n_threads=4,
            verbose=False
        )
        _cached_local_llm_path = str(model_path)
        return _cached_local_llm
Enter fullscreen mode Exit fullscreen mode

Deterministic Integer-Paise GST Math

Every transaction is represented and computed as integer paise (100 paise = ₹1.00), preventing floating-point rounding errors from corrupting GST filings:

// src/lib/money.ts: Deterministic Integer-Paise GST Arithmetic
export function calcLine(l: LineInput): LineCalc {
  const gross = l.price * l.qty
  const discount = Math.round((gross * l.discountPct) / 100)
  const taxable = gross - discount
  const tax = Math.round((taxable * l.gst) / 100)
  return { gross, discount, taxable, tax, total: taxable + tax }
}
Enter fullscreen mode Exit fullscreen mode

How I Built It

Quatern is engineered around a four-part open-source architecture designed for the hardware constraints of Indian retail:

  1. On-Device Open-Weight LLM (Gemma 4 E2B Q4_K_M): Downloadable directly inside the app with background chunk polling. Runs via llama-cpp-python across 4 CPU threads (n_ctx=2048, temperature=0.2), enabling any standard dual-core or quad-core PC with 4–8 GB RAM (and no dedicated GPU) to serve as a fluent Hinglish/Hindi/English retail analyst.
  2. Privacy-Preserving RFM Cohort Engine: Computes inter-purchase intervals from SQLite invoice records. When an interval exceeds regular buying frequency by 3+ days, customers are automatically grouped into the Replenishment Overdue bucket, while inactive shoppers (20–60 days) enter the Win-Back cohort.
  3. Statistical Demand Forecasting & Heuristic Fallback: Uses moving averages and single exponential smoothing (alpha = 0.3) for rapid demand projections. On low-memory machines where GGUF weights aren't downloaded, Quatern seamlessly falls back to a deterministic multilingual heuristic engine.
  4. Lightweight Native Desktop Distribution: desktop.py runs FastAPI on a background thread and renders via PyWebView using the OS-native Microsoft WebView2 runtime (avoiding Electron's heavy 200 MB Chromium footprint).

Why Does Open Innovation Matter?

Building Quatern on closed proprietary APIs would have rendered this solution economically unviable:

  1. Zero Token Tax Enables a ₹4/Day ($1.75/Month) Model: Neighborhood store owners will never pay $30/month for cloud AI. At ₹149/month ($1.75/mo), querying commercial cloud APIs 25+ times daily would consume the entire margin. On-device Gemma 4 E2B drops incremental inference costs to $0.00.
  2. Absolute Data Sovereignty: Kirana owners are fiercely private about daily cash sales, landed wholesale margins, and customer credit balances. Running SQLite locally and executing inference on-device guarantees no financial data ever leaves the counter.
  3. Uncompromised Offline Reliability: Internet connections frequently fluctuate in semi-urban and Tier-2/3 markets during peak evening billing hours (6 PM – 9 PM). Quatern operates entirely offline without interruption.
  4. Custom Hinglish Grounding: Open weights allow seamless pairing of verified local database metrics with tailored Hinglish prompts (Namaste {owner_name} ji) without third-party API restrictions.

My First User

Field Survey Across 64 Local Small Businesses

I took a working build of Quatern on a laptop and conducted live counter walkthroughs across 64 local small businesses in my area:

Cohort (n = 64 Local Shops) Stores Share Primary Feedback
Ready to Adopt (with Mobile Access) 12 18.8% Wanted 3-click POS, WhatsApp bills, and Hinglish AI; requested dual mobile access alongside desktop.
Data Conscious (Want Cloud Backup) 19 29.7% Eager to replace paper ledgers, but required an automated encrypted backup before committing.
Trade-Specific Workflows Needed 33 51.5% Requested industry-specific fields (medicine expiry alerts, clothing size/color matrices, loose-weight bulk billing).
Total Surveyed 64 100% 100% confirmed legacy POS (₹40,000+ hardware + ₹15,000/mo operator) is unaffordable.

First Active Pilot Store

Out of the 12 ready-to-adopt stores, a neighborhood provision and general store became Quatern's first active pilot:

  • Onboarded in 25 Minutes: Imported 180 fast-moving SKUs and 45 regular customer accounts using the fuzzy Excel importer.
  • Immediate Cash Flow Result: Using the Pending Udhaar screen, the owner sent polite 1-click WhatsApp payment reminders in Hinglish to 8 overdue customers—recovering ₹4,200 in pending balances that same evening without awkward confrontation.
  • Willingness to Pay: When shown that automated encrypted offsite backup + mobile sync would cost just ₹149/month (~₹5/day), 11 of the 31 interested stores offered to pre-pay ₹1,499 for an annual plan.

Prize Categories

  • Best Use of Gemma: Quatern integrates Google's open-weight Gemma 4 E2B (google_gemma-4-E2B-it-Q4_K_M.gguf) natively via llama-cpp-python with an in-app Hugging Face downloader. It grounds Gemma 4 E2B on real-time SQLite financial snapshots to answer merchant questions in Hinglish, Hindi, and English completely offline.
  • Best Use of GitHub Copilot: Developed with agentic architecture standards established in AGENTS.md and packaged end-to-end via GitHub Actions (.github/workflows/release.yml), compiling the React 19 UI, FastAPI backend, and llama-cpp-python CPU engine into a standalone Windows executable release on every tag.

Top comments (0)