Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .baseline/identity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"_comment": "THIS TREE'S OWN IDENTITY — the FROM side of every rebrand. tooling/rebrand/rebrand.mjs reads it to know what to rename AWAY from; a product's identity is the --values file, which is the TO side. Change a value here only together with the tree: these strings must be what the tree actually contains, or the rename silently misses and the product ships carrying this baseline's name. `productName` is the SITE_NAME seam in apps/web/app/site.ts; `domain` and `subdomain` are placeholders, because this baseline has never deployed under a name of its own; `githubOwner` is the owner in SOURCE_URL.",
"slug": "auth0-saas-starter",
"pascal": "Auth0SaasStarter",
"productName": "SaaStart",
"domain": "auth0-saas-starter.example.com",
"subdomain": "your-workers-subdomain",
"githubOwner": "sourceplane"
}
91 changes: 91 additions & 0 deletions .baseline/product/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# auth0-saas-starter — for coding agents

Start here before you change this site. This page is short on purpose: the
pages it points at hold the detail, and they are kept true.

## What this is

Auth0's B2B SaaS starter: sign-up that creates an organization, members,
invitations and roles, self-service SSO and SCIM, MFA and security policies
— all kept in an Auth0 tenant through its Management API, no database —
built by `@opennextjs/cloudflare` into one Cloudflare Worker with Static
Assets. Orun deploys it to `stage` and `prod` on every merge to `main`;
`dev` only verifies. One deployable component (`apps/web`), its tests
(`tests/web`) and the tenant bootstrap (`tooling/auth0`). The site connects
only when the build has the tenant's whole configuration
(`apps/web/lib/auth0-connection.ts`); until then the home page shows a
"connect Auth0" notice where sign-up would be.

## Read first, in this order

1. [README.md](README.md) — what is where, how to run it, the live URLs.
2. [ai/context/operations.md](ai/context/operations.md) — the operating
contract: how a merge deploys, the secrets model, common operations.
3. [ai/context/deployment.md](ai/context/deployment.md) — what is live, as
last probed.
4. [apps/web/docs/overview.md](apps/web/docs/overview.md) — the component,
with `architecture.md` and `runbook.md` beside it.
5. [apps/web/app/site.ts](apps/web/app/site.ts) — the site's name and the
repository its header links to.
6. [apps/web/lib/auth0-connection.ts](apps/web/lib/auth0-connection.ts) —
the one switch every Auth0 surface reads, and why.
7. [tooling/auth0/bootstrap.mjs](tooling/auth0/bootstrap.mjs) — what the
tenant must hold, and how an environment is connected.

## Working on it

```bash
pnpm install && pnpm typecheck && pnpm lint && pnpm test && pnpm build
pnpm --filter @app/web dev # http://localhost:3000
```

Local work needs a tenant set up for localhost: `pnpm auth0:bootstrap
--local` writes `apps/web/.env.local`; without it the home page shows the
"connect Auth0" notice. The home page is `apps/web/app/page.tsx`. Every
Auth0 surface — the middleware, a page or action that calls
`appClient`/`onboardingClient`/`managementClient` — runs only when
`auth0Connected` is true (the middleware sends the routes that need Auth0
home otherwise): keep that true of anything you add, or the unconnected
site breaks. Read the tenant's configuration (`process.env.AUTH0_*`) when a
request is handled, never at module load: on Workers it arrives with the
request (`apps/web/lib/lazy.ts`).

## How a change lands

- The repository is desired state. `intent.yaml` declares the environments
and the workspace; `apps/web/component.yaml` declares how the site is
built, deployed and smoke-tested.
- `orun plan --changed` shows which components and environments a change
touches. CI runs the same plan on every pull request.
- One task, one pull request to `main`. On the pull request `ci.yml`'s
verify lanes run (the site built and dry-deployed per environment); they
do not lint or run the tests, so run `pnpm typecheck && pnpm lint && pnpm
test` before you push. The merge's `ci.yml` run deploys stage and prod and
smoke-tests each. That run is the deployment: retry a red lane with
`gh run rerun --failed`.
- With Orun's work plane: `orun task create --brief "…"` issues a task key,
`orun pr open --task <KEY>` opens its pull request on `orun/<KEY>-<slug>`,
and `orun pr land` merges it once its checks pass. Leave the `BASE` prefix
to the bootstrap: CI checks `orun/BASE-…` branches with `plan` alone.
- A change to `intent.yaml` alone (a `SITE_URL`, say) deploys nothing;
carry it with a change under `apps/web`.

## Do not touch

- `execution.state.workspace` in `intent.yaml`: every remote operation, and
CI's OIDC exchange, claims that workspace.
- `ai/context/deployment.md`, and the README between `<!-- 03-docs:begin -->`
and `<!-- 03-docs:end -->`: rendered from probed URLs, never by hand.
- `.rebrand/values.json`: the identity the site was created with, which the
deployment record is rendered from.
- Secrets. `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID` are brokered
per run from the workspace's Cloudflare connection; the tenant's
configuration (`AUTH0_*`, `SESSION_ENCRYPTION_SECRET`, …) is Orun secrets
per environment the tenant bootstrap writes. Never put a value in the
repository or in GitHub, and never inline one into a bundle (no
`NEXT_PUBLIC_` name, no `next.config.ts` `env` entry — the tenant's domain
alone is public): the deploy hands them to the Worker as Worker secrets.
List them by name (operations.md).
- `ci.yml` stays the only workflow that runs on a push to `main`.
- `pnpm-lock.yaml` changes through `pnpm install`, never by hand: CI
installs with `--frozen-lockfile`.
186 changes: 186 additions & 0 deletions .baseline/product/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# auth0-saas-starter

A multi-tenant B2B SaaS on [Auth0](https://auth0.com) Organizations — sign-up
that creates an organization, members, invitations and roles, self-service
single sign-on (OIDC and SAML) with SCIM provisioning, MFA enrollment and
per-organization security policies — as a Next.js app on **Cloudflare
Workers + Static Assets** through
[`@opennextjs/cloudflare`](https://opennext.js.org/cloudflare). It has no
database of its own: every organization, member, role and connection lives
in your Auth0 tenant, reached through its Management API.

Working on it with a coding agent? [AGENTS.md](AGENTS.md) says what to read
first, how a change lands and what not to touch.

## Live deployment

<!-- 03-docs:begin -->
Not recorded yet. The bootstrap's last phase writes the live URLs, the
workspace and the secrets the site uses into
[ai/context/deployment.md](ai/context/deployment.md); how the site deploys
and how to operate it is in
[ai/context/operations.md](ai/context/operations.md).
<!-- 03-docs:end -->

## Connect Auth0

The site deploys and serves before it has a tenant: until its build is given
a tenant's configuration, the home page shows a **"connect Auth0"** notice
where the sign-up form would be, every route that needs Auth0 (`/dashboard`,
`/onboarding`, `/auth/*`) sends the visitor home, and `/api/health` reports
`"auth0":"not-connected"`. To turn sign-up on:

1. **Create a tenant** at [auth0.com](https://auth0.com/signup) (one for
stage and prod, or one each), install the
[Auth0 CLI](https://github.com/auth0/auth0-cli) and sign it in to the
tenant: `auth0 login`.
2. **Run the tenant bootstrap** from this repository, once per deployed
environment (with the [orun CLI](https://github.com/sourceplane/orun)
signed in to the workspace):

```bash
pnpm auth0:bootstrap --env stage
pnpm auth0:bootstrap --env prod
```

It sets the tenant up the way the site needs it — two applications
(`<site name> Management` and `<site name> Dashboard`), the Management
API grant, a shared database connection, the `admin` and `member` roles,
three post-login Actions and their bindings, the Universal Login theme,
the verification e-mail and the WebAuthn and one-time-password MFA
factors — adding the environment's origin to the applications' callback,
logout and origin lists. Then it stores the configuration as this
repository's Orun secrets for that environment: `AUTH0_DOMAIN`, the two
applications' ids and secrets, the role ids, the connection's id, the
claims namespace and a session secret it generates once. It is safe to
run again: it creates only what is missing, updates only what differs,
and leaves a secret alone when its value has not changed
(`--dry-run` says what it would do). It prints names, never a value. The
origin is the environment's `SITE_URL` in `intent.yaml`, else its
workers.dev URL; pass `--origin` to name another.
3. **Redeploy the site**: a secret is read when the site builds, and setting
one builds nothing. Use **Deploy by hand** below, or change the stamp on
the last line of `apps/web/component.yaml` (`# orun: redeploy …`) and
merge. The build inlines the tenant's domain into the pages and is told
only that the rest exists; the deploy hands the rest to the Worker as
Worker secrets (`wrangler secret bulk`), so no credential is in a bundle,
a build cache or a log. From that deploy on, the home page is the sign-up
form, `/dashboard` sends a signed-out visitor to Auth0's login, and
`/api/health` reports `"auth0":"connected"` — and the deploy's smoke test
fails if the Worker ever lacks a secret its build expects.

If you rotate the management application's secret, run the bootstrap with
`--refresh-actions`: the "Add Default Role" Action holds a copy of it.

To run it locally: `pnpm auth0:bootstrap --local` sets the tenant up for
`http://localhost:3000` and writes `apps/web/.env.local` (never committed);
then `pnpm --filter @app/web dev`. `wrangler dev`
(`pnpm --filter @app/web preview`) reads the same values from
`apps/web/.dev.vars`.

## What is here

| Surface | Where |
|---|---|
| The site's name and source link | `apps/web/app/site.ts` |
| Whether Auth0 is connected, and the notice until it is | `apps/web/lib/auth0-connection.ts`, `apps/web/components/connect-auth0.tsx`, `apps/web/next.config.ts` |
| Home, onboarding (`/onboarding/*`), the dashboard (`/dashboard/*`: the organization's members, SSO, security policies; the account's profile and MFA) | `apps/web/app` |
| The Auth0 clients (built on first use) and the middleware | `apps/web/lib/auth0.ts`, `apps/web/lib/auth0-clients.ts`, `apps/web/middleware.ts` |
| `/api/health` (the deploy's smoke) | `apps/web/app/api/health` |
| The tenant bootstrap, its Actions, theme and e-mail | `tooling/auth0` |
| The Worker-secret push | `tooling/wire/worker-secrets.mjs` |
| Workers build and deploy contract | `apps/web/next.config.ts`, `open-next.config.ts`, `wrangler.jsonc`, `component.yaml` |
| Tests | `tests/web` (vitest; `tests/web/src/fakes` is a stand-in tenant the bootstrap's tests run against) |

## Getting started

```bash
pnpm install
pnpm typecheck
pnpm lint
pnpm test
pnpm build # next build + opennextjs-cloudflare build → apps/web/.open-next
```

```bash
pnpm --filter @app/web dev # http://localhost:3000
pnpm --filter @app/web preview # wrangler dev over the built Worker
```

Build-time variables:

| Variable | What it does |
|---|---|
| `AUTH0_DOMAIN` | The tenant's domain. With the rest of the configuration (Connect Auth0), the site builds connected; without, it builds the "connect Auth0" site. |
| `NEXT_PUBLIC_SITE_URL` | The site's public origin: Auth0's base URL for its callback and logout URLs, and `metadataBase`. The deploy sets it per environment (see below). Defaults to `http://localhost:3000`. |

## How it deploys

Merges to `main` converge through [Orun](https://github.com/sourceplane/orun):
`.github/workflows/ci.yml` plans the changed components and runs each lane
against the workspace in `intent.yaml`. The site deploys to `stage`, then to
`prod` once stage has converged on the same commit; `dev` only verifies. The
Worker is `auth0-saas-starter-web-<env>` on your account's workers.dev
subdomain, and every deploy is smoke-tested over HTTP: the home page renders
to its end, and `/api/health` answers ok. A pull request runs the same
pipeline's verify lanes: the site built and dry-deployed for each
environment, with nothing deployed. They do not lint or run the tests, so
run `pnpm typecheck`, `pnpm lint` and `pnpm test` before you push. (A push
to `main` builds, deploys and smoke-tests.)

The pipeline holds one credential, GitHub's own `GITHUB_TOKEN`. The
Cloudflare token and account id are brokered per run from the workspace's
Cloudflare connection, and the tenant's configuration is Orun secrets;
nothing provider-shaped is stored in the repository or in GitHub.

**Deploy by hand.** Orunbase's **Deploy** button on a component, or **Run
workflow** on the CI workflow in GitHub's Actions tab (on `main`), runs
`ci.yml` for the environment and components you pick, and each one deploys
exactly as a merge would deploy it. Leave the component blank to redeploy
every component in that environment, with nothing changed: after running the
tenant bootstrap, say. A component with nothing to run in that environment
(a test suite in `prod`) is left out with a notice.

## Custom domain

The site answers on workers.dev from its first deploy. To serve it on your
own domain:

1. Add the domain to the Cloudflare account the site deploys into, and attach
it to the Worker (dashboard → Workers & Pages →
`auth0-saas-starter-web-prod` → Settings → Domains & Routes → Add →
Custom domain). Do the same for stage with a subdomain if you want one.
2. Set the environment's public origin in `intent.yaml`, so Auth0's
callbacks and the site's links use it (until then they use the
workers.dev URL):

```yaml
environments:
prod:
env:
SITE_URL: https://auth0-saas-starter.example.com
```

The site was born with the reserved placeholder
`auth0-saas-starter.example.com` where its domain goes: that example,
and `BASE_DOMAIN` under each environment (dev, stage and prod) in
`intent.yaml`. Replace it with your domain in the same change.
3. Run the tenant bootstrap for the environment again
(`pnpm auth0:bootstrap --env prod`): it adds the new origin to the
applications' callback, logout and origin lists.
4. Merge. The next deploy of `apps/web` builds with the new origin. (A change
to `intent.yaml` alone deploys nothing — touch `apps/web` in the same pull
request, or let the next change to the site carry it.)

## Before you go live

The privacy policy (`/privacy`) and terms (`/terms`) are the template's —
Okta's own texts, kept as placeholders. Replace them with yours. The logo and
icons are Auth0's marks; replace them too.

## Credits

The site is Auth0's B2B SaaS starter
([auth0-developer-hub/auth0-b2b-saas-starter](https://github.com/auth0-developer-hub/auth0-b2b-saas-starter),
MIT — `apps/web/LICENSE.md`), the template behind Vercel's SaaStart: Auth0 +
Next.js SaaS Starter Kit.
24 changes: 24 additions & 0 deletions .baseline/tasks/01-product.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Task contract template for the 01-product landing.
# Unbound to a key on purpose: `orun.task/ensure@v1` seals and attaches it to
# the key the allocator issues. It lives under `.baseline/`, not `tasks/`,
# because `tasks/` is this repository's own work tree (`intent.yaml` `work:`),
# where an unkeyed contract is an error. gates: [] is a DECLARATION — merge
# alone finishes this task; the main convergence is the gate the bootstrap
# watches, not one the plane observes as a PR check.
#
# The whole site in one landing. `affects` names COMPONENTS, by
# metadata.name: the phase's retouch hook reads this list to decide which
# component.yaml files get the redeploy marker, so the deploy set and the task
# plane's statement of the work are one list.
apiVersion: orun.io/v1
kind: TaskContract
spec:
goal: The site's repository is born and linked, the whole site lands in one pull request, and one convergence builds it with OpenNext and deploys it to stage and prod
affects:
- web
- web-tests
doneWhen:
- repo pushed, main pinned as default, workspace linked (orun cloud link)
- main convergence green (build, deploy and smoke on stage and prod)
- the home page answers on both workers.dev URLs
gates: []
13 changes: 13 additions & 0 deletions .baseline/tasks/03-docs.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Task contract template for the 03-docs landing. See 01-product's header.
apiVersion: orun.io/v1
kind: TaskContract
spec:
goal: The live deployment is recorded from verified facts as agent-readable state in the site's repo
affects:
- ai/context/deployment.md
- ai/context/operations.md
- README.md
doneWhen:
- committed deployment manifest matches probed reality
- prod waits on stage again, and dev verifies every merge to main again
gates: []
Loading
Loading