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

# Project structure

> A tour of a GatoJS project: the Next.js app router, feature folders, shared code, the multi-file Prisma schema, the .wa kit state, generated files, workspace packages, scripts and tests.

A GatoJS project is a regular Next.js 16 app. Everything the kit gave you sits in your repository as source you can read and change, organized so that each feature lives in one folder and the core learns about features through a generated registry.

## Top-level layout

```text theme={null}
my-app/
├── src/
│   ├── app/                       Next.js routes (App Router)
│   ├── features/<x>/              one folder per feature
│   ├── shared/                    code shared by all features
│   ├── components/ui/             shadcn/ui components (on Base UI)
│   ├── i18n/                      next-intl config and routing
│   ├── generated/prisma/          Prisma client (git-ignored)
│   ├── modules.generated.ts       module registry, server   ┐
│   ├── modules.client.generated.ts module registry, client  ┘ generated
│   ├── env.ts                     validated `env` object
│   ├── proxy.ts                   locale detection
│   └── instrumentation.ts         OpenTelemetry startup
├── prisma/
│   ├── schema/                    multi-file Prisma schema
│   └── migrations/                your migrations
├── packages/
│   ├── env/                       @gatojs/env
│   └── observability/             @gatojs/observability
├── .wa/
│   ├── kit.json                   kit state: version, modules, locales
│   └── bin/wa.mjs                 bundled CLI (npm run wa)
├── scripts/                       admin:create, mutation gate
├── e2e/                           Playwright tests
├── .claude/                       agent hooks, test agents, skills
├── .github/workflows/             CI
├── docker-compose.yml             PostgreSQL + mailpit (+ module services)
├── Dockerfile, railway.toml       deployment
├── AGENTS.md, CLAUDE.md           rules for AI coding agents
└── .env.example                   documented environment
```

## `src/app`: routes

Routes stay in `src/app/` because the App Router requires it. Pages are thin: they call a guard, fetch data through a feature's query and render the feature's components.

| Path | Contents |
| - | - |
| `[locale]/` | Every page lives under the locale segment. The default locale (`pl`) has no URL prefix; other locales use one (`/en/...`). |
| `[locale]/(app)/` | Pages after sign-in, with the shared app layout (sidebar, organization switcher, service-mode banner): `dashboard`, `users`, `account`, plus module pages such as `api-keys` and `audit-log`. |
| `[locale]/(auth)/` | `sign-in`, `sign-up`, `forgot-password`, `reset-password`, `set-password`. No session required. |
| `[locale]/accept-invitation/[id]`, `[locale]/no-organization` | Pages that need a session but no active organization. |
| `api/auth/[...all]` | The better-auth endpoint. |
| `api/healthcheck` | Runs `SELECT 1`; used as the deployment health check. |
| `emails/` | React Email templates. |
| `messages/` | Core translations for the shared namespaces `common`, `errors`, `sidebar` and `serviceMode`. |

Route groups in parentheses do not appear in the URL, so `src/app/[locale]/(app)/users/page.tsx` serves `/users`.

## `src/features/<x>`: a feature folder

A feature is one folder with everything about one piece of functionality except its routes. The core has five: `auth`, `organizations`, `users`, `account` and `dashboard` (see [Core features](https://docs.gatojs.com/concepts/core-features.md)). Modules and your own features add more.

```text theme={null}
src/features/<x>/
├── module.ts          defineModule({...}): key, menu entries, access rules
├── components/        React components (+ __tests__/)
├── contracts/         types and Zod schemas (*.types.ts, *.schemas.ts)
├── services/
│   ├── commands/      writes; server actions start with "use server"
│   ├── queries/       reads
│   └── *.ts           services called from other server code
├── i18n/
│   ├── pl.json
│   └── en.json
├── env.ts             optional: envSchema, the feature's env variables
├── auth.ts            optional: authPlugin, server-side better-auth plugin
├── auth-client.ts     optional: authClientPlugin, browser better-auth plugin
└── audit-sink.ts      optional: auditSink, receives trackAudit events
```

Rules that keep features predictable:

* **The folder name is the feature's identity.** It is the translation namespace, and `key` in `module.ts` must match it, because menu labels are looked up as `<key>.<labelKey>`.
* **Business logic stays in `services/`.** Not in components, `page.tsx`, layouts or route handlers. Prisma is used only in commands, queries and services.
* **Every external input is validated with Zod**, with schemas in `contracts/`.
* **Server actions** check their own permissions, validate input, and return `OperationResult<T>`. See [Code patterns](https://docs.gatojs.com/guides/code-patterns.md).
* **`module.ts` is data only.** The browser bundle imports it through the sidebar, so it must not import server code.
* **Tests sit next to the code** in `__tests__/` folders.

The generator reads only `module.ts`, `env.ts`, `auth.ts`, `auth-client.ts`, `audit-sink.ts` and `i18n/<locale>.json`. Everything else is ordinary code imported by pages. When you add or remove one of those files, run `npx gato generate`. See [Module registry](https://docs.gatojs.com/concepts/module-registry.md).

## `src/shared`: cross-cutting code

| Path | Contents |
| - | - |
| `lib/auth/` | better-auth config and client, `getOrgContext()`, `requireModuleAccess()`, role helpers, service-mode checks. |
| `lib/tenant-scope/` | The runtime guard that rejects queries on organization data without an organization filter, and `withoutTenantScope(reason, fn)` for deliberate cross-organization reads. |
| `lib/modules/` | `defineModule` and the sidebar navigation builder. |
| `lib/prisma.ts` | The Prisma client with the tenant-scope extension. |
| `lib/mailer.ts`, `lib/logger.ts`, `lib/audit.ts` | Email (SMTP or Resend), the OpenTelemetry logger, and `trackAudit` for audit events. |
| `components/` | The app sidebar and the service-mode provider, banner and confirmation hook. |
| `config/project.ts` | The project's display name and slug. |
| `types/`, `utils/`, `constants/` | `OperationResult`, `handleCommandError`, table pagination defaults. |

## `prisma/`: database

The schema is split into several files in `prisma/schema/`:

| File | Contents |
| - | - |
| `base.prisma` | Generator and datasource. |
| `auth.prisma` | `User`, `Session`, `Account`, `Verification`. |
| `organizations.prisma` | `Organization`, `Member`, `Invitation`. |
| `<module>.prisma` | One file per kit module, for example `uploads.prisma`. |

`User` and `Organization` contain a `wa:relations` region where modules add back-relations. The kit ships no migrations: your project creates its own in `prisma/migrations/` and commits them. See [Database and migrations](https://docs.gatojs.com/guides/database-and-migrations.md).

## `.wa/`: kit state

* **`.wa/kit.json`** records which kit version the project came from, the project name and slug, its locales, every installed kit module with its manifest and file hashes, and your own features under `projectModules`. The CLI writes it; you edit only `locales` and `projectModules`. Reference: [kit.json](https://docs.gatojs.com/cli/kit-json.md).
* **`.wa/bin/wa.mjs`** is the same CLI as `gato`, committed as a single bundled file. Run it with `npm run wa -- <command>`. It lets the project build and regenerate files without installing anything else.

## Generated files

These files are written by [`gato generate`](https://docs.gatojs.com/cli/generate) and committed. Do not edit them by hand; CI regenerates them and fails on any diff.

| File or region | Contents |
| - | - |
| `src/modules.generated.ts` | Server registry: module definitions, env schemas, auth plugins, audit sinks, translation loaders. |
| `src/modules.client.generated.ts` | Client registry: module definitions and browser auth plugins. |
| `src/i18n/locales.generated.ts` | The project's locales. |
| `wa:relations` in `prisma/schema/auth.prisma` and `organizations.prisma` | Back-relations from modules. |
| `wa:modules` in `.env.example` | Environment variables of modules. |
| `wa:services` in `docker-compose.yml` | Docker services of modules. |
| `wa:ci-integration` in `.github/workflows/ci.yml` and `mutation.yml` | CI steps of modules. |
| `wa:workspaces` in `Dockerfile` | `COPY` lines for workspace packages. |

`src/generated/prisma/` is different: Prisma generates it on `npm install` (or `npm run db:generate`) and it is git-ignored.

## `packages/`: workspace packages

The project is an npm workspace with two small internal packages:

* **`@gatojs/env`** holds the core environment schema and helpers (`httpUrl()`, `blankAsUndefined()` and others) that `src/env.ts` and feature `env.ts` files build on.
* **`@gatojs/observability`** wraps OpenTelemetry logging and tracing for `src/shared/lib/logger.ts`.

## Scripts and tooling

| Command | What it does |
| - | - |
| `npm run dev` | Development server on port 3000. |
| `npm run build`, `npm start` | Production build (`output: "standalone"`) and server. |
| `npm run verify` | The quality gate: lint, typecheck, unit tests, build, workspace tasks and hook tests. |
| `npm test` | Vitest unit tests. |
| `npm run test:integration` | Vitest on a real PostgreSQL database. |
| `npm run test:e2e` | Build plus Playwright. Needs `docker compose up -d`. |
| `npm run test:mutation` | Stryker mutation testing. |
| `npm run admin:create -- --email <email>` | Create an admin and the first organization. |
| `npm run db:generate` | Regenerate the Prisma client. |
| `npx gato <command>` | The kit CLI (`list`, `add`, `remove`, `update`, `generate`). `npm run wa -- <command>` runs the same CLI from the committed bundle. |

Configuration files at the root cover Next.js, Prisma (`prisma.config.ts`), Vitest, Playwright, Stryker (`mutation-gate.json` lists security-critical files), ESLint, Prettier, husky, commitlint, Docker and Railway.

## Tests

| Location | Kind |
| - | - |
| `src/**/__tests__/*.test.ts(x)` | Unit and component tests, next to the code. |
| `src/**/__tests__/*.integration.test.ts` | Integration tests on PostgreSQL, including organization isolation tests. |
| `src/__tests__/` | Architecture tests, for example that every server entry point calls a guard before Prisma. |
| `e2e/` | Playwright end-to-end tests. |
| `src/test/` | Test helpers and integration setup. |

See [Testing](https://docs.gatojs.com/guides/testing.md).

## AI agent files

`AGENTS.md` and `CLAUDE.md` describe the architecture and hard rules for coding agents. `.claude/` holds hooks (one blocks code comments, one locks test files during implementation), the test-writer and test-reviewer agents, and project skills for code review, new modules and dependency upgrades. These files are currently written in Polish. See [AI agents](https://docs.gatojs.com/guides/ai-agents.md).


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