Cookbook
Sample app: Fieldbook
A small but real app on one Rust core: field notes with photos, on the web, iOS and Android.
What it is#
Fieldbook is a small but real app: field notes with photos, for a team that works where there is no signal. One Rust core, three apps (web, iOS, Android) that use only the public API, and a test suite that runs the core with no device. The cookbook's recipes, in one product.
What it demonstrates#
| Feature | In the core |
|---|---|
| Sign-in with a team code, tokens in the secure store, one re-auth on a 401 | auth.rs |
| A note is on the device before the screen shows it, and is sent when there is a network, even after a kill | notes.rs: Kv, an idempotent push_note |
| Search, tag chips, pinned first, newest first | a keyed list, a DerivedList and a Computed |
| Photos kept in the app's files and uploaded in the background | Fs and the queue |
| An update that renames a field and adds three, without losing data | #[undra(default)], #[undra::migrate] |
| Who else is in the notebook | presence.rs: a reconnecting WebSocket (feature presence) |
State kept across a rebuild under undra dev | every store has a restore function, tested |
Run it#
Show the commands
cd examples/fieldbook/web && npm install && npm run dev # the web app, with an in-page demo server (team code: fieldbook)
node examples/fieldbook/server/server.mjs # a backend for the iOS and Android apps
cargo test -p fieldbook-core # the core, against the fakes
cd examples/fieldbook/web && npm test # the bindings over the real wasm coreTick offline in the web app, write two notes, reload, untick it: the notes were on the device the whole time, and the core sends them when the network returns.
How far it goes#
- The web, iOS and Android apps build in CI (
vite build,xcodebuild,assembleDebug); the screens are small on purpose. - Notes are stored in
Kv. TheDbport (SQLite) is the next step for a notebook that grows; it is an opt-in port. - SwiftUI previews and the web stories run the real core on the testing kit's fakes, and so do the web tests, with a manual clock. Android's Compose previews are not in the sample: they play a recording, and none was made.
Source: examples/fieldbook, with a README that says how to run each platform. The cookbook has the recipes it is made of.