Prototypes Prototype docsP11 · Docs and assistant
CRM on the device (P12)
DocsPage 15 of 30

CRM on the device (P12)

Contacts, deals, tasks and notes are stored on each device and synced between two people. Two people can change the same deal with no network, and both changes are kept.

Each record is a Yjs document

Every contact and every deal is its own Yjs document. It is stored in IndexedDB on the device. A change is written on the device first. A service worker caches the page, so it opens with no network.

Two people change the same deal

Text fields are Yjs text: a name, a title and the notes. Two people who type in the same notes at once both keep their letters. Tags and the people on a deal are sets. A tag added on each device gives two tags. Tasks are a list, and tasks added on both devices are all kept.

The stage, the owner, the amount and the close date are choices. Two people can choose differently while offline. The CRM then keeps both values and shows the conflict on both devices. A person keeps one value, or one per field. The conflict then closes on both devices. Undo brings both values back.

Sync

Each record with changes waits in a list on the device. With a network, the device sends what the server has not acknowledged. It receives the updates from other devices since its last sync. The server stores the updates per record. It merges a record's updates into one when there are more than 16. A WebSocket tells the other devices at once when something new arrives. The same WebSocket shows which record each device has open.

The keyboard

Every action is defined once in the design system's engine. The definition holds the label, the keys and the reason the action cannot run. The command palette, the menus, the bulk bar and the shortcuts sheet are all built from that list.

  • Command K opens the palette.
  • J and K move through the list, and Enter opens a record.
  • X selects a row, and S sets the stage with a digit.
  • G then D goes to the deals.
  • Command Z undoes the last change of any kind.

The palette finds a contact among 10,000 by the letters of its name in order, and in Chromium it searched all of them in under 5 milliseconds per key.

10,000 contacts

In Chromium the action Load 10,000 contacts wrote 10,000 contacts and 300 deals on the device in about 1 second. The list draws only the rows in view and six on either side. It reuses the same 30 elements as it scrolls. Scrolling through all 10,000 rows kept a frame every 9 milliseconds at the 95th percentile. Drawing the rows took under half a millisecond per frame. The 10,300 records reached the second device in about 10 seconds.

What is stored on the server

The server stores the Yjs updates of each record, which device sent them, and when. The updates are not encrypted, because the server keeps the team's records. Data older than 7 days is deleted.

Previous: How the prototypes are checked. Next: Team vault (P13).

How Prototype docs is built

The pages are written in Markdown and built into these pages and an index of 154 sections. The assistant answers from the index, and every answer names the sections it was taken from.