docs: BFF cart and PDP override guide — connector-override approach (CXSPA-13000) - #21827
docs: BFF cart and PDP override guide — connector-override approach (CXSPA-13000)#21827npapp-dev002 wants to merge 56 commits into
Conversation
…assic integration
…ssic BFF integration
…or clarity and accuracy
…with npm registry access details and component examples
…mentation for Spartacus integration
…ct.json in storefrontapp
…tents, correcting typing issues.
…larity and consistency
…-bff-reference-implementation documentation
…mplementation documentation
Co-authored-by: Krzysztof Platis <platonn.git@gmail.com>
…ementation documentation
…mit guidance for Spartacus schematics
…tation documentation
… state requirements and configuration examples
…rence-implementation documentation
…nce-implementation documentation
…-bff-reference-implementation documentation
Co-authored-by: Paweł Fraś <fras.pawel@yahoo.com>
…-bff-reference-implementation documentation
Co-authored-by: Paweł Fraś <fras.pawel@yahoo.com>
…ion documentation
…etup and clarify SSR requirements
…reference-implementation
…ation documentation
…pa-bff-reference-implementation
…pa-bff-reference-implementation
…-reference-implementation
…fy usage in spa-bff-reference-implementation
…ff-reference-implementation
…f-reference-implementation
… settings in spa-bff-reference-implementation
…rence-implementation
…ference-implementation
…nk in spa-bff-reference-implementation
…to doc/CXSPA-13587
…eference-implementation
Co-authored-by: Paweł Fraś <fras.pawel@yahoo.com>
…ration in spa-bff-reference-implementation
…ence-implementation
…erence-implementation
…spa-bff-reference-implementation
Documents the connector-override approach for integrating a Vivaldi BFF with a standard Spartacus Classic storefront, including the PDP aggregation demonstration that shows the core BFF performance benefit.
There was a problem hiding this comment.
I think we need to confirm who's the target of this documentation. If I'm not mistaken, we're targeting current/future users of classic Spartacus. If that's true, we could omit all Spartacus-BFF references, because, at this stage, this is a separate product with a separate target - I wouldn't mix-and-match these two and recommend doing that in customer's apps in documentation for classic Spartacus.
| - A BFF can be introduced into a running production storefront | ||
|
|
||
| **What it does not give you:** | ||
| - Fully clean architecture — unused OCC code remains in the browser bundle |
There was a problem hiding this comment.
query: The statement seem to be right due to how we provide the code and how barrel files works, but would be good double-checking if maybe tree-shaking does the work if particular occ-related layer is completely unused in the code.
|
|
||
| --- | ||
|
|
||
| ### Approach B — Purpose-built BFF storefront (spartacus-bff) |
There was a problem hiding this comment.
major: I don't feel comfortable with proposing this option for several reasons:
- Spartacus-BFF libraries are not as mature as classic Spartacus
- Spartacus-BFF contracts are MCS-based and may strongly differ from what is expected by classic Spartacus UI
- not all features from classic Spartacus are implemented in Spartacus-BFF
- from the architectural point of view, it might not be optimal to propose customers depending on two different products (with different release cycles), yet with similar public API - this will decrease the DX and this is what we want to avoid now in Spa-BFF by cutting off the dependency to classic Spa libraries.
Being honest, I'm not sure if we should mention spartacus-bff project/libraries in this document. They are two separate products and spartacus-bff was not ment to be integrated with classic Spartacus. We could base on how BFF is used in spa-bff, but for classic Spa customers, it should be rather from-scratch description, not a usage of spa-bff libraries.
EDIT: apoloigies, Only now I see it is not about combining both, classic Spartacus and Spartacus-BFF in one library. Still, I'm not sure if we should mention the product in document for classic Spartacus users. But I might be wrong.
| **Approach B** is the target architecture — what a new storefront would be | ||
| built on, or what an existing storefront would move to over time by replacing | ||
| feature modules one by one with their `@spartacus-bff/*` equivalents. |
There was a problem hiding this comment.
major: I would be careful with this statement since it is not something sure at this state and it may give classic Spartacus customers rise to the unfounded fear that they will have to switch to a new product in the future.
|
|
||
| --- | ||
|
|
||
| ## Which approach should I choose? |
There was a problem hiding this comment.
major: I'm not sure if we should include this or similar section, since this sounds like we recommend using BFF this way of another for classc Spartacus customers. I'm not sure if that's true at this moment and if we should recommend anything. I might be mistaken, but I'd stick to real-life examples of how to use BFF in classic Spa, without any recommendation.
Summary
This PR adds
docs/spa-bff-integration-guide.md, a guide explaining how toreplace direct OCC calls in a standard Spartacus Classic storefront with BFF
procedures. The storefront UI, components, and Angular routing are unchanged —
only the data layer is replaced.
Why a BFF simplifies the UI layer
With direct OCC the browser is responsible for fetching OAuth2 tokens, the OCC
base URL is embedded in
index.html, and every page may make multipleindependent round trips to OCC. A BFF moves all of this server-side. The
browser talks to a single relative
/bff/apiendpoint using tRPC, sends nocredentials for anonymous sessions, and sees no OCC URLs.
Two integration approaches
Approach 1 — Connector override
BffCartBaseModulereplacesCartConnectorandCartEntryConnectorinsidethe lazy cart feature injector.
BffProductModulereplaces the three productconnectors at root level. The existing NgRx graph, facades, and UI components
are completely unchanged.
Activating: point
CART_BASE_FEATUREatBffCartBaseModuleincart-base-feature.module.ts.Approach 2 — Facade override
BffActiveCartServiceimplementsActiveCartFacadedirectly using AngularSignals. There are no NgRx actions, reducers, or effects for cart — state is a
Signal updated in place after each BFF mutation. This is the default active
configuration in this workspace.
Activating: import
BffActiveCartModuleinapp.module.tsand keepcart-base-feature.module.tspointing at the standardCartBaseModule.PDP aggregation
The BFF exposes a
product.getPageDataprocedure that fans three OCC callsout in parallel server-side using
Promise.allSettled, returning a merged{ product, references, reviews }payload in one server round trip. Thedocument explains why the browser still makes three
/bff/apicalls inApproach 1 (three independent NgRx effects, no shared connector call path)
and what would be required to reduce it to one.
Angular DI problem — documented
CartBaseCoreModulere-providesCartConnectorin its lazy injector, shadowingany root-level override. The document explains three approaches that fail and
the working solution: define connector subclasses inline in the same file as
the lazy wrapper module so the bundler cannot split them into separate chunks.
Known pitfalls documented
toObservable()injection context — must be called as field initializersguidvscode— OCC anonymous carts useguid; usingcodealone causes write operations to silently exitAddedToCartDialogComponentwaits forCartAddEntrySuccessEventwhich is normally fired by NgRx effects; must bedispatched manually in the facade override
_reload()completesso
isStable()is alreadytrueandgetLastEntry()finds the new entryTest plan
/bff/api/product.*calls and no direct OCC calls429430or23355) to cart; verifycart.createandcart.addEntryappear under/bff/api/with no directOCC cart calls
flickering or spinner flash
stored for anonymous sessions