Skip to main content

Integration

storefront-web has one upstream, the storefront-bff, and no downstream consumers apart from the shopper's browser and the web gateway in front of it. It is not a Kafka producer or consumer, exposes no REST API of its own (beyond /healthz, /readyz and the proxy), no MCP and no A2A, and calls nothing else: the context rule in ADR 0002 is "the web app talks only to the BFF", enforced by the no-network-url-in-bundle sensor, the eslint ban on absolute URL literals and the CSP's connect-src 'self'.

Edges​

EdgeDirectionProtocolContractPresent?
storefront-bffweb calls itHTTP/JSON under /api/storefront, errors as RFC 9457 application/problem+jsonthe BFF's apis/openapi.yaml (reference)yes, the only one
Web gatewaycalls the webHTTP; routes / to this Service and /api/storefront to the BFFnot in this repoyes in a cluster; the in-server proxy covers direct access
Shopper's browsercalls the webHTTP; HTML, JS, CSS, SVG, /api/storefrontn/ayes
Kubernetes probescall the webGET /healthz, GET /readyzserver/index.tsyes
Any storefront or retail-network service (product-discovery, shopping-cart, checkout, customer-ordering, delivery-promise, pricing, payment provider)nonenonenoneabsent by design; they are reached only through the BFF
Kafka / CloudEventsnonenonenoneabsent: no producer, no consumer
Authentication providernonenonenoneabsent: there is no auth anywhere; sign-in is a synthetic e-mail lookup
Telemetry backendnonenonenoneabsent: no OpenTelemetry dependency

The BFF routes it calls​

All paths are relative to /api/storefront. In the browser they are fetched with credentials: "same-origin"; on the server (SSR loaders) the base is <BFF_URL>/api/storefront with the incoming Cookie forwarded. Every operation is one function in app/lib/queries.ts.

FunctionMethod and pathWhere it runsUsed byUpstream behind the BFF
searchProductsGET /products (q, categoryId, inStock, priceMin, priceMax, sort, cursor, limit)server/, /searchproduct-discovery
getProductGET /products/{id}server, and browser (cart, checkout, order detail titles)/products/:id, /cart, /checkout, /orders/:idproduct-discovery
listCategoriesGET /categoriesserverroot layout, /product-discovery
quoteDeliveryDatesPOST /products/{id}/delivery-date-quotes body {postalPrefix}browserbuy box, cartdelivery-promise joined with pricing
createCartPOST /cartsbrowserfirst add to cartshopping-cart
listCartsGET /carts?state=OPENbrowser, only with a remembered shoppercart lookupshopping-cart
getCartGET /carts/{id}browsercart, checkout, confirmationshopping-cart
addCartLinePOST /carts/{id}/lines body {catalogItemId, quantity}browseradd to cartshopping-cart
setLineQuantityPATCH /carts/{id}/lines/{item} body {quantity}browsercartshopping-cart
removeLineDELETE /carts/{id}/lines/{item}browsercartshopping-cart
setDestinationPUT /carts/{id}/destination body {destinationPostalPrefix}browsercartshopping-cart
quoteCartDeliveryPOST /carts/{id}/delivery-quotesbrowsercartshopping-cart
selectCartDeliveryPUT /carts/{id}/delivery-selection body {groupNo, offerId}browsercartshopping-cart
openCheckoutPOST /checkout body {shipToAddressId, cartId?}browsercheckoutcheckout
getCheckoutGET /checkout/{id}browsercheckout, confirmationcheckout
confirmCheckoutPOST /checkout/{id}/confirmations body {paymentMethodToken}browsercheckoutcheckout
listOrdersGET /orders?cursor=browser/orderscustomer-ordering
getOrderGET /orders/{id}browserconfirmation, order detailcustomer-ordering
cancelOrderPOST /orders/{id}/cancellations body {reason}browserorder detailcustomer-ordering
createSessionPOST /sessions body {email}browsersign incustomer-ordering
registerShopperPOST /shoppersbrowserregistercustomer-ordering
getMeGET /mebrowseraccount, checkout, headercustomer-ordering
addMyAddressPOST /me/addressesbrowseraccountcustomer-ordering

The "upstream behind the BFF" column is informational and comes from the aggregator's storefront components page (warehouse-docs, storefront/docs/components.md); the web never addresses those services. All 23 operations above exist in the BFF's storefront/apis/storefront-bff/openapi.yaml on warehouse-docs main; the BFF also serves GET /healthz and GET /readyz, which the web does not call.

Every POST and PATCH carries Idempotency-Key (one random UUID per user action, reused on a retry of the same click until it succeeded; callRaw mints a fresh one when a caller gives none). The retired X-Action-Id header is gone. 409 /problems/idempotency-key-reused is a bug in the page (it is logged, never retried); a missing or malformed key is 400 idempotency-key-required / idempotency-key-invalid. PUT and DELETE take no key. Lists answer {items, nextCursor} (search adds facets and categorySuggestions): the web sends limit and cursor (never after) and reads items; search and orders show one page with a "Next page" / "Older orders" link carrying nextCursor, and GET /carts?state=OPEN reads the first page. GET /categories is the BFF's exempt navigation view and keeps {version, categories}.

Contract rules the web relies on​

  • State cookie. The BFF sets and reads sf_state (cart, shopper and last-checkout ids) with HttpOnly; SameSite=Lax; Path=/api/storefront. The web forwards it implicitly in the browser and explicitly in SSR loaders (serverOpts). It is state, not authentication.
  • Destination prefix. The retail network keys delivery quotes by the first 3 characters of the postal code. The web sends postalPrefixOf(zip) for /delivery-date-quotes ({postalPrefix}) and for the cart destination ({destinationPostalPrefix}); upstream decoders are strict, so any other field is a 400.
  • Session-required. GET /carts, GET /me and the order calls answer 422 /problems/session-required without a shopper in the cookie; the web asks only when it holds a shopper marker.
  • Payment. POST /checkout/{id}/confirmations receives only tok_approve, tok_decline or tok_timeout. The BFF refuses card-shaped tokens with 422.
  • Time zones. Delivery windows carry an optional IANA timeZone; absent means UTC (ADR 0006).
  • Optional route. GET /categories may be missing on an older BFF; the web degrades to an "All" department bar.

Failure behaviour​

The web has no retry, no circuit breaker, no cache and no fallback data: a failed call is shown to the shopper, and the next user action retries. The BFF enforces its own time budgets (the aggregator records 2 s for queries, 5 s for commands, 15 s for checkout confirmation, answering 504 on expiry and never retrying).

FailureWhere it surfacesWhat the shopper seesRetried by the web?
BFF unreachable from an SSR loader (/, /search, /products/:id)thrown out of the loaderthe root error boundary: "Something went wrong" or the problem title, with a link homeno; reload
GET /categories fails or 404caught in the root and home loadersthe department bar shows "All"no
Product 404product.tsx loaderthe "Page not found" boundaryno
BFF unreachable through the in-server proxyserver/proxy.tsbrowser call fails with 503 /problems/upstream-unavailable (after at most 20 s); the action shows "The store is temporarily unavailable. Please try again shortly."no
504 from the BFF (budget expired)problemMessage"That took too long. Nothing was changed; please try again."no
session-required (422)problemMessage, cart-session.ts, shopper.ts"Please sign in or register on the Account page first.", or an anonymous visitor is treated as having no cart and no accountno
stale-delivery-selection (409)cart actions"Delivery options were just refreshed. Please choose your delivery option again."no
cancel-after-lock (409)order detail action"This order can no longer be cancelled because fulfilment has started."no
Payment declined (session state DECLINED)checkout actionthe shopper stays on checkout with the declined messageby the shopper
Placement in doubt (PLACING/AUTHORIZING)confirmation page"We are placing your order"; revalidates every 2 s up to 30 timesyes, polling for about a minute
REQUOTE_REQUIRED, EXPIRED, FAILEDcheckout actionexplains that nothing was chargedno
Delivery dates failbuy box and cart"Delivery dates are unavailable right now" (cart: charges omitted); the page still worksno
Remembered cart id gone (404) or not OPENcurrentCartthe key is cleared and the cart looks emptyn/a
Any other problemproblemMessagethe problem's detail, else its title, else "The request could not be completed."no

A BFF outage never fails the probes: /healthz and /readyz stay 200, so the Deployment keeps serving error pages instead of restarting. See Troubleshooting and the Runbook.

Changing a contract​

When the BFF contract changes, update app/lib/queries.ts, the stub (server/stub*.ts) and the contract assertions in app/lib/queries.test.ts and server/stub.test.ts in the same change. The stub is deliberately as strict as the services behind the BFF so that a drift fails in CI rather than on the cluster; two incidents (a wrongly named destination field and a full ZIP sent as destination) are recorded in INCIDENTS.md.