llms.txt Content
# Remult
> Remult is a TypeScript library for building full-stack apps without boilerplate. Define entities once and use them on the frontend, the backend, and in the database, with a single SSOT (Single Source of Truth) for schema, validation, permissions, and CRUD.
## Core Concepts
- **Entity** - a TypeScript class decorated with `@Entity('key', options)` is your SSOT: schema, REST API, validation, permissions, and lifecycle in one place.
- **Fields** - `@Fields.string()`, `.number()`, `.boolean()`, `.date()`, `.json()`, `.uuid()`, `.cuid()`, `.autoIncrement()`, plus `@Relations.toOne()` / `.toMany()` for entity links.
- **Repository (`repo(Entity)`)** - universal CRUD: `.find()`, `.findFirst()`, `.findId()`, `.insert()`, `.update()`, `.delete()`, `.save()`, `.count()`, `.query()`, `.liveQuery()`. Same API on frontend and backend.
- **Permissions** - entity-level `allowApiRead/Insert/Update/Delete/Crud` and per-field `allowApiUpdate`; values are boolean, role string, role array, or `(entity, remult) => boolean`. Use `apiPrefilter` / `backendPrefilter` for row-level filtering.
- **Lifecycle hooks** - `validation`, `saving`, `saved`, `deleting`, `deleted` run on the server before/after persistence; `saving` mutates the entity in place.
- **BackendMethod** - `@BackendMethod({ allowed })` exposes a server-only function callable from the client; runs in the server context with `remult.user` populated.
- **Live queries** - `repo(X).liveQuery(options).subscribe(({ items, changes }) => ...)` pushes inserts/updates/deletes to all connected clients over SSE.
- **Custom filters** - `Filter.createCustom` / `SqlDatabase.filterToRaw` to express complex queries that round-trip to the server safely.
- **Validators** - built-ins under `Validators.*` (`required`, `min`, `max`, `email`, `url`, `unique`, `regex`, `enum`, ...) or `validate: (entity) => string | undefined` for custom logic.
- **Admin UI** - turnkey `/api/admin` panel via `admin: true` (or `admin: { allow: 'admin' }`