Web and Mobile AppsProgressive web app
Matjari: an Offline-First Customer Ledger for a Small Shop
An Arabic web app, installable on a PC and an Android phone, built for a small retail shop to record customers' purchases, payments and balances with or without a connection, and to keep the devices in sync through a Cloudflare Worker.
- TypeProgressive web app
- RoleSolo project
- ClientA small retail shop
- WhenNov 2026
- 18automated tests
- 7kinds of conflict put to a person
- 4,790lines of JavaScript, app and server
- 33app files kept on each device, so it opens offline

Highlights
- Works with no connection: every entry is saved on the device first, and a service worker keeps the app itself on the device
- PC and phone sync through one Cloudflare Worker backed by a SQLite Durable Object; the server only numbers the changes and the devices do the merging
- Edits to different fields merge by themselves; seven kinds of real conflict are shown with what happened on each device and the valid choices as buttons
- Nothing to install on the shop's PC except a browser; written for Chrome 109 and Firefox 115 ESR, the last browsers that run on Windows 7
- 18 automated tests: 14 on the merge and conflict rules and 4 that run the sync protocol against a local server
The problem
A small retail shop sells on account: customers buy now and pay later, often in parts. The accounts lived in a desktop program on one PC, so a balance could not be checked or updated from a phone, and a second device would have meant a second copy that drifts away from the first.
The replacement had to run on an old Windows 7 PC and on an Android phone, keep working when the connection drops, and never lose or double an entry when two devices have been working apart.
Approach
Matjari (Arabic for "my shop") is a web app that installs from the browser. It is plain static files written with Preact and htm, with no build step. A service worker keeps the whole app on the device and every record lives in the browser's IndexedDB, so opening the app and recording a sale never wait for the network.
Sync is one call: a device sends its unsent changes and receives everyone else's. The server is a single Cloudflare Worker with one SQLite-backed Durable Object. It gives every accepted change a sequence number and sends back any change whose author had not seen the latest version; all merging happens on the devices.
The merge is three-way and per field, so a phone number changed on one device and an address changed on the other are both kept. A person is asked only when it matters: the same field with two values, an edit against a delete, a customer or a payment that looks entered twice, and three more cases. The conflicts page says what happened on each device and offers only the valid choices. A record with an open conflict is held back while everything else keeps syncing.
The manager password is never stored or sent as typed (PBKDF2), each device gets its own key that can be revoked, and a one-time setup code stops a stranger from claiming the shop. Old entries can be archived into one carried balance per customer, and the data of the earlier desktop version can be imported.
Results
- Arabic, right-to-left screens for the dashboard, customers, a customer's statement, the history and the reports, plus settings and the conflicts page; tables become cards on a phone
- In a local run with two devices, the phone reopened the app with the network off, queued four changes and sent them on reconnecting; a clashing phone-number edit and a payment entered on both devices appeared on the conflicts page, while the address and notes edits merged by themselves
- 18 automated tests, all passing: 14 on the merge and conflict rules, 4 on the sync protocol
- About 4,800 lines of JavaScript for the app and the server, with three small libraries (Preact, htm, and sql.js for the import)
- One-file backup and restore, CSV export, archiving, and a list of deleted items that can be restored
- Ships with a repeatable demo data set:
npm run demostarts a local demo shop with 40 invented customers and six months of entries, generated the same way every time - That demo shop (40 customers, 424 entries) takes 364 KB on the server
What this means for you
Moving data between devices is the smaller half of sync. The useful work is deciding which differences a program may settle by itself and which a person has to see, and then explaining each one in plain words. Keeping those rules as pure functions meant they could be tested without a browser or a server.
Tools
- JavaScript
- Preact
- htm
- IndexedDB
- Service Worker
- Web Crypto
- Cloudflare Workers
- Durable Objects
- SQLite
- sql.js
- Node.js test runner
Figures
Select a figure to enlarge it.

The app at a glance
From a sale at the counter to the same balance on the phone: record on either device, save locally, send, merge, and see the same books everywhere.

Dashboard
The start page (the interface is Arabic, right to left): total purchases, total collected, total owed and the number of customers, three quick actions (a sale, a payment, a new customer) and the latest entries. The demo shop: 40 invented customers, 29 of them with a balance.

Customers
Every customer with number, phone, total bought, total paid and balance. The search matches names, phone numbers and customer numbers; the second chip shows only those who owe. The names and numbers are invented.

A customer's statement
One customer's account: the balance owed, contact details, buttons to record a sale or a payment, and the statement of every purchase and payment (22 here) with its date and payment method. Editing or deleting an entry asks for the manager password.

Reports
Totals and the share collected so far (74% in the demo shop), the five customers who bought the most, and everyone with an outstanding balance. The button at the top exports the entries as a CSV file for Excel.

The conflicts page on the PC
After the PC worked offline while the phone carried on. Top: the same address changed on both devices, choose one. Middle: a purchase whose total was edited here (1,555 to 1,605) but which was deleted on the phone, restore it or keep it deleted. Bottom: a customer added on both devices with the same name and phone, merge them or keep both.

A conflict on the phone
The phone and the PC each changed one customer's phone number while the phone was offline. The card names the other device, shows the old value and both new ones, and asks which to keep. The address and the note changed in the same edits were merged without a question.

Working offline
The phone with the network switched off, after the app was reopened from its stored copy: the status reads "no connection, 4 changes waiting to upload". They are sent as soon as the connection returns.

The dashboard on a phone
The same app at phone size: the totals, large buttons for a sale, a payment and a new customer, and the latest entries as cards. The chip at the top shows the sync state.

Settings: sync and linked devices
The sync status with a "sync now" button, this device's name, and the two linked devices (the shop PC and the shop phone); either can be unlinked. Below it, backup, restore and the import from the old desktop program.

What merges by itself and what is asked
The five kinds of change that combine silently, how a clash is found, and the seven cases put to a person with the choices offered for each.

Architecture
Each device carries the app, a service worker and its own database; one Cloudflare Worker with a SQLite Durable Object links them. Below: how access is protected, and where the code is.