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

# Installation

> Requirements, every way to create a GatoJS project, manual local setup, the .env file, runtime modes, the admin:create script, port changes and fixes for common setup problems.

The [Quickstart](https://docs.gatojs.com/quickstart.md) covers the happy path. This page covers everything around it: what you need installed, the different ways to create a project, how to set one up by hand, and what to do when something gets in the way.

## Requirements

| Tool | Version | Notes |
| - | - | - |
| Node.js | 22 or newer | Projects ship an `.nvmrc` with `22`, so `nvm install` / `nvm use` picks the latest 22.x. Releases older than 22.18.0 work but print `npm warn EBADENGINE` warnings, because some dev tools declare a higher minimum. |
| npm | the one bundled with Node 22 | Projects pin `npm@11.21.1` in `packageManager`. See [Troubleshooting](#troubleshooting). |
| git | any recent | The CLI reads kit files with `git ls-files`, and new projects get a first commit, so set `user.name` and `user.email`. |
| Docker | Compose v2 | The `docker compose` command, not the legacy `docker-compose`. |
| `nc` (netcat) | optional | Handy for checking ports. Built into macOS; `netcat-openbsd` on Debian and Ubuntu. |

## Create a project

> [tab] create-gato-app (recommended)
>
> ```bash theme={null}
> npx create-gato-app@latest my-app
> # or
> npm create gato-app@latest my-app
> ```
>
> `create-gato-app` checks your Node version, picks the highest `v<x.y.z>` release tag of the kit, downloads that tag as a tarball (no clone, no git history) and runs [`gato create`](https://docs.gatojs.com/cli/create) on it. The new project gets `gato-cli` as a devDependency, so inside it you run the CLI as `npx gato <command>`.
>
> Flags of `create-gato-app` itself:
>
> | Flag | Meaning |
> | - | - |
> | `--kit-version <x.y.z>` | Use a specific kit release instead of the latest. |
> | `--kit <path>` | Use a local kit checkout instead of downloading one. Cannot be combined with `--kit-version`. |
> | `--skip-install` | Write files only. Passes `--no-install` to `gato create`. |
> | `--help`, `--version` | Print usage or the `create-gato-app` version. |
>
> Every other flag is passed to `gato create` unchanged. The useful ones:
>
> | Flag | Meaning |
> | - | - |
> | `--modules a,b` | Kit modules besides the core, for example `audit-logs,api-keys,uploads`. `--modules ""` means core only. |
> | `--locales pl,en` | App languages. `pl` is required, `en` is optional. Default: both. |
> | `--title <text>` | Display name. Default: derived from the directory name (`my-app` becomes `My App`). |
> | `--admin-email <email>` | First admin's email, also written to `ADMIN_EMAIL` in `.env`. |
> | `--yes` | No questions; defaults for everything you did not pass. Required without a terminal (CI). |
> | `--setup` | After install: start Docker, run the first migration, create the admin. |
> | `--no-install` | Skip `npm install`. Cannot be combined with `--setup`. |
> | `--no-git` | Skip `git init` and the first commit. |
>
> ```bash theme={null}
> npx create-gato-app@latest acme-crm --yes --modules audit-logs,uploads \
>   --admin-email you@example.com --setup
> ```
>
> > [!NOTE]
> >
> > `create-gato-app` talks to the GitHub API to find the latest tag. Anonymous requests are limited to 60 per hour. If you hit the limit, set `GITHUB_TOKEN` (or `GH_TOKEN`, or log in with the `gh` CLI), or pass `--kit-version`.

> [tab] gato create from a clone
>
> If you want to assemble projects from a specific checkout, for example a fork of the kit or a branch you are working on, clone it and point `gato create` at it:
>
> ```bash theme={null}
> git clone https://github.com/webamigos/gatojs.git ~/gatojs
> npx gato-cli@latest create ./my-app --kit ~/gatojs
> ```
>
> Outside a project, use `npx gato-cli`: the `gato` package on npm is unrelated, so `npx gato` only works where `gato-cli` is installed (inside a project, or globally with `npm install -g gato-cli`).
>
> The kit checkout also carries the same CLI as a committed bundle, so this works without npm:
>
> ```bash theme={null}
> cd ~/gatojs
> npm run wa -- create ../my-app
> ```
>
> The flags are the same as in the table on the other tab. See [`gato create`](https://docs.gatojs.com/cli/create) for the full reference.

### What `create` does

1. Validates the project name: the last segment of the directory, 2-50 characters, lowercase letters, digits and hyphens, starting with a letter. The target directory must be empty or not exist.
2. Copies the core and the chosen modules, replacing placeholders with your project name. The database becomes `<slug with underscores>` (`my-app` → `my_app`).
3. Writes `.wa/kit.json` and runs [`gato generate`](https://docs.gatojs.com/cli/generate) to build the [module registry](https://docs.gatojs.com/concepts/module-registry.md).
4. Writes `.env` from `.env.example` with a random `BETTER_AUTH_SECRET` and, if given, `ADMIN_EMAIL`. The file gets mode `600`.
5. Runs `git init`, `npm install` and a first commit (`chore: initial commit from wa-kit v<version>`).
6. With `--setup`: `docker compose up -d --wait`, `npx prisma migrate dev --name init`, and `npm run admin:create -- --email <email>` when an admin email is known.
7. Prints the next steps that are still left to do.

> [!NOTE]
>
> The interactive prompts and some CLI messages are currently in Polish. The questions are, in order: modules (`Moduły`), languages (`Języki`), display name (`Nazwa wyświetlana`), admin email (`Email admina (puste = pomiń)`, empty to skip) and whether to run the database setup now (`[t/N]`, where `t` means yes).

## Manual setup

Run these in the project root, in this order, if you created the project without `--setup`, or if setup stopped half way. The database must be running before the migration, and the migration must exist before you create the first account.

**1. Install dependencies**

Skip this if `create` already ran `npm install`.

```bash theme={null}
npm ci
```

`postinstall` runs `prisma generate`, which writes the Prisma client to `src/generated/prisma` (git-ignored). `prepare` installs the git hooks (husky).

**2. Check .env**

`create` already wrote `.env`. If you are working in a fresh clone of the kit itself, create it:

```bash theme={null}
cp .env.example .env
```

The defaults are fine for local work. See [Environment file](#environment-file) for what you might change.

**3. Check the ports**

```bash theme={null}
for port in 3000 5432 8025 1025; do nc -z localhost "$port" 2>/dev/null && echo "in use: $port"; done
```

No output means all ports are free. Do not rely on Docker to complain: on macOS a container can start even when a local PostgreSQL listens on `localhost:5432`, and your connections then reach the local server, not the container. If a port is taken, [change it](#change-ports) first.

**4. Start PostgreSQL and mailpit**

```bash theme={null}
docker compose up -d --wait
```

`--wait` returns once the services are healthy. Without it, repeat `docker compose ps` until `db` shows `(healthy)`.

**5. Create the database schema**

```bash theme={null}
npx prisma migrate dev --name init
```

The kit does not ship migrations: every project creates its own first migration from the schema in `prisma/schema/`. Commit the generated `prisma/migrations/` folder. See [Database and migrations](https://docs.gatojs.com/guides/database-and-migrations.md).

> [!WARNING]
>
> If Prisma prints `Drift detected` or suggests `prisma migrate reset` on a fresh project, `DATABASE_URL` points at a database with a different history, usually a local PostgreSQL or another project's container on the same port. Do not reset until you are sure it is your container. See "Prisma or admin:create cannot reach the database" under [Troubleshooting](#troubleshooting).

**6. Create the first account**

```bash theme={null}
npm run admin:create -- --email you@example.com
```

The `--` separator is required, otherwise npm swallows `--email`. The generated password is printed once. See [First admin account](#first-admin-account).

**7. Start the app**

```bash theme={null}
npm run dev
```

Open `http://localhost:3000/en/sign-in` and sign in.

## Docker services

`docker-compose.yml` defines two services. Use their names in commands such as `docker compose logs db`.

| Service | Image | Host port (default) | Port variable | Purpose |
| - | - | - | - | - |
| `db` | `postgres:16` | 5432 | `DB_PORT` | PostgreSQL. User `postgres`, password `postgres`, database named after your project. |
| `mail` | `axllent/mailpit` | 8025 (web UI), 1025 (SMTP) | `MAILPIT_UI_PORT`, `MAILPIT_SMTP_PORT` | Catches every email the app sends. |

PostgreSQL data lives in `volumes/postgres/` (git-ignored), so it survives `docker compose down`. The file ends with a `wa:services` region where modules add their own services; the `uploads` module adds MinIO there behind the `s3` Compose profile. Do not edit that region by hand; see [Module registry](https://docs.gatojs.com/concepts/module-registry.md#generated-regions).

## Environment file

`.env` is git-ignored. It is read by Next.js (`dev`, `build`, `start`), by Prisma, `admin:create` and Vitest through dotenv (`.env.local` first, then `.env`; shell variables win over both), and by Docker Compose for the port variables.

You do not need to change anything for local work. Typical edits:

| Variable | When to change it |
| - | - |
| `DATABASE_URL`, `SMTP_URL` | Together with Docker ports. See [Change ports](#change-ports). |
| `APP_URL` | When the app runs on a port other than 3000. |
| `BETTER_AUTH_SECRET` | Generated by `create`. To rotate it: `openssl rand -base64 32`. At least 32 characters. |
| `MULTI_ORG`, `AUTH_PUBLIC_SIGNUP`, `ADMIN_IMPERSONATION` | To try another [runtime mode](#runtime-modes). |
| `ADMIN_EMAIL`, `ADMIN_PASSWORD` | To run `admin:create` without `--email` and `--password`. |

The full list is in [Environment variables](https://docs.gatojs.com/configuration/environment-variables.md).

The Next.js server validates the environment at startup. With a bad `.env`, `npm run dev` prints a report of every problem and exits. Validation results are cached for the life of the process, so restart `npm run dev` after editing `.env`. `npm run build` does not validate the environment.

## Runtime modes

Three flags change how the app behaves. Each takes `true` or `false`; missing or empty means `false`. Any other value (`1`, `yes`) fails validation. Restart the server after changing a flag.

| Variable | `false` (default) | `true` |
| - | - | - |
| `MULTI_ORG` | The app has a single organization (the oldest one in the database). | Many organizations; every signed-in user can create their own. |
| `AUTH_PUBLIC_SIGNUP` | `/sign-up` works only with an invitation. | `/sign-up` works without an invitation too. |
| `ADMIN_IMPERSONATION` | Only `superadmin` can sign in as another user. | `admin` can too, but only as accounts with the global role `user`. |

What changes in the UI for each combination of `MULTI_ORG` and `AUTH_PUBLIC_SIGNUP`:

| | `AUTH_PUBLIC_SIGNUP=false` | `AUTH_PUBLIC_SIGNUP=true` |
| - | - | - |
| **`MULTI_ORG=false`** | One organization. `/sign-up` without an invitation redirects to `/sign-in`; new accounts come from **Invite user**. | One organization. `/sign-up` shows a form that creates an account with the role `member` in the existing organization. |
| **`MULTI_ORG=true`** | A **+** button above the content opens **Create organization**. Organization owners and admins see a **Members** page with an invite form. `/sign-up` without an invitation redirects to `/sign-in`. | Same **+** button and **Members** page. `/sign-up` creates a new organization with the new account as its `owner`. |

A few things hold in every mode:

* Global `admin` and `superadmin` accounts have an **Invite user** button on the **Users** page. It creates an account in the active organization and emails a link to set a password.
* The sign-in page never links to sign-up. Users reach `/sign-up` by typing it or from an invitation page.
* Signing up with an `invitationId` always works and joins the organization from the invitation, with its role.
* An organization switcher appears whenever an account can access more than one organization.

Roles, the access matrix and server-side enforcement are covered in [Auth and roles](https://docs.gatojs.com/concepts/auth-and-roles.md) and [Organizations](https://docs.gatojs.com/concepts/organizations.md).

## First admin account

`npm run admin:create` creates an account and, on an empty database, the first organization. It needs a running database with the migration applied and a valid `.env`.

**--email** `string`

The account's email, stored in lowercase. Required unless `ADMIN_EMAIL` is set.

**--password** `string`

The password. Without it the script uses `ADMIN_PASSWORD`; if that is empty or missing, it generates a 20-character password and prints it once.

**--name** `string`

Display name. Defaults to the part of the email before `@`.

**--org-name** `string`

Name of the first organization. Defaults to the project's display name.

**--role** `string` (default: admin)

Global role: `admin` or `superadmin`. `superadmin` is the support account for the team that builds and maintains the app. See [Superadmin and service mode](https://docs.gatojs.com/concepts/superadmin-and-service-mode.md).

**--yes** `boolean`

Upgrade an existing account to a higher role without asking.

How it behaves:

* **New account:** gets the chosen global role and a verified email, so the first sign-in needs no email.
* **Organization:** on an empty database it creates an organization and makes the account its `owner`. If an organization already exists, it adds the account to the oldest one as `owner` instead of creating a second.
* **Re-running** is safe: it creates nothing new and never changes the password.
* **Existing account with a lower role:** the script asks before upgrading (`[t/N]`, `t` for yes) and stops without consent. It never downgrades a role.

The script cannot recover a password. If you lose it, use **Forgot your password?** on the sign-in page and read the email in mailpit.

## Change ports

### Database and mailpit

Each Docker port lives in two places that nothing keeps in sync: Compose reads `DB_PORT`, while the app and Prisma read only `DATABASE_URL`. Change both together in `.env`:

```bash .env theme={null}
DB_PORT=5433
DATABASE_URL=postgresql://postgres:postgres@localhost:5433/my_app

MAILPIT_UI_PORT=8026
MAILPIT_SMTP_PORT=1026
SMTP_URL=smtp://localhost:1026
```

Then run `docker compose up -d`. Compose recreates the changed services and keeps the data in `volumes/postgres/`. If the port is held by another GatoJS project's containers, you can also run `docker compose stop` in that project instead.

E2E and integration tests do not read ports from `.env`; see [Testing](https://docs.gatojs.com/guides/testing.md).

### App port

Set the Next.js port with `-p` or a shell variable, not in `.env` (Next.js picks the port before it loads `.env`):

```bash theme={null}
npm run dev -- -p 3001
# or
PORT=3001 npm run dev
```

After any port change, set the same port in `APP_URL` (for example `APP_URL=http://localhost:3001`) and restart. better-auth trusts only the origin from `APP_URL` by default, and email links are built from it.

Without `-p`, when 3000 is busy, `next dev` silently moves to the next free port. Sign-in then fails with `Invalid origin` in the terminal until you update `APP_URL`.

## Troubleshooting

> [accordion] Install prints EBADENGINE or rewrites package-lock.json
>
> **Cause:** Node older than 22.18.0 (warnings), or `npm install` with npm 10 instead of the pinned npm 11 (lock file changes).
>
> **Fix:** install the latest Node 22 (`nvm install`). Revert the lock file with `git checkout package-lock.json` and use `npm ci`, or `npx -y npm@11.21.1 install` when you need to add packages.

> [accordion] Cannot find module @/generated/prisma/client
>
> **Cause:** the Prisma client was not generated, usually after installing with `--ignore-scripts` or deleting `src/generated/`.
>
> **Fix:** `npm run db:generate`.

> [accordion] docker compose up reports a port in use
>
> **Symptom:** `port is already allocated` (another container) or `address already in use` (another program).
>
> **Fix:** [change the port](#change-ports) or stop the other project's containers.

> [accordion] Prisma says datasource.url is required
>
> **Cause:** `prisma.config.ts` did not find `DATABASE_URL`, usually because there is no `.env`. The dotenv line shows `injected env (0)`.
>
> **Fix:** create `.env` from `.env.example` in the project root.

> [accordion] Prisma or admin:create cannot reach the database
>
> **Symptom:** `P1001: Can't reach database server`, an authentication error, `Drift detected`, or commands that succeed but changes never reach your container.
>
> **Cause:** the container is not running yet, the port in `DATABASE_URL` differs from `DB_PORT`, or another PostgreSQL listens on the same port and receives the connection.
>
> **Fix:**
>
> 1. Compare the ports: `grep -E '^(DB_PORT|DATABASE_URL)=' .env`. Without `DB_PORT` the port must be 5432. Shell variables win over `.env`, so also check `echo "$DB_PORT $DATABASE_URL"`.
> 2. Stop your containers (`docker compose stop`) and re-run the port check. If the database port is still taken, another program holds it: change `DB_PORT` and `DATABASE_URL`.
> 3. `docker compose up -d --wait`.
> 4. Run the migration and `admin:create` again, because they may have gone to a different database.

> [accordion] The server exits with 'Nieprawidłowe zmienne środowiskowe'
>
> The message means "Invalid environment variables". It is followed by one line per problem, `- <VARIABLE>: <message>`. A `✓ Ready` line before the report does not mean the server is running.
>
> | Variable | Message | Fix |
> | - | - | - |
> | `DATABASE_URL`, `BETTER_AUTH_SECRET`, `APP_URL`, `EMAIL_FROM` | `expected string, received undefined` | Missing, usually no `.env`. Copy the value from `.env.example`. |
> | `DATABASE_URL`, `EMAIL_FROM` | `Too small: expected string to have >=1 characters` | Empty value. |
> | `BETTER_AUTH_SECRET` | `co najmniej 32 znaki…` ("at least 32 characters") | Use a longer secret, for example `openssl rand -base64 32`. |
> | `APP_URL` | `Invalid URL` | Include the scheme: `http://localhost:3000`. |
> | `MULTI_ORG`, `AUTH_PUBLIC_SIGNUP`, `ADMIN_IMPERSONATION` | `expected one of ""\|"true"\|"false"` | Use `true` or `false`. |
> | `NODE_ENV` | `expected one of "development"\|"test"\|"production"` | A non-standard `NODE_ENV` in your shell: `unset NODE_ENV`. |
> | `RESEND_API_KEY` | `wymagana w produkcji` ("required in production") | `NODE_ENV=production` without a Resend key. |
> | `BETTER_AUTH_SECRET` | `w produkcji nie może być wartością z .env.example` | In production the secret cannot be the `.env.example` value. |
>
> The last two only apply with `NODE_ENV=production`, which `npm start` sets. Running a production build locally therefore needs a `RESEND_API_KEY` (any non-empty value works while `SMTP_URL` is set) and your own secret.

> [accordion] admin:create says 'Podaj --email albo ustaw ADMIN\_EMAIL' or 'Unexpected argument'
>
> The first message means "Pass --email or set ADMIN\_EMAIL". The second appears when you forget the `--` separator and npm passes the bare address to the script.
>
> **Fix:** `npm run admin:create -- --email you@example.com`.

> [accordion] The root URL returns 404
>
> The app has no home page. Go to `/sign-in` (or `/en/sign-in`); `/dashboard` without a session redirects to sign-in.

> [accordion] Sign-in fails although the page loads
>
> Check the `npm run dev` terminal. `Invalid origin: <origin>` means `APP_URL` has a different port than the server ([App port](#app-port)). Otherwise the credentials are wrong or the database is unreachable. A forgotten password can be reset through mailpit.

> [accordion] Emails do not show up in mailpit
>
> **Cause:** `SMTP_URL` points at another port than `MAILPIT_SMTP_PORT`, the `mail` service is down (the terminal shows `[MAILER] Failed to send`), or `SMTP_URL` is empty. With an empty `SMTP_URL` the app falls back to Resend if `RESEND_API_KEY` is set, and otherwise only logs `SMTP_URL and RESEND_API_KEY not set, email not sent`.
>
> **Fix:** set `SMTP_URL=smtp://localhost:1025` (or your custom port) and check `docker compose ps`. See [Email](https://docs.gatojs.com/guides/email.md).

> [accordion] An invitation link fails
>
> **Symptom:** "Could not accept the invitation", or the sign-up form says sign-up is disabled or the invitation is invalid.
>
> **Cause:** the invitation expired, was already accepted or cancelled, or you are signed in with a different email than the invited one, for example the account that sent it.
>
> **Fix:** open the link in a private window or after signing out. Without an account, choose **Create account** and use the invited address. With an account, sign in with that address and open the link again: signing in alone does not accept the invitation.


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