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

Read the architecture guide →

Domain principles and boundaries

The guiding principles BookWorm uses to keep ownership, contracts, and change propagation consistent across its bounded contexts.

Architecture

BookWorm enforces strict bounded-context isolation so every business fact has one authoritative owner, every derived view can be rebuilt safely, and every cross-service interaction uses an explicit versioned contract. These principles prevent shared-database coupling and keep operational work (scheduling and email delivery) cleanly separated from core commerce state.

Context and motivation

As a microservices platform grows, reading or mutating another service’s database table directly is the fastest way to create hidden coupling and data corruption. BookWorm eliminates shared-table shortcuts by pairing clear domain ownership rules with automated verification in CI (ArchUnitNET.TUnit, Pact consumer/provider tests, buf breaking, and turbo boundaries).

How it works

This diagram summarizes the four boundary rules governing data ownership and cross-context communication in BookWorm.

Loading graph...

Four guiding principles

  • One authoritative source of truth: Each business record belongs to one bounded context—books to CatalogDomainv1.0.0CatalogCore BookWorm subdomain that makes books discoverable, purchasable, and consistently described across the customer journ...Ownercatalog-experience-teamDiagramOpen docs, baskets to ShoppingDomainv1.0.0ShoppingCoordinates the customer basket and pre-purchase checkout intent, from selecting books through handing an accepted purch...Ownercommerce-fulfillment-teamDiagramOpen docs, accepted orders to OrderingDomainv1.0.0OrderingCreates durable Orders from a buyer's current basket, locks purchase-time pricing, and owns order lifecycle transitions ...Ownercommerce-fulfillment-teamDiagramOpen docs, and individual reviews to ReviewsDomainv1.0.0ReviewsCaptures individual customer feedback for books, publishes rating changes for Catalog discovery, and provides privacy-sc...Ownercatalog-experience-teamDiagramOpen docs.
  • Derived views are disposable and rebuildable: Catalog rating summaries, Qdrant vector indexes, FusionCache entries, and Marten OrderSummary views exist for fast reads and search. They never replace authoritative records and can be regenerated if they drift.
  • Explicit contracts over shared storage: Services never read or write another context’s database. Cross-context communication uses versioned REST (/api/v1/*), gRPC (book.v1, basket.v1), MCP (/mcp), A2A gRPC, or CloudEvents Kafka topics.
  • Operational work never mutates business state: Scheduled jobs (ProcessVectorBatchJob, HeartbeatJob) and email delivery (Notification with MailKit resilience and Kafka DLQs) never alter authoritative Order or Book business status.

Ownership matrix

Bounded contextAuthoritative ownershipExplicitly out of scope
CatalogDomainv1.0.0CatalogCore BookWorm subdomain that makes books discoverable, purchasable, and consistently described across the customer journ...Ownercatalog-experience-teamDiagramOpen docsBook metadata, taxonomies, pricing, availability, cover blobs, and derived search/rating viewsIndividual customer reviews, baskets, and accepted order snapshots
ShoppingDomainv1.0.0ShoppingCoordinates the customer basket and pre-purchase checkout intent, from selecting books through handing an accepted purch...Ownercommerce-fulfillment-teamDiagramOpen docsCustomer-scoped mutable baskets (Redis) and pre-order shopping intentAccepted orders, order lifecycle state, and product master data
OrderingDomainv1.0.0OrderingCreates durable Orders from a buyer's current basket, locks purchase-time pricing, and owns order lifecycle transitions ...Ownercommerce-fulfillment-teamDiagramOpen docsBuyer profiles, Order records, purchase-time item snapshots, and lifecycle transitionsMutable baskets, live catalog descriptions, and external payment settlement
ReviewsDomainv1.0.0ReviewsCaptures individual customer feedback for books, publishes rating changes for Catalog discovery, and provides privacy-sc...Ownercatalog-experience-teamDiagramOpen docsIndividual Feedback documents (Cosmos DB) and AI feedback summariesAuthoritative book metadata and Catalog’s derived rating summary
ConversationalDomainv1.0.0ConversationalRoutes BookWorm customer requests through privacy-filtered AI agents for catalog-backed book discovery and read-only sto...Ownerai-capabilities-teamDiagramOpen docsAG-UI session state (chatting-blob), routing decisions, and agent orchestrationCatalog book records, baskets, billing, and authoritative orders
PlatformDomainv1.0.0PlatformProvides cross-cutting capabilities for recurring scheduled triggers and durable, idempotent transactional email notific...Ownerplatform-engineering-teamDiagramOpen docsQuartz schedules (schedulerdb), notification idempotency (Redis), and SMTP submissionBusiness records owned by Catalog, Shopping, Ordering, or Reviews

Automated boundary enforcement

BookWorm validates these principles automatically in CI rather than relying on manual code review alone:

  • Backend architecture rules: tests/BookWorm.ArchTests (ArchUnitNET.TUnit) checks cross-service dependency isolation, domain entity/value-object rules, and handler conventions.
  • Asynchronous message contracts: Pact.NET consumer and provider tests (tests/pacts/) verify Kafka CloudEvents compatibility across producer/consumer pairs.
  • gRPC compatibility: buf lint and buf breaking --against lock.binpb protect book.v1 and basket.v1 Protobuf schemas.
  • Frontend layer boundaries: bun run boundaries (turbo boundaries in src/Clients) enforces the 4-tier dependency graph (config → foundation → domain → app).

Three-question pre-change boundary gate

Before implementing any cross-context feature, answer three questions:

  1. Which bounded context owns the authoritative state?
  2. Which explicit versioned contract carries the interaction?
  3. Is every downstream copy classified as derived (rebuildable) rather than authoritative?

Design trade-offs

DecisionBenefitsCosts and limits
No cross-service database readsServices deploy and change schemas independently without breaking neighborsCross-context displays require gRPC enrichment (Basket → Catalog) or asynchronous projections (Reviews → Catalog)
Anti-pattern prohibitionPrevents hidden coupling, status conflation, and non-rebuildable cachesRequires upfront contract design and Pact/Buf updates when schemas evolve

Anti-patterns prohibited in BookWorm

  • Querying another service’s PostgreSQL, Cosmos DB, or Redis store directly.
  • Treating a rating summary, Qdrant vector, or cache entry as authoritative truth.
  • Treating Finance saga timeout or SMTP acceptance as proof of Order completion or customer inbox delivery.
  • Embedding business-state mutations inside Quartz jobs or Notification workers.

Alternatives considered

  • Shared relational database with cross-schema joins: Reduces initial query boilerplate but couples every service release to a single schema and removes independent scaling (Cosmos DB for Reviews, Redis for Basket).