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
1 change: 1 addition & 0 deletions specs/epics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ folder is the adoption; the merge creates the epic in the workspace.

| Epic | Cluster | Status | What it is |
|------|---------|--------|------------|
| [`catalyst-commerce/`](./catalyst-commerce/) | **CA** | In progress (CA0) | BigCommerce's Catalyst (Vercel's Catalyst by BigCommerce) on Cloudflare Workers, its BigCommerce reads cached in R2 and revalidated through Durable Objects, its route lookups in KV — and an Orun baseline that instantiates it in one landing, live before a store is connected (CA2) |

As-built ≠ intent: what shipped lives in each epic's `IMPLEMENTATION-STATUS.md`.
11 changes: 11 additions & 0 deletions specs/epics/catalyst-commerce/IMPLEMENTATION-STATUS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# catalyst-commerce — implementation status

| Milestone | State | Landed |
|---|---|---|
| CA0 — the spec | ✅ | CA-1 |
| CA1 — the storefront on Workers | planned | CA-2 |
| CA2 — a baseline | planned | CA-3 |

## Departures from the upstream template

Recorded as they land, from CA1 on.
33 changes: 33 additions & 0 deletions specs/epics/catalyst-commerce/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# catalyst-commerce — BigCommerce's Catalyst storefront on Cloudflare Workers

BigCommerce's Catalyst, the storefront Vercel lists as "Catalyst by
BigCommerce", as one Cloudflare Worker with Static Assets — its BigCommerce
reads in Next's data cache in R2, the tag cache and the revalidation queue in
Durable Objects, its route lookups in KV — live before a store is connected,
and an Orun baseline that takes a new storefront from nothing to live on stage
and prod in one landing.

| | |
|---|---|
| Status | In progress — CA0 on main |
| Upstream | [bigcommerce/catalyst](https://github.com/bigcommerce/catalyst) (`@bigcommerce/catalyst-core` 1.13.1, MIT), at `6faa4b5` (2026-10-27) |
| Reference | [commerce](https://github.com/sourceplane/commerce) — the same OpenNext, R2 and Durable Object shape for a storefront on a hosted commerce API; [kv-redis-starter](https://github.com/sourceplane/kv-redis-starter) for the KV root |
| Key | `CA` |

## Read in this order

1. [design.md](design.md) — the storefront, how each Vercel piece maps to
Cloudflare, the cache, the schema, the store before and after it is
connected, the session key, the tests, and the alternatives rejected.
2. [implementation-plan.md](implementation-plan.md) — the three landings.
3. [risks-and-open-questions.md](risks-and-open-questions.md).
4. [IMPLEMENTATION-STATUS.md](IMPLEMENTATION-STATUS.md) — what shipped, every
departure from upstream, and what was verified.

## Milestones

| Milestone | What it lands | Task |
|---|---|---|
| CA0 — the spec | this doc set and the three task contracts | CA-1 |
| CA1 — the storefront on Workers | `apps/web`, `packages/`, the R2 and KV roots, `tests/web` | CA-2 |
| CA2 — a baseline | the card, the build document, the rename, the tiers | CA-3 |
104 changes: 104 additions & 0 deletions specs/epics/catalyst-commerce/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# catalyst-commerce — design

## 1. The storefront

Catalyst is BigCommerce's Next.js storefront: home, categories, brands,
faceted search, product pages with options and variants, a cart, the store's
own checkout (BigCommerce's hosted checkout, reached from the cart), customer
accounts with orders, addresses and wish lists, a blog, web pages, gift
certificates, several languages (next-intl). Its data is the store's, read
over the Storefront GraphQL API by `@bigcommerce/catalyst-client`
(`packages/client`), the queries typed by gql.tada. Customers sign in through
Auth.js. Upstream lives in `core/` of a monorepo; here it is `apps/web`, and
the two workspace packages it needs, the client and its ESLint config, are
`packages/`.

## 2. Vercel → Cloudflare

OpenNext builds the storefront into one Worker with Static Assets, the
commerce baseline's shape. Catalyst already supports Cloudflare: it ships a
KV adapter for its route cache (`lib/kv/adapters/cloudflare-kv.ts`) and an
OpenNext template for BigCommerce's own hosting. The pieces Vercel provided:
the data cache (→ R2), `revalidateTag` (→ a Durable Object tag cache),
stale-while-revalidate (→ a Durable Object queue), the Runtime Cache for route
lookups (→ KV, Catalyst's adapter), `AUTH_TRUST_HOST` (→ a Worker var) and
the project's env vars (→ Orun secrets, set as Worker secrets by the deploy).

## 3. The cache

Every query carries `next: { revalidate, tags }` — the window
`DEFAULT_REVALIDATE_TARGET`, an hour by default — so the answers live in
Next's data cache, which OpenNext keeps in R2. Cart, checkout and customer
reads skip the cache; the server actions that change them revalidate their
tags. Catalyst does not use Cache Components, so nothing upstream is turned
off for the adapter (unlike saleor-commerce and your-next-store, whose Cache
Components hang on workerd).

## 4. The schema

Upstream generates `bigcommerce.graphql` from the live store at every build.
BigCommerce publishes the Storefront schema (bigcommerce/checkout-sdk-js,
`packages/core/schema/storefront.graphql`, MIT); committed as
`apps/web/bigcommerce.graphql`, every Catalyst query typechecks against it,
so the build, the type check, the lint and the tests need no store.
`generate:schema` refreshes it from a connected store.

## 5. Before a store, and after

A fresh product has no store. `lib/bigcommerce-connection.ts` is the one seam:
connected when the store hash and a storefront token are both set.
Unconnected, `next.config.ts` writes default settings instead of reading the
store's, the client defaults to channel 1, the sitemap, `robots.txt` and
favicon answer without the store, the proxy rewrites `/` to a static
`connect-store` page and redirects everything else to `/`, and the `[locale]`
layout redirects too (a path the proxy's matcher skips, `/api/<x>`, lands
there as a locale). Connected, upstream runs unchanged. The store's settings
are optional Orun secrets: the build reads the store's settings with them,
and the deploy sets them as Worker secrets (`tooling/wire/worker-secrets.mjs`),
because the Worker reads them on every request.

## 6. The session key

Auth.js needs `AUTH_SECRET`. There is no database to generate it in (the
Supabase starters keep theirs in Postgres), so `worker.ts` wraps OpenNext's
Worker and hands it one: the owner's `AUTH_SECRET` if set, otherwise a key the
environment generated the first time one was needed and keeps in its KV
namespace (`lib/auth-secret.ts`). KV is eventually consistent; the value read
back after the write is the one used, so isolates converge, and a session
signed in a fresh store's first moment may end once.

## 7. Tests

The storefront's own vitest suite (upstream's, 286 tests) runs as it is, with
a `URLPattern` polyfill where Node 22 lacks it. `tests/web` covers the seam,
the connection, the proxy before a store, the store-free routes, the health
route and the session key. The end-to-end tier serves the built Worker as
born and then connected to a stand-in BigCommerce — graphql-js over the
published schema with one default resolver — and proves the cache: no reads
on a second visit, a change held for the window and then re-read in the
background. A canary storefront token proves no build artifact carries it.

## 8. The rename

The rename engine is the commerce baseline's. The slug, its Pascal form and
its env prefix appear nowhere in upstream; the store's name is one seam,
`SITE_NAME` in `lib/site.ts`, the title before a store is connected and the
fallback when a store has none. `Catalyst` and `BigCommerce` are the
storefront's own words and are never renamed.

## 9. Alternatives rejected

- **A bundled demo catalogue** (the commerce baseline's demo mode): Catalyst
has dozens of deep typed queries; faking them in the Worker would be a
second storefront. The connect page is the template's unconfigured state
made explicit.
- **Upstream's self-fetch revalidation queue** (its BigCommerce-hosting
template): it exists because a dispatch-namespace script cannot have a
self-reference binding; a plain Worker can, so OpenNext's Durable Object
queue (with its retries) is used, as commerce does.
- **The session key in Terraform state** (`random_password`): it would sit in
the state file; generated at run time it never leaves Cloudflare.
- **Turbopack**: its middleware bundle misses `@opentelemetry/api`'s ESM
build on OpenNext; webpack bundles.
- **Trimming the Worker to Workers Free** (3.4 MiB → under 3): it would mean
dropping Catalyst's features; Workers Paid is stated instead.
29 changes: 29 additions & 0 deletions specs/epics/catalyst-commerce/epic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The epic's declaration. metadata.name equals the directory name; metadata.key
# is the task-key prefix this epic reserves (CA → CA-1, CA-2, …). Owner, target
# date and health are the platform's — never written here.
apiVersion: orun.io/v1
kind: Epic
metadata:
name: catalyst-commerce
key: CA
spec:
title: "BigCommerce's Catalyst storefront on Cloudflare Workers"
summary: "BigCommerce's Catalyst (Vercel's Catalyst by BigCommerce) — home, categories, brands, faceted search, product pages, a cart, BigCommerce's checkout, accounts, wish lists, a blog — runs as one Cloudflare Worker with Static Assets, its BigCommerce reads in Next's data cache in R2 with the tag cache and revalidation queue in Durable Objects and its route lookups in KV, live before a store is connected, and becomes an Orun baseline that takes a new storefront from nothing to live on stage and prod in one landing."
state: started
milestones:
- name: "CA0 — the spec"
exitCriteria:
- "the repository is born with its intent, CI, tooling and spec index, and this doc set and the task contracts are on main"
tasks: [CA-1]
- name: "CA1 — the storefront on Workers"
exitCriteria:
- "apps/web is upstream's storefront built by OpenNext into one Worker with Static Assets, the R2 incremental cache, the Durable Object tag cache and queue, and Catalyst's own KV route cache in a namespace Terraform provisions"
- "the GraphQL types are generated from BigCommerce's published Storefront schema; typecheck, lint, test (upstream's suite and tests/web) and build are green with no store"
- "with no store connected the storefront says \"Connect your BigCommerce store\" and sends every page there, never a 500; connected, wrangler dev serves the catalogue, reuses the cache and revalidates after its window"
tasks: [CA-2]
- name: "CA2 — a baseline"
exitCriteria:
- "blueprint.yaml (the console card) and repo-blueprint.yaml (the build) take a new storefront from nothing to live on stage and prod in one landing, then record it"
- "a storefront built from it carries the product only, renamed throughout to its own name, repository, Worker, bucket and namespace, with Catalyst's licence intact"
- "Baseline CI is green: contract tests, the wiring path, generated component docs, the blueprint read by the pinned orun, the leak gate, the offline bootstrap and the end-to-end tier — the stage lane's steps in a staged tree, served as born, then connected to a stand-in BigCommerce and browsed"
tasks: [CA-3]
18 changes: 18 additions & 0 deletions specs/epics/catalyst-commerce/implementation-plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# catalyst-commerce — implementation plan

Three landings, one per milestone, each a pull request merged on green.

1. **CA0 — the spec (CA-1).** This doc set and the three task contracts.
2. **CA1 — the storefront on Workers (CA-2).** Upstream's `core/` into
`apps/web` and its `client` and `eslint-config-catalyst` into `packages/`,
the lockfile seeded from upstream's; OpenNext with the R2 incremental
cache and the Durable Object tag cache and queue; the KV root
(kv-redis-starter's) for Catalyst's route cache; the vendored Storefront
schema; the connection seam and the connect page; the Worker entry and the
generated session key; the store's settings as optional secrets and Worker
secrets; `tests/web`. Done when typecheck, lint, test and build are green
with no store, and `wrangler dev` serves it unconnected and connected.
3. **CA2 — a baseline (CA-3).** The card and the build document, the rename
(identity and seam), the deployment record, the phase pages, the context
pack, and every tier of Baseline CI, including the end-to-end tier with a
stand-in BigCommerce.
13 changes: 13 additions & 0 deletions specs/epics/catalyst-commerce/risks-and-open-questions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# catalyst-commerce — risks and open questions

| ID | Risk | State | Notes |
|---|---|---|---|
| CA-A | `baseline-v1` is not yet proven live | OPEN | Proven offline in Baseline CI: the offline bootstrap with the blueprint's own hooks, the stage lane's steps in a staged tree, the product served as born and connected to a stand-in. A real store's checkout and sign-in, the real applies and the Worker secrets on a real account are unproven. |
| CA-B | Workers Paid | OPEN | The Worker is 3.4 MiB gzipped (16.8 MiB raw); Free allows 3 MiB. Stated on the card. |
| CA-C | Next's Node.js middleware (`proxy.ts`) on OpenNext | ACCEPTED | `opennextjs-cloudflare build` calls it experimental; the e2e drives the proxy on every request, unconnected and connected. |
| CA-D | Next 16.3.8, webpack | ACCEPTED | Inside upstream's `~16.3.4`; @opennextjs/cloudflare 1.20.11 needs `>=16.3.8`. Turbopack's middleware bundle cannot resolve `@opentelemetry/api`. |
| CA-E | The schema is vendored | ACCEPTED | BigCommerce's published Storefront schema (2026-08-31). A store on a newer API may have fields the committed schema lacks; `generate:schema` refreshes it. |
| CA-F | The session key in KV | ACCEPTED | Generated on first use; KV is eventually consistent, so two first requests in different places may each write one and a session signed in that moment ends once. `AUTH_SECRET` (an Orun secret) replaces it. |
| CA-G | The stand-in is not a catalogue | ACCEPTED | It answers every query from the schema, deterministically; no checkout, sign-in or cart mutation is completed against it. |
| CA-H | `pnpm dev` needs Node 24 | ACCEPTED | The proxy uses `URLPattern`, a global in Node 24 and in workerd, not in Node 22 (the lanes' Node); the tests polyfill it. |
| CA-I | A removed store secret stays on the Worker | ACCEPTED | The deploy sets the secrets that exist and deletes none; `wrangler secret delete` removes one (operations.md). |
14 changes: 14 additions & 0 deletions tasks/CA-1.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: orun.io/v1
kind: TaskContract
metadata:
name: CA-1
title: "The catalyst-commerce epic doc set"
spec:
goal: The epic's README, design, plan, risks and status, and the three task contracts, are on main
affects:
- specs/epics/catalyst-commerce
- tasks
doneWhen:
- epic.yaml, the README, the design, the implementation plan, the risks and the status are on main
- the three task contracts are on main
gates: []
20 changes: 20 additions & 0 deletions tasks/CA-2.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: orun.io/v1
kind: TaskContract
metadata:
name: CA-2
title: "The storefront on Workers"
spec:
goal: BigCommerce's Catalyst runs as one Cloudflare Worker with Static Assets, its BigCommerce reads cached in R2 and revalidated through the Durable Object tag cache and queue, its route lookups in KV, live before a store is connected
affects:
- apps/web
- packages
- infra/terraform/cloudflare-r2
- infra/terraform/cloudflare-kv
- tests/web
- pnpm-lock.yaml
- pnpm-workspace.yaml
- README.md
doneWhen:
- pnpm typecheck, lint, test and build are green with no BigCommerce store
- wrangler dev serves the unconnected storefront without a 500, and a connected one from cached reads revalidated after their window
gates: []
22 changes: 22 additions & 0 deletions tasks/CA-3.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: orun.io/v1
kind: TaskContract
metadata:
name: CA-3
title: "catalyst-commerce becomes an Orun baseline"
spec:
goal: A new BigCommerce storefront can be built from this repository — the console card, the build document, the rename, the deployment record — and every tier of Baseline CI proves it offline
affects:
- blueprint.yaml
- repo-blueprint.yaml
- .baseline
- BOOTSTRAP.md
- docs/phases
- ai/context
- hooks
- testing
- tooling
- .github/workflows
doneWhen:
- every tier of Baseline CI passes
- the card reads with the platform's own reader
gates: []
Loading