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
9 changes: 9 additions & 0 deletions .baseline/identity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"_comment": "THIS TREE'S OWN IDENTITY — the FROM side of every rebrand. tooling/rebrand/rebrand.mjs reads it to know what to rename AWAY from; a product's identity is the --values file, which is the TO side. Change a value here only together with the tree: these strings must be what the tree actually contains, or the rename silently misses and the product ships carrying this baseline's name. `productName` is the SITE_NAME seam in apps/web/app/site.ts; `slug` also names the R2 bucket names (terraform `repo`), the Worker and its self-reference binding, and the secret project — and, being an English word, it may appear NOWHERE ELSE in a shipped file (the rename would rewrite it), nor may the capitalised `pascal` form (the leftover sweep fails on it); `domain` and `subdomain` are placeholders, because this baseline has never deployed under a name of its own; `githubOwner` is the owner in SOURCE_URL.",
"slug": "commerce",
"pascal": "Commerce",
"productName": "Next.js Commerce",
"domain": "commerce.example.com",
"subdomain": "your-workers-subdomain",
"githubOwner": "sourceplane"
}
174 changes: 174 additions & 0 deletions .baseline/product/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# commerce

A headless storefront — home, search, collections, product pages and a cart —
on **Cloudflare Workers + Static Assets** through
[`@opennextjs/cloudflare`](https://opennext.js.org/cloudflare), built from
Vercel's open-source Next.js storefront template (MIT, `apps/web/license.md`).
The Next.js data cache lives in an **R2 bucket** that Terraform provisions per
environment, and its tag cache and revalidation queue in **Durable Objects**
the Worker itself exports.

It is live from its first deploy with no third-party key: until you connect a
Shopify store it serves a **bundled demo catalogue** (six sample products, two
collections, menus and pages) and keeps the cart in a cookie, and checkout
says plainly that a payment provider must be connected first.

## Live deployment

<!-- 02-docs:begin -->
Not recorded yet. The bootstrap's last phase writes the live URLs, the
workspace and the secrets inventory into
[ai/context/deployment.md](ai/context/deployment.md); how the store deploys
and how to operate it is in
[ai/context/operations.md](ai/context/operations.md).
<!-- 02-docs:end -->

## What is here

| Surface | Where |
|---|---|
| Home, `/search`, `/search/[collection]`, `/product/[handle]`, `/cart`, `/checkout`, `/[page]`, OG images, sitemap, robots | `apps/web/app` |
| The store's name and source link | `apps/web/app/site.ts` |
| The Shopify client (`"use cache"` readers, cart mutations, the webhook's `revalidate`) — and the switch to the demo when no store is connected | `apps/web/lib/shopify` |
| The demo catalogue and the cookie cart | `apps/web/lib/demo`, images in `apps/web/public/demo` |
| Cart (server actions, optimistic context, modal), navbar, grid, product gallery | `apps/web/components` |
| Workers build, cache bindings and deploy contract | `apps/web/next.config.ts`, `open-next.config.ts`, `wrangler.template.jsonc` + `wiring.fixture.json` (→ `wrangler.jsonc`), `component.yaml` |
| The R2 bucket (stage, prod) | `infra/terraform/cloudflare-r2` |
| Tests | `tests/web` (vitest) |

## 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 Shopify facts in the environment both serve the demo catalogue. Make
the store yours in `apps/web/app/site.ts` (its name and the repository the
footer links to); the demo's products are `apps/web/lib/demo/catalogue.ts`.

## Connecting Shopify

The storefront reads one store through the Shopify Storefront API. Shopify is
not a provider the platform brokers, so you connect it yourself, once, after
the store is live:

1. **In Shopify**, create a Storefront API access token (Settings → Apps and
sales channels → Develop apps, or the Headless channel), and set up what
the storefront reads by handle: the menus `next-js-frontend-header-menu`
and `next-js-frontend-footer-menu`, and the collections
`hidden-homepage-featured-items` (the home page's three-item grid) and
`hidden-homepage-carousel` (its carousel). Collections whose handle starts
with `hidden` never appear in search; products tagged
`nextjs-frontend-hidden` are left out of listings.
2. **Give each environment's Worker the store's three facts** as Worker
secrets. The deploy lane never sets or clears them, so this is once:

```bash
cd apps/web
for env in stage prod; do
wrangler secret put SHOPIFY_STORE_DOMAIN --name commerce-web-$env # your-store.myshopify.com
wrangler secret put SHOPIFY_STOREFRONT_ACCESS_TOKEN --name commerce-web-$env
wrangler secret put SHOPIFY_REVALIDATION_SECRET --name commerce-web-$env # any long random string
done
```

Setting a secret publishes a new version of the Worker; its next request
reads the store. The demo banner goes, the catalogue, menus, pages and cart
are Shopify's, and nothing is rebuilt. Demo answers were never cached, so
none outlives the switch.
3. **Register Shopify's webhooks** (Settings → Notifications → Webhooks) for
`products/create`, `products/update`, `products/delete`,
`collections/create`, `collections/update` and `collections/delete`,
pointing at
`https://commerce-web-prod.your-workers-subdomain.workers.dev/api/revalidate?secret=<SHOPIFY_REVALIDATION_SECRET>`
(and the stage URL, if stage has a store of its own). Each delivery
revalidates the `products` or `collections` tag in the Durable Object tag
cache; the next request re-renders from Shopify.

Product images then come from `cdn.shopify.com`, which `next.config.ts`
already allows. To use another store backend instead, replace the functions
`lib/shopify/index.ts` exports — `lib/demo` is a complete second
implementation of the same surface to copy from.

## Checkout and payments

The storefront never takes payment itself. With Shopify connected, "Proceed to
Checkout" sends the shopper to the cart's Shopify-hosted checkout, which takes
payment through whichever payment provider the Shopify store has enabled
(Shopify Payments or another, in the Shopify admin under Settings →
Payments). Without a store there is no payment provider: `/checkout` answers
with a notice — "Connect a payment provider to enable checkout" — the cart is
kept on the shopper's device, and nothing is charged.

## How the cache is wired

The Worker binds the bucket as `NEXT_INC_CACHE_R2_BUCKET` (every `"use cache"`
entry and pre-rendered page), and two Durable Objects: `NEXT_TAG_CACHE_DO_SHARDED`
(which tags were revalidated, and when) and `NEXT_CACHE_DO_QUEUE` (background
revalidation of stale routes, through the Worker's own
`WORKER_SELF_REFERENCE` binding). The bucket's name is never hand-written:
`apps/web/wrangler.template.jsonc` names it as a wiring token, and
`wrangler.jsonc` is that template rendered — from `wiring.fixture.json` for
local work and verification, and on every deploy from the document the
`cloudflare-r2` Terraform root publishes after its apply
(`WIRING_CLOUDFLARE_R2`, per environment). Edit the template, then
`pnpm run wire:fixture`; Checks fails if the committed `wrangler.jsonc` is not
the fixture render. The Durable Objects need no root: the migration in the
config creates them on the first deploy.

## How it deploys

Merges to `main` converge through [Orun](https://github.com/sourceplane/orun):
`.github/workflows/ci.yml` plans the changed components and runs each lane
against the workspace in `intent.yaml`. The R2 bucket applies first, then the
storefront builds with that environment's bucket name and deploys — to
`stage`, then to `prod` once stage has converged on the same commit; `dev`
only verifies. The Worker is `commerce-web-<env>` on your account's
workers.dev subdomain, and every deploy is smoke-tested over HTTP: the home
page must answer, and `robots.txt` must name the origin it was asked on, which
only the Worker renders. `checks.yml` runs install, the fixture render,
typecheck, lint, test and build on every pull request. (A push to `main` runs
`ci.yml` alone, which applies, builds and deploys.)

The pipeline holds one credential, GitHub's own `GITHUB_TOKEN`. The Cloudflare
tokens and account id are brokered per run from the workspace's Cloudflare
connection — one to deploy the Worker, one with R2 access for the bucket's
apply — and the bucket names travel as Orun secrets; nothing provider-shaped
is stored in the repository or in GitHub. Shopify's facts are Worker secrets,
set once on the Workers themselves.

## 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`) |
| Data Cache: `"use cache"` entries with `cacheLife("days")` | The R2 bucket bound as `NEXT_INC_CACHE_R2_BUCKET`, written at request time |
| Tag revalidation from the Shopify webhook, `updateTag` from cart actions | A sharded Durable Object tag cache consulted on every cache read |
| Stale-while-revalidate (ISR) | A Durable Object queue that re-renders stale routes through the Worker |
| `VERCEL_PROJECT_PRODUCTION_URL` | Nothing: absolute URLs are built on the request's origin (`app/site.ts`) |
| Shopify integration env vars | Worker secrets (above); the demo catalogue until they are set |
| Deploy on push | Orun applies the bucket and deploys `commerce-web-{stage,prod}` on merge to `main` (`apps/web/component.yaml`) |

Partial prerendering is off: `@opennextjs/cloudflare` 1.20 cannot run Next 16's
Cache Components on workerd yet, so the storefront keeps the template's
`"use cache"` directives through `experimental.useCache` and renders every
route at request time.

## Custom domain

The store answers on workers.dev from its first deploy. To serve it on your
own domain, add the domain to the Cloudflare account the store deploys into
and attach it to the Worker (dashboard → Workers & Pages →
`commerce-web-prod` → Settings → Domains & Routes → Add → Custom domain), and
point Shopify's webhooks at it. Nothing in the repository changes: the store
builds its absolute links from the request it is answering.
27 changes: 27 additions & 0 deletions .baseline/tasks/01-product.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Task contract template for the 01-product landing.
# Unbound to a key on purpose: `orun.task/ensure@v1` seals and attaches it to
# the key the allocator issues. It lives under `.baseline/`, not `tasks/`,
# because `tasks/` is this repository's own work tree (`intent.yaml` `work:`),
# where an unkeyed contract is an error. gates: [] is a DECLARATION — merge
# alone finishes this task; the main convergence is the gate the bootstrap
# watches, not one the plane observes as a PR check.
#
# The whole product in one landing. `affects` names COMPONENTS, by
# metadata.name: the phase's retouch hook reads this list to decide which
# component.yaml files get the redeploy marker, so a re-run of the phase has a
# diff and exactly these components are re-planned — the deploy set and the
# task plane's statement of the work are one list.
apiVersion: orun.io/v1
kind: TaskContract
spec:
goal: The product's repository is born and linked, the whole product lands in one pull request, and one convergence applies the R2 cache bucket and deploys the storefront on stage and prod
affects:
- cloudflare-r2
- web
- web-tests
doneWhen:
- repo pushed, main pinned as default, workspace linked
- WIRING_CLOUDFLARE_R2 published on stage and prod
- main convergence green (R2 applied, then the storefront built, deployed and smoke-tested on stage and prod)
- the storefront answers on both workers.dev URLs
gates: []
13 changes: 13 additions & 0 deletions .baseline/tasks/02-docs.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Task contract template for the 02-docs landing. See 01-product's header.
apiVersion: orun.io/v1
kind: TaskContract
spec:
goal: The live deployment is recorded from verified facts as agent-readable state in the product's repo
affects:
- ai/context/deployment.md
- ai/context/operations.md
- README.md
doneWhen:
- committed deployment manifest matches probed reality
- prod waits on stage again, and dev verifies every merge to main again
gates: []
136 changes: 136 additions & 0 deletions .github/workflows/baseline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: Baseline CI

# THE FACTORY'S OWN LANES — this repository tested as a BASELINE: that its
# build document parses with the orun a bootstrap actually runs, that its card
# agrees with it, that every component is placed by the one product phase,
# that the R2 bucket's wiring reaches the Worker's config, that a placed
# tree comes up branded and carrying nothing of the factory — and plans the
# bucket before the Worker on a merge — and that the product it produces
# installs, builds, deploys (dry), serves, and takes a cart.
#
# ─── WHY THIS IS NOT IN ci.yml OR checks.yml ──────────────────────────────
#
# `repo-blueprint.yaml`'s `github-workflows` module copies the WHOLE `.github`
# directory into every site built from this repository. These jobs run
# `testing/*.sh`, and `testing/` is deliberately not placed — so in a site they
# would be steps that cannot pass, red on its very first pull request. This
# file is in the blueprint's `ignore` list, and `testing/coverage.test.sh`
# fails on any workflow that reads `testing/` and is not.

on:
push:
branches: [main]
pull_request:

concurrency:
group: baseline-ci-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

permissions:
contents: read

jobs:
# Tier 0. bash, python3 and git; node for the tools. No workspace install,
# no network, no credential — the job that most certainly fails a PR.
baseline-contract:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v5
with:
node-version: 22
# setup-node v5 turns on the pnpm cache by itself when package.json
# names a packageManager, and then fails on a runner with no pnpm.
# This job installs nothing.
package-manager-cache: false
- name: Contract tests (manifest, phases, coverage, rebrand, retouch, bootstrap-defer, wire)
run: |
set -euo pipefail
python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
for t in manifest phases coverage rebrand retouch bootstrap-defer wire; do
echo "── $t"
bash "testing/$t.test.sh"
done

# Tier 1. THE BLUEPRINT, READ AND PLACED BY THE BINARY A BOOTSTRAP RUNS.
#
# Pinned at the bootstrap floor (BOOTSTRAP.md), not the site's lane pin:
# every test here reads YAML with PyYAML, which parses anything well-formed;
# only the pinned orun can say whether the document is one a bootstrap can
# run. `--status` parses it, validates every hook against the action
# registry, compiles every `when` and narration template, and writes
# nothing. Then the leak gate (what a product would carry, derived by the
# floor too), and the placement tier (the offline bootstrap: both phases
# placed and finished by the blueprint's own hooks, then the product's own
# `orun plan` for the 01-product merge — the R2 apply before the Worker's
# deploy — under the product's lane pin, below).
blueprint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.58.11
- uses: pnpm/action-setup@v4
with:
version: 10.12.1
- uses: actions/setup-node@v5
with:
node-version: 22
- name: repo-blueprint.yaml, read by the pinned CLI
run: |
set -euo pipefail
orun --version
python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
# Required inputs must be supplied for the document to resolve; the
# values are arbitrary and nothing is written.
orun new --blueprint repo-blueprint.yaml --status \
--out "$(mktemp -d)" \
--set reponame=acme-shop \
--set "productname=Acme Shop" \
--set productdomain=shop.acme.dev \
--set githuborg=acme-inc
- name: the leak gate — what a product carries
run: bash testing/leak.test.sh
# The placement tier ENDS with the product's own `orun plan` — what the
# product's ci.yml runs — so it runs under the product's lane pin, not
# the bootstrap floor. v2.58.11 plans a pull request with apps/web
# waiting on the R2 plan: it does not apply a dependsOn edge's
# `modeRules`. The lane pin does (advisory on a PR, enforced on main),
# and the test refuses an orun older than the pin rather than assert
# the wrong CLI's plan. Its placements are valid under either.
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.78.4
- name: placement — the offline bootstrap, and the product's own plan
run: |
git config --global user.email ci@example.invalid
git config --global user.name "baseline ci"
bash testing/placement.test.sh

# Tier 2. THE PRODUCT IT PRODUCES WORKS: its one landing under the checks
# its pull request waits on, the stage lane's own structure check, build
# (the live wiring render included), output check and dry deploy in the tree
# orun stages, and the built Worker served and smoke-tested with the
# component's own smoke command. Pinned at the product's lane version,
# because that is the orun the product's CI runs.
site:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.78.4
- uses: pnpm/action-setup@v4
with:
version: 10.12.1
- uses: actions/setup-node@v5
with:
node-version: 22
cache: pnpm
- name: e2e — the bootstrapped product builds, deploys (dry) and serves
run: |
python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
git config --global user.email ci@example.invalid
git config --global user.name "baseline ci"
bash testing/e2e.test.sh
Loading
Loading