Kaucjomat

Offline-first mobile pass wallet and return-points map for Poland's beverage deposit system, featuring a two-stage Polish thermal RVM receipt parser, pure-vector GS1/ISO barcodes, and Firestore REST sync.

Kaucjomat deposit pass wallet grouped by retail chain alongside the high-contrast vector CODE128 checkout barcode view
Chain-grouped deposit voucher wallet (left) and vector CODE128 checkout pass with ISO quiet zones (right).

Overview

Kaucjomat is an offline-first mobile and web pass wallet built with Expo and strict TypeScript for Poland’s beverage container deposit scheme (system kaucyjny). It converts 58 mm thermal deposit vouchers printed by supermarket reverse vending machines (butelkomaty) into chain-grouped digital checkout passes paired with a container-filterable return-points map.

Problem

Digitizing thermal deposit slips for supermarket checkout introduces three practical constraints:

  • Noisy Polish thermal-slip OCR: Real 58 mm RVM slips place unit-rate lines (8 x 0,50 ZL) and 10-digit NIP tax headers above the actual payout and barcode, while worn thermal heads drop Polish diacritics and confuse O/0, I/1, and S/5—causing naive regular expressions to extract wrong amounts or tax IDs.
  • Scanner reliability in dark mode: Browser-oriented <canvas> barcode libraries fail under React Native’s New Architecture, and dark-mode color inversion or narrow margins prevent laser checkout scanners from reading 1D symbologies.
  • Sync bundle weight and privacy: Pulling the full gRPC/WebChannel Firestore SDK adds substantial client bundle overhead for simple household voucher sync, and local receipt photos should not be uploaded implicitly when syncing ledger entries.

Approach and architecture

The codebase enforces a five-layer downward dependency graph (ui -> services -> adapters -> parsers -> domain) checked automatically via static AST inspection:

  • Two-stage Polish RVM slip parser: polish-receipt-parser.ts normalizes diacritics, repairs context-dependent O/0, I/1, and S/5 OCR substitutions, filters date and multiplier decoy lines, cross-checks totals against statutory container denominations (50 gr PET/can, 100 gr glass) in integer grosze, and scans bottom-up for GS1 modulo-10 verified EAN13 or voucher barcodes—with an optional Gemini 2.5 Flash multimodal fallback when configured.
  • Pure-vector GS1/ISO barcode encoder: Encodes CODE128 (with automatic Subset C digit-pair compression), EAN13 (L/G/R parity), ITF, and Version-2 QR codes (Reed-Solomon GF(256) error correction) directly into <Svg> primitives over an invariant #FFFFFF background and >= 10x quiet zones.
  • Local-first SQLite + Firestore REST v1 sync: Stores vouchers in expo-sqlite (WAL mode) for zero-account offline operation, with optional shared-household sync over Cloud Firestore REST v1 (fetch), stripping local receiptPhotoUri fields prior to serialization and enforcing hasOnly/hasAll schemas and allow list: if false room isolation in firestore.rules.

Engineering decisions and trade-offs

  • Integer grosze domain ledger and zero-gRPC REST sync: Representing all balances as integer grosze avoids floating-point rounding discrepancies, while targeting Firestore REST v1 over injectable fetch() avoids ~460 KB of WebChannel client overhead at the expense of manual polling/refresh rather than persistent streaming sockets.

Evaluation and benchmarks

Evaluated against a 24-slip synthetic Polish RVM benchmark corpus (scripts/benchmark-parser.ts) and Vitest + Firestore emulator suites:

  • Receipt extraction accuracy: Improved exact full-slip match (retail chain + PLN deposit in grosze + verified barcode) from 4.2% (1/24 on a naive regex baseline) to 100.0% (24/24) at 0.07 ms p50 (< 1.0 ms p95) parse latency.
  • Security rules verification: Verified schema enforcement, room-enumeration denial, and in-app room deletion against the local Firestore rules test suite.

Limitations

Kaucjomat is an open-source prototype; bundled return-point coordinates represent a curated sample dataset rather than a live retail-chain feed, and the pure-vector QR encoder targets compact voucher payloads (Version 2) rather than arbitrary long binary payloads.