Lessons in this course (8)

5. Modular monolith and DDD building blocks

IntermediateMediumLesson 5 of 8

Modular monolith — one deployable application, divided into modules by business capability; each module has its own folders/projects, its own database schema and a small public API; modules communicate via interfaces or in-process events.

text
src/
├── Shop.Host/                      ASP.NET Core host — registers all modules
├── Modules/
│   ├── Catalog/   Catalog.Api (endpoints) · Catalog.Core (domain + use cases) · Catalog.Infrastructure (schema "catalog")
│   ├── Ordering/  Ordering.Api · Ordering.Core · Ordering.Infrastructure (schema "ordering")
│   └── Billing/   Billing.Api · Billing.Core · Billing.Infrastructure (schema "billing")
└── Shared/       Shared.Kernel (base types), Shared.Infrastructure (event bus, outbox)

Rules: no module reads another's tables; communication through a module's public contracts or integration events; architecture tests enforce boundaries. A module can later become a microservice.

DDD building blocks:

BlockMeaningExample
EntityHas identity that persistsOrder (Id 1001)
Value objectDefined by its values, immutableMoney(4500, "INR"), Address
Aggregate (root)Consistency boundary; outside code changes it only through the rootOrder with OrderLines
Domain serviceLogic that doesn't belong to one entityPricingService
Domain eventSomething that happenedOrderPlaced
RepositoryCollection-like access to aggregatesIOrderRepository
Bounded contextBoundary where a model appliesSales vs Shipping