# Local services (/docs/starter/local-services)

The `--infra` module decides how the project runs its development services. Change it later with `pnpm clubedge add infra <option>`.

<Tabs items={['Docker', 'Supabase CLI', 'No Docker (local)', 'Neon', 'None']} groupId="infra" persist>
  <Tab value="Docker">
    `docker-compose.dev.yml` runs the services this project uses on your machine, listening on `127.0.0.1` only. Install Docker Desktop (or Docker Engine with Compose), then:

    ```sh
    pnpm infra:up      # start and wait until every service is healthy
    pnpm db:migrate    # create the tables
    pnpm check:services
    ```

    It contains the services for your modules:

    - **PostgreSQL 17** on port 5432, database `app`, user and password `postgres`. Data survives restarts in a Docker volume.
    - **Redis** on port 6379, with `--cache redis`.
    - **S3-compatible storage** (adobe/s3mock) on port 9090 with the bucket `app`, with `--storage s3`. It accepts any credentials and is for development only.
    - **Mailpit**, with `--email smtp`. It catches every email the app sends: SMTP on port 1025, and the inbox at [http://localhost:8025](http://localhost:8025).

    `pnpm infra:down` stops the services, `pnpm infra:reset` also deletes their data, and `pnpm infra:logs` follows their logs. The file is for development; in production, point the same variables at managed services.
  </Tab>
  <Tab value="Supabase CLI">
    `supabase/config.toml` configures the Supabase CLI's local stack: PostgreSQL, Auth, Storage, the Studio dashboard, and an inbox that captures emails. The CLI runs it in Docker, so install Docker Desktop first. Then:

    ```sh
    pnpm infra:up       # start the stack (the first run downloads its images)
    pnpm infra:status   # print the local URLs and keys
    pnpm db:migrate
    pnpm check:services
    ```

    The database is on port 54322 and the API on port 54321, matching the example environment. Copy the publishable key from `pnpm infra:status` into the Supabase variables. Email confirmation is off locally, so sign-up signs the user in directly. With `--email smtp`, the app's own email goes to the same inbox over SMTP, on port 54325.

    `pnpm infra:down` stops the stack and `pnpm infra:reset` also deletes its data.
  </Tab>
  <Tab value="No Docker (local)">
    The project runs its development services without Docker or any other installation:

    - **PostgreSQL:** `pnpm dev` also starts [PGlite](https://pglite.dev), PostgreSQL compiled to WebAssembly, and serves it on `127.0.0.1:5433`. Each start applies the migrations. Data is kept in `.data/pglite`. `pnpm infra:up` runs the database on its own, for `pnpm check:services` or browser tests.
    - **Files:** with `--storage s3`, while `STORAGE_DIRECTORY` is set, uploads are stored in that folder (`.data/storage`) instead of S3. Set the S3 variables and remove `STORAGE_DIRECTORY` to use object storage.
    - **Cache:** without `REDIS_URL`, the cache and rate limits use process memory.
    - **Email:** without a provider configured, emails are printed to the `pnpm dev` output, links included.

    PGlite runs a single database session, so connections take turns. That is plenty for development but not for production: deploy against a managed PostgreSQL by setting `DATABASE_URL`. Supabase Auth and Supabase Storage need a Supabase project, local or hosted. Better Auth works fully offline. `pnpm infra:reset` deletes everything in `.data/`.
  </Tab>
  <Tab value="Neon">
    The database is hosted on [Neon](https://neon.com), so there is nothing to install or start (Starter v0.19.0 or newer):

    - **PostgreSQL:** create-clubedge-app created a free, unclaimed Neon database and wrote `DATABASE_URL` (pooled) and `DATABASE_URL_DIRECT` into `apps/web/.env.local`, or `apps/api/.env.local` with a separate API. It expires 72 hours after creation unless you claim it with `pnpm clubedge neon claim`. See [A database on Neon](../cli/neon.mdx).
    - **Cache:** without `REDIS_URL`, the cache and rate limits use process memory.
    - **Email:** without a provider configured, emails are printed to the `pnpm dev` output, links included.

    ```sh
    pnpm db:migrate
    pnpm check:services
    ```

    Pull requests can each get their own branch of the database: see [Preview environments](./deploy/preview-environments.mdx).
  </Tab>
  <Tab value="None">
    The project does not include local service definitions. Point `DATABASE_URL` and the provider variables at services you run yourself or at hosted ones, such as Supabase or Neon for PostgreSQL and Upstash for Redis, then run `pnpm check:services` to confirm the app can reach them.
  </Tab>
</Tabs>

## With a separate API [#with-a-separate-api]

In a project with a [frontend and its API](../cli/frontend-and-api.mdx), the API owns the database, and its `DATABASE_URL` is in `apps/api/.env.local`. It holds the database URL for the chosen infrastructure, the same as above. With Better Auth, `apps/web/.env.local` has a `DATABASE_URL` too, for the frontend's auth server: keep the two the same. With Hono or FastAPI, the API also uses the other local services, so their settings, such as `REDIS_URL`, `STORAGE_ENDPOINT`, or `SMTP_URL`, are in `apps/api/.env.local`, and with `--infra local`, `STORAGE_DIRECTORY` is relative to the API.

A project [without a website](../cli/without-a-website.mdx) works the same way, with `apps/api/.env.local` as its only server env file. With the Supabase CLI, copy the Supabase API URL and the publishable key that `pnpm infra:status` prints into it.

<Callout type="warn">
  Projects from Starter v0.24.1 and earlier always got `postgresql://postgres:postgres@127.0.0.1:5432/postgres` in `apps/api/.env.local`. With the Supabase CLI or No Docker, change the port to 54322 or 5433; with Docker, the database to `app`.
</Callout>
