Skip to content

0014 postgres source of truth

github-actions[bot] edited this page Nov 18, 2026 · 3 revisions

Postgres is the source of truth for all data

Status: accepted · Implementation: done · Date: 2026-11-18

From LibreLifts ADR 0024. Where Postgres and the API are hosted gets its own record. As built so far, 2026-11-18: the API and its Postgres exist and hold accounts. No personal data reaches them yet, so this stays planned. Built 2026-11-18: personal data reaches Postgres through sync, in a schema of its own. Reference data is still files in packages/data. What has to exist before a real person uses it is tracked in 0016.

Context

LibreBars has two kinds of data. Personal data is one person's training: routines, workouts, sets, settings. Reference data is the open database: exercises and what belongs to them (0008).

A log kept only on the phone is lost with the phone, and most people never export anything. Reference data kept only as files in git cannot be edited from a website and shown without a rebuild. Two stores side by side would be two places that can disagree.

Decision

  • One Postgres database, behind the API, is the source of truth for all data, personal and reference alike.
  • The API is the only thing that talks to it. The app and the website go through the API.
  • The app writes to a database on the device first and works with no connection (0018). The server's copy is a backup and the way to another device, never something a screen waits for.
  • The website is online-only. It stores no personal data in the browser.
  • Drizzle defines the tables and their migrations, in apps/api.
  • Personal data and reference data are kept apart in the database, as they are in the API: the paid API can read only reference data.
  • What is said about the data is what is true. The app is not described as keeping data only on the device. The wording on the website and in the app follows the architecture and changes in the same pull request.
  • Personal data is never logged, never sent to an outside service, and never used in tests or fixtures.

Consequences

  • There is one place to look for the truth.
  • The project needs a running database and API, with their cost, backups and upkeep.
  • Holding personal data brings duties: a privacy policy, a limit on how long an abandoned account is kept, and a way to delete one's data. None of it exists yet, and all of it is due before the first real person's data is stored (0016).
  • The app still has to work without the API, so every screen reads from the device.

LibreBars

Clone this wiki locally