> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gatojs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Kit modules

> How GatoJS kit modules differ from the core and from your own features, which modules exist, and how to add, remove and choose them for a project.

A GatoJS project starts with the core: sign-in, organizations, users, account and dashboard. Everything else is optional and comes as a **kit module** that you add when the project needs it and remove when it doesn't. A module is copied into your repository as plain Next.js, Prisma and TypeScript code. There is no runtime plugin system and no package in `node_modules` to work around.

This page explains how modules relate to the core, what each module does, and how the core learns about a module without importing it.

## Core, kit modules and project modules

The word "module" means two things in GatoJS:

* a **kit module** is the unit the CLI copies into a project and removes from it. A manifest in the kit (`kit/modules/<name>.json`) describes its files, npm dependencies, environment variables, schema relations, Docker services and CI steps.
* a **module definition** is a `src/features/<name>/module.ts` file that calls `defineModule({...})`. It describes one feature: its key, menu entries, roles and declarations. The generator puts it in the module registry.

The core is the kit module `core` with five features (`account`, `auth`, `dashboard`, `organizations`, `users`). Each optional kit module has a single feature with the same name. Features you write yourself are **project modules**.

| | Core (`core`) | Optional kit module | Project module |
| - | - | - | - |
| Where it comes from | The kit, always. | The kit, chosen at `gato create` or added with `gato add`. | Your team writes it ([Build a feature](https://docs.gatojs.com/guides/build-a-feature.md)). |
| Entry in `.wa/kit.json` | `modules.core`: version, manifest, file hashes. | `modules.<name>`: version, manifest, file hashes. | `projectModules.<name>`: manifest only, no version or hashes. |
| Removal | Not possible. | `npx gato remove <name>`. | By hand: delete the files and the `projectModules` entry. |
| Registration | `gato generate`, first. | `gato generate`, after the core, in name order. | `gato generate`, after kit modules. |
| Fixes | Pull request to the kit, if other projects benefit. | Same as the core. | Only in your project. |

See [`.wa/kit.json`](https://docs.gatojs.com/cli/kit-json) for the full file format.

## Available modules

| Module | What it does | Status |
| - | - | - |
| [`audit-logs`](https://docs.gatojs.com/modules/audit-logs) | Who changed what, and when, in each organization: an audit log page, a per-entity history component and the storage behind `trackAudit`. | Ready |
| [`api-keys`](https://docs.gatojs.com/modules/api-keys) | Organization API keys with scopes, stored as HMAC hashes. Your routes declare the scope they need and get the organization from the key. | Ready |
| [`uploads`](https://docs.gatojs.com/modules/uploads) | Organization files on local disk or S3-compatible storage, with public and organization-only files and image resizing. | Ready |
| Background jobs | A job queue and scheduled tasks, including retention and cleanup. | Planned |
| MCP | Expose your app to AI assistants over MCP with OAuth, built on better-auth. | Planned |
| Legal pages | Terms, privacy policy and a cookie banner. | Planned |

See the [roadmap](https://docs.gatojs.com/roadmap.md) for planned work.

### What each module adds

| Module | Database | Pages and routes | Environment | Services |
| - | - | - | - | - |
| `audit-logs` | `audit_logs` table, `AuditChannel` enum | `/audit-log`, `<AuditTrail>` | none | none |
| `api-keys` | `api_keys` table | `/api-keys`, `GET /api/v1/organization` | `API_KEY_PEPPER` (required) | none |
| `uploads` | `uploads` table, `UploadVisibility` enum | `POST /api/uploads`, `GET /api/uploads/<id>`, `<FileUpload>` | `STORAGE_PROVIDER`, `STORAGE_LOCAL_PATH`, `S3_*` (all optional in development) | MinIO under the Compose profile `s3`, MinIO steps in CI |

### Dependencies between modules

No kit module lists another in `requires`, so you can add and remove each one independently. They still cooperate through core entry points: a module uses another module's contribution when it is installed, and works without it.

| Module | Uses another module when present | Without that module |
| - | - | - |
| `audit-logs` | Shows labels for actions declared by `api-keys` and `uploads`. | Undeclared actions show as raw strings. |
| `api-keys` | Records key events through `trackAudit`; `audit-logs` stores them. | Key events go nowhere. |
| `uploads` | Records `upload.created` and `upload.deleted` through `trackAudit`; `audit-logs` stores them. | File events go nowhere. |

A project module can list a kit module in `requires`. `gato remove` then refuses to remove that kit module, and every CLI command refuses to run if a required module is missing.

## How a module reaches your app

A module only adds files. It never edits core code. The core learns about the module through a generated registry and a few marked regions, which together form the **seam layer**.

**1. Manifest**

The kit describes the module in `kit/modules/<name>.json`. When you install it, the manifest is copied into `.wa/kit.json`, so from then on `gato generate` and `gato remove` work without the kit.

**2. Copy**

`gato create --modules <list>` or `gato add <name>` copies the module files, adds its npm dependencies to `package.json` and runs `gato generate`. If any module file already exists, `gato add` stops without changing anything.

**3. Generate**

`gato generate` rewrites `src/modules.generated.ts`, `src/modules.client.generated.ts` and `src/i18n/locales.generated.ts`, and fills the `wa:*` regions in core files.

**4. Run**

The core reads the registry (environment schemas, better-auth plugins, translations, menu, guards, audit sinks). Modules read each other's declarations (`auditActions`, `apiScopes`, `uploadPurposes`) from the same registry.

### Generated seams

A feature lands in a registry array only if it has the matching file.

| Seam | Built from | Read by |
| - | - | - |
| `modules` (server registry) | `module.ts` | Modules: `knownApiScopes` (`api-keys`), `listUploadPurposes` (`uploads`), `<AuditTrail>` (`audit-logs`). |
| `clientModules` | `module.ts` | Core: page guard and `requireModuleAccess`, navigation menu. Modules: `/audit-log` view, API key form. |
| `moduleEnvSchemas` | `env.ts` (export `envSchema`) | `createEnv`, which merges the core schema with every module schema into one. |
| `authPlugins` | `auth.ts` (export `authPlugin`) | better-auth server `plugins`. |
| `authClientPlugins` | `auth-client.ts` (export `authClientPlugin`) | better-auth client `plugins`. No kit module has one. |
| `auditSinks` | `audit-sink.ts` (export `auditSink`) | `trackAudit`. |
| `moduleMessages` | `i18n/<locale>.json` | `src/i18n/request.ts`; messages live under a namespace equal to the feature folder name. |
| `wa:relations` region in `auth.prisma` and `organizations.prisma` | `schemaRelations` in the manifest | Prisma back-relations on `User` and `Organization`. |
| `wa:modules` region in `.env.example` | `env` in the manifest | You, when copying variables into `.env`. |
| `wa:services` region in `docker-compose.yml` | `compose` in the manifest | Docker Compose. |
| `wa:ci-integration` region in `ci.yml` and `mutation.yml` | `ciSteps` in the manifest | The integration test job in your CI. |

Don't edit generated files or regions by hand: your CI checks that `gato generate` produces no diff. Adding or removing a `module.ts`, `env.ts`, `auth.ts`, `audit-sink.ts` or translation file requires `npx gato generate`. Changing the contents of an existing one does not, because the registry imports the files. See [Module registry](https://docs.gatojs.com/concepts/module-registry.md) for details.

> [!WARNING]
>
> A module's `env.ts` becomes part of the whole app's environment schema. A missing or invalid variable stops the entire server at startup, not just the module. After adding `api-keys`, set `API_KEY_PEPPER` in `.env` before starting the app.

## Core entry points that work without a module

Generated seams tell the core which modules exist. Entry points work the other way: they are core code that a module, or your own code, calls. Because they live in core files, they exist in every project, including projects without the module that handles them.

| Entry point | File | Contract | Without the module |
| - | - | - | - |
| `trackAudit(event)` | `src/shared/lib/audit.ts` | Calls every sink in `auditSinks` in order. Logs a failing sink as `trackAudit failed` and continues. Never throws. | `auditSinks` is empty: the call records nothing and reports nothing. |
| `auditActor(context)` | `src/shared/lib/audit.ts` | Returns `organizationId`, `actorUserId` and `serviceMode` from an `OrgContext`. | Pure function, always works. |
| `AuditSink` / `audit-sink.ts` | `src/shared/lib/audit.ts` | `(event: AuditEvent) => Promise<void>` exported as `auditSink`; the generator adds it to `auditSinks`. | No sink, nothing is stored. |
| `auditActions` in `defineModule` | `define-module.ts` | `{ action, labelKey }[]`: display labels for audit actions. | Type-checks and does nothing. |
| `apiScopes` in `defineModule` | `define-module.ts` | `{ key, labelKey }[]`: scopes an API key can be granted. | Type-checks and does nothing. |
| `uploadPurposes` in `defineModule` | `define-module.ts` | `{ key, mimeTypes, maxBytes, visibility, resizeImage? }[]`: what an upload may contain. | Type-checks and does nothing. |
| `useServiceModeAction().requestConfirmation()` | `use-service-mode-action.tsx` | Outside service mode returns `undefined`; in service mode shows a dialog and returns `null` or `{ serviceModeConfirmed: true, organizationId }`. For calls that aren't server commands, such as `fetch`. | Part of the core, always works. |

The declaration types from `src/shared/lib/modules/define-module.ts`:

```ts src/shared/lib/modules/define-module.ts theme={null}
export interface ModuleAuditAction {
  action: string;
  labelKey: string;
}

export interface ModuleApiScope {
  key: string;
  labelKey: string;
}

export interface ModuleUploadPurpose {
  key: string;
  mimeTypes: readonly string[];
  maxBytes: number;
  visibility: "public" | "organization";
  resizeImage?: { maxWidth: number };
}
```

Labels in `auditActions` and `apiScopes` are looked up in the translation namespace of the module that declares them. That namespace is the feature folder name, so a module's `key` must equal its folder name.

Three rules follow for your code:

* **Use entry points and declarations freely.** Calls to `trackAudit` and the `auditActions`, `apiScopes` and `uploadPurposes` fields build and run in a core-only project. They start working once the handling module is added, with no code change.
* **Import module files only when the module is installed.** Importing `<AuditTrail>`, `authenticateApiKey` or `<FileUpload>` without `audit-logs`, `api-keys` or `uploads` fails typecheck and build with `TS2307: Cannot find module '@/features/…'`. A project module that has such imports should list the module in `requires`.
* **`requireModuleAccess("<module>")` for a missing module always returns 404** to a user with an active organization, because the registry has no definition for that key.

## Shared rules

Kit modules follow the same rules as the core:

* **Organization isolation.** Queries and commands get context from `getOrgContext()` or `requireModuleAccess()` and filter by `organizationId` explicitly. Routes authenticated with an API key have no session, so they filter by the organization from the key. See [Organizations](https://docs.gatojs.com/concepts/organizations.md).
* **Service mode.** Commands that change organization data have the signature `(input, confirmation?)` and call `assertServiceModeConfirmed` before touching Prisma. The UI calls them through `useServiceModeAction().run`. See [Superadmin and service mode](https://docs.gatojs.com/concepts/superadmin-and-service-mode.md).
* **Tests and mutation gate.** Module files are covered by the server entry point architecture test, and each module's `services/` folder is on the `critical` list in `mutation-gate.json`. See [Testing](https://docs.gatojs.com/guides/testing.md).
* **Modules don't edit core files.** `gato add` and `gato remove` only touch `wa:*` regions and generated files in the core.

## Install and remove a module

> [tab] New project
>
> Choose modules when you create the project:
>
> ```bash theme={null}
> npm create gato-app@latest acme-app -- --modules audit-logs,api-keys,uploads
> ```
>
> `create-gato-app` downloads the kit and passes `--modules` to `gato create`. The first migration (`npx prisma migrate dev --name init`) creates the module tables. See [create-gato-app](https://docs.gatojs.com/cli/create-gato-app.md) and [`gato create`](https://docs.gatojs.com/cli/create).

> [tab] Existing project
>
> Add a module, then create and commit a migration:
>
> ```bash theme={null}
> npx gato add uploads
> npx prisma migrate dev --name add-uploads
> ```
>
> `gato add` copies the files, adds npm dependencies, runs `gato generate` and `npm install`, and prints the migration command. It doesn't touch `.env`: copy any new variables from the `wa:modules` region of `.env.example` yourself. See [`gato add`](https://docs.gatojs.com/cli/add).

> [tab] Remove
>
> Remove a module, then create the migration that drops its tables:
>
> ```bash theme={null}
> npx gato remove uploads
> npx prisma migrate dev --name remove-uploads
> ```
>
> `gato remove` deletes the module files, its npm dependencies and its `.wa/kit.json` entry, then runs `gato generate`. It refuses if a project module requires the module, and refuses if you changed module files unless you pass `--force`. See [`gato remove`](https://docs.gatojs.com/cli/remove).

The alias `npm run wa -- add uploads` runs the same command.

> [!WARNING]
>
> `gato remove` leaves your data alone: database tables stay until you apply the migration, and stored files (local directory or bucket), `.env` values and your own code that imports the module are untouched. The migration permanently deletes the module's data. Back up the tables first if you need the history.

A module added later with `gato add` works the same as one chosen at `gato create`. After either command the schema changes, so the migration belongs in your repository. See [Database and migrations](https://docs.gatojs.com/guides/database-and-migrations.md).

## Choosing modules for a project

Pick each module on its own merits.

| Module | Add it when | Cost in the project | Skip it when |
| - | - | - | - |
| `audit-logs` | The client needs a trail of changes to organization data: membership, keys, files, your own events. | The `audit_logs` table grows without limit; there is no retention yet. | Nobody will read the log. Your code can call `trackAudit` without the module, so you can add it later. |
| `api-keys` | An external system (integration, AI agent, script) calls your API on behalf of an organization. | A stable `API_KEY_PEPPER` secret per environment; changing it invalidates every key. | Only signed-in users call your API; a session is enough. |
| `uploads` | Users upload files: images, attachments. | Production needs a persistent directory on a single instance (`local`) or S3-compatible storage (`s3`). Adds `@aws-sdk/client-s3`, `file-type` and `sharp`. | The project doesn't accept files, stores them outside the app, or handles large files such as video. |

The kit CI builds and tests the core alone, each module alone, and all three modules together.

## Next steps

> [card] [Audit logs](https://docs.gatojs.com/modules/audit-logs.md)
>
> Record and browse organization events.

> [card] [API keys](https://docs.gatojs.com/modules/api-keys.md)
>
> Let external systems call your API.

> [card] [Uploads](https://docs.gatojs.com/modules/uploads.md)
>
> Accept and serve organization files.

> [card] [Write a kit module](https://docs.gatojs.com/contributing/new-kit-module.md)
>
> Add a new module to the kit itself.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.