How we built an offline-first cash book for small shops
The engineering behind Cashnbook: an Android app that keeps working without internet, a Laravel API, PDFs from headless Chromium, and a static site on Cloudflare.
By Sohel Rana6min read

Cashnbook is a cash book, dues and shop app for small businesses, mostly in South Asia. The people who use it run grocery shops, pharmacies and workshops. They use budget Android phones, mobile data that comes and goes, and they write in Bangla as often as in English.
Those three facts shaped almost every technical decision. This post walks through the main ones: how the app keeps working offline, how it ships a large product catalog to the phone, how it makes PDFs, and how the website is built for search and AI tools.
The shape of the system
- Android app: Flutter. It holds the books on the phone, queues changes while offline, and prints to Bluetooth receipt printers.
- Web app: React, served as static files from Cloudflare Workers.
- API: Laravel on PHP, with PostgreSQL on a managed database, Redis for cache, and queue workers for anything slow (imports, notifications, reports).
- Documents: PDFs rendered by headless Chromium through Gotenberg, in a container on the API server.
- Messages: email through Amazon SES, and WhatsApp business templates for sign-in codes and notices.
- Website: Astro, built to static HTML and served from Cloudflare Workers.
- Monitoring: Sentry on the API, the web app and the Android app.
Nothing exotic. The interesting parts are in how the pieces deal with a bad connection.
Offline writes: an outbox, not a sync engine
The first version needed a connection for everything. That works in an office. It does not work at a shop counter, where the network drops exactly when there is a queue.
We did not want a full two-way sync engine with conflict resolution. A cash book is mostly append-only: people add entries far more often than they edit old ones. So the design is an outbox.
- Every write gets its id on the phone. When the app creates an entry, it generates a UUID itself and sends it with the request.
- Creating is idempotent on the server. If the API receives a create with an id it already stored, it answers with the stored entry instead of making a second one. A retry after a timeout can never double a sale.
- Offline writes go to a local queue. If the phone is offline, or the request fails at the network level, the change is saved locally and the entry shows as Unsynced in the list.
- The queue drains in order. When the connection returns, when the app resumes, or when the user pulls to refresh, the app sends the queued changes one by one, oldest first.
- Failures are sorted, not hidden. A network failure stops the drain and waits for the next chance. A server error is retried a few times. A rejection, such as an entry the server refuses as invalid, is parked and shown to the user, who can retry or discard it. Nothing is silently dropped.
The same pattern now covers sales, customer and supplier payments and staff purchases, not only cash entries.
What we learned: the hard part was not the queue. It was everything around it. When a session expires mid-drain, the queue must survive the sign-out. A pull-to-refresh must drain first, then load, or the fresh list hides the pending rows. “Unsynced” must be visible but not alarming.
A 95,000-item catalog on a budget phone
Shop owners hate typing product names. So Cashnbook has a ready catalog for Bangladesh: about 95,000 items, from groceries to medicines, many with Bangla names and barcodes.
Searching that over the network on every keystroke would be slow on mobile data. Instead, the app keeps a local copy of the part of the catalog that fits the shop:
- the catalog is split by shop type, so a pharmacy downloads medicines and a grocery downloads groceries;
- the copy lives in SQLite on the phone and is searched locally;
- the server exposes a version number and a paged change feed (by update time and id), so the app only fetches what changed;
- the app checks for updates weekly, or when the owner asks.
The result is instant search at the counter, even offline.
Money is not a float
Every amount is stored as an integer. Each currency carries its own number of decimals, so taka stays whole while a currency that uses cents gets two places. Quantities, which really do have fractions (1.5 kg of rice), are a separate type with up to three decimals.
It sounds obvious. It still took a careful pass through the API, the web app and the Android app when we opened the app to currencies other than taka.
PDFs from a real browser
Shops send invoices, receipts and statements on WhatsApp, and they want them to look right in A4, A5 and receipt-roll widths (80 mm and 58 mm). Bangla text needs proper shaping, which many PDF libraries handle badly.
So the documents are HTML, rendered by headless Chromium through Gotenberg. The container runs with a hard memory cap and no swap, so a huge report gets stopped cleanly instead of slowing the whole server. Large reports are generated by queue workers and stored for a few days, then expire on their own.
Receipts can also go straight to a Bluetooth thermal printer from the Android app, which works without internet.
Three languages, one of them right-to-left
The app speaks English, Bangla and Arabic. Arabic means right-to-left layouts, which flushed out every place where we had written “left” when we meant “start”. Bangla means a font that shapes conjuncts correctly, and line heights tall enough for vowel signs above and below the line.
Dates, numbers and currencies are formatted per language, and each business picks its own currency.
A website for search engines and AI assistants
The marketing site is plain static HTML built with Astro, so it is fast on a slow connection and cheap to serve. A few things we did on purpose:
- Question pages. Each common need (“cash book app”, “due tracking app”, “offline accounting app”) has its own page that opens with a short, quotable answer, in English and Bangla.
- llms.txt. A plain-text summary of the product at /llms.txt, built from the same data as the pages, so AI tools can describe the app correctly.
- Clean addresses. Every page has one address, with a permanent redirect from the version without the trailing slash.
- IndexNow. After a deploy, a small script tells Bing which pages changed.
- This blog. Posts are Markdown files in the same repository, written in a browser editor that saves them to Git.
What we would tell someone starting today
- Design for the worst connection your users have, not the one in your office.
- Make writes idempotent from day one. Client-generated ids cost nothing early and save you later.
- Keep the money model boring: integers, explicit decimals, no floats.
- Render documents with a browser if you need non-Latin scripts to look right.
- Ship the website as static files. It is the fastest, cheapest and safest part of the stack.
If you run a small business, or build for people who do, you can try Cashnbook free on Google Play or on the web. The story of why we built it is in From the paper khata to your phone.