# Stack packs (/docs/cli/stack-packs)

From Starter v0.22.0 (CLI 0.33.0), a Starter describes itself in packs (template schema 4, schema 5 from Starter v0.27.0 for the `shell` role, and schema 6 from Starter v0.28.0 for the `mobile` role, optional slots, and rules). Each part is described in one place, so adding a stack, in any language, adds a folder and changes nothing shared.

| File                              | Describes                                                                                          |
| --------------------------------- | -------------------------------------------------------------------------------------------------- |
| `clubedge.template.json`          | The project: its slots, the module order, and from schema 6 the selections it refuses (`rules`).   |
| `clubedge/modules/<id>.json`      | A module: its options, packages, and scripts.                                                      |
| `apps/<name>/clubedge.stack.json` | A stack: its id, name, role, env example, Dockerfile (none for a shell or a native app), optional toolchain (such as uv), optional deployment, optional `auditIgnores`, and its own files for each module option, relative to its folder. |

The CLI leaves every descriptor out of generated projects.

## Deployment [#deployment]

From Starter v0.24.0 (CLI 0.35.0), a stack can declare how it runs as a service, in an optional `deployment` field:

```json title="apps/api/clubedge.stack.json"
"deployment": {
  "id": "api",
  "port": 3001,
  "healthPath": "/api/health",
  "platforms": ["docker", "railway"]
}
```

| Field | Meaning |
| --- | --- |
| `id` | The service's id, used in its name, such as `<package>-api` on Railway, and in Docker Compose for the service, its image (`<prefix>-<id>`), and its entry in the workflow that publishes the images. |
| `port` | The port the app listens on. |
| `healthPath` | The path the health check calls. |
| `platforms` | The `deploy` options the stack supports. |

The CLI records the selected stacks' deployment in the project's `package.json`, by slot, as `clubedge.services`. `deploy` reads it to write the Docker Compose file or create the Railway services for a [frontend and its API](./frontend-and-api.mdx#production), with the API private behind the frontend. From CLI 0.42.0, the Compose file puts the frontend behind Caddy, which serves it over HTTPS. A full-stack stack needs no deployment facts for Docker: its app is the root `Dockerfile`'s image, the `web` service on port 3000. [Without a website](./without-a-website.mdx#deploy) (CLI 0.44.0 or newer), the API is the public service on both: Caddy serves it, and Railway gives it the public domain.

## Slots and roles [#slots-and-roles]

A slot is a place for one app in generated projects:

| Slot        | Path          | Roles                   | Flag          |
| ----------- | ------------- | ----------------------- | ------------- |
| `framework` | `apps/web`    | `fullstack`, `frontend` | `--framework` |
| `api`       | `apps/api`    | `api`                   | `--api`       |
| `mobile`    | `apps/mobile` | `mobile`                | `--mobile`    |
| `shell`     | `apps/shell`  | `shell`                 | `--shell`     |

A stack has one role, which puts it in one slot. The `api`, `mobile`, and `shell` slots have no default, so they are optional: `--api none`, `--mobile none`, and `--shell none` leave them empty. From schema 6, a slot with a default can be optional too, with `"optional": true`: the framework's is, so `--framework none` leaves the website out of a project that is only an API and its native app. The project records `none` for that slot, so `add`, `remove`, and `upgrade` keep it empty instead of bringing the default back.

The roles must fit together, and a project needs a web app or an API:

- A `frontend` calls an API, so it needs an `api` stack, and a `fullstack` app has its own server, so it takes none.
- A `shell` packages a frontend's static build as a mobile app, so it needs a `frontend`, which still needs its API; a `fullstack` app renders its pages on its server, so no shell can package it.
- A `mobile` app has its own native screens and calls the API, so it needs an `api` stack, with a `frontend` or no website; a `fullstack` app has no separate API for it to call.

A project can have a shell and a native app at once. The CLI asks for the slots in their order, offering only the stacks that fit the answers so far.

`clubedge:if` and `clubedge:only` conditions name a slot by its id, like a module: `shell!=none`, `mobile=expo`, `framework=none`, or `framework=vite && shell=capacitor`.

### A slot's own files and scripts [#a-slots-own-files-and-scripts]

From schema 6, a slot that can be left empty may also name what only its apps use:

- `files`: Starter paths, such as the browser tests, left out when the slot is empty;
- `filesWhenEmpty`: paths only used when the slot is empty, left out when it is filled, such as the native app's screen for the emailed links a website would otherwise open;
- `scripts`: root `package.json` scripts, removed when the slot is empty;
- `fallback`: the slot whose package the root scripts filter on when this one is empty, so `pnpm dev` (`turbo run dev --filter=@clubedge/web`) starts the API in a project without a website.

The Starter's framework slot, in part:

```json title="clubedge.template.json"
"framework": {
  "path": "apps/web",
  "package": "@clubedge/web",
  "roles": ["fullstack", "frontend"],
  "default": "next",
  "optional": true,
  "fallback": "api",
  "files": ["e2e", "playwright.config.ts", "scripts/smoke-generated-app.mjs"],
  "filesWhenEmpty": ["apps/expo/src/app/reset-password.tsx"],
  "scripts": ["test:e2e", "test:e2e:ui", "docker:build", "docker:start"]
}
```

## Rules [#rules]

From schema 6, `clubedge.template.json` can list the selections the Starter refuses, each a condition written like a marker's, with the reason the CLI gives:

```json title="clubedge.template.json"
"rules": [
  {
    "when": "framework=none && payments!=none",
    "message": "Payments send users back to the website's pages, and a project without a website has none: choose --payments none, or a web app with --framework."
  }
]
```

A rule counts once every slot and module it names has a value, so prompts and `add` only offer what the rules allow given the answers so far, a default the rules refuse gives way to the first option they allow, and a requested option they refuse fails with the rule's message. The CLI refuses a rule that names a slot, stack, module, or option the Starter doesn't have. Starter v0.28.0's rules are those of a [project without a website](./without-a-website.mdx#modules-without-a-website).

## Stacks without a server [#stacks-without-a-server]

A `shell` stack (schema 5, CLI 0.42.0 or newer) packages another app's build, and a `mobile` stack (schema 6, CLI 0.44.0 or newer) is an app installed on devices. Neither runs a server, so neither it nor its slot has a Dockerfile, and it declares no `deployment`: the CLI refuses a descriptor of either that names one. `deploy` builds and runs the frontend and the API, and leaves them out. Like a frontend, each lists only the modules it takes part in, so a native app that implements only some sign-in options limits `--auth` to those when it is selected. The Starter's Capacitor shell lists none:

```json title="apps/capacitor/clubedge.stack.json"
{
  "id": "capacitor",
  "name": "Capacitor",
  "role": "shell",
  "envExample": ".env.example",
  "conditional": [".env.example"]
}
```

The Starter's Expo app lists sign-in only, with Supabase, Better Auth, or none. An excerpt, without the screens that Supabase and Better Auth share:

```json title="apps/expo/clubedge.stack.json"
{
  "id": "expo",
  "name": "Expo",
  "role": "mobile",
  "envExample": ".env.example",
  "auditIgnores": ["GHSA-86w9-cpqp-85rv", "GHSA-mrhx-c7xc-m3w5"],
  "modules": {
    "auth": {
      "none": {},
      "supabase": { "replace": { "src/lib/auth.ts": "src/variants/auth.supabase.ts" } },
      "better-auth": { "replace": { "src/lib/auth.ts": "src/variants/auth.better-auth.ts" } }
    }
  }
}
```

The rest works as for other stacks: its folder moves to the slot's path, `apps/shell` or `apps/mobile`, its `envExample` to the slot's env example, and the slot's `package`, `@clubedge/shell` or `@clubedge/mobile-app`, names it. A Starter that offers a shell declares schema 5, and one that offers a native app schema 6, so a CLI that predates the role refuses it and asks to be updated.

### Advisories a stack's tools need [#advisories-a-stacks-tools-need]

`auditIgnores` (optional, schema 6) lists the advisories `pnpm audit` skips because of a stack's dependencies, such as one in a build tool that has no fix yet. The Starter's `package.json` lists them under `pnpm.auditConfig.ignoreGhsas`, and the CLI removes them from projects without the stack, which then audit every advisory. The Starter's Expo app lists two, in Expo's development CLI.

## Module scope [#module-scope]

A module is about the apps, such as authentication or storage, or about the project as a whole, such as local infrastructure or deployment. Each stack lists the options of the app modules it implements. A full-stack stack implements every option; a frontend lists only the modules it takes part in, and an API lists the options it implements.

The selected option must be implemented by every selected stack that lists the module. That is why the CLI only offers those options, and falls back to one the stacks implement when you leave a module to its default. See [Modules on these stacks](./frontend-and-api.mdx#modules-on-these-stacks).

## Packages from the registry [#packages-from-the-registry]

A module option's `packages` are workspace packages, left out with their folders when the option isn't selected. From CLI 0.46.0, its `dependencies` are packages from the registry that apps depend on directly, only for that option, such as a native plugin. A native module links into an app wherever it is a dependency, used or not, so projects without the option leave it out of every `package.json` and of the lockfile's importers. A package another selected option lists stays, and earlier CLIs ignore the field and keep the packages.

```json title="clubedge/modules/push.json"
"native": {
  "name": "FCM and APNs, directly (the native app and the mobile shell)",
  "packages": { "@clubedge/push": "packages/push", "@clubedge/push-native": "packages/push-native" },
  "dependencies": ["expo-notifications", "@capacitor/push-notifications"]
}
```

## Adding a stack [#adding-a-stack]

1. Add `apps/<name>/` with the app, its `package.json` scripts (`dev`, `build`, `lint`, `typecheck`, `test`, calling its own tools), `.env.example`, `Dockerfile` (unless it is a shell or a native app), and `clubedge.stack.json`, with its `deployment` when it runs as its own service.
2. Implement the module options it supports, as files in its folder, and list them.
3. For an API, pass the [conformance suite](./frontend-and-api.mdx#prove-an-api).
4. Generate a project with `--template-dir` and run its checks.

Nothing else changes: not the CLI, not the other stacks, not the module descriptors. The FastAPI API was added this way: Starter v0.23.0 added its folder, and CLI 0.34.0 generates it with no code change.

Schema 6 is schema 5 with the `mobile` role, a slot's `optional`, `files`, `filesWhenEmpty`, `scripts`, and `fallback`, a stack's `auditIgnores`, and the template's `rules`. Schema 5 is schema 4 with the `shell` role. Each older schema is read as before, without what came after it. A CLI that predates a schema refuses a Starter that declares it and asks to be updated, rather than misread it: before schema 6, it would bring the website back into a project without one, and leave the native app's advisories in every project. Starters with schema 1 to 3 are read into the same model, so projects created from them still add, remove, and upgrade. The full guide, with a stack descriptor, is [docs/stack-packs.md](https://github.com/Clubedge/create-clubedge-app/blob/main/docs/stack-packs.md).
