How ardalis/ddd-guestbook works
1. CleanArchitecture.Core – This is the heart of the system. It holds the domain layer containing entities (e.g., Guestbook, GuestbookEntry, ToDoItem), domain events, handlers, specifications, and shared kernel aspects. It defines the business rules and core logic with minimal external dependencies.
2. CleanArchitecture.Infrastructure – This layer implements the interfaces defined in the Core. It contains data access code (using Entity Framework Core), migration scripts, service implementations (email sender, domain event dispatcher), and dependency registration setups.
3. CleanArchitecture.Web – This is the user interface and entry point (an ASP.NET Core web project). It contains controllers (both API and MVC), pages, views, and configuration files (appsettings.json, startup settings). It also integrates the dependency injection container (StructureMap) to wire up the application’s components.
Additionally, there are several test projects (unit, functional, and integration) confirming the layered design and ensuring the system functions as expected.
A. Identify the Main Components:
• Domain Layer (Core Project)
• Domain Entities: Guestbook, GuestbookEntry, ToDoItem.
• Domain Events: EntryAddedEvent, ToDoItemCompletedEvent.
• Handlers: e.g., GuestbookNotificationHandler, ItemCompletedEmailNotificationHandler.
• Services and Specifications.
• Shared Kernel components (ValueObject, BaseEntity, etc.).
• Infrastructure Layer
• Data Access: AppDbContext, EF based repository implementations, EF Migrations.
• Domain Event Dispatcher and Email Message Sender implementations.
• Container Setup/Dependency Injection configuration.
• Web (Presentation) Layer
• API Controllers: GuestbookController, ToDoItemsController, MetaController.
• MVC Controllers & Views: HomeController, ToDoController, Razor Pages.
• Startup and Program configuration, along with static assets (wwwroot).
• External/Supporting Components
• External services such as email providers (via EmailMessageSenderService).
• CI/CD pipeline tools (Azure Pipelines configuration).
• Test Projects (Unit, Functional, Integration tests).
B. Determine Relationships and Interactions Between Components:
• The Web (Presentation) Layer depends on the Core Layer to receive business logic. It calls into controllers which either communicate directly with domain services or use API Models (DTOs) to transfer data.
• The Infrastructure Layer bridges between external resources (like the database or external APIs) and the Core. The Domain Layer defines interfaces (e.g., IRepository, IMessageSender) which the Infrastructure implements.
• Dependency inversion is central: higher-level modules (Core) shouldn’t depend on lower-level modules (Infrastructure) directly; instead, the Infrastructure implements interfaces defined in Core.
• Domain events flow out from the Domain Layer then are dispatched via the Infrastructure (DomainEventDispatcher) to trigger side effects (like email notifications).
C. Highlight Architectural Patterns and Design Principles:
• Domain-Driven Design (DDD): Focus on encapsulating business rules within entities, value objects, and domain services.
• Dependency Injection and Inversion: Use dependency injection frameworks (StructureMap and/or Autofac) to decouple layers.
• Separation of Concerns: Each layer is strictly responsible for its tasks (Core for business rules, Infrastructure for data persistency and external calls, and Web for UI concerns).
D. Include Relevant Technologies and Frameworks:
• ASP.NET Core for the Web layer.
• Entity Framework Core (with SQL Server as an example) for data access.
• StructureMap (or similar DI container) for dependency management.
• xUnit, Moq, and Microsoft.AspNetCore.TestHost in the test projects.
• Additional tools such as Azure Pipelines (CI/CD) are also part of the project’s broader ecosystem.
• Since this is a full-stack web application using Clean Architecture, focus on clearly separating the presentation (Web) part from the business logic (Core) and from external integrations (Infrastructure).
• Annotations or a key that notes the technology choices (ASP.NET Core, EF Core, StructureMap, etc.) associated with each layer.
• Use clear, descriptive labels such as “Domain (Core)”, “Infrastructure”, “Web (Presentation)”, and “Tests”.
• Optionally, add a segment for “CI/CD” showing Azure Pipelines as part of the development and deployment processes.
Happy diagramming!