How sswconsulting/ssw.cleanarchitecture works
Main Components
• Infrastructure Layer (src/Infrastructure): Handles cross-cutting concerns such as persistence (ApplicationDbContext, migrations), Interceptors, Middleware (like EventualConsistencyMiddleware), and integration with external resources (like the database). Represent this as “Infrastructure”.
• Tests: Represent the testing strategy separately (Unit Tests, Integration Tests, Architecture Tests) to show the validation of the system’s design and behavior.
Relationships & Interactions
• The WebAPI layer communicates directly with the Application layer to dispatch commands and queries.
• The Application layer, while orchestrating business logic, interacts with the Domain layer. Domain classes and events are used to enforce business rules.
• The Infrastructure layer acts as a support system (e.g., EF Core for persistence, interceptors for domain events) and is usually injected into the Application layer. Illustrate dependency flow (often via dependency inversion) from Application to Infrastructure.
• Tools are used during development or deployment (e.g., for migrations) and are external to the runtime flow.
Architectural Patterns and Key Design Principles
• Clean Architecture: Emphasize the separation of concerns and dependency inversion, where the inner layers (Domain, Application) have no dependency on outer layers (Infrastructure, Presentation).
• CQRS: Separate reading (queries) from writing (commands) in the Application layer.
• Additional Patterns: Use of Mediator (MediatR) for decoupling, Specification Pattern to encapsulate business rules, and a fluent result (ErrorOr) pattern to handle errors instead of using exceptions.
Relevant Technologies & Frameworks
• .NET (the entire solution is built on Dotnet 9).
• Entity Framework Core for ORM and persistence.
• MediatR for the CQRS messaging pattern.
• FluentValidation for validation, and potentially ErrorOr for result handling.
• OpenAPI/Scalar documentation for documenting API endpoints.
• The use of GitHub Actions for CI/CD (build, test, publish).
• Presentation/WebAPI Layer: Include endpoints (HeroEndpoints, TeamEndpoints), health checks, global exception handling.
• Application Layer: Commands, queries for Heroes and Teams, common behaviors (LoggingBehavior, ValidationErrorOrResultBehaviour, etc.).
• Domain Layer: Core business entities (Hero, Team), base classes (AggregateRoot, Entity), domain events (e.g., PowerLevelUpdatedEvent).
• Infrastructure Layer: Persistence (ApplicationDbContext, EF Core migrations), configurations (HeroConfiguration, TeamConfiguration), interceptors.
• Tools Layer: MigrationService, AppHost for running commands and orchestrating the environment.
• External Dependencies: Database, potential external APIs, and deployment tools.
• Flow from WebAPI to Application.
• Application calls into Domain for business processing.
• Application uses Infrastructure to handle interactions with persistence or external services.
• Dependency injection flows where Infrastructure is injected into Application or WebAPI.
• Annotations:
• Brief notes on each layer’s responsibilities and any key patterns (like CQRS, DDD).
• That the inner core (Domain) remains independent and technology-agnostic compared to outer layers.
This level of detail will help in visualizing and understanding the overall architecture while also serving as a communication tool for future development and onboarding. Start by sketching out these major components, then refine with interactions and dependencies until all essential architectural elements are captured.