How nguyentanphatka/cleanarchitecture works
Main Project Type and Purpose
• Recognize that this is a full-stack, clean architecture solution template. It includes a Blazor WebAssembly client (the presentation layer), an ASP.NET Core Server (hosting the API and additional web services), and a strongly layered backend that is broken up into Application, Domain, and Infrastructure projects.
• Its purpose is to provide an enterprise-grade boilerplate that implements patterns like CQRS (commands/queries), repository/unit-of-work, mapping profiles, validators, and rich localization resources.
File Structure to Identify the Key Architectural Components
• The top-level “src” folder contains multiple projects including:
• Application: Houses business logic, use-case implementations (commands and queries), configurations, validators, mappings, requests/responses, and service interfaces.
• Domain: Contains the core domain entities, contracts, and enums.
• Infrastructure & Infrastructure.Shared: Contains data-access concerns, EF Core contexts, repository implementations, services (e.g., Audit, Mail, etc.), and database migrations.
• Client and Client.Infrastructure: Contains the Blazor WebAssembly front-end including UI pages, shared components, resource files for localization and state management. The “Client.Infrastructure” project covers concerns like authentication, HTTP interceptors, routing, and managers to communicate with the API.
• Server: Contains ASP.NET Core controllers (grouped by feature such as Identity, Catalog, Utilities), middleware, signalR hubs, Dockerfile and startup configuration.
• Shared: Contains common utilities, helpers, constants, and wrappers (for handling responses, pagination, etc.)
• Notice also the presence of docker-compose files and related Docker configuration files, indicating that this solution is container-friendly.
Major Components and Layers
• Presentation Layer:
• Client (Blazor WebAssembly with MudBlazor Components)
• Client.Infrastructure (Communication managers, Authentication handlers)
• Server/API Layer:
• ASP.NET Core “Server” project with Controllers organized by feature areas (Identity, Catalog, Communication, Utilities, etc.)
• SignalR Hub for real-time communication
• API Endpoints for Blazor client calls
• Application Layer:
• “src/Application”: Implements business rules using CQRS (commands, queries) and validations.
• Service Interfaces and mapping profiles (AutoMapper configuration)
• Domain Layer:
• “src/Domain”: Contains business entities, contracts (interfaces like IEntity, IAuditableEntity), and enums defining core domain types.
• Infrastructure/Data Access Layer:
• “src/Infrastructure” & “src/Infrastructure.Shared”: Implements repository patterns, EF Core contexts (e.g., BlazorHeroContext), migrations, and configuration classes.
• Services to support external integrations like SMTP/SendGrid for mail, storage providers, and other utilities.
• Shared/Common Layer:
• “src/Shared”: Provides common constants, models, wrappers, and settings which are used across the solution.
Relationships and Data Flow
• The Blazor client interacts with the ASP.NET Core API (Server) via RESTful endpoints and real-time communication via SignalR.
• The Server controllers then use the Application layer to process requests (via commands and queries) and enforce business rules.
• The Application layer, in turn, calls into the Infrastructure layer (through repository interfaces and unit-of-work implementations) to manipulate data or fetch domain objects.
• The Domain layer represents the core business model and is used by both the Application and Infrastructure layers.
• Shared components provide utilities like error wrapping, pagination, and localizations across multiple layers.
• Docker and deployment configurations form the outer layer, ensuring that the entire solution can be containerized and deployed consistently.
Architectural Patterns and Design Principles to Highlight
• Clean (Layered) Architecture: With separation of concerns among Presentation, Application, Domain, and Infrastructure.
• CQRS Pattern: Visible in the Application layer with directories for Commands and Queries.
• Repository and Unit-of-Work Patterns in the Infrastructure layer.
• Dependency Injection: Usage throughout the solution, especially in controllers and services.
• Mapping Profiles and Validators: For translating between DTOs and domain entities, as well as ensuring data integrity.
• Localization/Resource Management: There is extensive use of resource files for multiple languages within Client and Server projects.
• Docker and Containerization: Noting docker-compose and Dockerfile configuration.
Summary of Essential Elements to Capture
• The separation of the solution into Presentation (Blazor Client), API/Server, Application (Business Logic via CQRS), Domain (Core Entities and Contracts), Infrastructure (Data Access & External Service Integrations), and Shared/Common utilities.
• How these layers interact with each other using defined interfaces and dependency inversion.
• Docker/Deployment boundaries and external dependencies where applicable.
• Annotations for key patterns like CQRS, Repository/Unit-of-Work, and Dependency Injection.