Skip to content

0015 fastify api

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

The API is Fastify, and it owns LibreBars accounts

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

From LibreLifts ADR 0021, and from how its API was built. Built 2026-11-18: buildApp, one file that listens, settings checked at start, the health check and the private account part. The public data API is not built; that is 0010.

Context

Something has to stand between the apps and Postgres (0014): to say who is asking, to take and give a person's changes, and later to serve the open database to others (0010).

Decision

  • The API is a Fastify service in apps/api, written in TypeScript and run by Node directly, without a build step.
  • LibreBars has its own accounts, and the API owns them.
  • One service has two parts, kept apart:
    • a private part for accounts and sync, used only by LibreBars' own app and website;
    • the public data API, the paid product, which serves reference data only. It does not exist yet.
  • buildApp() builds the app without starting it and takes its settings and its database as arguments. One file listens, and one file reads the environment.
  • Routes are plugins, and every route has a schema for what it takes and what it returns. The shapes come from packages/contracts; neither side restates one.
  • Settings are environment variables, checked against a schema when the API starts, and mirrored in .env.example. No secret is committed.
  • The logger hides the headers that carry a session.
  • Who is asking comes from the session only, never from the body, the path or a header the caller sets.

Consequences

  • One service to run, and one place where an account is defined.
  • Tests can build the whole API in memory and call it without a network (0021).
  • The line between the two parts has to stay visible in the code and in the documentation, so that what is sold stays reference data. The app must work without the paid part.
  • Node running TypeScript directly allows only syntax that can be erased: no enums and no parameter properties, and imports name the .ts file.

LibreBars

Clone this wiki locally