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
113 changes: 105 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,107 @@
# shopware-commerce

[Next.js Shopware Starter](https://github.com/shopwareLabs/nextjs-shopware-starter) on
**Cloudflare Workers**, deployed by [Orun](https://github.com/sourceplane/orun) to stage
and prod on every merge, and then packaged as an Orun baseline.

This commit is the repository's frame: `intent.yaml` (with the placeholder
workspace `ws_CHANGE_ME`, so CI plans nothing until it is linked), the Orun
CI workflow, the shared TypeScript and ESLint configuration, and the spec
index. The work is tracked as an epic under [`specs/epics`](specs/epics/README.md).
[Shopware's Next.js starter](https://github.com/shopwareLabs/nextjs-shopware-starter)
β€” a fork of Vercel's Next.js Commerce on Shopware 6's Store API: a home page
with a featured grid and a carousel, the shop's categories with sorting and
filters, search, product pages with variants, a cart and CMS pages, every
Store API read a `"use cache"` entry dropped by tag when the shop changes β€”
running on **Cloudflare Workers + Static Assets** through
[`@opennextjs/cloudflare`](https://opennext.js.org/cloudflare), with the
Next.js data cache in an **R2 bucket** provisioned by Terraform through
[Orun](https://github.com/sourceplane/orun) and the tag cache and revalidation
queue in **Durable Objects** the Worker itself exports, deployed by
[Orun](https://github.com/sourceplane/orun) to stage and prod on every merge.
Packaging it as an Orun baseline is the next milestone (SW2).

A fresh build needs no Shopware store: until its owner connects one, `/` says
"Connect your Shopware store" and every other page answers with an empty
catalogue and the same note β€” never a 500. The owner connects a shop by
setting its domain and its sales channel's access key as Orun secrets and
redeploying. The Worker is about 2.5 MiB gzipped, inside Workers Free's
3 MiB. See [`specs/epics/shopware-commerce`](specs/epics/shopware-commerce/README.md)
for the design, the milestones and the as-built status.

## What is here (the product)

| Surface | Where |
|---|---|
| The storefront's routes: `/`, `/search`, `/search/<category>`, `/product/<seo-url>`, `/cms/<page>`, `/api/revalidate`, `/api/health`, the sitemap and the Open Graph images | `apps/web/app` |
| The store's name and its source link | `apps/web/app/site.ts` (`SITE_NAME`, `SOURCE_URL`) |
| Whether a Shopware store is connected, and what the storefront says until one is | `apps/web/lib/shopware/connection.ts`, `apps/web/components/connect-store.tsx` |
| The Store API client, its cached reads and their tags, the revalidation route's logic | `apps/web/lib/shopware` |
| The Store API's types (`@shopware/api-gen`) | `apps/web/api-types`, `apps/web/shopware.d.ts` |
| Workers build, cache bindings and deploy contract | `apps/web/next.config.ts`, `open-next.config.ts`, `wrangler.template.jsonc` + `wiring.fixture.json` (β†’ the committed `wrangler.jsonc`), `component.yaml` |
| The R2 bucket (stage, prod) | `infra/terraform/cloudflare-r2` |
| The wrangler renderer, and the step that puts the revalidation secret on the Worker | `tooling/wire` |
| Tests | `tests/web` (the port's seams: the store name, the connection, health, the store domain, revalidation) |

## Getting started

```bash
pnpm install
pnpm run wire:fixture # render apps/web/wrangler.jsonc from the offline fixture
pnpm typecheck
pnpm lint
pnpm test
pnpm build # next build + opennextjs-cloudflare build β†’ apps/web/.open-next
```

```bash
pnpm --filter @app/web dev # http://localhost:3000, Next's dev server
pnpm --filter @app/web preview # wrangler dev over the built Worker, a local R2 bucket and local Durable Objects
```

With no `SHOPWARE_STORE_DOMAIN` both serve the "connect your Shopware store"
storefront. To run against a shop, put its domain and access key in
`apps/web/.env.local` (from `apps/web/.env.example`). Offline, the e2e's
stand-in Store API answers the storefront's calls from a three-product
catalogue: `node testing/lib/fake-shopware.mjs --port 4010 --key <any-key>`,
then `SHOPWARE_STORE_DOMAIN=http://127.0.0.1:4010`.

## How it maps to Vercel

| Vercel | Here |
|---|---|
| Next.js hosting (SSR, server actions, route handlers, `next/og`) | One Cloudflare Worker (`.open-next/worker.js`) + Static Assets (`ASSETS`) |
| Cache Components with `"use cache"`, `cacheLife` and `cacheTag` | `"use cache"`, its lifetimes and its tags kept through `experimental.useCache`; every route renders per request from those cached reads |
| Data Cache entries | The R2 bucket bound as `NEXT_INC_CACHE_R2_BUCKET` |
| `revalidateTag` | A sharded Durable Object tag cache (`NEXT_TAG_CACHE_DO_SHARDED`) consulted on every cache read |
| Stale-while-revalidate | A Durable Object queue (`NEXT_CACHE_DO_QUEUE`) that re-renders stale entries through the Worker's `WORKER_SELF_REFERENCE` binding |
| Image Optimization | Off (`images.unoptimized`): images come from the shop's media URLs |
| `SHOPWARE_STORE_DOMAIN`, `SHOPWARE_ACCESS_TOKEN` | Orun secrets (optional build env) β€” and, unset, the "connect your Shopware store" storefront instead of a failed build |
| `SHOPWARE_REVALIDATION_SECRET` | An Orun secret each deploy puts on the Worker; the build never sees it, and the route answers 503 until it is set |
| `VERCEL_PROJECT_PRODUCTION_URL` | Each environment's `SITE_URL`, else its workers.dev URL, set by the build as `NEXT_PUBLIC_SITE_URL` |
| Deploy on push | Orun applies the bucket and deploys `<repo>-web-{stage,prod}` on merge to `main` (`apps/web/component.yaml`) |
| "Deploy with Vercel" (clone the template) | `orun new --blueprint repo-blueprint.yaml` β€” a new repository, branded, deployed |

Cache Components are off: `@opennextjs/cloudflare` 1.20 cannot run Next 16's
Cache Components on workerd yet (a Cache Components page answers 500 and then
hangs β€” opennextjs-cloudflare#1450), so the storefront keeps upstream's
`"use cache"` reads through `experimental.useCache` and renders every route at
request time. The epic's [IMPLEMENTATION-STATUS](specs/epics/shopware-commerce/IMPLEMENTATION-STATUS.md)
has the evidence.

## How the bucket reaches the Worker

```
infra/terraform/cloudflare-r2 ──apply (r2-data token)──► orun secret WIRING_CLOUDFLARE_R2 (stage, prod)
β”‚ (each deploy resolves it as it starts;
β”‚ a missing one fails the lane)
β–Ό
apps/web dependsOn cloudflare-r2 (enforced on main) Β· secretEnv WIRING_CLOUDFLARE_R2_<ENV>
build: tooling/wire/live.mjs β†’ wrangler.jsonc with the environment's bucket name
(dev, verify-only, renders the fixture) β†’ next build β†’ opennextjs-cloudflare
β†’ tooling/wire/worker-secrets.mjs puts SHOPWARE_REVALIDATION_SECRET on the Worker
deploy: workers-deploy token β†’ <repo>-web-<env>, its Durable Objects migrated on first deploy
```

`wrangler.jsonc` is committed as the fixture render of
`wrangler.template.jsonc`, because the deploy lane's `verify-app-structure`
step checks the config exists before it builds; `testing/e2e.test.sh` fails
if the two disagree.

## CI

| Workflow | What it runs | Ships to a product |
|---|---|---|
| `ci.yml` | the Orun pipeline, and the only workflow a product carries: `orun plan --changed`, then one job per lane. A pull request runs the verify lanes (the R2 root planned for stage and prod, the storefront built and dry-deployed per environment; they neither lint nor run the tests, which `baseline.yml`'s e2e tier runs before every tag), except the bootstrap's own landings (`orun/BASE-*`), where `plan` alone runs and nothing waits for it (the landing checked its commit in the box); a merge applies the R2 bucket, then deploys stage β†’ prod. It plans nothing while `intent.yaml` names the placeholder workspace `ws_CHANGE_ME`, as this repository does. A manual run (Orunbase's Deploy button, or Run workflow on `main`) plans the environment and components it names under the push-to-main trigger, so they deploy as a merge deploys them | yes |
19 changes: 19 additions & 0 deletions apps/web/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Local development. Every value is optional: with no Shopware store the
# storefront builds and serves an empty catalogue that says how to connect
# one. The store's name is apps/web/app/site.ts.
#
# Next's dev server (`pnpm dev`) and `pnpm build` β†’ copy to .env.local
#
# It is git-ignored. On the deployed Workers these are this repository's Orun
# secrets, one value per environment (the README, "Connecting Shopware"):
# SHOPWARE_STORE_DOMAIN and SHOPWARE_ACCESS_TOKEN are read by the build, and
# each deploy puts SHOPWARE_REVALIDATION_SECRET on the Worker as a secret β€”
# for the Worker preview (`pnpm preview`) put that one in .dev.vars instead.
COMPANY_NAME=""
# The shop's domain (shop.example.com; https:// unless you write http://).
SHOPWARE_STORE_DOMAIN=""
# The sales channel's Store API access key.
SHOPWARE_ACCESS_TOKEN=""
SHOPWARE_API_TYPE="store-api"
SHOPWARE_USE_SEO_URLS="true"
SHOPWARE_REVALIDATION_SECRET=""
48 changes: 48 additions & 0 deletions apps/web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
e2e-tests/node_modules
/.pnp
.pnp.js

# testing
/coverage
.playwright
e2e-tests/reports

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*
!.env.example

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
.env*.local

# Cloudflare Workers: OpenNext's build, wrangler's local state and secrets
/.open-next/
/.wrangler/
/.turbo/
.dev.vars
.dev.vars.*
8 changes: 8 additions & 0 deletions apps/web/.oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": false,
"trailingComma": "all"
}
8 changes: 8 additions & 0 deletions apps/web/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxlint/configuration_schema.json",
"rules": {
"no-unused-vars": "warn",
"no-console": "off"
},
"ignorePatterns": ["node_modules", ".next", "e2e-tests"]
}
6 changes: 6 additions & 0 deletions apps/web/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Generated, with their generators' own layout: wrangler.jsonc is the
# template rendered (`pnpm run wire:fixture`), docs/ is the component's
# generated pages; both carry names a new product's rename makes longer.
wrangler.jsonc
wrangler.template.jsonc
docs/
49 changes: 49 additions & 0 deletions apps/web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# apps/web β€” the storefront

Shopware's Next.js starter (MIT, `license.md`) β€” a fork of Vercel's Next.js
Commerce on Shopware 6's Store API β€” on Cloudflare Workers + Static Assets:
server components over the Store API, a server-action cart kept in your
shop, `"use cache"` reads revalidated by tag. The starter's pages and
components are kept; what this app adds is the Workers build, the cache
bindings, a storefront that says how to connect a shop while none is, a
bearer-checked revalidation route and `/api/health`.

- `app/` β€” the routes: home, `/search`, `/search/<category>`,
`/product/<seo-url>`, `/cms/<page>` (the `(cms)/[...cms]` catch-all), the
Open Graph images,
`robots.txt`, `sitemap.xml`, `/api/revalidate` and `/api/health`
- `app/site.ts` β€” the store's name and the repository its footer links to
- `lib/shopware/` β€” the Store API client (`@shopware/api-client`), its cached
readers and their tags, the transforms to the page's types, and the
revalidation route's logic; `connection.ts` says whether a shop is
connected, and while none is every reader answers empty without a call
- `api-types/`, `shopware.d.ts` β€” the Store API's types
(`pnpm generate-types` regenerates them from your shop)
- `components/` β€” cart (server actions, modal), navbar, grid, carousel,
product gallery and variants, the connect-store note
- `e2e-tests/` β€” upstream's Playwright suite, run by hand against a deployed
storefront connected to a shop (`BASE_E2E_URL=https://<host> pnpm test:e2e`
inside it); upstream ran it on Vercel's deployment events

```bash
pnpm dev # next dev on http://localhost:3000
pnpm build # next build + opennextjs-cloudflare build β†’ .open-next/
pnpm test # upstream's check: oxlint and the oxfmt format check
pnpm preview # wrangler dev over the built Worker: a local R2 bucket, local Durable Objects
```

The cache's bucket is not hand-written. `wrangler.template.jsonc` names it as
a wiring token; `wrangler.jsonc` is that template rendered from
`wiring.fixture.json` (placeholder names, for local work and verification),
and every deploy renders it again from the name the `cloudflare-r2` Terraform
root published for the environment (`component.yaml`'s `buildCommand`).

## Store backend

| `SHOPWARE_STORE_DOMAIN` + `SHOPWARE_ACCESS_TOKEN` | catalogue, menus, pages | cart |
| ------------------------------------------------- | ---------------------------------------------------------------------------------- | ----------------------------------------------- |
| unset (a fresh deploy) | empty; `/` says "Connect your Shopware store" and every page carries the note | none |
| set (read by the build) | the Store API, cached in R2 (`"use cache"`), revalidated through `/api/revalidate` | the shop's own cart (`sw-context-token` cookie) |

Connecting a shop is two Orun secrets and a redeploy, and revalidation a
third β€” the repository's README, "Connecting Shopware".
3 changes: 3 additions & 0 deletions apps/web/api-gen.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"patches": "./api-types/storeApiTypes.overrides.json"
}
Loading
Loading