Walkthrough: a field service app offline
demo/demo-field-service is a field technician’s app: work orders, inspections and a parts
catalogue. What goes offline is declared once, in
src/main/resources/specs/ui/offline.yaml:
| Dataset | Direction | What |
|---|---|---|
products | down (Wi-Fi only) | the parts catalogue, read-only on the phone |
work-orders | both | the jobs: listed, opened, changed and created offline, synced later (UUID keys, @Version for conflicts) |
inspections | up | written on site and uploaded; their work order is picked from the phone’s copy of work-orders; their photo waits on the phone until the next sync |
There is no offline code in the demo. The three screens are plain AutoCrud classes over in-memory
stores, and PhotoStorage is a demo FileStorage that keeps uploaded photos in a temp folder.
1. Run the backend
Section titled “1. Run the backend”The demo tracks the repository, so install the backend first:
cd backend && mvn install -DskipTestscd ../demo/demo-field-servicemvn spring-boot:run -Dspring-boot.run.arguments=--mateu.cors.allowed-origins=http://localhost:8081It listens on 8690. The CORS setting lets the app’s web build (served on 8081) call it; a phone or an emulator does not need it.
Check what a phone would download:
curl -s -X POST -H 'Content-Type: application/json' http://localhost:8690/mateu/v3/sync/x \ -d '{"route":"","serverSideType":"io.mateu.demo.fieldservice.Shell","actionId":"_offline-manifest","componentState":{},"parameters":{}}'The answer lists the three datasets and the three routes (/workOrders, /inspections,
/products). The other actions are in the protocol reference.
2. Open it in the Mateu app
Section titled “2. Open it in the Mateu app”In a browser, the quickest way:
cd frontend/app/react-nativenpm ciEXPO_PUBLIC_MATEU_BACKEND_PORT=8690 npm run webThe web build keeps the offline copy in the browser’s localStorage, unencrypted: fine for
trying it, never for real data.
On a phone, use a development build (npx expo run:android / npx expo run:ios) on the same Wi-Fi
as your laptop: the encrypted on-device database needs the native SQLCipher build. See
the React Native renderer for how the app finds the
backend.
The app opens on Work orders. The sync indicator in the app bar goes from Syncing… to Synced: the phone downloaded the manifest, the screens of the three routes and the work orders. (The products wait for Wi-Fi: on mobile data the Sync screen says “Download (Wi-Fi)”.)
3. Go offline
Section titled “3. Go offline”- Browser: DevTools → Network → Offline. (Stopping the backend works too: a server that does not answer is treated the same.)
- Phone: airplane mode.
Now work as the technician would:
- Open Inspections, then come back to Work orders. The list still opens, answered on the phone. A line says how old the data is: “Offline — data from …”.
- Search
kitchenand press Enter. Only Leak under kitchen sink is left: the search runs on the phone, with the server’s rules. - Open it, press Edit, change the title, press Save. The app says “Saved on this device. It will be sent when you are back online.” The indicator says 1 pending, and the record says Not synced.
- Go to Inspections, press New, type a reading (
Pressure 1.5 bar) and pick the work order: the picker searches the phone’s copy ofwork-orders. On a phone, take a photo too. Save. The indicator says 2 pending. - Back in Work orders, the row you changed is marked Not synced.
A button whose action only the server can run says Needs a connection.
4. Sync
Section titled “4. Sync”Turn the network back on. Within a moment the indicator goes back to Synced: the phone sent the
two changes in order (the photo first, through PhotoStorage, then the inspection), and pulled what
changed. Check the server:
curl -s -X POST -H 'Content-Type: application/json' http://localhost:8690/mateu/v3/sync/x \ -d '{"route":"","serverSideType":"io.mateu.demo.fieldservice.Shell","actionId":"_offline-pull","componentState":{},"parameters":{"dataset":"work-orders"}}'The edited work order has the new title and is one version up.
5. A conflict
Section titled “5. A conflict”- Go offline again, open Install water filter, edit the technician, save.
- Meanwhile someone else changes the same record on the server — open the web UI at
http://localhost:8690in another browser and edit it there. - Go back online. The indicator says 1 needs attention:
work-ordersusesconflicts: ask. - Tap the indicator. On the Sync screen, the change says it was changed by someone else in the
meantime. Press Resolve: a
RecordMergeshows theirs and yours, field by field. Pick, merge, and the result is sent on the server’s current version.
6. The same from a test
Section titled “6. The same from a test”OfflineManifestTest in the demo drives the same server side with mateu-test’s simulated device —
no phone, no browser:
cd demo/demo-field-service && mvn testSee Testing in the guide.
The repository also has an end-to-end probe of this walkthrough against the web build,
e2e/rn-offline-probe.mjs (its header says how to start the backend and the app for it).