> ## 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.

# Add a new kit module

> Add a module to the GatoJS kit end to end: core seams, feature code, manifest, dependencies, placeholders, test setup, kit sync, ownership, CI matrix and documentation.

A kit module is code that many projects can add with `gato add` and remove with `gato remove`. If you are building a feature for one project only, write a [project module](https://docs.gatojs.com/cli/kit-json.md#project-modules) instead ([Build a feature](https://docs.gatojs.com/guides/build-a-feature.md)).

You write the feature code the same way as any feature. What differs for a kit module is registration through a manifest, file ownership, the core seams it may need, and CI. Discuss a new module in an issue before you start; see [Roadmap](https://docs.gatojs.com/roadmap.md) for modules that are already planned.

## The rule about core files

A kit module does not edit core files in its own commits. The core learns about modules only through the generated registry and `wa:*` regions ([Module registry](https://docs.gatojs.com/concepts/module-registry.md)), and a module uses the core through its public entry points.

When a module genuinely needs a core change (a new seam in `src/shared/`, values in `src/test/integration/setup-env.ts` or `e2e/env.ts`, entries in `mutation-gate.json` or `stryker.integration.config.json`), make it in a **separate commit that bumps `version` in `kit/modules/core.json`**. Every project gets that change with the core, with or without your module, so it must be harmless without it.

## Steps

**1. Add a core seam, if the module needs one**

Examples of seams added for the current modules: `trackAudit` and the `auditActions`, `apiScopes` and `uploadPurposes` declarations in `defineModule`; the `auditSinks` registry array; the `ciSteps` manifest field with its `wa:ci-integration` region. A seam that needs a new region or registry entry is a CLI change: rebuild the bundle and pass the CLI gate ([Kit repository](https://docs.gatojs.com/contributing/kit-repository.md#the-cli-bundle)). Separate commit, `core` version bump.

**2. Write the module code**

`src/features/<name>/` with `module.ts`, the schema in `prisma/schema/<name>.prisma`, pages in `src/app/[locale]/(app)/<name>/`, API routes in `src/app/api/<name>/`, translations in `i18n/pl.json` and `i18n/en.json`. Do not commit migrations: the kit has none, projects create their own. Follow [Code patterns](https://docs.gatojs.com/guides/code-patterns.md): organization context, `organizationId` filters, service mode, guards.

**3. Write the manifest**

Create `kit/modules/<name>.json` with `name` equal to the file name, `version` `0.1.0`, a one-line `description`, `files`, `requires`, npm dependencies, `env`, `schemaRelations` and, if needed, `compose` and `ciSteps` ([manifest reference](https://docs.gatojs.com/cli/kit-json.md#module-manifest)). Give every new directory its pattern in `files` in the same commit that creates it. Use `{{projectSlug}}` in an `env` example that contains the project name, such as a bucket name.

```json kit/modules/reports.json theme={null}
{
  "name": "reports",
  "version": "0.1.0",
  "description": "Organization reports",
  "requires": [],
  "files": [
    "prisma/schema/reports.prisma",
    "src/features/reports/**",
    "src/app/[locale]/(app)/reports/**"
  ],
  "dependencies": {},
  "devDependencies": {},
  "env": [{ "name": "REPORTS_LIMIT", "example": "100", "required": false }],
  "schemaRelations": [{ "model": "Organization", "field": "reports Report[]" }],
  "compose": null,
  "ciSteps": null,
  "workspaces": []
}
```

**4. Add Docker services and CI steps, if any**

Put service definitions in `docker/<name>.compose.yml` (without the `services:` key) and integration-test steps in `ci/<name>.integration-steps.yml`. Both must be listed in the module's `files`, because the generator reads them from the project. Consider a Compose profile, as `uploads` does with `s3`, so `docker compose up -d` does not start services a project may not use.

**5. Add npm dependencies**

Install them with npm 11 into the kit's `package.json` (with `package-lock.json`) and declare them in the manifest, in the same section at the same version. This includes dependencies used only by the module's tests, in `devDependencies`.

**6. Register placeholder files**

A module file that contains the project name, slug or database name (for example a bucket `wa-app-<name>` in a compose file) goes into `placeholderFiles` in `kit/kit.json`. Do not add tests.

**7. Provide variables to the reference app's tests**

The kit runs e2e and integration tests with every module installed. A variable your module's `env.ts` requires needs a value in `e2e/env.ts` and `src/test/integration/setup-env.ts`. Without it the e2e servers stop at startup with an environment report. These are core files: separate commit, `core` bump.

**8. Check the core tests and gates your module touches**

Core tests that compare the registry with a literal filter it to core modules, so a new module does not break them. If your module's service directory should be in the app's mutation gate, add `src/features/<name>/services/` to `critical` in `mutation-gate.json` (a core file). Prefer moving a function out of `services/queries/` over adding an exception to the server entry point guard test, because such an exception would fail in projects without your module.

**9. Sync and regenerate**

```bash theme={null}
npm run wa -- kit sync
npm run wa -- generate
```

Commit the result with the module: `.wa/kit.json`, the generated registry files and the regions in the Prisma schema, `.env.example`, `docker-compose.yml` and the workflows.

**10. Check ownership**

`git add` the new files, then run the ownership test or the whole CLI gate ([File and dependency ownership](https://docs.gatojs.com/contributing/kit-repository.md#file-and-dependency-ownership)). Every file must have exactly one owner and every dependency a matching manifest entry.

**11. Add the module to the CI matrix**

In `.github/workflows/kit.yml`, add `{ name: <name>, modules: "<name>" }` to the `assemble` matrix and add the module to the `all` combination. If its integration tests need a service, give the `assemble` job its own steps with `if: contains(matrix.combo.modules, '<name>')` and the variables for the "Integration tests" step.

**12. Try it in a project**

```bash theme={null}
node .wa/bin/wa.mjs create ../trial --yes --kit . --modules <name>
```

Then in the trial project: `npx prisma migrate dev --name init`, `npm run verify`, and `npm run wa -- remove <name>` to check that removal leaves a working project.

**13. Document it**

Add the module to the module table in `kit/README.md` and the `.github/README.md` module list, describe it in the docs (a page under Modules in this site), and record design decisions as an ADR in `docs/adrs/`.

**14. Open the pull request**

Run `npm run verify` and `npm run verify --prefix packages/gato-cli`, then open a pull request with a `feat(<name>): …` commit. After merge, the release workflow cuts a new kit version ([Releases](https://docs.gatojs.com/contributing/releases.md)).

## What reaches projects without your module

Changes from the core steps (seams, test variables, mutation gate entries) live in core files, so every project gets them, including core-only projects. That is fine as long as they are inert without the module: the mutation gate only looks at files present in a report, and unread variables do nothing. The `assemble` job's `core` combination proves that a project without your module still verifies and builds.

## Afterwards

When you change the module's files later, bump its `version` in the manifest and run `npm run wa -- kit sync`. Nothing enforces the bump, so reviewers check it.


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