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
78 changes: 78 additions & 0 deletions .baseline/product/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# AGENTS.md — {{ .productname }}

You are working in `{{ .githuborg }}/{{ .reponame }}`, a multi-tenant SaaS on
Cloudflare Workers and Supabase Postgres. It is an Orun desired-state repo:
every directory with a `component.yaml` is a component, and merging to `main`
is what deploys it.

## Read first, in this order

1. [`ai/context/operations.md`](ai/context/operations.md) — the operating
contract: how a merge deploys, the secrets model, how to verify, common
operations.
2. [`ai/context/deployment.md`](ai/context/deployment.md) — this product's
live facts: URLs, workspace, secrets by name. Generated, so it is only as
current as its last refresh.
3. [`intent.yaml`](intent.yaml) — the environments (`dev` verify-only,
`stage`, then `prod`), the pinned composition catalog, the workspace.
4. `apps/api-edge/docs/` — the one public entry point and how it routes to
the workers. Every app has the same three pages: overview, architecture,
runbook.
5. `apps/cms/docs/` — the CMS, which is the console: the Payload admin
with Lumen sign-in and the account and billing pages, how it deploys,
how the owner opens its admin, and how to change a collection (a
migration, never a push).
6. `apps/web-console-next/docs/` — the old console URL, now a redirect
Worker into the CMS.

## Layout

- `apps/api-edge` is public; the twelve `apps/*-worker` are reached only
through it, over service bindings.
- `apps/cms` — the product: Payload CMS on Workers (OpenNext), public on
its own hostname. Its admin is the console: a Lumen account signs in
(no Payload passwords), and the account, organization, notifications,
security activity and billing pages call `api-edge` server to server
over the `LUMEN_API` service binding. No worker calls the CMS. Its schema is `cms`, changed only by migrations in
`packages/db`.
- `apps/web-console-next` — a small redirect Worker: every old console
path answers 308 to its place in the same environment's CMS.
- `packages/*` — contracts, SDK, CLI, database harness, policy engine.
- `infra/terraform/*` — Supabase, Hyperdrive, KV, and the CMS's own
Hyperdrive (`cloudflare-hyperdrive-cms`); `infra/db-migrate` — the schema
migrations.
- `tests/*` — one suite per component.

## How a change lands

- One task, one branch, one pull request into `main`.
- Locally: `pnpm install`, then `pnpm typecheck`, `pnpm lint`, `pnpm test`
and `pnpm build`.
- `orun plan --changed --intent intent.yaml` lists the component lanes your
change plans — what CI will run. A change that touches no component plans
nothing and deploys nothing.
- The pull request's CI plans and verifies. Merging deploys `stage`, then
`prod`. A green run is not proof: check the URLs and the published wiring
the way `operations.md` shows.
- A new component is a directory under `apps/`, `packages/`, `infra/` or
`tests/` with a `component.yaml`; Orun discovers it on the next plan.
- Secrets are never committed. Provider credentials are brokered per run;
runtime secrets are set with `orun secrets set`.

## Do not touch

- `execution.state` in `intent.yaml` (`workspace`, `backendUrl`,
`requireOrg`): CI's credential-free sign-in depends on it.
- `.rebrand/values.json` — this product's identity record; the docs refresh
reads it.
- `ai/context/deployment.md`, and the README between the `08-docs` markers:
both are regenerated, and hand edits are overwritten.
- `.github/workflows/ci.yml` beyond its version pins. CI runs `orun plan` and
`orun run`, never pnpm, Wrangler or Terraform directly.
- `pnpm-lock.yaml` by hand — run `pnpm install`.
- A worker's `wrangler.jsonc` where a `wrangler.template.jsonc` sits beside
it: edit the template; the render is gitignored.
- The service bindings between billing, membership, notifications and events
form a loop that deploys in two passes on a fresh account. The loop is
pinned in `tests/config-worker/src/deployment-config.test.ts`; do not grow
it.
78 changes: 78 additions & 0 deletions .baseline/product/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# {{ .productname }}

`{{ .githuborg }}/{{ .reponame }}` — a multi-tenant SaaS on Cloudflare Workers
and Supabase Postgres, run as an [Orun](https://github.com/sourceplane/orun)
component-native desired-state repo. Identity, organizations, projects, RBAC,
audit, metering, billing, webhooks and notifications are separate
bounded-context Workers behind one public edge API. The product opens in its
Payload CMS admin, which is the console: a Lumen account signs in, and the
account, organization, notifications and billing pages live inside it.

## Live deployment

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

## Working on it

Start at [AGENTS.md](AGENTS.md). It is written for a coding agent and is the
shortest way in for a person too: what to read first, how a change lands, and
what not to touch.

## What is here

| Path | What it is |
|---|---|
| `apps/api-edge` | The one public HTTP entry point; reaches the workers over service bindings |
| `apps/*-worker` | Twelve bounded-context Workers — identity, membership, projects, policy, events, config, metering, billing, notifications, webhooks, integrations, admin. Never public |
| `apps/cms` | The product and its console: Payload CMS on Workers (OpenNext), signed in with a Lumen account; content, media on R2, and the account and billing pages, calling the edge server to server |
| `apps/web-console-next` | The old console URL, now a redirect Worker: every path answers 308 to its place in the CMS |
| `packages/*` | Shared libraries: contracts, SDK, CLI, the database harness, the policy engine, the notifications client, the webhook verifier |
| `infra/terraform/*` | The data plane: Supabase projects, Hyperdrive for the fleet and a cache-disabled one for the CMS, the CMS's R2 media bucket, the edge's idempotency KV, and the custom-domain component (parked until a domain is set) |
| `infra/db-migrate` | Database migrations — planned on pull requests, applied on merge |
| `tests/*` | Per-component contract and verifier suites |
| `intent.yaml` | The environments, the pinned composition catalog, and the Orun workspace this repository deploys into |

`stage` and `prod` are provisioned and deployed; `dev` is verify-only.

## Getting started

Node.js 20 or later and pnpm 10.

```bash
pnpm install
pnpm typecheck
pnpm lint
pnpm test
pnpm build
```

## How it deploys

Merges to `main` converge through Orun: `.github/workflows/ci.yml` runs
`orun plan --changed`, then one `orun run` lane per planned component. A pull
request plans and verifies; a push to `main` deploys `stage`, then `prod` once
`stage` has converged on the same commit. No pnpm, Wrangler or Terraform
command runs directly in CI.

The pipeline holds one credential, GitHub's own `GITHUB_TOKEN`. Cloudflare and
Supabase credentials are brokered per run from the workspace's connections;
nothing provider-shaped is stored in the repository or in GitHub.

## The first CMS admin

The admin opens to nobody until its owner says so: the first admin is created
with a one-time setup token the owner sets, and every later person is let in
from inside the admin. [Open the admin](apps/cms/docs/runbook.md#open-the-admin-first-admin)
is the step, per environment.

## Custom domain

The product answers on workers.dev from its first deploy. Setting a domain is
one pull request, later:
[Setting the domain later](ai/context/operations.md#setting-the-domain-later).
8 changes: 8 additions & 0 deletions .baseline/product/deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# {{ .reponame }} — live deployment manifest

> Not rendered yet. The bootstrap's `08-docs` phase probes every live URL —
> the edge, the CMS that is the console, and the console URL that redirects
> into it — and regenerates this file from what answered: the workspace, the
> URLs and their status, and the secrets inventory by name. Until then,
> nothing here claims the product is live. The operating contract is
> [operations.md](operations.md).
144 changes: 144 additions & 0 deletions .github/workflows/baseline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
name: Baseline CI

# THE FACTORY'S OWN LANES — tiers 0 to 2 (saas-bootstrap-engine BE5, BE6;
# ported from cirrus).
#
# These test the BASELINE: that its build document parses with the orun a
# bootstrap actually runs, that every component it ships is placed by exactly
# one phase, that a placed tree comes up branded and answering, and that a
# product carries nothing it should not.
#
# ─── WHY THIS IS NOT IN ci.yml ──────────────────────────────────────────
#
# `repo-blueprint.yaml`'s `github-workflows` module copies the WHOLE `.github`
# directory, so every workflow here travels into every product built from this
# repository — unless the blueprint's `ignore` names it, which it does for this
# file. These jobs run `testing/*.sh`, and `testing/` is deliberately not
# placed — so in a product they would be steps that cannot pass, red on its
# very first pull request, in a repository whose owner has no idea what a
# "blueprint" is.
#
# `ci.yml` carried exactly that until now, as its `flows-contract` job. It
# keeps `plan` and `run`: those are the orun component lanes, and a product
# genuinely needs them.
#
# The split is enforced, not remembered: `testing/coverage.test.sh` fails on
# any workflow that reads a path under `testing/` and is not in the blueprint's
# `ignore` list.

on:
push:
branches: [main]
pull_request:

concurrency:
group: baseline-ci-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

permissions:
contents: read

jobs:
# The baseline's contract suite, run directly rather than through a
# component. It used to ride a `tests/flows` component whose `quick-check`
# profile runs setup, install and a package-structure check — and no tests
# (observed live on cirrus: `4 passed, 0 failed`, none of them a test).
# These scripts need bash, python3 and git and nothing else — no workspace
# install, no network, no credential.
#
# THIS is the job that makes the suite able to fail a PR.
baseline-contract:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Contract tests (manifest, phases, coverage, rebrand, retouch, bootstrap-defer, fleet-stubs, pen-reset)
run: |
set -euo pipefail
python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
for t in manifest phases coverage rebrand retouch bootstrap-defer fleet-stubs pen-reset; do
echo "── $t"
bash "testing/$t.test.sh"
done

# THE BLUEPRINT PARSES WITH THE BINARY A BOOTSTRAP ACTUALLY RUNS.
#
# Every other test here reads the YAML with PyYAML, which will parse anything
# well-formed. On cirrus that let a blueprint reach main that no released orun
# could read a word of:
#
# ✕ unknown flag: --phase
# ✕ parse blueprint: yaml: unmarshal errors:
# line 613: cannot unmarshal !!map into []scaffold.Hook
#
# So this job pins the same version the bootstrap does and makes orun itself
# answer. `--status` derives every phase's state: it parses the document,
# validates each phase's hooks against the action registry, compiles every
# `when` and every narration template, and writes nothing. It does not probe
# — derivation asks the tree, not the network — so it needs no credential.
blueprint-parses:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: sourceplane/orun-action@v1.2.0
with:
# The bootstrap floor (BOOTSTRAP.md), not the product lane pin. It
# used to be v2.58.11 — the first CLI that could read this document
# at all (`orun.run/watch@v1`'s `sha:`, a landing's whole-run check
# wait, `githubOwner`, `environments`, a deferred project probe, and
# `from: workspace`). It is v2.88.0 now, for three keys an older CLI
# refuses at parse: `hooks.preInstantiate[].background`,
# `orun.pr/land@v1`'s `checks: local`, and
# `orun.integrations/reconcile@v1`'s `secrets:` list (v2.87.0).
version: v2.88.0
- name: repo-blueprint.yaml, read by the pinned CLI
run: |
set -euo pipefail
orun --version
# Inputs that are `required: true` must be supplied for the document
# to resolve; the values are arbitrary and nothing is written. No
# domain: the console asks for none, so the document must resolve
# without one.
orun new --blueprint repo-blueprint.yaml --status \
--out "$(mktemp -d)" \
--set reponame=acme-cloud \
--set "productname=Acme Cloud" \
--set githuborg=acme-inc
# Tier 1's leak gate. It derives what every phase WOULD place and gates
# that set — so it needs orun, which is why it rides this job rather than
# the bash-only one above.
- name: the leak gate — what a product carries
run: bash testing/leak.test.sh
# Tier 1's other half. This one PLACES the tree, brands it exactly as
# 01-scaffold's hooks do, and runs the phases that follow. It needs node
# for rebrand alongside orun, and about thirty seconds. Still offline:
# placement writes files, and a run with hooks off does not probe.
- uses: actions/setup-node@v6
with:
node-version: "20"
- name: Tier 1 — the tree is placed, branded, and made to answer
run: bash testing/placement.test.sh

# TIER 2 — THE PLACED, BRANDED PRODUCT COMPILES AND PASSES ITS OWN SUITES.
#
# Placement proves a product comes out branded and that orun accepts it. It
# cannot prove the product's CODE survived the rebrand, and here the rebrand
# renames code: the CMS names the platform `lumen` in every case-form — a
# Payload field and the column derived from it, route and module
# directories, a binding, a cookie, a migration — and every one of those
# must still agree after it. So this places the whole blueprint, brands it
# as the phases do, and asks the product: a frozen install, every package
# typechecked, every suite run. About three minutes; no credential.
branded-fork:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.88.0
# pnpm's version is package.json's `packageManager`, as in the product.
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v6
with:
node-version: "22"
- name: Tier 2 — the branded product installs, typechecks and passes its suites
run: bash testing/branded-fork.test.sh
Loading
Loading