diff --git a/specs/epics/README.md b/specs/epics/README.md index 29155e3..2e81209 100644 --- a/specs/epics/README.md +++ b/specs/epics/README.md @@ -7,5 +7,6 @@ folder is the adoption; the merge creates the epic in the workspace. | Epic | Cluster | Status | What it is | |------|---------|--------|------------| +| [`shopware-commerce/`](./shopware-commerce/) | **SW** | In progress (SW0) | Shopware's Next.js starter (a Next.js Commerce fork on Shopware 6's Store API) on Cloudflare Workers, its Store API reads cached in R2 and revalidated by a bearer-checked route — and an Orun baseline that instantiates it in one landing, live before a store is connected (SW2) | As-built ≠ intent: what shipped lives in each epic's `IMPLEMENTATION-STATUS.md`. diff --git a/specs/epics/shopware-commerce/IMPLEMENTATION-STATUS.md b/specs/epics/shopware-commerce/IMPLEMENTATION-STATUS.md new file mode 100644 index 0000000..2b0f889 --- /dev/null +++ b/specs/epics/shopware-commerce/IMPLEMENTATION-STATUS.md @@ -0,0 +1,11 @@ +# shopware-commerce — implementation status + +| Milestone | State | Landed | +|---|---|---| +| SW0 — the spec | ✅ | SW-1 | +| SW1 — the storefront on Workers | planned | SW-2 | +| SW2 — a baseline | planned | SW-3 | + +## Departures from the upstream template + +Recorded as they land, from SW1 on. diff --git a/specs/epics/shopware-commerce/README.md b/specs/epics/shopware-commerce/README.md new file mode 100644 index 0000000..d030fd1 --- /dev/null +++ b/specs/epics/shopware-commerce/README.md @@ -0,0 +1,37 @@ +# shopware-commerce — Shopware's Next.js starter on Cloudflare Workers + +**Shopware's starter is Vercel's Next.js Commerce rebuilt on Shopware 6's +Store API, with Next.js 16's Cache Components on. The port keeps every one +of its `"use cache"` reads — their lifetimes and their tags — and moves them +onto Cloudflare: one Worker, its data cache in R2, its tag cache in Durable +Objects, and the revalidation route upstream left as a stub made to work. +Cache Components are the one thing the adapter cannot run yet. A product +built from it deploys before its owner connects a shop, and sells from +theirs once they set its domain and access key.** + +| | | +|---|---| +| Status | In progress — SW0 on main | +| Upstream | [shopwareLabs/nextjs-shopware-starter](https://github.com/shopwareLabs/nextjs-shopware-starter) (MIT, `license.md`), at `7066aa7` (2026-05-20) | +| Reference | [commerce](https://github.com/sourceplane/commerce) — the same OpenNext, R2 and Durable Object shape for a Next.js Commerce storefront on a hosted commerce API | +| Key | `SW` | + +## Read in this order + +1. [design.md](design.md) — the storefront, how each Vercel piece maps to + Cloudflare, the cache, build-time settings, the unconnected store, + revalidation, the tests, and the alternatives rejected. +2. [implementation-plan.md](implementation-plan.md) — the milestones and + what each one lands. +3. [risks-and-open-questions.md](risks-and-open-questions.md) — what is not + proven, and what was accepted. +4. [IMPLEMENTATION-STATUS.md](IMPLEMENTATION-STATUS.md) — what shipped, and + every departure from upstream. + +## Milestones + +| Milestone | What it lands | Task | +|---|---|---| +| SW0 — the spec | this doc set and the three task contracts | SW-1 | +| SW1 — the storefront on Workers | `apps/web`, the R2 root, `tests/web` | SW-2 | +| SW2 — a baseline | the card, the build document, the rename, the tiers | SW-3 | diff --git a/specs/epics/shopware-commerce/design.md b/specs/epics/shopware-commerce/design.md new file mode 100644 index 0000000..ff2da82 --- /dev/null +++ b/specs/epics/shopware-commerce/design.md @@ -0,0 +1,127 @@ +# shopware-commerce — design + +## 1. The storefront + +Shopware's Next.js starter (shopwareLabs/nextjs-shopware-starter `7066aa7`): +a fork of Vercel's Next.js Commerce, Next.js 16.2 App Router with Cache +Components on. Routes: the home page (a three-item grid and a carousel, each +one category's products), `/search` and `/search/` with sorting +and filters, `/product/` with variants, CMS pages under `/cms/`, +Open Graph images (`next/og`), the sitemap and robots.txt. Every Store API +call goes through `@shopware/api-client` 1.4 (`lib/shopware/api.ts`), and +every read in `lib/shopware/index.ts` is a `"use cache"` function with +`cacheLife("hours")` and the tag `collections` or `products`. The cart is +the shop's, kept by its `sw-context-token` in a cookie and changed by server +actions. Upstream has no checkout of its own and its revalidation route is a +stub; it reads every setting from the environment at request time. + +## 2. Vercel → Cloudflare + +| Vercel | Here | +|---|---| +| Next.js hosting | `@opennextjs/cloudflare` 1.20.11: one Worker (`.open-next/worker.js`) + Static Assets | +| Data Cache | R2 (`NEXT_INC_CACHE_R2_BUCKET`), a bucket per environment from `infra/terraform/cloudflare-r2` | +| Tag revalidation | the sharded Durable Object tag cache (`NEXT_TAG_CACHE_DO_SHARDED`) | +| Stale-while-revalidate | the Durable Object queue (`NEXT_CACHE_DO_QUEUE`) through `WORKER_SELF_REFERENCE` | +| Image Optimization | off — the shop's media is served as the shop sends it | +| Env vars | the domain and access key as optional build secrets, inlined; the revalidation secret as a Worker secret the deploy sets | +| `VERCEL_PROJECT_PRODUCTION_URL` | `NEXT_PUBLIC_SITE_URL`: the environment's `SITE_URL`, else its workers.dev URL | + +## 3. The cache + +The commerce baseline's shape, unchanged: R2 incremental cache, sharded +Durable Object tag cache (base shard size 12), Durable Object queue — +`open-next.config.ts`, the bindings and the `migrations` in +`wrangler.template.jsonc`. No database to provision or seed, and strongly +consistent per tag shard. + +## 4. Cache Components off, `"use cache"` kept + +On workerd through the adapter a Cache Components page answers 500 and then +hangs (opennextjs-cloudflare#1450) — the reference port's finding and its +choice. So `cacheComponents` is off and `experimental.useCache` keeps every +`"use cache"` read with its lifetime and tags; routes render per request +from cached reads. Measured under `wrangler dev` against the stand-in: a +second visit reads the catalogue not at all, and revalidating `products` +re-reads the products and nothing of the collections. Next is 16.3.8, the +lowest 16.x the adapter's peer range accepts; 16.4.x fails every request on +it. + +## 5. Build-time settings + +On Vercel the starter reads `SHOPWARE_STORE_DOMAIN`, `SHOPWARE_ACCESS_TOKEN`, +`SHOPWARE_API_TYPE`, `SHOPWARE_USE_SEO_URLS`, `COMPANY_NAME` and the origin +from `process.env` per request. A Worker's `process.env` holds only its vars +and secrets, so `next.config.ts` `env` inlines those six at build — the +deploy builds once per environment with that environment's values. Only a +literal `process.env.NAME` is replaced, so upstream's +`validateEnvironmentVariables` (a read by computed name) no longer runs in +the sitemap; the connection seam does its job. The values reach the server +bundle only: no client component reads them. + +## 6. Before a store, and after + +A baseline goes live with no key the platform cannot broker. The starter's +pages and cart are typed on Shopware's own schemas, so a bundled catalogue +would fake the Store API inside the Worker. Upstream's `.env.example` names +Shopware's demo shop as sample values, not as a fallback in code, so the +demo is documented (the README's "Connecting Shopware") and not defaulted. +Instead the starter's unconfigured state is made explicit: +`lib/shopware/connection.ts` says whether the build had a domain and a key; +unconnected, `getApiClient` throws `ShopwareNotConnected`, which every +reader's existing catch turns into an empty answer without logging it; +every page carries the note "No Shopware store is connected yet", `/` says +"Connect your Shopware store" and how, and the sitemap lists `/` alone. +`/api/health` reports the connection for the smoke and the record. The +owner sets the two Orun secrets and redeploys. + +## 7. Revalidation + +Upstream's `/api/revalidate` answered "never tested". The port's route takes +`POST` with `Authorization: Bearer `, compares +SHA-256 digests in constant time, and calls `revalidateTag(tag, "seconds")` +for `?tag=products`, `?tag=collections`, or both; the cart's tag is not +accepted. With no secret it answers 503, a missing or wrong bearer 401, an +unknown tag 400. The secret is an Orun secret: the build runs without it +(`env -u`), so it is in no bundle, and `tooling/wire/worker-secrets.mjs` puts +it on the environment's Worker after the build, on deploy lanes only. +Shopware sends no cache webhook of its own, so the README names the shop's +ways to call it: Flow Builder's webhook action, an app, or a job. + +## 8. Tests + +Upstream's check (`oxlint` and `oxfmt --check`) is `@app/web`'s `test`. +`tests/web` covers the port's seams: the store name, the connection, +`/api/health`, the store-domain helper and the revalidation route's bearer +check and tags (17 tests). Upstream's Playwright suite (`e2e-tests/`) browses +a deployment connected to Shopware's demo shop; it is carried and run by +hand. The e2e serves the bootstrapped product twice: as born (the deploy's +own smoke, every page with the note, health, revalidation off, the sitemap, +the Open Graph image), then rebuilt by the stage lane's own build step with +a stand-in Store API connected (`testing/lib/fake-shopware.mjs`: it checks +the `sw-access-key`, answers the calls the storefront makes from a +three-product catalogue with categories, a footer CMS page and SEO URLs, and +counts every call) — catalogue pages, cache reuse, a change that stays +cached until the bearer revalidates `products`, a refused bearer that drops +nothing, and the revalidation secret absent from the build output. + +## 9. The rename + +Slug `shopware-commerce`, Pascal `ShopwareCommerce`, store name +`Next.js Shopware Starter` (the starter's own name) at the `SITE_NAME` seam +(`app/site.ts`), with `SOURCE_URL` beside it. The leak gate fails any other +spelling of the name under `app/`, `components/` or `lib/`. The storefront's +own word `Shopware` is not the identity and no rule touches it. + +## 10. Alternatives rejected + +- **Cache Components on, a patched adapter**: hacking around an open + upstream bug. +- **Shopware's demo shop as the default**: a stranger's catalogue in + somebody's store, gone when Shopware moves it, and no connect state. +- **A bundled demo catalogue**: the Store API faked inside the Worker for a + cart that still needs a real shop. +- **The revalidation secret as a build secret**: it would be inlined into the + Worker's bundle. +- **Upstream's revalidation stub kept**: a cached catalogue would change + only when its lifetime ends. diff --git a/specs/epics/shopware-commerce/epic.yaml b/specs/epics/shopware-commerce/epic.yaml new file mode 100644 index 0000000..c7454fe --- /dev/null +++ b/specs/epics/shopware-commerce/epic.yaml @@ -0,0 +1,29 @@ +# The epic's declaration. metadata.name equals the directory name; metadata.key +# is the task-key prefix this epic reserves (SW → SW-1, SW-2, …). Owner, target +# date and health are the platform's — never written here. +apiVersion: orun.io/v1 +kind: Epic +metadata: + name: shopware-commerce + key: SW +spec: + title: "Shopware's Next.js starter on Cloudflare Workers" + summary: "Shopware's Next.js starter (a Next.js Commerce fork on Shopware 6's Store API) — a home page with a grid and a carousel, categories, search, product pages with variants, a cart and CMS pages, every Store API read a \"use cache\" entry dropped by tag through a bearer-checked route — runs as one Cloudflare Worker with Static Assets, its data cache in R2 and its tag cache and revalidation queue in Durable Objects, live before a Shopware 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: "SW0 — 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: [SW-1] + - name: "SW1 — the storefront on Workers" + exitCriteria: + - "apps/web is upstream's starter built by OpenNext into one Worker with Static Assets, the R2 incremental cache, the Durable Object tag cache and queue, Cache Components off and every \"use cache\" read kept" + - "typecheck, lint, upstream's check, tests/web and build are green with no store" + - "with no store connected every page answers with the connect note and / says \"Connect your Shopware store\", never a 500; connected, wrangler dev serves the catalogue, reuses the cache and revalidates through the bearer-checked route" + tasks: [SW-2] + - name: "SW2 — 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 and buckets, with upstream'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 Store API and browsed" + tasks: [SW-3] diff --git a/specs/epics/shopware-commerce/implementation-plan.md b/specs/epics/shopware-commerce/implementation-plan.md new file mode 100644 index 0000000..757e8b6 --- /dev/null +++ b/specs/epics/shopware-commerce/implementation-plan.md @@ -0,0 +1,12 @@ +# shopware-commerce — implementation plan + +| Milestone | Lands | Done when | +|---|---|---| +| SW0 — the spec | the repository born (intent, CI, tooling, spec index), this doc set, SW-1…SW-3 | on main | +| SW1 — the storefront on Workers | `apps/web` (upstream at `7066aa7` plus the departures in IMPLEMENTATION-STATUS), `infra/terraform/cloudflare-r2`, `tests/web` | typecheck, lint, upstream's check, tests/web and build green with no store; served unconnected and connected under `wrangler dev` | +| SW2 — a baseline | `blueprint.yaml`, `repo-blueprint.yaml`, `.baseline/`, the rename engine and bootstrap helpers, the record renderer, the context pack, `testing/` with the stand-in Store API, `baseline.yml`, `tag.yml` | Baseline CI green; `baseline-v1` tagged | + +Order inside SW1: the spike (Cache Components off, `useCache`, the R2/DO +caches, a cached read reused and revalidated under `wrangler dev`); the +build-time settings; the unconnected seam; the revalidation route; the Open +Graph images on workerd; the workspace; the tests. diff --git a/specs/epics/shopware-commerce/risks-and-open-questions.md b/specs/epics/shopware-commerce/risks-and-open-questions.md new file mode 100644 index 0000000..e7ba61a --- /dev/null +++ b/specs/epics/shopware-commerce/risks-and-open-questions.md @@ -0,0 +1,16 @@ +# shopware-commerce — risks and open questions + +| ID | Risk | State | Notes | +|---|---|---|---| +| SW-A | Not proven live: the repository and link, the minted tokens, a real `terraform apply` and `wrangler deploy`, the revalidation secret put on a real Worker, the probes, a real Shopware shop | OPEN | Baseline CI proves everything else offline; one bootstrap with Shopware's demo shop connected closes it | +| SW-B | Size: the Worker is 2.48 MiB gzipped (10.7 MiB raw), half a MiB under Workers Free's 3 MiB | WATCH | `wrangler deploy --dry-run` after a build prints the size; a dependency upgrade could cross the line | +| SW-C | Cache Components off | ACCEPTED | opennextjs-cloudflare#1450; turning them back on needs no change to the `"use cache"` reads | +| SW-D | Next pinned to 16.3.8 (upstream 16.2.6) | ACCEPTED | The adapter's peer range starts at 16.3.8 on 16.x; 16.4.x fails every request on 1.20.11 | +| SW-E | Images unoptimized | ACCEPTED | Shopware generates thumbnails; the owner's media host is not known at build | +| SW-F | `revalidateTag(tag, "seconds")` is stale-while-revalidate | ACCEPTED | The first request after a revalidation may be served the old entry while the fresh one is read; the e2e allows ten visits | +| SW-G | The e2e's store is a stand-in: the calls the storefront makes, answered from a three-product catalogue; the cart is read but no line item is added end to end | ACCEPTED | Upstream's Playwright suite adds to a real cart; a real shop is SW-A | +| SW-H | The store's name: the rename rewrites one line and the sweep does not look for it | ACCEPTED, gated | The leak gate fails any other spelling under `app/`, `components/` and `lib/`; the placement and e2e tiers check the branded product | +| SW-I | The cart's "Proceed to Checkout" links to Shopware's demo frontend (`checkoutUrl` in `lib/shopware/transform.ts`), as upstream's does | OPEN — the owner's | Stated in the product's README ("Checkout"); the storefront has no checkout of its own, as upstream | +| SW-J | Two coarse tags: revalidating `products` drops every product entry | ACCEPTED | Upstream's own tags; a finer scheme would change every reader | +| SW-K | The sales channel's access key is inlined into the Worker's bundle | ACCEPTED | It is Shopware's public Store API key (it reads what the channel publishes and acts on a shopper's own cart); no client bundle carries it; it is an Orun secret, never committed | +| SW-L | Upstream's Playwright suite is carried but no tier runs it | ACCEPTED | It needs a live shop; its CMS-page check expects upstream's demo title, so it fails one check under any other store name (README) | diff --git a/tasks/SW-1.TaskContract.yaml b/tasks/SW-1.TaskContract.yaml new file mode 100644 index 0000000..afb4809 --- /dev/null +++ b/tasks/SW-1.TaskContract.yaml @@ -0,0 +1,13 @@ +apiVersion: orun.io/v1 +kind: TaskContract +metadata: + name: SW-1 + title: "The shopware-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/shopware-commerce + - tasks + doneWhen: + - the doc set and SW-1, SW-2 and SW-3 are merged + gates: [] diff --git a/tasks/SW-2.TaskContract.yaml b/tasks/SW-2.TaskContract.yaml new file mode 100644 index 0000000..83378d4 --- /dev/null +++ b/tasks/SW-2.TaskContract.yaml @@ -0,0 +1,18 @@ +apiVersion: orun.io/v1 +kind: TaskContract +metadata: + name: SW-2 + title: "The storefront on Workers" +spec: + goal: Shopware's Next.js starter runs as one Cloudflare Worker with Static Assets, its Store API reads cached in R2 and revalidated through the Durable Object tag cache by a bearer-checked route, live before a store is connected + affects: + - apps/web + - infra/terraform/cloudflare-r2 + - tests/web + - pnpm-lock.yaml + - pnpm-workspace.yaml + - README.md + doneWhen: + - pnpm typecheck, lint, test and build are green with no Shopware store + - wrangler dev serves the unconnected storefront without a 500, and a connected one from cached reads revalidated through /api/revalidate + gates: [] diff --git a/tasks/SW-3.TaskContract.yaml b/tasks/SW-3.TaskContract.yaml new file mode 100644 index 0000000..2281dfb --- /dev/null +++ b/tasks/SW-3.TaskContract.yaml @@ -0,0 +1,23 @@ +apiVersion: orun.io/v1 +kind: TaskContract +metadata: + name: SW-3 + title: "shopware-commerce becomes an Orun baseline" +spec: + goal: A new storefront goes from nothing to live on stage and prod in one landing, its own name throughout, with Baseline CI proving it offline + affects: + - blueprint.yaml + - repo-blueprint.yaml + - .baseline + - testing + - tooling + - hooks + - docs/phases + - ai/context + - .github/workflows + - BOOTSTRAP.md + - README.md + doneWhen: + - Baseline CI is green on main + - baseline-v1 is tagged + gates: []