MakeReady

Synchronisation and offline operation

Principles

  • A tablet must be able to work through a full match day without internet: log in, score, show standings.
  • As soon as there is a network, every approved score goes to the portal immediately (and from there to the MakeReady website, scoreboards and webhooks).
  • Multiple tablets per match are normal (one per stage or per squad). All tablets receive each other's scores via pull.

Accounts on the tablet

  1. Sign in with e-mail + password → POST /api/v1/auth/device/login (registers the tablet in devices, returns a long-lived device token, the profile and the club roles). Stored locally in accounts: profile, device token, expiry date and a salted hash of the password (SHA-256, 10,000 rounds). The password itself is never stored in clear.
  2. No internet? The same e-mail + password are checked against the stored hash and the session starts offline: the status line at the top right of the app says so. There is no separate offline mode or PIN to remember. That line has a fixed height and is always there ("● Online" in grey, "● Offline · scores are kept on this device" in orange), so nothing on the screen moves when the connection comes or goes while an RO is scoring.
  3. The last signed-in account is remembered: after a restart the tablet signs in by itself, online when the portal answers, offline otherwise, until the user signs out. A token the portal rejects (revoked, password changed) forgets the account and shows the sign-in screen.
  4. The app checks every 10 seconds whether the portal answers (GET /health). When it comes back, the status line says so and the tablet pushes its queued scores and pulls the latest state of every match it holds; when it drops, the line turns to offline and scoring continues locally. Expired device token (180 days) → sign in online again.
  5. Multiple ROs can be cached on the same tablet (RO change between squads).

Permissions are also enforced server-side: pushing requires staff or admin in the club of the match. A cached account that has lost its role in the meantime gets a 403 on the next push; the scores remain stored locally.

Local hub (tablets without internet)

One tablet can be the hub for the Wi-Fi on the range. Scoring tablets and dashboards connect to it by IP address; the hub keeps the approved scores of every tablet, forwards them to the portal when it is online, and shares the "on the range" panel. A tablet that has no copy of the event (set up without internet, e.g. a dashboard at the range) downloads the hub's copy from the event list ("Download from the hub"); it is view only until it has synced with the portal once. Scores stay in each tablet's own outbox as well, so the first tablet to reach the portal delivers them; the portal ignores duplicates by id. Stages, squads and competitors added, edited or removed without a connection travel through the hub too (see below). Details in docs/live-scoreboard.md.

The exchange with the hub runs every two seconds and only carries what is new: a tablet remembers which scores the hub already has and offers its edits again only after another edit, and the hub stores a score once and reloads its own screens only when a score is new. (Without internet the outbox for the portal keeps growing; offering all of it every two seconds made the hub slower as the evening went on.)

Documents of an event

The portal lists the documents of an event (stage briefings as PDF, a presentation) in the bundle of every pull. After each pull the app downloads the files it does not have yet, or whose checksum changed, into its documents folder (attachments/<event>/<id>.<ext>), and deletes the files of documents that were removed. The squad list and the scoring screen show Documents: a tap opens the file in the PDF reader or presentation app of the device, with no connection needed once it is downloaded. A document that is not on the device yet is fetched when tapped (that needs a connection once). Documents do not travel through the local hub: a device that only ever saw the hub's copy of an event has none until it reaches the portal.

Drafts on the scoring screen

What the RO enters on the scoring screen (time, hits, procedurals, DNF/DQ, the strings of a drill) is stored on the tablet as it changes (src/core/scoreDraft.ts, key-value store) until the competitor approves. Cancel, the back button or closing the app never loses it: the squad list marks the competitor with "draft" and opening them on that stage again restores it ("Start over" throws it away). Approving removes the draft.

Push (POST /api/v1/sync/push)

Payload: { deviceId, matchId, scores: StageScore[] } (zod schema in packages/shared/src/sync.ts). Rules in the portal:

SituationResult
id already knownignored ("already known")
revision ≤ highest known revision for (competitor, stage)ignored
otherwiseinserted as a new revision, received_at = server time

Afterwards: live standings to the Durable Object, webhook events stage_score.approved scheduled. The tablet removes both accepted and ignored ids from its outbox; failed attempts remain with an error message and a counter.

Pull (GET /api/v1/sync/matches/:id?since=<cursor>)

Delivers the match definition, stages, squads, registrations and all scores with received_at > since. The tablet stores serverTime as the next cursor. Without since everything is returned (first download).

Discipline rules

On every sync pass (and on each match download) the tablet calls GET /api/v1/rules and replaces its local copy of a discipline only when the portal reports a higher version. Offline, the tablet keeps the last synced rules for reference (divisions, categories, RO notes); the actual scoring of a match always uses the profile copied into that match (Match.scoring, Match.rulesVersion), so all tablets and the portal compute identical results regardless of when they last synced the rules.

Events created offline

A match or training can be created on the tablet without internet. It is built from the discipline rules stored on the tablet (synced at the last online refresh) with a locally generated id, and its stages, squads and competitors are edited locally; scoring works as for any other event. The event list marks it "Created on this tablet". At the next refresh with internet the sync creates it on the portal with the same id (POST /matches with id), uploads the stages, squads and competitors, pushes the scores approved in the meantime and pulls the portal's copy. A failed attempt is shown on the event list and retried on the next refresh.

Stages, squads and competitors edited offline

On an event that is on the portal, Manage keeps working without a connection for stages, squads and competitors: adding, editing and removing them (admins of the event; the role last seen online counts, so open Manage or refresh once with a connection; signing out forgets it). That role is on screen at once, without waiting for the portal, so the buttons to save and delete are there on a range without internet too. The edit is applied to the tablet's copy at once, so the competitor can be scored right away, and queued in manage_outbox (one entry per stage, squad or competitor: the latest edit wins). The manage screen shows how many changes are waiting.

The next sync with a connection replays the queue on the portal, oldest first and before the scores, so scores of a competitor or stage added offline find it there (src/sync/manageOutbox.ts). Every management call made online also sends the queue first, so the portal sees the edits in the order they were made. Until then a pull keeps the queued edits on top of the portal's copy.

An edit made with a connection goes to the portal first and is then applied to the tablet's copy as well, so the screens (which read that copy) show it at once instead of after the next pull.

Randomize on the squad screen redeals the shooting order. With a squad selected only that squad is dealt: its members swap the numbers they have between them and the other squads keep theirs, so on a match with several squads in several bays an RO never changes the order of a squad that is shooting elsewhere. With "All competitors" selected the whole event is dealt. The order of a squad is fixed from its first approved score. The new numbers reach the other tablets like any other change: through the portal at their next sync (every 15 seconds while scoring), and through the local hub within a few seconds when there is no internet, so every tablet shows the same order and the same rotation over the stages. It always works this way round: all new numbers are written to the tablet's copy and queued in one go, and the queue is pushed in the background. The list changes immediately, with or without internet, and the deal is repeated until the order of the squad on screen really differs (src/core/randomOrder.ts). An RO may do this: the portal accepts a renumbered competitor from staff as long as nothing else changed (an unchanged chrono measurement that travels along is not a change).

Moving a competitor works the same way. Hold a competitor in the list of the squad screen to pick them up, then tap the place in the list where they shoot (or use the Earlier/Later buttons) and finish with Done. The competitors in view keep the numbers they have between them; the numbers are handed out again so that the list on the selected stage reads as arranged (numbersForShootingOrder in packages/scoring, the inverse of the rotation), and the rotation over the other stages follows from it. No-shows are not part of it. Like Randomize, this is possible until the first score is approved.

Competitor numbers change only on purpose. Saving a competitor (a division, a no-show, a chrono measurement, the club portal's sync) does not send the number: the portal keeps the one it has, and a new competitor gets the next free number. Only Randomize, moving a competitor and the Number field on the website send one. Before this rule every save wrote back the number the device or page had last seen, which undid a redeal made elsewhere in the meantime and left two competitors on the same number. In the tablet's queue a deliberate number change is marked (sendNumber), and the mark stays when a later edit of the same competitor replaces it in the queue. Should two competitors still share a number, Randomize and moving hand out numbers of their own (distinctNumbers in packages/scoring), and the Competitors tab on the website shows a warning with a button that does the same.

Only what was changed is saved. An edit of an existing competitor (a no-show, a chrono measurement, a new number, what was changed in the editor) sends only those fields (PATCH /api/v1/matches/:id/competitors/:cid); everything else stays as the portal has it. Before this rule every save sent the whole competitor from the copy the tablet or page had, which could put back a division, squad or category that was corrected elsewhere a moment earlier. In the tablet's queue the fields of an edit are kept with it (fields); two edits of the same competitor that wait together send the fields of both, and after a download only those fields are put on top of the portal's copy (applyQueuedCompetitor, mergeQueuedCompetitor in src/db/local.ts, changedCompetitorFields in src/core/competitorChanges.ts). A competitor added on the tablet is sent whole.

The portal checks each replayed edit as if it were made now. An edit it refuses (no rights any more, the stage was scored on another tablet meanwhile, a club-portal registration) is dropped, the portal's version is kept, and the manage screen lists what was refused until it is dismissed.

The same rules apply on the tablet as on the portal, as far as the tablet knows the scores: a stage with a score only changes its Active flag, a stage or competitor with a score cannot be removed, and the club portal's registrations and squads cannot be removed in MakeReady. Event settings, the change log, linking a competitor to an account and the account autocomplete need a connection.

Through the local hub the other tablets see these edits within one sync pass (15 s), before the portal has them: a walk-in added on one tablet can be scored on every other tablet on the Wi-Fi. Every edit carries an id and the time it was made (manage_changes); tablets and the hub exchange the latest edit per stage, squad and competitor (GET/POST /hub/matches/:id/changes, before the scores), apply what is newer than what they know and queue it for the portal as well, so whichever tablet gets a connection first delivers it (before its scores). Once a tablet has delivered an edit, the hub passes that on and the other tablets drop it from their queue. Two tablets editing the same competitor: the later edit wins everywhere. Refusals are only listed on the tablet that made the edit; an edit an RO tablet may not deliver (no admin rights) is left to the tablet that made it.

Conflicts

Two tablets scoring the same competitor on the same stage (a mistake on the range) produce two revisions; the highest wins, and on an equal revision the most recently created one. Both remain visible in the history, and the stats officer can add a correction revision in the portal; such a correction counts at once but is flagged until the competitor approves it again on a tablet (Approve correction on the Score screen, which stores a new revision). Because revision numbers are determined locally, a tablet that was offline for a long time can push a revision 1 while the portal already knows revision 2: that push is ignored and after the pull the tablet sees the current score.

Local storage (expo-sqlite)

Schema in apps/tablet/src/db/schema.ts: kv, cached_accounts, matches/stages/squads/competitors (JSON), stage_scores (append-only), outbox (scores), event_outbox (events created offline) and manage_outbox (stage, squad and competitor edits made offline). The sync loop (src/sync/engine.ts) runs every 15 s while scoring and immediately after every approval.

When the app does not get past "MakeReady is starting…"

Startup opens the database, reads the settings, prepares the hub and the timer and restores the last account from what is stored on the tablet; the profile and club roles are refreshed from the portal in the background, so a start without internet does not wait for a network timeout. When one of the steps fails, the app shows MakeReady could not start with the step and the error (the text can be selected and copied), and when a step takes more than 15 s it names the step it is busy with. Both screens offer Try again. There is no button that deletes the local data: the scores on the device are never thrown away from these screens.

When JavaScript throws a fatal error later on, the app shows MakeReady has crashed with the message and stack (selectable) instead of closing (src/core/crash.ts: a global error handler plus an error boundary around the whole app), with Restart (the scores on the device are kept). Native crashes cannot be caught this way; those appear in Play Console → Android vitals.