# How it works (/docs/cli/how-it-works)

## The bundled Starter [#the-bundled-starter]

Each CLI release bundles one Starter release. When the release is built, `scripts/bundle-template.mjs` clones the pinned Starter tag, verifies that it resolves to the pinned commit, and copies its tracked files into the package (`template/` and `template.lock.json`). Running the CLI then needs no GitHub access for the default Starter.

## The template manifest [#the-template-manifest]

The Starter describes itself in `clubedge.template.json`: its app directory, site config, environment files, Docker image name, and files that stay out of generated projects.

- **Schema 2** lists each framework's app directory, environment example, and Dockerfile. The CLI moves the selected framework's app to `apps/web` (renaming its package to `@clubedge/web`), moves its environment example and Dockerfile to the project root, leaves the other frameworks out, and removes their entries from `pnpm-lock.yaml` so `pnpm install --frozen-lockfile` keeps working.
- **Schema 3** adds `modules`: for each option, the workspace packages it uses, the files it owns, the variant files that replace defaults, the root `package.json` scripts it sets, and the options it requires.
- **Schema 4** (Starter v0.22.0) splits the manifest into [stack packs](./stack-packs.mdx): each module in `clubedge/modules/<id>.json`, and each app in its own `apps/<name>/clubedge.stack.json` with its role and its files for each module option. Slots place the selected apps: `framework` in `apps/web` and an optional `api` in `apps/api`. The CLI checks that the selected apps implement each chosen option, and runs an app's toolchain, such as `uv sync`, after `pnpm install`. A stack's optional `deployment` (its service id, port, health path, and platforms) is recorded in the project's `package.json` as `clubedge.services`, which `deploy` reads. Older schemas are read into the same model.
- **Schema 5** (Starter v0.27.0, CLI 0.42.0) adds the `shell` role, for an app that packages a frontend's static build, such as the [mobile app](../starter/mobile-app.mdx), in an optional `shell` slot (`apps/shell`, `--shell`). A shell runs no server, so it has no Dockerfile or deployment. Nothing else changes, and schema 4 Starters are read as before.
- **Schema 6** (Starter v0.28.0, CLI 0.44.0) adds the `mobile` role, for an app installed on devices that calls the API, such as the [native app](../starter/native-app.mdx), in an optional `mobile` slot (`apps/mobile`, `--mobile`). A slot with a default can be optional, as the framework's is for a [project without a website](./without-a-website.mdx) (`--framework none`), with the files and root scripts only its apps use. The template lists the selections it refuses as `rules`, and a stack the advisories `pnpm audit` skips for it, as `auditIgnores`. See [Stack packs](./stack-packs.mdx#rules).

Files listed under `conditional` contain blocks that the CLI keeps or drops for the selection, always removing the markers. A block spans several lines; `clubedge:only` applies to a single line. From the Starter's README:

```md title="README.md"
<!-- clubedge:if infra=docker -->

Start PostgreSQL and the other local services with Docker, apply the migrations, ...

<!-- clubedge:end -->

- `packages/auth-supabase/`: Supabase Auth adapter <!-- clubedge:only auth=supabase -->
```

The markers work in `#`, `//`, `<!-- -->`, and JSX comments, and conditions can combine options, as in `framework=next && auth=supabase`. `clubedge:if starter-repository` marks sections for Starter maintainers only.

The CLI refuses a Starter whose manifest schema is newer than it understands and asks you to update. Starters before v0.3.0 have no manifest and use the previous layout.

## Plan, then apply [#plan-then-apply]

The CLI first builds a plan (the files to copy and the edits to make), which `--dry-run` prints, and then applies it. If applying fails, it removes whatever it wrote. The source is organized the same way:

```text
src/
  index.ts        create, and the entry point for every command
  modify.ts       add, remove, and upgrade
  inspect.ts      status and doctor
  deploy*.ts      deploy, one file per platform, and deploy --preview
  try.ts          try on a Railway VM
  neon.ts         neon, and the free Neon database
  mcp-server.ts   the MCP server for coding agents
  cli/            argument parsing and terminal output
  core/           manifest, template sources, customizations, planning, merging, and execution
  steps/          Git initialization and dependency installation
  utils/          file listing and copying, processes, and naming
```

## Contributing [#contributing]

```sh
corepack enable
pnpm install
pnpm check            # type-check sources and tests
pnpm test             # unit and scaffolding tests
pnpm build            # compile src/ to dist/
node ./bin/create.mjs my-app --template-dir ../clubedge-starter --dry-run
```

Without a bundled template, a local build downloads the pinned Starter release from GitHub and verifies its commit. Run `pnpm bundle-template` to bundle it, or `pnpm bundle-template --from ../clubedge-starter` to bundle a local checkout. See the CLI's [CONTRIBUTING.md](https://github.com/Clubedge/create-clubedge-app/blob/main/CONTRIBUTING.md).
