How misiukanis/simple-shop works
Main Components
• User Interface (Presentation Layer):
• The “Shop” project contains the Blazor components (pages, layouts, components), controllers (CustomersController, OrdersController, ProductsController), and the associated configuration (appsettings, Launch Settings, etc.).
• Application Layer:
• “Shop.Application” implements the CQRS pattern by having separate directories for commands, queries, event handlers, DTOs, and validators. It also contains Automapper profiles and behavior filters like the “ValidationBehavior”.
• Domain Layer:
• “Shop.Domain” holds your core business logic including aggregates (CustomerAggregate, OrderAggregate, ProductAggregate), shared core concepts (entities, aggregate roots, value objects, domain events), and domain-specific exceptions.
• Infrastructure Layer:
• “Shop.Infrastructure” includes implementations for persistence (repositories, MongoDbContext, DatabaseInitializer) and domain event dispatching (DomainEventDispatcher). The infrastructure is also integrated with external systems (EventStoreDB and MongoDB).
• Shared/Resources:
• “Shop.Shared” and “Shop.Resources” include constants, settings, and localization resources that support the entire system.
• Tests:
• “Shop.UnitTests” contains unit tests, such as for command handler testing, which verifies the core logic in the application layer.
Relationships and Interactions
• The Presentation Layer interacts with both the API controllers and Blazor components, which call into the Application Layer.
• The Application Layer leverages MediatR to execute commands, handle queries, validate inputs (using FluentValidation), and orchestrate responses from the domain.
• Domain events propagate from the Domain Layer and are handled in the Application Layer via event handlers, following the DDD and event sourcing patterns.
• The Infrastructure Layer provides the concrete implementations for repositories (both for MongoDB and EventStoreDB) and acts as the bridge for persistence and external system integrations.
• Dependency Injection is set up across layers to allow for loose coupling and ease of testing, also mentioned under “DependencyInjection.cs” files in the Shop, Shop.Application, and Shop.Infrastructure projects.
Architectural Patterns and Technologies
• Use of DDD for structuring the business logic, where Aggregates in the Domain layer encapsulate core behaviors.
• CQRS architecture: separate command and query paths in Shop.Application, complete with Validators, Handlers, and Mediator integration (MediatR).
• Event Sourcing where events (e.g., CustomerCreatedEvent, OrderCreatedEvent, ProductDeletedEvent) are stored and dispatched via the Infrastructure’s dispatcher.
• AutoMapper for mapping between domain models, DTOs, and read models.
• Mention logging (NLog), validations (FluentValidation), and web technologies (.NET 9.0, C# 13, and Blazor Server).
• Presentation Layer (Shop): Show UI components, controllers, and static assets (wwwroot).
• Application Layer (Shop.Application): Illustrate components such as Command Handlers, Query Handlers, Validators, DTOs, and Automapper Profiles.
• Domain Layer (Shop.Domain): Represent Aggregates (Customer, Order, Product), Domain Events, Entities, and Value Objects.
• Infrastructure Layer (Shop.Infrastructure): Represent Persistence (MongoDBContext, Repositories for MongoDB and EventStoreDB) and the Domain Event Dispatcher.
• Shared/Resources: Include support libraries such as Settings (from Shop.Shared) and Messages (from Shop.Resources).
• From the Presentation Layer to the Application Layer (calls from UI or API endpoints to command/query execution).
• From the Application Layer to the Domain Layer (invocations of domain logic and event generation).
• From the Domain Layer back to the Application Layer via domain events and event handlers.
• From the Application/Domain to the Infrastructure Layer (interaction with persistence mechanisms and external services).
• Use additional markers to indicate:
• Usage of architectural principles like CQRS and DDD.
• The flow of data (e.g., user initiates a command, command reaches an appropriate handler, business logic executes, events are triggered and stored).