Kit, core and modules
Kit
The GatoJS repository: one reference application plus a manifest per module saying which files and npm dependencies belong to it.
Core
What every project gets: sign-in, organizations, users, account and dashboard, plus shared libraries and tooling.
Modules
Optional units you add and remove with the CLI:
audit-logs, api-keys, uploads.Copied into your repo, not installed
The core and modules are copied into your repository, not installed from npm. You change them like any other file, with no fork and no package to publish. The trade-off is deliberate:
The CLI (
gato) creates projects, adds and removes modules, lists them, updates the kit version and regenerates the registry. It does not push your changes back to the kit: a fix that would help other projects goes to the GatoJS repository as a pull request.
Kit principles
These decisions shape the rest of the codebase.- Kit code becomes project code. See above.
- The kit is one reference application. It lives at the root of the GatoJS repository with the same layout as a generated project, so it is developed and tested like a normal app. Each file belongs to exactly one module, and a test enforces that.
- A module only adds files. It never edits core files. The core learns about a module only through seams: the generated registry and
wa:*regions. In the other direction, a module uses the core through entry points such astrackAuditand declarations indefineModule. If modules edited core files, every add, remove or update would turn into merging someone else’s changes into the same files. - Generated files are committed. The project builds, tests and deploys without the CLI (the Docker image never runs it). CI checks that the committed files match the generator’s output exactly.
- A module definition is pure data. The server-side page guard and the browser-side menu both read it, and both decide access with the same function,
canAccessModule. The menu therefore shows exactly the pages the guard lets you open. - Modules bring their own schema; features bring their own translations. Prisma models go in a module’s own file in
prisma/schema/; translations go insrc/features/<x>/i18n/under a namespace equal to the folder name. Back-relations on core models go into thewa:relationsregion. - The server checks data and access, not the UI. Every query on domain data filters by
organizationIdfromgetOrgContext(). Every feature page in(app)callsrequireModuleAccess(key). Every server action checks permissions itself. Hiding a menu entry protects nothing, because a URL can be typed by hand. - Logs and traces go through OpenTelemetry. The logger sends entries through the OpenTelemetry logs API, and
OTEL_EXPORTER_OTLP_ENDPOINTturns on export. See Logging and observability.
Runtime services
The app is a single Node.js process. better-auth (sessions), Prisma (database access) and next-intl (translations) are libraries inside that process, not separate services.- Browser → app. Pages, server actions (POST requests to the current page URL), the better-auth endpoint
/api/auth/*, and/api/healthcheck, which runsSELECT 1for the deployment health check. - App → PostgreSQL. Prisma with the
@prisma/adapter-pgdriver adapter. better-auth stores accounts and sessions in the same database. - App → email. SMTP when
SMTP_URLis set (mailpit locally), otherwise Resend whenRESEND_API_KEYis set, otherwise a log entry only. Production requiresRESEND_API_KEY. See Email. - Module services.
uploadsstores files on local disk or S3-compatible storage.uploadsandapi-keysadd their own API routes.
npm run dev runs the app and docker compose up -d runs PostgreSQL and mailpit. In production the app runs from the Dockerfile image; see Docker and Railway.
The request path
Two flows show where each check happens: rendering a page (GET) and running a server action (POST). Both pass through the proxy first.Proxy: locale only
src/proxy.ts is the Next.js 16 proxy (formerly middleware). In GatoJS it only resolves the locale with next-intl; it does not check sessions or permissions.
src/proxy.ts
/api and everything below it, Next.js internals, and any path with a dot. A path that merely starts with api, like /api-keys, still goes through the proxy. A URL without a locale prefix is rewritten to the default locale (pl), unless next-intl detects English from the NEXT_LOCALE cookie or Accept-Language, in which case it redirects to /en/....
Rendering a page
An organization owner opens/users with MULTI_ORG=true:
The layout and the page render independently, and the layout does not re-render on client-side navigation between pages. That is why the layout check is not enough: the page calls its own guard, and the query calls getOrgContext() again before touching Prisma. getOrgContext() reads the session from the database rather than the cookie cache, so role and membership changes take effect immediately.
Running a server action
A global admin submits Invite user: A server action is an exported function from a"use server" file. Next.js calls it directly: the layout and page do not run first, so their checks do not protect it. The command therefore checks the role, validates input, gets the organization context and confirms service mode before it reaches Prisma. Every command on organization data follows this contract; see Code patterns and Superadmin and service mode.
Who checks what
An architecture test (
src/__tests__/server-entrypoints-guard.test.ts) checks that every exported function in a "use server" file and in services/queries/ calls a guard before Prisma. That a new page calls requireModuleAccess is a convention, not a test.
A superadmin without membership in the active organization does not get redirected. They get a context with
serviceMode: true, and the layout shows the service-mode banner. See Superadmin and service mode.Module definition
A feature needs amodule.ts to have a menu entry or a page protected by requireModuleAccess. Each core feature has one:
src/features/users/module.ts
defineModule returns its argument unchanged; it exists so TypeScript checks the object against ModuleDef and keeps its exact type. Two places in the core read definitions, both from clientModules in the client registry:
- The page guard.
requireModuleAccess(key)finds the definition with that key (404 if none), then callscanAccessModule(definition, { userRole, orgRole, multiOrg }). - The sidebar.
getNavEntrieskeeps the definitionscanAccessModuleallows, collects theirnavitems and sorts them byorderacross all features. The label is the translation at<key>.<labelKey>.
canAccessModule decides in this order:
- Global
adminandsuperadmin, or a definition withpublic: true: allowed. - No organization role: denied.
adminOnly: true: allowed only whenMULTI_ORG=trueand the organization role is inmultiOrgRoles.- Otherwise: allowed if
rolesis not set or contains the organization role.
ModuleDef reference
Identifier passed to
requireModuleAccess(key) and the start of the menu label path. Must equal the feature folder name.Sidebar entries. Can be
[].The feature’s routes. Required by the type, but it does not protect any route; only
requireModuleAccess in the page does.Limits access to these organization roles (
owner, admin, member). Without it, every role has access. Ignored when adminOnly is true.true grants access to every role. It does not mean “no sign-in”: a page with requireModuleAccess still needs a session and an active organization.true grants organization roles access only with MULTI_ORG=true, and only to roles in multiOrgRoles.Audit actions with label keys, read by the
audit-logs module. Pure data: without the module nothing reads it.Scopes the feature exposes to API keys, read by the
api-keys module.Upload purposes with allowed MIME types, a size limit, visibility (
public or organization) and optional image resizing, read by the uploads module.ModuleNavItem has href (path without the locale prefix), labelKey, optional multiOrgLabelKey (used instead of labelKey when MULTI_ORG=true and the user has the global role user), icon (a lucide icon name such as layout-dashboard) and order. Core entries use dashboard 10, users 80 and account 90.