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
43 changes: 43 additions & 0 deletions ai/context/current.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# commerce — 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 storefront built from it;
the two pages that do are [operations.md](operations.md) and
[deployment.md](deployment.md).

## What it is

Vercel's Next.js Commerce (the Shopify headless storefront) on Cloudflare
Workers + Static Assets through `@opennextjs/cloudflare`, its Next.js cache in
an R2 bucket and two Durable Objects the Worker exports, packaged as an Orun
baseline: `orun new --blueprint repo-blueprint.yaml` builds a new storefront in
its own repository and takes it to live on stage and prod in one landing
(`01-product`) — the R2 bucket applied before the Worker that binds it — then
records what went live (`02-docs`). With no Shopify store connected it serves
a bundled demo catalogue and a cookie cart; checkout asks for a payment
provider.

## Release

| | |
|---|---|
| Latest tag | `baseline-v1` (CM4, [#5](https://github.com/sourceplane/commerce/pull/5)) |
| On `main` since | CM5 — 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; the tokens minted, a real R2 apply, a real `wrangler deploy` with the bucket and Durable Object bindings, the probes and a real Shopify store are still to come (risks CM-P, CM-M) |

## Where to read

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

## Next

1. Bootstrap one storefront from the next tag against a workspace and record
its timings; its deploy answers CM-M, and it closes CM-P. Connect a Shopify
development store to it once.
2. Cut the next `baseline-vN` with `tag.yml` so the registry can pin CM5.
20 changes: 20 additions & 0 deletions ai/context/decisions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# commerce — 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 | The template is a Next.js App Router storefront; `next/og`, server actions and route handlers run in the Worker | `specs/epics/commerce/design.md` §2 |
| 2 | The incremental cache in R2, the tag cache (sharded) and the revalidation queue in Durable Objects the Worker exports — no D1, no KV | Tag revalidation needs strong consistency; KV is eventually consistent | design.md §3, §8, risk CM-F |
| 3 | `experimental.useCache`, not `cacheComponents`; partial prerendering off | A Worker built with Cache Components hangs on every request under the adapter (opennextjs-cloudflare#1450) | risk CM-A |
| 4 | The `next/og` font is read through the `ASSETS` binding when the filesystem has none | A Worker has no filesystem | risk CM-D |
| 5 | `wrangler.jsonc` is rendered per environment from the R2 root's wiring document, and committed as the fixture render; `dev` renders the fixture | The deploy lane checks the file exists before it builds; no root applies to `dev` | risks CM-J, CM-K |
| 6 | The Shopify facts are Worker secrets an owner sets once per environment, and optional: without them a bundled demo catalogue and a cookie cart, the switch outside `"use cache"` | A baseline goes live with no key the platform cannot broker; a cached demo answer would outlive the connected store | risks CM-B, CM-N, design.md §9 |
| 7 | One landing (`01-product`) then the record (`02-docs`); the plan applies the bucket before the Worker (`dependsOn: cloudflare-r2`, enforced on `main`, advisory on a pull request) | A landing has a fixed cost; the plan, not the phases, carries deploy order (cirrus-baseline since `baseline-v22`) | design.md §9 |
| 8 | The R2 root has its own key, `CLOUDFLARE_R2_TOKEN` from `r2-data` | `workers-deploy` grants no R2 | risk CM-L |
| 9 | The store's identity is one seam (`app/site.ts`), the origin is the request's own (no `SITE_URL`), and shipped prose says "store" — never the slug | The slug is an English word the rename would rewrite everywhere | risk CM-O, design.md §9 |
| 10 | `ci.yml` plans nothing while `intent.yaml` names `ws_CHANGE_ME`; `checks.yml` runs on pull requests only | A bootstrap cannot set a repository variable (replaced the `ORUN_CI` gate); the convergence watch takes the newest run on the merge sha from any workflow | IMPLEMENTATION-STATUS (CM4) |
| 11 | 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 (CM4), design.md §9 |
| 12 | orun is pinned only where it runs (the `orun-action` `version:` in each workflow); no kiox. Component docs are generated from the manifests and checked in CI | `kiox.yaml` pinned a version nothing ran; a hand-written copy of the dependency graph and bindings drifts silently | IMPLEMENTATION-STATUS (CM5), `tooling/catalog/gen-component-docs.py` |
17 changes: 17 additions & 0 deletions ai/context/open-risks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# commerce — 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/commerce/risks-and-open-questions.md`; this page lists only what
is still live, so it should be short.

| ID | Risk | State | What closes it |
|---|---|---|---|
| CM-P | No live bootstrap yet: the repository created and linked, the two tokens minted, a real `terraform apply`, a real `wrangler deploy` with the R2 and Durable Object bindings, the probes and a real Shopify store are all unproven | OPEN | One bootstrap from a tag against a workspace |
| CM-M | The deploy uploads a Worker that binds the bucket with the `workers-deploy` token, which has no R2 permission; whether Cloudflare's upload check needs it is undocumented | OPEN | The first live deploy (if refused: give the deploy the `r2-data` key, not drop the binding) |

Accepted, and worth knowing before you change them: CM-E (images served
unoptimised), CM-F (a webhook racing a render), CM-H (Next/OpenNext versions
pinned together; mitigated), CM-I (upstream's own prettier check), CM-O (the
slug is an English word; gated), CM-Q (the bootstrap floor plans every edge
enforced), CM-R (a custom domain is the owner's step).
30 changes: 30 additions & 0 deletions apps/web/docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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 |
| --------------------------- | --------------- | ------------------------------------- |
| `NEXT_INC_CACHE_R2_BUCKET` | R2 bucket | `r2_bucket_name` from `cloudflare-r2` |
| `NEXT_CACHE_DO_QUEUE` | Durable Object | class `DOQueueHandler` |
| `NEXT_TAG_CACHE_DO_SHARDED` | Durable Object | class `DOShardedTagCache` |
| `WORKER_SELF_REFERENCE` | Service binding | Worker `commerce-web-__ENV__` |
| `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_R2_PROD`
- `WIRING_CLOUDFLARE_R2_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 storefront (Next.js on Cloudflare Workers + Static Assets via @opennextjs/cloudflare, per environment; R2 + Durable Objects as the Next.js cache; a bundled demo catalogue until a Shopify store is connected)

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-r2** — Provisions the Cloudflare R2 bucket 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
curl -sfL -o /dev/null "${DEPLOYED_URL}/" && robots=$(curl -sfL "${DEPLOYED_URL}/robots.txt") && echo "${robots}" | grep -qiF "Host: ${DEPLOYED_URL}"
```

## 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-r2/docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# cloudflare-r2 — architecture

A `terraform` root at `infra/terraform/cloudflare-r2/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_r2_bucket.app`

## 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_R2` | `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-r2/docs/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# cloudflare-r2

Provisions the Cloudflare R2 bucket the app binds (stage and prod)

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

| | |
| ------------ | ---------------------------------------------------------------------------------------------------- |
| Type | `terraform` |
| Source | `infra/terraform/cloudflare-r2` |
| 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 storefront (Next.js on Cloudflare Workers + Static Assets via @opennextjs/cloudflare, per environment; R2 + Durable Objects as the Next.js cache; a bundled demo catalogue until a Shopify store is connected)
20 changes: 20 additions & 0 deletions infra/terraform/cloudflare-r2/docs/runbook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# cloudflare-r2 — 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 R2 bucket first, then the storefront built with its name, 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 }}, the storefront answering with its demo catalogue until a Shopify store is connected. That took {{ .meta.elapsed }}."
failed: "The product did not come up. The failing lane above names the component — the R2 apply, or the storefront's build, deploy or smoke — and a provider error is in its log; whatever deployed is still there."
modules: [ai-deployment, ai-operations, cloudflare-r2, 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-r2, 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 |
|------|---------|--------|------------|
| [`commerce/`](./commerce/) | **CM** | ✅ Shipped | Vercel's Next.js Commerce, equivalent in code and function, on Cloudflare Workers with the Shopify Storefront API as its backend — and an Orun baseline that instantiates it in one landing, live on a bundled demo catalogue until a store is connected (CM4) |
| [`commerce/`](./commerce/) | **CM** | ✅ Shipped (`baseline-v1`); live bootstrap pending | Vercel's Next.js Commerce, equivalent in code and function, on Cloudflare Workers with the Shopify Storefront API as its backend — and an Orun baseline that instantiates it in one landing, live on a bundled demo catalogue until a store is connected (CM4) |

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