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; `slug` also names the KV namespace titles (terraform `repo`) and the secret project; `domain` is the root domain tenants hang off (BASE_DOMAIN; stage's is `stage.<domain>`) and `subdomain` the workers.dev placeholder, both placeholders because this baseline has never deployed under a name of its own; `githubOwner` is the owner in any link to this repository.",
"slug": "platforms-starter-kit",
"pascal": "PlatformsStarterKit",
"productName": "Platforms Starter Kit",
"domain": "platforms-starter-kit.example.com",
"subdomain": "your-workers-subdomain",
"githubOwner": "sourceplane"
}
139 changes: 139 additions & 0 deletions .baseline/product/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# platforms-starter-kit

A multi-tenant app: anyone creates a tenant — a name and an emoji — from the
landing page, every tenant gets a page of its own, and `/admin` lists and
deletes them. Next.js on **Cloudflare Workers + Static Assets** through
[`@opennextjs/cloudflare`](https://opennext.js.org/cloudflare), with the
tenants in a **Workers KV** namespace that Terraform provisions per
environment.

## Live deployment

<!-- 02-docs:begin -->
Not recorded yet. The bootstrap's last phase writes the live URLs, the
workspace and the secrets inventory 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).
<!-- 02-docs:end -->

## What is here

| Surface | Where |
|---|---|
| The landing page (create a tenant), a tenant's page `/s/[subdomain]`, `/admin`, not-found | `apps/web/app` |
| The site's name | `apps/web/app/site.ts` |
| Where a tenant lives: `<tenant>.<root domain>`, or `/s/<tenant>` on any other host | `apps/web/lib/addresses.ts`, `apps/web/proxy.ts` |
| The tenant store (`get / set / del / keys / mget` over the `KV` binding) | `apps/web/lib/redis.ts`, `apps/web/lib/subdomains.ts` |
| Workers build, bindings and deploy contract | `apps/web/next.config.ts`, `open-next.config.ts`, `wrangler.template.jsonc` + `wiring.fixture.json` (→ `wrangler.jsonc`), `component.yaml` |
| The KV namespace (stage, prod) | `infra/terraform/cloudflare-kv` |
| Tests | `tests/web` (vitest) |

## Getting started

```bash
pnpm install
pnpm run wire:fixture # render apps/web/wrangler.jsonc from the offline fixture
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 — a local KV through wrangler's platform proxy
pnpm --filter @app/web preview # wrangler dev over the built Worker, same local KV
```

Under `pnpm dev` a tenant is `http://<tenant>.localhost:3000` (browsers
resolve `*.localhost` to the loopback address); under `preview` it is
`/s/<tenant>`. Make the pages yours in `apps/web/app`, and the site's name in
`apps/web/app/site.ts`.

## Where tenants live

Every tenant is a subdomain of the environment's root domain —
`<tenant>.platforms-starter-kit.example.com` on prod,
`<tenant>.stage.platforms-starter-kit.example.com` on stage — once that
domain's wildcard route points at the Worker (below). Until then the site
answers on its workers.dev address, where a subdomain cannot resolve, so
there a tenant is a path on the same host: `/s/<tenant>`. The landing form
says which, creating a tenant redirects to it, and `/admin` links to it. The
app decides per request, from the host it was asked on: nothing is rebuilt
when the domain goes live, and the workers.dev address keeps working
afterwards.

## How the tenant store is wired

The Worker binds the namespace as `KV`; a tenant is `subdomain:<name>` →
`{ emoji, createdAt }`. The namespace id is never hand-written:
`apps/web/wrangler.template.jsonc` names it as a wiring token, and
`wrangler.jsonc` is that template rendered — from `wiring.fixture.json`
(placeholder ids) for local work and verification, and on every deploy from
the document the `cloudflare-kv` Terraform root publishes after its apply
(`WIRING_CLOUDFLARE_KV`, per environment). Edit the template, then
`pnpm run wire:fixture`; Checks fails if the committed `wrangler.jsonc` is
not the fixture render.

KV is eventually consistent across locations: a tenant created in one place
reads back at once there and within about a minute everywhere else. The
create → redirect → tenant page flow reads where it wrote.

## 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 KV namespace applies first, then
the app builds with that environment's namespace id and root domain and
deploys — to `stage`, then to `prod` once stage has converged on the same
commit; `dev` only verifies. The Worker is
`platforms-starter-kit-web-<env>` on your account's workers.dev subdomain,
and every deploy is smoke-tested over HTTP: `/` must be rendered for the host
it was asked on, and `/admin` must read the tenant list from KV.
`checks.yml` runs install, the fixture render, typecheck, lint, test and
build on every pull request. (A push to `main` runs `ci.yml` alone, which
applies, builds and deploys.)

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 namespace ids travel as Orun secrets; nothing
provider-shaped is stored in the repository or in GitHub.

## After the first deploy: what is yours to do

### Tenant subdomains (a custom domain)

A fresh deployment has no domain of its own. To give every tenant its
subdomain, on the Cloudflare account the site deploys into:

1. **The zone.** Add the root domain's zone (`platforms-starter-kit.example.com`,
or the domain above it) to the account.
2. **DNS.** A proxied wildcard record, `*.platforms-starter-kit.example.com`
(an `AAAA` to `100::` is enough: the Worker answers, not an origin), and
one for the apex.
3. **The route.** Workers & Pages → `platforms-starter-kit-web-prod` →
Settings → Domains & Routes → Add → Route:
`*.platforms-starter-kit.example.com/*` and
`platforms-starter-kit.example.com/*`. For stage, the same with
`stage.platforms-starter-kit.example.com` and
`platforms-starter-kit-web-stage` — a second-level wildcard needs an
Advanced Certificate, because Universal SSL covers one level only.
4. **`BASE_DOMAIN`**, only if tenants should hang off another domain: it is
each environment's `env.BASE_DOMAIN` in `intent.yaml`, inlined at build
time. A change there maps to no component, so land it together with a
change under `apps/web` (its last line, `# orun: redeploy …`, is a deploy
trigger) and the next convergence rebuilds with it.

Nothing else changes: requests arriving on the root domain get subdomain
links, requests on workers.dev keep `/s/<tenant>`. For customer-owned
domains, Cloudflare for SaaS custom hostnames with the Worker as the
fallback origin is the same idea.

### A gate on `/admin`

`/admin` lists and deletes every tenant and has no authentication (the
template's `TODO`). Before you rely on it, put
[Cloudflare Access](https://developers.cloudflare.com/cloudflare-one/policies/access/)
in front of `/admin*` on the Worker's hostnames — no code change. The deploy
smoke reads `/admin`; once it is gated, drop that half of `smokeCommand` in
`apps/web/component.yaml`.
27 changes: 27 additions & 0 deletions .baseline/tasks/01-product.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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 product 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 a re-run of the phase has a
# diff and exactly these components are re-planned — the deploy set and the
# task plane's statement of the work are one list.
apiVersion: orun.io/v1
kind: TaskContract
spec:
goal: The product's repository is born and linked, the whole product lands in one pull request, and one convergence applies the tenant store's KV namespace and deploys the multi-tenant app on stage and prod
affects:
- cloudflare-kv
- web
- web-tests
doneWhen:
- repo pushed, main pinned as default, workspace linked
- WIRING_CLOUDFLARE_KV published on stage and prod
- main convergence green (KV applied, then the app built, deployed and smoke-tested on stage and prod)
- the landing page answers on both workers.dev URLs, tenants served there at /s/<tenant>
gates: []
13 changes: 13 additions & 0 deletions .baseline/tasks/02-docs.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Task contract template for the 02-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 product'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: []
136 changes: 136 additions & 0 deletions .github/workflows/baseline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: Baseline CI

# THE FACTORY'S OWN LANES — this repository tested as a BASELINE: that its
# build document parses with the orun a bootstrap actually runs, that its card
# agrees with it, that every component is placed by the one product phase,
# that the KV namespace's wiring reaches the Worker's config, that a placed
# tree comes up branded and carrying nothing of the factory — and plans the
# namespace before the Worker on a merge — and that the product it produces
# installs, builds, deploys (dry) and serves.
#
# ─── WHY THIS IS NOT IN ci.yml OR checks.yml ──────────────────────────────
#
# `repo-blueprint.yaml`'s `github-workflows` module copies the WHOLE `.github`
# directory into every site built from this repository. These jobs run
# `testing/*.sh`, and `testing/` is deliberately not placed — so in a site they
# would be steps that cannot pass, red on its very first pull request. This
# file is in the blueprint's `ignore` list, and `testing/coverage.test.sh`
# fails on any workflow that reads `testing/` and is not.

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:
# Tier 0. bash, python3 and git; node for the tools. No workspace install,
# no network, no credential — the job that most certainly fails a PR.
baseline-contract:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v5
with:
node-version: 22
# setup-node v5 turns on the pnpm cache by itself when package.json
# names a packageManager, and then fails on a runner with no pnpm.
# This job installs nothing.
package-manager-cache: false
- name: Contract tests (manifest, phases, coverage, rebrand, retouch, bootstrap-defer, wire)
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 wire; do
echo "── $t"
bash "testing/$t.test.sh"
done

# Tier 1. THE BLUEPRINT, READ AND PLACED BY THE BINARY A BOOTSTRAP RUNS.
#
# Pinned at the bootstrap floor (BOOTSTRAP.md), not the site's lane pin:
# every test here reads YAML with PyYAML, which parses anything well-formed;
# only the pinned orun can say whether the document is one a bootstrap can
# run. `--status` parses it, validates every hook against the action
# registry, compiles every `when` and narration template, and writes
# nothing. Then the leak gate (what a product would carry, derived by the
# floor too), and the placement tier (the offline bootstrap: both phases
# placed and finished by the blueprint's own hooks, then the product's own
# `orun plan` for the 01-product merge — the KV apply before the Worker's
# deploy — under the product's lane pin, below).
blueprint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.58.11
- uses: pnpm/action-setup@v4
with:
version: 10.12.1
- uses: actions/setup-node@v5
with:
node-version: 22
- name: repo-blueprint.yaml, read by the pinned CLI
run: |
set -euo pipefail
orun --version
python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
# Required inputs must be supplied for the document to resolve; the
# values are arbitrary and nothing is written.
orun new --blueprint repo-blueprint.yaml --status \
--out "$(mktemp -d)" \
--set reponame=acme-tenants \
--set "productname=Acme Tenants" \
--set productdomain=tenants.acme.dev \
--set githuborg=acme-inc
- name: the leak gate — what a product carries
run: bash testing/leak.test.sh
# The placement tier ENDS with the product's own `orun plan` — what the
# product's ci.yml runs — so it runs under the product's lane pin, not
# the bootstrap floor. v2.58.11 plans a pull request with apps/web
# waiting on the KV plan: it does not apply a dependsOn edge's
# `modeRules`. The lane pin does (advisory on a PR, enforced on main),
# and the test refuses an orun older than the pin rather than assert
# the wrong CLI's plan. Its placements are valid under either.
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.78.4
- name: placement — the offline bootstrap, and the product's own plan
run: |
git config --global user.email ci@example.invalid
git config --global user.name "baseline ci"
bash testing/placement.test.sh

# Tier 2. THE PRODUCT IT PRODUCES WORKS: its one landing under the checks
# its pull request waits on, the stage lane's own structure check, build
# (the live wiring render included), output check and dry deploy in the tree
# orun stages, and the built Worker served and smoke-tested with the
# component's own smoke command. Pinned at the product's lane version,
# because that is the orun the product's CI runs.
site:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.78.4
- uses: pnpm/action-setup@v4
with:
version: 10.12.1
- uses: actions/setup-node@v5
with:
node-version: 22
cache: pnpm
- name: e2e — the bootstrapped product builds, deploys (dry) and serves
run: |
python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
git config --global user.email ci@example.invalid
git config --global user.name "baseline ci"
bash testing/e2e.test.sh
24 changes: 18 additions & 6 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
name: Checks

# Credential-free verification: install, render the offline wrangler fixtures,
# typecheck, lint, test and build. Runs on every push and pull request and is
# the merge gate until the product is linked to an Orun workspace, at which
# point `ci.yml` (Orun plan/run with brokered Cloudflare credentials) takes
# over — it stays gated behind the `ORUN_CI` repository variable until then.
# typecheck, lint, test and build, on every pull request, linked or not.
# `ci.yml` is the Orun pipeline beside it (plan/run with brokered Cloudflare
# credentials, deploys on merge); it plans nothing until intent.yaml names a
# workspace.
#
# PULL REQUESTS ONLY — not pushes to main. A push to main must start exactly
# one workflow, `ci.yml`, because the bootstrap's convergence watch
# (`orun.run/watch@v1` with `sha:`) takes the newest run for the merge commit
# from ANY workflow. With this one on push too, the first live bootstrap
# watched this run go green while ci.yml's deploy lanes had failed, and called
# the site converged. On main the convergence builds and tests the site
# anyway. The baseline's coverage gate holds the rule.
on:
push:
branches: [main]
pull_request:
workflow_dispatch:

concurrency:
group: checks-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
Expand All @@ -33,6 +40,11 @@ jobs:
# Templated deployables render their wrangler config from the committed
# fixture; an unresolved wiring token fails here, not at deploy time.
- run: pnpm run wire:fixture
# …and the render is what is committed. The deploy lane checks that the
# config exists before it builds, so wrangler.jsonc is in the tree as the
# fixture render; a template edited without re-rendering fails here.
- name: the committed wrangler config is the fixture render
run: git diff --exit-code
- run: pnpm typecheck
- run: pnpm lint
- run: pnpm test
Expand Down
Loading
Loading