Storefront has been decoupled into micro-frontends with a dedicated commerce app and shared shell.

Read the architecture guide →

Client State & Feature Slices

Separation of server cache from ephemeral UI state, thin route entrypoints, vertical feature slices, and client error boundaries.

ArchitectureReference

Purpose & Scope

This reference governs internal application structure and client-side state management across Storefront, Commerce, and Backoffice. It defines how route entrypoints stay thin, how vertical feature slices mirror backend bounded contexts, and how server cache is strictly separated from ephemeral UI state.

Architectural Principles & Rules

  • Thin route entrypoints: Application route files only declare page metadata, loading/error boundaries, and server-side data prefetching, delegating all presentation and interaction logic to domain-aligned feature slices.
  • Vertical feature slices: Inside each surface, UI components, filters, forms, and state are grouped by business capability (Catalog, Shopping, Ordering, Reviews) rather than technical file type, mirroring backend service boundaries.
  • Strict state separation: Remote domain data lives exclusively in the server-state query cache (hydrated from server prefetching); ephemeral client state (session-derived flags, feature toggles, derived basket badge counts) lives in lightweight atomic state.
  • Auth-gated background queries: Customer-specific queries such as basket state are gated on authenticated session status so anonymous visitors never trigger failing unauthorized requests.
  • Explicit error & loading boundaries: Every route segment defines declarative loading skeletons and error boundaries so transient failures degrade gracefully within the affected slice without crashing the entire page shell.
No Remote Domain Data in Global Client Stores

Never duplicate backend entities (books, orders, reviews, or basket items) into a manual global client store. Use the centralized query cache so deduplication, SSR hydration, stale-while-revalidate, and invalidation remain consistent.

Patterns & Boundaries

Concern / SurfaceArchitectural ApproachResponsibility BoundaryKey Trade-off
Route EntrypointsThin server wrappers handling metadata, prefetch hydration, and error/loading boundariesRoute layer owns URL mapping and SSR handoff; feature slices own UI and interactionsAdds one layer of indirection, repaid by clean Server/Client Component boundaries
Server State CacheCentralized query client (per-request on server, singleton in browser) with shared cache keysShared query layer owns keys, stale windows, and hydration; feature slices consume hooksRequires disciplined cache key invalidation on mutations
Ephemeral Client StateMinimal atomic state for auth flags, derived basket counts, and feature togglesCustomer shell owns cross-zone session/basket atoms; apps own local feature flagsContributors must distinguish server state from client-only UI state
Conversational AI StateStreaming AG-UI client runtime with declarative generative UI cards (Storefront only)Storefront manages chat session UI and live announcements; Chat API owns agent stateReal-time token streaming requires dedicated accessibility pacing

Quality & Operational Impact

  • Predictability: Single-source cache keys prevent hydration mismatches between server-rendered HTML and client-side query caches.
  • Performance: Per-request server query clients prevent cross-user data leaks while pre-hydrating initial views for fast first paint.
  • Maintainability: Vertical feature slices allow teams to evolve Catalog, Shopping, Ordering, or Reviews UI independently without cross-feature coupling.