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
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** | Draft | Vercel's Platforms Starter Kit, equivalent in code and function, on Cloudflare Workers with tenants in Workers KV |
| [`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 |

As-built β‰  intent: what shipped lives in each epic's `IMPLEMENTATION-STATUS.md`.
114 changes: 109 additions & 5 deletions specs/epics/platforms-starter-kit/IMPLEMENTATION-STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,115 @@ the code departed from `design.md` or from the upstream template.

| Milestone | State | PR |
|---|---|---|
| PS0 β€” the spec | | |
| PS1 β€” the platform on Workers | | |
| PS2 β€” the KV namespace from Terraform | | |
| PS3 β€” ready to instantiate | | |
| PS0 β€” the spec | βœ… Shipped | [#1](https://github.com/sourceplane/platforms-starter-kit/pull/1) |
| PS1 β€” the platform on Workers | βœ… Shipped | [#2](https://github.com/sourceplane/platforms-starter-kit/pull/2) |
| PS2 β€” the KV namespace from Terraform | βœ… Shipped | [#3](https://github.com/sourceplane/platforms-starter-kit/pull/3) |
| PS3 β€” ready to instantiate | βœ… Shipped | [#4](https://github.com/sourceplane/platforms-starter-kit/pull/4) |

## Departures from the upstream template

_None yet._
### `lib/redis.ts` is Workers KV behind the Upstash client's surface

Upstream: `new Redis({ url: KV_REST_API_URL, token: KV_REST_API_TOKEN })`
from `@upstash/redis`. Here: an object with `get / set / del / keys / mget`
over `getCloudflareContext().env.KV`, the same `subdomain:<name>` keys and
JSON records. `keys()` accepts only `<prefix>*` (KV lists by prefix) and
follows the list cursor; `mget` is `get` per key. `@upstash/redis` is gone
from the dependencies. `lib/subdomains.ts` and `app/actions.ts` are
byte-for-byte upstream.

### `export const dynamic = 'force-dynamic'` on `app/admin/page.tsx`

Upstream's admin page is rendered on demand only because every Upstash
command is a `cache: 'no-store'` fetch, which opts the route out of static
rendering. A KV binding is not a fetch, so without this line `next build`
would pre-render the page β€” with no binding, or with an empty list that
`revalidatePath` could never refresh through the read-only static-assets
cache. The build now reports `Ζ’ /admin`.

### Cloudflare Web Analytics instead of `@vercel/speed-insights`

`components/analytics.tsx` renders the beacon script when
`NEXT_PUBLIC_CF_BEACON_TOKEN` is set at build time; otherwise nothing.
`@vercel/speed-insights` and the unused `@vercel/analytics` are gone from
the dependencies; `app/layout.tsx` mounts `<CloudflareWebAnalytics />`
where `<SpeedInsights />` was.

### `extractSubdomain` is exported from `proxy.ts`

One word (`export`) so `tests/web` can exercise the routing decision as a
pure function. The body is upstream's, Vercel preview branch included.

### `NEXT_PUBLIC_ROOT_DOMAIN` is a build-time value, not a wrangler var

`next build` inlines it into the server, proxy and client bundles (a probe
build left no `process.env.NEXT_PUBLIC_ROOT_DOMAIN` read in `.next/server`),
so the component's `buildCommand` sets it from the environment's
`BASE_DOMAIN` in `intent.yaml` and `wrangler.template.jsonc` carries no
copy. Locally it is `.env.local` for `next dev` and the code's
`localhost:3000` default for `wrangler dev` over a plain build. The Upstash
`KV_REST_API_*` variables the template read no longer exist.

### `next.config.ts`

`output: "standalone"` + `outputFileTracingRoot` (what `@opennextjs/cloudflare`
bundles), and `initOpenNextCloudflareForDev()` so `next dev` reaches the KV
binding declared in the rendered `wrangler.jsonc`. The upstream comment
block about Vercel Speed Insights headers went with the script.

### The monorepo wrapper

`package.json` is `@app/web` with the Workers build script; `next` is
pinned to `16.3.8` (below, Versions); `@cloudflare/workers-types` and
`wrangler` are dev dependencies; `cloudflare-env.d.ts` declares
`CloudflareEnv.KV`; `eslint.config.mjs` is the workspace's shared config
(upstream ships no lint setup). `tests/web/tsconfig.json` turns
`noUncheckedIndexedAccess` off because it compiles upstream's `proxy.ts`,
which indexes `split()` results.

### `.gitignore`: `!.dev.vars.example`

The skeleton's `.dev.vars.*` pattern swallowed the committed example; the
negation keeps it tracked while every real `.dev.vars` stays ignored.

### The KV root's wiring keys

The factory's copy of the baseline root emitted `app_kv_kv_id` /
`app_kv_kv_title` (a doubled `kv` from the rename of the baseline's
idempotency namespace). This repository's root emits `app_kv_id` /
`app_kv_title`, the names `wrangler.template.jsonc` and `wiring.fixture.json`
use, and its comments and locals speak of the tenant store.

## Verified

- Local: `pnpm run wire:fixture`, `pnpm typecheck`, `pnpm lint` (two
upstream `any` warnings, no errors), `pnpm test` (19 tests: the adapter
over a fake namespace with cursor paging, `lib/subdomains.ts`,
`extractSubdomain`, the proxy's rewrite and redirect, `cn`), `pnpm build`
green (`β—‹ /`, `β—‹ /_not-found`, `Ζ’ /admin`, `Ζ’ /s/[subdomain]`, proxy
bundled as Node.js middleware).
- `wrangler dev` over `.open-next/worker.js` with a local KV: `/` 200
(landing), `Host: nope.localhost:3000` 404 (not-found page), `/admin` 200,
`/admin` on a tenant host 307 β†’ `/`, CSS chunk 200. The create flow
driven in a browser (the emoji picker and the form need JavaScript; a
no-JS POST to the static landing page is served from the prerender cache)
wrote `subdomain:acme`, after which `Host: acme.localhost:3000` is 200
with the emoji, `/s/acme` is 200 and `/admin` lists it; delete from
`/admin` emptied the namespace and the tenant host is 404 again, with
`revalidatePath('/admin')` a silent no-op.
- `terraform init -backend=false && terraform validate` green on
`infra/terraform/cloudflare-kv` (cloudflare 4.52.9, external 2.4.2).
- CI: `Checks` green on #2 and #3 (install, wire, typecheck, lint, test,
build).
- Not verified: the KV apply and a live deploy, which need the product
linked to an Orun workspace with a Cloudflare connection, and tenant
hostnames on a real zone (a wildcard record and a Worker route).

## Versions

| Package | Version | Why |
|---|---|---|
| next | 16.3.8 | newest inside `@opennextjs/cloudflare` 1.20.11's peer range; 16.4.x fails at worker boot (`preview-props.json` manifest) |
| @opennextjs/cloudflare | ^1.20.11 | static-assets incremental cache + `populateCache local`; `initOpenNextCloudflareForDev` |
| wrangler | ^4.151.0 | compatibility_date 2026-10-01; local KV for `wrangler dev` |
| @cloudflare/workers-types | ^5.20261014.1 | `KVNamespace` for `CloudflareEnv.KV` (the 4.x line is no longer published) |
4 changes: 2 additions & 2 deletions specs/epics/platforms-starter-kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ The upstream code stays the code: the proxy, the pages, the server actions, `lib

| Field | Value |
|-------|-------|
| Status | Draft |
| Status | βœ… Shipped β€” PS0–PS3 landed (#1, #2, #3, #4) |
| Cluster | **PS** (PS0–PS3) |
| Owner(s) | `apps/web` (the app) Β· `tests/web` (adapter and proxy tests) Β· `infra/terraform/cloudflare-kv` (the namespace) |
| Builds on | `cirrus-baseline` conventions β€” the `cloudflare-kv` Terraform root and the `@@wiring(...)@@` per-environment render; intent, components, `checks.yml` gate, gated `ci.yml` |
| Upstream | [vercel/platforms](https://github.com/vercel/platforms) |
| Changes | Adds the Workers build, the monorepo wrapper, `lib/redis.ts` over KV, tests, the KV root and the deploy contract; swaps Vercel Speed Insights for the Cloudflare Web Analytics beacon; makes `/admin` explicitly dynamic |
| Decisions locked | (1) OpenNext on Workers + Static Assets. (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. (3) The adapter keeps the Upstash surface; app code is untouched. (4) `wrangler.jsonc` is rendered per environment from the wiring document; never committed. (5) The root domain is one knob β€” the environment's `BASE_DOMAIN` in `intent.yaml`, inlined by `next build`. |
| Gate | PS1 is the first user-visible rung. PS2 needs a workspace with a Cloudflare connection to apply; it is verified by `terraform validate` and `plan`. |
| Shipped as | |
| Shipped as | `main` after [#4](https://github.com/sourceplane/platforms-starter-kit/pull/4); verified locally under `wrangler dev` with a local KV, `terraform validate` on the root, deploy gated until a workspace is linked |

## Read order

Expand Down
2 changes: 1 addition & 1 deletion specs/epics/platforms-starter-kit/epic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ metadata:
spec:
title: "Vercel's Platforms Starter Kit on Cloudflare Workers, tenants in Workers KV"
summary: "The Vercel platforms template β€” a multi-tenant app where every tenant is a subdomain routed by a Next.js proxy, created from a landing form with an emoji and managed from an admin page, with the tenant records in Upstash Redis β€” runs on Cloudflare Workers + Static Assets through @opennextjs/cloudflare with Workers KV standing in for Redis behind the same client surface, the namespace provisioned by Terraform through Orun and bound per environment, inside the Cirrus baseline's repository conventions. It is the Cloudflare-only multi-tenant port the coverage analysis ranks first."
state: backlog
state: completed
milestones:
- name: "PS0 β€” the spec"
exitCriteria:
Expand Down
8 changes: 4 additions & 4 deletions specs/epics/platforms-starter-kit/implementation-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
Milestones land in order; each task is one pull request on an
`orun/PS-n-<slug>` branch with an `Orun-Task: PS-n` trailer.

## PS0 β€” the spec
## PS0 β€” the spec βœ…

This doc set, `epic.yaml` and the task contracts, merged to `main`.

**Done when**
- the five documents and `epic.yaml` are on `main`
- `tasks/PS-1..PS-4.TaskContract.yaml` exist

## PS1 β€” the platform on Workers
## PS1 β€” the platform on Workers βœ…

`apps/web` is the upstream template with the Workers build around it and
`lib/redis.ts` speaking the Upstash surface over the `KV` binding;
Expand All @@ -24,7 +24,7 @@ This doc set, `epic.yaml` and the task contracts, merged to `main`.
- `wrangler dev` answers `/` with the landing page (200), an unknown tenant host (`Host: nope.localhost:3000`) with the not-found page (404), and after a tenant is created through the landing form, `Host: <tenant>.localhost:3000` with the tenant page (200) and `/admin` with it listed
- `/admin` is built as a dynamic route (`Ζ’`), never pre-rendered

## PS2 β€” the KV namespace from Terraform
## PS2 β€” the KV namespace from Terraform βœ…

`infra/terraform/cloudflare-kv` provisions a namespace per environment and
publishes `{app_kv_id, app_kv_title}` as the `WIRING_CLOUDFLARE_KV`
Expand All @@ -36,7 +36,7 @@ document; `apps/web/component.yaml` depends on it and declares the
- the root's wiring keys match the template's tokens (`wire:fixture` renders the same keys)
- the component's `secretEnv` names match the root's `secretOutputs`

## PS3 β€” ready to instantiate
## PS3 β€” ready to instantiate βœ…

README (run, test, preview, deploy, the wildcard domain), `IMPLEMENTATION-STATUS.md`
with PRs and departures, epic `completed`.
Expand Down
Loading