Repository navigation
0014 postgres source of truth
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.
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.
- 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.
- 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.
Generated from docs/ on dev. Edit the docs there; changes made on the wiki are overwritten.
- Development
- Workflow
-
Decisions
- 0001 Decisions are recorded
- 0002 Apache License 2.0
- 0003 Changes land on dev by fast-forward; main is the last release
- 0004 Conventional Commits, Keep a Changelog and Semantic Versioning
- 0005 docs/ is for developers and is mirrored to the wiki
- 0006 LibreBars is a free workout log for calisthenics
- 0007 The tracker is an iOS and Android app; its web build stays until the store release
- 0008 LibreBars is an app and a crowd-sourced open database
- 0009 The database is ODbL, media is CC BY-SA, and neither can be closed later
- 0010 A hosted API with a free tier is the paid product
- 0011 The workspace is app, web and api, with engine, ui, data and contracts
- 0012 The engine is small pure functions, in the style of date-fns
- 0013 Web and app share a Tailwind theme, not components
- 0014 Postgres is the source of truth for all data
- 0015 The API is Fastify, and it owns LibreBars accounts
- 0016 Every install is a guest account, made in the background
- 0017 Accounts use Better Auth
- 0018 The on-device database is SQLite with Drizzle, on every platform
- 0019 Sync is our own push and pull
- 0020 The app says it backs up, and backup can be turned off
- 0021 Postgres 18, run with Docker Compose and tested on two databases
- 0022 expo-sqlite is patched so the web build reuses one buffer
- 0023 Seed data is TypeScript modules in packages/data, with permanent ids
- 0024 The first tables
- 0025 One TanStack Start app is the website, on GitHub Pages
- 0026 The catalog reaches the app as a snapshot plus updates, and the website through the API
- 0027 The app's first components are its own