Domain principles and boundaries
The guiding principles BookWorm uses to keep ownership, contracts, and change propagation consistent across its bounded contexts.
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
OrderSummaryviews 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 (Notificationwith MailKit resilience and Kafka DLQs) never alter authoritativeOrderorBookbusiness status.
Ownership matrix
| Bounded context | Authoritative ownership | Explicitly out of scope |
|---|---|---|
| CatalogDomainv1.0.0CatalogCore BookWorm subdomain that makes books discoverable, purchasable, and consistently described across the customer journ...Ownercatalog-experience-teamDiagramOpen docs | Book metadata, taxonomies, pricing, availability, cover blobs, and derived search/rating views | Individual 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 docs | Customer-scoped mutable baskets (Redis) and pre-order shopping intent | Accepted 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 docs | Buyer profiles, Order records, purchase-time item snapshots, and lifecycle transitions | Mutable 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 docs | Individual Feedback documents (Cosmos DB) and AI feedback summaries | Authoritative 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 docs | AG-UI session state (chatting-blob), routing decisions, and agent orchestration | Catalog 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 docs | Quartz schedules (schedulerdb), notification idempotency (Redis), and SMTP submission | Business 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 lintandbuf breaking --against lock.binpbprotectbook.v1andbasket.v1Protobuf schemas. - Frontend layer boundaries:
bun run boundaries(turbo boundariesinsrc/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:
- Which bounded context owns the authoritative state?
- Which explicit versioned contract carries the interaction?
- Is every downstream copy classified as derived (rebuildable) rather than authoritative?
Design trade-offs
| Decision | Benefits | Costs and limits |
|---|---|---|
| No cross-service database reads | Services deploy and change schemas independently without breaking neighbors | Cross-context displays require gRPC enrichment (Basket → Catalog) or asynchronous projections (Reviews → Catalog) |
| Anti-pattern prohibition | Prevents hidden coupling, status conflation, and non-rebuildable caches | Requires 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
Ordercompletion 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).
Related documentation
- Developer OnboardingCustom DocDeveloper OnboardingA Day 1 and Week 1 roadmap for understanding BookWorm, verifying a workspace, and making a first contribution.Ownerarchitecture-enabling-teamOpen doc — High-level contributor guide.
- Run BookWorm locallyCustom DocRun BookWorm locallyThe shortest path from a prepared machine to a responding local BookWorm application.Ownerarchitecture-enabling-teamOpen doc — End-to-end local quickstart tutorial.
- BookWormDomainv1.0.0BookWormCore e-commerce domain for the BookWorm online bookstore, coordinating catalog discovery, customer baskets, order fulfil...Ownerarchitecture-enabling-teamDiagramRepositoryOpen docs — Context map and service inventory.
- GlossaryCustom DocGlossaryShared plain-language definitions for BookWorm domain concepts, architecture terms, and recurring acronyms.Ownerarchitecture-enabling-teamOpen doc — Canonical terms and ownership notes.
- ADR-BW-001: Capability-aligned boundaries — Architectural decision record for bounded-context decomposition.