Overview
How the pieces of a Crudy deployment fit together.
A Crudy deployment is three processes plus a license file. The framework owns most of the code; your app is a thin entry point that picks modules and exposes them through a backend and a frontend.
The pieces
- Backend. A Fastify server built by
createCrudyServer({ modules, appConfig }). Owns authentication, the management API, the data API, audit logging, module wiring, and license enforcement. - Frontend. A Next.js App Router app wrapped in
CrudyProviders. Ships pre-built pages for login, settings, organizations, users, roles, and audit. Module pages plug into a catch-all route. - Database. PostgreSQL with the
pgmorbacextension and anappschema. Migrations are embedded in the framework packages (the morbac schema ships in@crudy/pgmorbac-fastify, the core tables in@crudy/backend) and are applied at boot together with any module and per-app (apps/<name>/migrations/) migrations. There is no separate database folder or init script; the backend creates roles, runs every migration, and re-applies grants on startup. - Data API. restloom (
@crudy/restloom), running inside the backend, answers the data routes modules declare. It reads and writes as a database role without BYPASSRLS, so the database's row security applies to every row. - License file. A signed token loaded from disk at boot. Declares the app name (audience), expiry, enabled modules, and per-org limits. Issued only by Crudy.
Request flow
A data route runs in four steps:
- Fastify authenticates the JWT or session cookie.
- The route's declaration decides: a
permissionofnulllets any signed-in user through,{ activity, view }requires that permission in the org named byX-Org-Id(or in each org ofX-Org-Ids). A path nobody declared does not exist. - The permission is checked by pgmorbac, with the licence and other permission hooks applied.
- restloom runs the query in a transaction carrying the caller's morbac context. Row security filters the rows; the response is JSON built by the database.
Authentication
Login uses the OAuth2 password grant at POST /oauth/token. The response includes a JWT signed with JWT_SECRET. Subsequent requests pass it as Authorization: Bearer <token> or via the session cookie set by the frontend.
Every interactive sign-in opens a server-side session (app.sessions) and the JWT names it. Each request checks that row, so signing out, revoking a session, an idle timeout or a deactivated account takes effect on the next request. Refreshing keeps the session's absolute expiry. Defaults: 12 hours absolute, 60 minutes idle (only user interaction counts, not polling), 5 sessions per user with the oldest signed out beyond that. Holders of update/auth_admin change them under Settings > Authentication; users see and sign out their sessions under Profile > Security. A password change or an MFA removal signs out the other sessions. The same settings can require a second factor of privileged accounts (those that manage accounts, roles, rules or sign-in) or of everyone, optionally only security keys and passkeys; until such an account enrols one it reaches nothing but the enrolment page. Adding or removing a second factor, or changing the sign-in address, needs proof that the caller is the account holder: the password, or for an account without one (email sign-in, SSO) a sign-in or an emailed code in the last 10 minutes.
API keys use the same endpoint with grant_type=client_credentials and a client_secret issued through the management UI.
Permissions
Crudy uses pgmorbac, a multi-org role-based access control extension. Activities (read, create, update, delete, ...) and views (orgs, users, documents, ...) are first-class records. Rules grant a user an activity on a view within an org. Roles bundle rules. Global rules grant unscoped access.
The same check, morbac.is_allowed(user, org, activity, view), runs on every protected backend route and on every row-level policy in PostgreSQL.
Licensing
The license is verified cryptographically once at boot. A cheap per-request guard then compares the in-memory expiry timestamp to the current time on every incoming request, and a timer self-terminates the process at expiry so the next boot trips the fail-closed check. There is no fallback path and no grace period. Module enablement and per-org quotas come out of the license file and are stacked on top of the database-level app.org_modules toggles. Both must allow for a module to run for an org.
Licenses are issued by Crudy. See Licensing for the consumer view, or request one at /contact.
Modules
Modules are the unit of feature you add to an app. Each module ships a backend half and a frontend half through a single package. The backend half registers routes, migrations, morbac requirements and quotas. The frontend half registers pages, navigation items, settings tabs, and slot contributions. They are wired into an app from backend/server.ts and frontend/app/providers.tsx, and nowhere else.
Continue with Core Packages for what each @crudy/* package owns.