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

Read the architecture guide →

ADR-BW-009: Use local CQRS handlers and the established Mediator

Reuse CQRS and Mediator.SourceGenerator for in-process request handling without treating local messages as service integration contracts.

November 7, 2026Proposed
FieldValue
StatusProposed
Date2026-11-07
OwnersArchitecture Enabling TeamTeamArchitecture Enabling TeamEnabling team facilitating BookWorm's architecture governance, ADRs, arc42 documentation, engineering standards, testing...Open docs
Affected ResourcesBookWormDomainv1.0.0BookWormCore e-commerce domain for the BookWorm online bookstore, coordinating catalog discovery, customer baskets, order fulfil...Ownerarchitecture-enabling-teamDiagramRepositoryOpen docs
Related ADRsADR-BW-011: Reuse request validation and structured HTTP errorsDecision Recordv1.0.0ADR-BW-011: Reuse request validation and structured HTTP errorsValidate applicable requests before handlers and expose predictable HTTP problem responses without leaking internal exce...Ownerarchitecture-enabling-teamOpen docs, ADR-BW-016: Verify behavior, contracts, and boundaries in separate layersDecision Recordv1.0.0ADR-BW-016: Verify behavior, contracts, and boundaries in separate layersCombine focused business tests, consumer/provider contracts, architecture checks, schema validation, and high-value user...Ownerarchitecture-enabling-teamOpen docs

Context & Problem Statement

HTTP and gRPC endpoints require consistent validation, logging, tracing, and transaction boundaries. Placing business logic directly inside endpoint definitions duplicates cross-cutting plumbing and complicates unit testing, while sharing internal command classes across services leaks private implementation details.

Decision Drivers

  • Testability: Unit-test commands and queries independently of HTTP/gRPC transport.
  • Zero reflection overhead: Use compile-time source generation (Mediator.SourceGenerator) over runtime reflection.
  • Consistent pipelines: Apply uniform validation, logging, and transaction behaviors.

Options Considered

OptionProsCons
Vertical-slice CQRS handlers via Mediator.SourceGeneratorCompile-time dispatch, clean testing, uniform pipeline behaviorsContributors must follow the vertical-slice handler convention
Alternative runtime-reflection mediator (MediatR)Familiar to some developersRuntime reflection overhead and licensing/ecosystem divergence
Inline logic in minimal API endpointsFewer files per endpointBloated endpoints, duplicated validation, harder unit testing
Share internal CQRS commands across servicesAvoids contract mappingCouples service deployments and breaks bounded-context isolation

Decision & Consequences

Chosen Option: Organize in-process commands and queries as small, service-local vertical-slice handlers dispatched through Mediator.SourceGenerator. Internal commands and queries remain private to their owning service and are never exposed as cross-service integration contracts.

  • Positive: Clean separation between transport endpoints and business logic; fast compile-time dispatch.
  • Negative: Contributors must learn and adhere to the repository’s vertical-slice conventions.

Compliance Criteria

  • New backend endpoints must delegate to service-local CQRS handlers via Mediator.SourceGenerator (do not add MediatR).
  • Internal command/query types must not be referenced by other services.
  • Cross-cutting validation and logging must live in shared pipeline behaviors rather than repeated per handler.