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
6 changes: 6 additions & 0 deletions .github/workflows/baseline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ jobs:
echo "── $t"
bash "testing/$t.test.sh"
done
# Every component's docs/{overview,architecture,runbook}.md is generated
# from what the component declares (its manifest, Worker config,
# Terraform, migrations, package scripts). A pull request that changes
# one of those facts without regenerating the pages fails here.
- name: Component docs match their manifests
run: python3 tooling/catalog/gen-component-docs.py --check

# Tier 1. THE BLUEPRINT, READ AND PLACED BY THE BINARY A BOOTSTRAP RUNS.
#
Expand Down
42 changes: 42 additions & 0 deletions ai/context/current.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# platforms-starter-kit — where this repository stands

The entry page for anyone (or any agent) picking this repository up. It is
this repository's own state and does not ship to a product built from it; the
two pages that do are [operations.md](operations.md) and
[deployment.md](deployment.md).

## What it is

Vercel's Platforms Starter Kit — a multi-tenant app, every tenant a subdomain
— on Cloudflare Workers + Static Assets (`@opennextjs/cloudflare`), its tenant
records in Workers KV behind a module that keeps the Upstash client's surface,
the namespace provisioned per environment by Terraform through Orun. Packaged
as an Orun baseline: `orun new --blueprint repo-blueprint.yaml` builds a new
product in its own repository and takes it to live on stage and prod in one
landing (`01-product`: cloudflare-kv → web per environment), then records
what went live (`02-docs`). Off the root domain a tenant is `/s/<tenant>`, so
a fresh product is whole on workers.dev before any custom domain.

## Release

| | |
|---|---|
| Latest tag | `baseline-v1` (PS4) |
| On `main` since | PS5 — the cirrus standard (no kiox, generated component docs, this context pack) |
| Proven live | No. Everything short of the platform is proven offline in Baseline CI; a live bootstrap from a tag, and tenant subdomains on a real zone, are still to come (risk PS-K) |

## Where to read

| Question | Page |
|---|---|
| What shipped, and every departure from upstream | `specs/epics/platforms-starter-kit/IMPLEMENTATION-STATUS.md` |
| Why it is built this way | [decisions.md](decisions.md), then `specs/epics/platforms-starter-kit/design.md` |
| What could still go wrong | [open-risks.md](open-risks.md), then `specs/epics/platforms-starter-kit/risks-and-open-questions.md` |
| How to instantiate it | `BOOTSTRAP.md`, `docs/phases/` |
| What each component is | `apps/web/docs/`, `infra/terraform/cloudflare-kv/docs/`, `tests/web/docs/` (generated; `python3 tooling/catalog/gen-component-docs.py`) |

## Next

1. Bootstrap one product from the next tag against a workspace, and record
its timings (closes PS-K); then the registry row can leave `unlisted`.
2. Cut the next `baseline-vN` with `tag.yml` so the registry can pin PS5.
20 changes: 20 additions & 0 deletions ai/context/decisions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# platforms-starter-kit — decisions

The choices that shape this repository, one line each, with where the full
reasoning lives. Superseded decisions stay listed, marked, so the history
reads in order.

| # | Decision | Why | Source |
|---|---|---|---|
| 1 | OpenNext on Workers + Static Assets (`cloudflare-workers-assets-turbo`), the proxy inside the Worker | The template's pages, proxy and server actions run as written | `specs/epics/platforms-starter-kit/design.md` §2 |
| 2 | Workers KV, not a Durable Object per tenant | The template's store is a key-value map with a prefix scan, and that is what KV is | design.md §8, risk PS-B |
| 3 | `lib/redis.ts` keeps the Upstash client's surface (`get / set / del / keys / mget`, same keys, same JSON) | The template's data access and server actions stay untouched | design.md §3, risk PS-C |
| 4 | `wrangler.jsonc` rendered per environment from the KV wiring document, and committed as the fixture render; `dev` renders the fixture | The deploy lane checks the file exists before the build; no root applies to `dev` (PS4) | risks PS-I, PS-J |
| 5 | The root domain is one knob: the environment's `BASE_DOMAIN` in `intent.yaml`, inlined by `next build` | A wrangler var would never be read in production and would be a second place to edit | risk PS-E |
| 6 | One landing (`01-product`) then the record (`02-docs`); `web` depends on `cloudflare-kv`, enforced on a push to `main`, advisory on a pull request | The plan, not a landing boundary, orders the namespace before the Worker (cirrus-baseline since baseline-v22) | design.md §9 |
| 7 | Off the root domain a tenant is `/s/<tenant>` on the request's host; no domain phase | A fresh deploy has no zone, and `workers-deploy` carries no zone permissions; subdomains are the owner's step | design.md §8b, risk PS-D |
| 8 | `/admin` stays unauthenticated, as upstream | No auth provider to carry; Cloudflare Access in front of `/admin*` is the zero-code gate | risk PS-H |
| 9 | `ci.yml` plans nothing while `intent.yaml` names `ws_CHANGE_ME` (replaced the `ORUN_CI` gate) | A bootstrap cannot set a repository variable | IMPLEMENTATION-STATUS (PS4) |
| 10 | stack-tectonic 0.19.0, not 0.20.0 | 0.20.0's lane-scoped install is refused by Next 16's Turbopack | IMPLEMENTATION-STATUS (PS4) |
| 11 | orun is pinned only where it runs (the `orun-action` `version:` in each workflow); no kiox | `kiox.yaml` pinned a version nothing ran | IMPLEMENTATION-STATUS (PS5) |
| 12 | Component docs are generated from the manifests and checked in CI | A hand-written copy of the dependency graph, bindings and published outputs drifts silently | `tooling/catalog/gen-component-docs.py` |
15 changes: 15 additions & 0 deletions ai/context/open-risks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# platforms-starter-kit — open risks

What is not yet proven or not yet decided. The full write-up of every risk,
including the accepted and resolved ones, is
`specs/epics/platforms-starter-kit/risks-and-open-questions.md`; this page
lists only what is still live, so it should be short.

| ID | Risk | State | What closes it |
|---|---|---|---|
| PS-K | No live bootstrap yet: the repository created and linked, the token minted, a real `terraform apply`, the lease-published wiring document, a real `wrangler deploy`, the probes and tenant subdomains on a real zone are all unproven | OPEN | One bootstrap from a tag against a workspace (and a zone routed to the Worker for subdomains) |

Accepted, and worth knowing before you change them: PS-B (KV is eventually
consistent across locations), PS-D (tenant hostnames need a zone; the
baseline provisions none), PS-H (no authentication on `/admin`, as upstream),
PS-L (the bootstrap floor, orun v2.58.11, plans every edge enforced).
27 changes: 27 additions & 0 deletions apps/web/docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# web — architecture

Built by the turbo pipeline from `apps/web` and deployed with wrangler.

| | |
| ------------------- | ----------------------------------------------- |
| Worker config | `apps/web/wrangler.template.jsonc` |
| Entry | `.open-next/worker.js` |
| Compatibility date | `2026-10-01` |
| Compatibility flags | `nodejs_compat`, `global_fetch_strictly_public` |

## Bindings

| Binding | Kind | Source |
| -------- | -------------------- | -------------------------------- |
| `KV` | Workers KV namespace | `app_kv_id` from `cloudflare-kv` |
| `ASSETS` | Static assets | `.open-next/assets` |

Identifiers marked _from_ a component are filled in at deploy time from
that component's published outputs for the environment being deployed.

## Wiring

Resolved at deploy time from secrets the infrastructure lanes publish (names only):

- `WIRING_CLOUDFLARE_KV_PROD`
- `WIRING_CLOUDFLARE_KV_STAGE`
20 changes: 20 additions & 0 deletions apps/web/docs/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# web

The Platforms Starter Kit (multi-tenant subdomains, tenants in Workers KV; Next.js on Cloudflare Workers + Static Assets via @opennextjs/cloudflare, per environment)

A Cloudflare Worker with Static Assets (server rendering plus static files), deployed per environment by its CI lane.

| | |
| ------------ | ------------------------------------------------------------------------------------------------------------------ |
| Type | `cloudflare-workers-assets-turbo` |
| Source | `apps/web` |
| Package | `@app/web` |
| Environments | `dev`: `verify` · `stage`: `verify`, `deploy` on a push to `main` · `prod`: `verify`, `deploy` on a push to `main` |

## Depends on

- **cloudflare-kv** — Provisions the Cloudflare KV namespace the app binds (stage and prod)

## Depended on by

- (none)
40 changes: 40 additions & 0 deletions apps/web/docs/runbook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# web — runbook

## How it runs

Pull requests verify it; a merge to `main` deploys it to `stage`, `prod`.
CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`;
the plan orders a component after everything it depends on.

## Local commands

```bash
pnpm --filter @app/web dev
pnpm --filter @app/web build
pnpm --filter @app/web typecheck
pnpm --filter @app/web lint
pnpm --filter @app/web preview
```

## Verify

After a deploy the lane runs this smoke against the environment it
deployed (`ORUN_ENVIRONMENT`); `DEPLOYED_URL` overrides the URL:

```bash
host="${DEPLOYED_URL#*://}" && html=$(curl -sfL "${DEPLOYED_URL}/") && echo "${html}" | grep -qF "${host}/s/" && curl -sf -o /dev/null "${DEPLOYED_URL}/admin"
```

## Rollback

Revert the commit on `main`. The next convergence applies the previous desired
state; nothing was changed out of band, so there is nothing else to undo.

## Common failures

- **A `WIRING_*` secret is missing at deploy**: an infrastructure lane upstream
has not applied for this environment yet. Within one convergence the plan
runs it first; on its own, re-run that lane.
- **The smoke fails right after a first deploy**: a new workers.dev route can
answer 4xx for a few seconds and the lane retries. A failure that persists
is a regression in the deployed code.
29 changes: 29 additions & 0 deletions infra/terraform/cloudflare-kv/docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# cloudflare-kv — architecture

A `terraform` root at `infra/terraform/cloudflare-kv/terraform`.

- **State** lives in the Orun Cloud HTTP state backend — no local state and
no state bucket to manage.
- **Credentials are brokered per run** from the workspace's provider
connections and resolved by name; none is stored in this repository.
- **Adoption** (`adopt.tf`): when state is empty but the resource already
exists, plan-time import adopts it instead of failing.

## Resources

- `cloudflare_workers_kv_namespace.app_kv`

## Published outputs

Written as job-output secrets on each environment after an apply; deploy
lanes downstream resolve them by name.

| Secret | Terraform output |
| ---------------------- | ---------------- |
| `WIRING_CLOUDFLARE_KV` | `wiring` |

## Resolved at run time (names only)

- `CLOUDFLARE_ACCOUNT_ID`
- `CLOUDFLARE_API_TOKEN`
- `TF_VAR_cloudflare_account_id`
19 changes: 19 additions & 0 deletions infra/terraform/cloudflare-kv/docs/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# cloudflare-kv

Provisions the Cloudflare KV namespace the app binds (stage and prod)

Terraform-managed infrastructure, planned and applied per environment by its CI lane.

| | |
| ------------ | ---------------------------------------------------------------------------------------------------- |
| Type | `terraform` |
| Source | `infra/terraform/cloudflare-kv` |
| Environments | `stage`: `plan-only`, `apply` on a push to `main` · `prod`: `plan-only`, `apply` on a push to `main` |

## Depends on

- (none)

## Depended on by

- **web** — The Platforms Starter Kit (multi-tenant subdomains, tenants in Workers KV; Next.js on Cloudflare Workers + Static Assets via @opennextjs/cloudflare, per environment)
20 changes: 20 additions & 0 deletions infra/terraform/cloudflare-kv/docs/runbook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# cloudflare-kv — runbook

## How it runs

Pull requests plan it; a merge to `main` applies it to `stage`, `prod`.
CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`;
the plan orders a component after everything it depends on.

## Rollback

Revert the commit on `main`. The next convergence applies the previous desired
state; nothing was changed out of band, so there is nothing else to undo.

## Common failures

- **Provider authentication fails**: the workspace's provider connection is
missing or revoked. Reconnect it in the console; credentials are brokered
from it per run.
- **"Already exists" on a first apply**: state is empty but the resource is
not. `adopt.tf` imports it at plan time; if it still fails, the resource was renamed outside Terraform.
11 changes: 0 additions & 11 deletions kiox.lock

This file was deleted.

6 changes: 0 additions & 6 deletions kiox.yaml

This file was deleted.

12 changes: 1 addition & 11 deletions repo-blueprint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,6 @@ modules:
source: baseline
from: turbo.json
to: turbo.json
- name: root-kiox
mode: copy
source: baseline
from: kiox.yaml
to: kiox.yaml
- name: root-kiox-lock
mode: copy
source: baseline
from: kiox.lock
to: kiox.lock
- name: root-gitignore
mode: copy
source: baseline
Expand Down Expand Up @@ -406,7 +396,7 @@ phases:
await: "One convergence is deploying the product: the KV namespace first, then the app built with its id, on stage and prod side by side. The Next.js build is the long pole; nothing is stuck."
done: "{{ .inputs.reponame }} is live on stage and prod — {{ .meta.files }} files on main, branded as {{ .inputs.productname }}, tenants answering at /s/<tenant> on workers.dev. That took {{ .meta.elapsed }}."
failed: "The product did not come up. The failing lane above names the component — the KV apply, or the app's build, deploy or smoke — and a provider error is in its log; whatever deployed is still there."
modules: [ai-deployment, ai-operations, cloudflare-kv, discovery-roots, github-workflows, rebrand-values, root-gitignore, root-intent, root-kiox, root-kiox-lock, root-package-json, root-pnpm-lock, root-pnpm-workspace, root-readme, root-turbo, tooling-eslint, tooling-tsconfig, tooling-wire, vscode, web, web-tests]
modules: [ai-deployment, ai-operations, cloudflare-kv, discovery-roots, github-workflows, rebrand-values, root-gitignore, root-intent, root-package-json, root-pnpm-lock, root-pnpm-workspace, root-readme, root-turbo, tooling-eslint, tooling-tsconfig, tooling-wire, vscode, web, web-tests]
# THE PLATFORM MUST BE ABLE TO SEE THE REPOSITORY BEFORE IT EXISTS. Every
# phase lands a pull request that files under its task, and the platform
# learns of a PR only through the GitHub App installation on the account
Expand Down
2 changes: 1 addition & 1 deletion specs/epics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ folder is the adoption; the merge creates the epic in the workspace.

| Epic | Cluster | Status | What it is |
|------|---------|--------|------------|
| [`platforms-starter-kit/`](./platforms-starter-kit/) | **PS** | ✅ Shipped | Vercel's Platforms Starter Kit, equivalent in code and function, on Cloudflare Workers with tenants in Workers KV — and an Orun baseline that instantiates it in one landing, live on workers.dev before any custom domain (PS4) |
| [`platforms-starter-kit/`](./platforms-starter-kit/) | **PS** | ✅ Shipped (`baseline-v1`); live bootstrap pending | Vercel's Platforms Starter Kit, equivalent in code and function, on Cloudflare Workers with tenants in Workers KV — and an Orun baseline that instantiates it in one landing, live on workers.dev before any custom domain (PS4) |

As-built ≠ intent: what shipped lives in each epic's `IMPLEMENTATION-STATUS.md`.
Loading
Loading