How jeangatto/asp.net-core-clean-architecture-cqrs-event-sourcing works
This is a customer-management ASP.NET Core API demonstrating Clean Architecture, CQRS, and event sourcing. The primary workflow accepts customer create/update/delete requests, dispatches commands to application handlers, applies domain behavior, and persists changes; customer events also update the query-side model. Reads use separate query handlers and repositories, with caching for customer lookups. The tree and samples support the API, command/query, domain, event-projection, and cache paths shown; some infrastructure wiring and event-store internals are inferred only from names and README claims, so uncertain links are omitted.
Main entry points: Handlers Command handlers · CustomerEventHandler.cs Customer event handler · CustomerReadOnlyRepository.cs Customer read repository · DistributedCacheService.cs Cache service
Components 22
Public API
- Customers controller
src/Shop.PublicApi/Controllers/v1/CustomersController.cs - MediatR dispatcher
Command and Domain
- Customer commands
src/Shop.Application/Customer/Commands - Command handlers
src/Shop.Application/Customer/Handlers - Command validators
src/Shop.Application/Customer/Commands - Customer aggregate
src/Shop.Domain/Entities/CustomerAggregate/Customer.cs - Customer factory
src/Shop.Domain/Factories/CustomerFactory.cs - Customer write repository
src/Shop.Infrastructure/Data/Repositories/CustomerWriteOnlyRepository.cs - Unit of work
src/Shop.Infrastructure/Data/UnitOfWork.cs - Write database context
src/Shop.Infrastructure/Data/Context/WriteDbContext.cs
Events and Projection
- Customer domain events
src/Shop.Domain/Entities/CustomerAggregate/Events - Event store repository
src/Shop.Infrastructure/Data/Repositories/EventStoreRepository.cs - Customer event handler
src/Shop.Query/EventHandlers/CustomerEventHandler.cs - Event projection mapping
src/Shop.Query/Profiles/EventToQueryModelProfile.cs
Query Side
- Query synchronization
src/Shop.Query/Abstractions/ISynchronizeDb.cs - Query database context
src/Shop.Query/Data/Context/NoSqlDbContext.cs - Customer query model
src/Shop.Query/QueriesModel/CustomerQueryModel.cs - Customer query handlers
src/Shop.Query/Application/Customer/Handlers - Customer read repository
src/Shop.Query/Data/Repositories/CustomerReadOnlyRepository.cs - Cache service
src/Shop.Infrastructure/Data/Services/DistributedCacheService.cs
Other components
- API client
- Cache backend
Connections 24
- API client → Customers controller: sends HTTP
- Customers controller → MediatR dispatcher: dispatches request
- MediatR dispatcher → Command handlers: dispatches command
- MediatR dispatcher → Customer query handlers: dispatches query
- Command handlers → Command validators: validates input
- Command handlers → Customer write repository: checks and saves
- Command handlers → Customer factory: creates customer
- Customer factory → Customer aggregate: constructs aggregate
- Command handlers → Unit of work: commits changes
- Customer write repository → Write database context: persists customer
- Customer aggregate → Customer domain events: raises events
- Unit of work → Event store repository: stores events
- Customer domain events → Customer event handler: notifies handler
- Customer event handler → Event projection mapping: maps events
- Customer event handler → Query synchronization: upserts or deletes
- Query synchronization → Query database context: updates projection
- Customer event handler → Cache service: invalidates keys
- Customer query handlers → Customer read repository: requests customer data
- Customer query handlers → Cache service: gets or creates
- Cache service → Customer read repository: loads on miss
- Customer read repository → Query database context: reads projection
- Event projection mapping → Customer query model: builds model
- Customer read repository → Customer query model: returns models
- Cache service → Cache backend: reads and writes