@synapse/api #
The Synapse server, a NestJS app in clean architecture. domain/ holds the
entities and the repository ports, application/ the use cases with one service
per aggregate, infrastructure/ the Drizzle repositories and the external
services, interface/ the controllers and DTO validation, and auth/ the
session guard with the Passport strategies. The application layer depends on the
ports in domain/ports.ts and never on Drizzle or fetch, so the tests bind
doubles to the same tokens app.module.ts binds the real adapters to.
Courses, chapters, annotations, the lexicon and the attempt log never reach a
server table. They stay in the clients' Loro CRDT documents. What this app stores
is an append-only sync log of opaque update blobs per (owner, doc), which a
compaction job folds into snapshots, plus a content store that addresses the
uploaded files and the CRDT payloads by their sha256. Every read is scoped to
the caller's owner id. The app also runs the accounts, proxies the AI calls
through @synapse/ai-core, converts uploads through pandoc and LibreOffice, and
serves the built web app with an SPA fallback for non-/api routes. SQLite is
the default at data/synapse.db and Postgres needs DB_DIALECT=postgres.
Migrations apply themselves at boot, so there is no migrate step to forget.
Configuration, the local scripts and the test layout are in Development. Architecture explains the sync log and the content store, and Authentication covers sessions, users and SSO.