Outdoor Reflections
I built an offline-first editor that saves writing and sketches in the browser and syncs pending edits when the connection returns.
Problem and scope
A connection can disappear while someone is writing or sketching outdoors. I built the editor, local persistence, and sync flow so a saved entry can be reopened on the same device while offline and uploaded later.
How it works
After a short pause in editing, the browser saves the entry to IndexedDB and marks it as pending. When the connection returns, the sync client sends pending changes to the NestJS API and reconciles the server response with edits still on the device.
- EditorWrite or sketch
- IndexedDBSave locally
- Sync clientSend pending edits
- NestJS APIReconcile with PostgreSQL
Engineering decisions
- Autosave locally before syncing
- Saving to IndexedDB after a short pause keeps network latency out of the editor. It also makes pending changes explicit so the client can retry after an interruption.
- Keep drawings as SVG paths
- Each stroke is stored as a path with its colour. That lets drawings scale with the editor and travel in the same entry payload as the writing.
- Reconcile updates per entry
- The API checks ownership and edit timestamps before applying updates. It reports mixed outcomes so one rejected entry does not discard the rest of the batch.
How I verified it
I covered several failure cases in the sync tests on the development branch.
- After a deletion syncs, retry both the deletion and an older copy of the entry. The stored deletion marker should remain, with the encrypted content cleared.
- Send a valid encrypted entry and invalid plaintext entries in the same batch. The valid entry should save, and the API should report the rejected entries.
- Deliver an older sync acknowledgement after a local deletion. The deletion should stay pending on the device.
Current state
The deployed version supports writing and sketching offline, then syncing to an account. The development branch adds browser-side encryption for entry content and tests for encrypted sync and deletion handling.