Skip to content

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:

DatasetDirectionWhat
productsdown (Wi-Fi only)the parts catalogue, read-only on the phone
work-ordersboththe jobs: listed, opened, changed and created offline, synced later (UUID keys, @Version for conflicts)
inspectionsupwritten 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.

The demo tracks the repository, so install the backend first:

Terminal window
cd backend && mvn install -DskipTests
cd ../demo/demo-field-service
mvn spring-boot:run -Dspring-boot.run.arguments=--mateu.cors.allowed-origins=http://localhost:8081

It 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:

Terminal window
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.

In a browser, the quickest way:

Terminal window
cd frontend/app/react-native
npm ci
EXPO_PUBLIC_MATEU_BACKEND_PORT=8690 npm run web

The 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)”.)

  • 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:

  1. 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 …”.
  2. Search kitchen and press Enter. Only Leak under kitchen sink is left: the search runs on the phone, with the server’s rules.
  3. 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.
  4. Go to Inspections, press New, type a reading (Pressure 1.5 bar) and pick the work order: the picker searches the phone’s copy of work-orders. On a phone, take a photo too. Save. The indicator says 2 pending.
  5. 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.

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:

Terminal window
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.

  1. Go offline again, open Install water filter, edit the technician, save.
  2. Meanwhile someone else changes the same record on the server — open the web UI at http://localhost:8690 in another browser and edit it there.
  3. Go back online. The indicator says 1 needs attention: work-orders uses conflicts: ask.
  4. Tap the indicator. On the Sync screen, the change says it was changed by someone else in the meantime. Press Resolve: a RecordMerge shows theirs and yours, field by field. Pick, merge, and the result is sent on the server’s current version.

OfflineManifestTest in the demo drives the same server side with mateu-test’s simulated device — no phone, no browser:

Terminal window
cd demo/demo-field-service && mvn test

See 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).