How heitorgiacomini/modulith works
Purpose and Entry Points
Reference .NET 10 e-commerce modular monolith: Catalog, Basket, Ordering, and Accounts run in one ASP.NET Core API process. The API composition root is src/Bootstrapper/Api/Program.cs; its REST and source GraphQL schemas are consumed directly or through a Fusion gateway at src/Bootstrapper/Gateway/Program.cs. Angular starts at src/web-client/src/main.ts.
Host Composition and Module Boundaries
The API registers independently structured modules, each owning its endpoints, domain model, and EF Core context. Module bootstrap files are src/Modules/Catalog/Catalog/CatalogModule.cs, src/Modules/Basket/Basket/BasketModule.cs, and src/Modules/Ordering/OrderingModule.cs. Accounts is registered through src/Modules/Accounts/AccountsModule.cs. Cross-module business assembly dependencies are constrained; Basket accesses Catalog only through src/Modules/Catalog/Catalog.Contracts/Products/Features/GetProductById/GetProductByIdQuery.cs.
Request and Application Pipeline
Carter endpoint slices map REST requests to MediatR command/query handlers, e.g. src/Modules/Catalog/Catalog/Products/Features/CreateProduct/CreateProductEndpoint.cs and src/Modules/Basket/Basket/Features/CheckoutBasket/CheckoutBasketHandler.cs. Shared MediatR logging and validation execute around handlers via src/Shared/Shared/Behaviors/LoggingBehavior.cs and src/Shared/Shared/Behaviors/ValidationBehavior.cs. GraphQL source schemas are module-owned extensions: src/Modules/Catalog/Catalog/GraphQL/CatalogGraphQLExtensions.cs, src/Modules/Basket/Basket/GraphQL/BasketGraphQLExtensions.cs, and src/Modules/Ordering/Orders/GraphQL/OrderingGraphQLExtensions.cs.
Domain Modules and Persistence
Catalog owns product lifecycle and emits price-change domain/integration events (src/Modules/Catalog/Catalog/Products/Models/Product.cs, src/Modules/Catalog/Catalog/Data/CatalogDbContext.cs). Basket owns carts, validates products synchronously through Catalog contracts, and uses repository/cache abstraction (src/Modules/Basket/Data/Repository/CachedBasketRepository.cs, src/Modules/Basket/Data/BasketDbContext.cs). Ordering consumes checkout events to create orders (src/Modules/Ordering/Orders/EventHandlers/BasketCheckoutIntegrationEventHandler.cs, src/Modules/Ordering/Data/OrderingDbContext.cs). Accounts owns customer profile, addresses, and saved payment methods behind authenticated REST (src/Modules/Accounts/Accounts/Features/AccountEndpoints.cs, src/Modules/Accounts/Data/AccountsDbContext.cs).
Events, Reliability, and Consistency
EF Core interceptors audit entities and dispatch domain events in-process: src/Shared/Shared/Data/Interceptors/AuditableEntityInterceptor.cs and src/Shared/Shared/Data/Interceptors/DispatchDomainEventsInterceptor.cs. Catalog publishes price changes; Basket consumes them through src/Modules/Basket/Basket/EventHandlers/ProductPriceChangedIntegrationEventHandler.cs. Basket checkout persists an outbox message transactionally, then src/Modules/Basket/Data/Processors/OutboxProcessor.cs publishes src/Shared/Shared.Messaging/Events/BasketCheckoutIntegrationEvent.cs to RabbitMQ for Ordering.
Edge Services, Security, and Runtime
Docker Compose defines the deployable topology in src/docker-compose.yml and overrides in src/docker-compose.override.yml: PostgreSQL, Redis, RabbitMQ, Keycloak, Seq, API, Fusion gateway/composer, and Angular. Fusion composes API-hosted Catalog/Basket/Ordering schemas; the gateway forwards authorization using src/Bootstrapper/Gateway/AuthorizationForwardingHandler.cs and its generated archive src/Bootstrapper/Gateway/gateway.far. Keycloak realm provisioning is src/docker-config/keycloak/myrealm-realm.json.
Client Boundary
Angular 21 is organized by bounded context, with routes and facades separating UI from API access. Representative boundaries are src/web-client/src/app/contexts/catalog/catalog.routes.ts, src/web-client/src/app/contexts/basket/basket.facade.ts, and src/web-client/src/app/core/auth/auth.interceptor.ts. It authenticates with Keycloak, sends GraphQL to Fusion for composed reads, and uses direct API REST calls where required, notably Accounts.
Main entry points: Program.cs ASP.NET Core API · CatalogModule.cs Catalog · main.ts Angular client · OrderingModule.cs Ordering
Components 20
Clients
- Angular client · Context routes and facades separate UI from API access.
src/web-client/src/main.ts - Auth interceptor
src/web-client/src/app/core/auth/auth.interceptor.ts
Edge & Identity
- Fusion gateway · Composes module source schemas for client reads.
src/Bootstrapper/Gateway/Program.cs - Authorization forwarding
src/Bootstrapper/Gateway/AuthorizationForwardingHandler.cs - Keycloak
src/docker-config/keycloak/myrealm-realm.json
API Host & Pipeline
- ASP.NET Core API · Single process hosting all modules and their REST and source GraphQL endpoints.
src/Bootstrapper/Api/Program.cs - Carter endpoint slices · Maps HTTP requests to MediatR commands and queries.
src/Modules/Catalog/Catalog/Products/Features/CreateProduct/CreateProductEndpoint.cs - MediatR behaviors · Logging and validation wrap command and query handlers.
src/Shared/Shared/Behaviors/ValidationBehavior.cs - EF Core interceptors · Audits entities and dispatches domain events in-process.
src/Shared/Shared/Data/Interceptors/DispatchDomainEventsInterceptor.cs
Business Modules
- Catalog · Owns products and price-change events.
src/Modules/Catalog/Catalog/CatalogModule.cs - Basket · Owns carts, checkout, and cached basket access.
- Ordering · Creates orders from checkout integration events.
src/Modules/Ordering/OrderingModule.cs - Accounts · Owns authenticated customer profiles, addresses, and payment methods.
src/Modules/Accounts/AccountsModule.cs - Catalog product contract · Basket synchronously validates products through this contract.
src/Modules/Catalog/Catalog.Contracts/Products/Features/GetProductById/GetProductByIdQuery.cs
Data & Messaging
- Catalog database
src/Modules/Catalog/Catalog/Data/CatalogDbContext.cs - Basket store and cache
src/Modules/Basket/Data/Repository/CachedBasketRepository.cs - Ordering database
src/Modules/Ordering/Data/OrderingDbContext.cs - Accounts database
src/Modules/Accounts/Data/AccountsDbContext.cs - Basket outbox processor · Publishes persisted checkout messages after commit.
src/Modules/Basket/Data/Processors/OutboxProcessor.cs - RabbitMQ
src/Shared/Shared.Messaging/Events/BasketCheckoutIntegrationEvent.cs
Connections 23
- Angular client → Auth interceptor: uses
- Auth interceptor → Keycloak: authenticates with
- Angular client → Fusion gateway: composed GraphQL reads
- Angular client → ASP.NET Core API: direct REST, including Accounts
- Fusion gateway → Authorization forwarding: applies
- Authorization forwarding → ASP.NET Core API: forwards authorized GraphQL
- ASP.NET Core API → Carter endpoint slices: hosts
- Carter endpoint slices → MediatR behaviors: dispatches through
- ASP.NET Core API → Catalog: registers REST and GraphQL
- ASP.NET Core API → Basket: registers REST and GraphQL
- ASP.NET Core API → Ordering: registers REST and GraphQL
- ASP.NET Core API → Accounts: registers authenticated REST
- Catalog → Catalog database: persists products
- Basket → Basket store and cache: persists and caches carts
- Ordering → Ordering database: persists orders
- Accounts → Accounts database: persists customer data
- Basket → Catalog product contract: validates product
- Catalog product contract → Catalog: queries
- Catalog → EF Core interceptors: domain events on save
- EF Core interceptors → Basket: price-change event
- Basket → Basket outbox processor: checkout transaction
- Basket outbox processor → RabbitMQ: publishes checkout event
- RabbitMQ → Ordering: checkout event