How stphnwlsh/cleanminimalapi works
Main Components
• Presentation Layer: This is the entry point of the application. It includes the Minimal API endpoint definitions (e.g., AuthorsEndpoints.cs, MoviesEndpoints.cs, ReviewsEndpoints.cs, VersionEndpoints.cs), configuration files (appsettings.json variants), filters (ValidationFilter, ValidationAttribute), and extension methods that set up the WebApplication. Represent this component as “Presentation” or “API Endpoints”.
• Application Layer: This component encapsulates the business logic and the domain. It contains domain entities (like Author, Movie, Review, Version), CQRS-based commands and queries (such as GetAuthorsQuery/GetAuthorsHandler, CreateReviewCommand/CreateReviewHandler, etc.), interfaces representing domain repositories (IAuthorsRepository, IMoviesRepository, IReviewsRepository), and layers for dependency injection. Represent this component as “Application” with submodules for domain entities, queries/commands, and business logic.
• Infrastructure Layer: This is responsible for data persistence and interacting with the database. It includes Entity Framework’s DbContext (MovieReviewsDbContext), repository implementations (EntityFrameworkMovieReviewsRepository), entity configurations and mappings (e.g., AuthorConfiguration, MovieMappingProfile), and supporting extensions. Represent it as “Infrastructure – Data Access”.
Relationships and Data Flow
• Client/External Consumer → Presentation Layer: Indicate that incoming HTTP requests hit the Minimal API endpoints.
• Application → Infrastructure: The business logic accesses persistence by calling repository interfaces, with actual implementations provided in the Infrastructure layer.
• Optional Feedback Loop: The response flows backward from Infrastructure (if data is retrieved) to Application (to process it) and then back to Presentation for delivery to the client.
Architectural Patterns/Design Principles
• Clean Architecture: Stress the separation of concerns by having distinct layers that only interact through well-defined contracts and dependency injection.
• CQRS Influence: Although not strictly enforced for all operations, the separation between commands (writes) and queries (reads) exists in the Application layer.
• Dependency Injection: Note that even though the Presentation layer references Infrastructure (primarily for dependency resolution), the key domain logic remains isolated.
• Repository Pattern and Entity Mapping: Used in the Infrastructure layer to abstract the data access, typically using EF Core with AutoMapper for object mapping.
Relevant Technologies and Frameworks
• .NET 8 SDK (building the application)
• Minimal APIs in ASP.NET Core (Presentation layer)
• Mediator Pattern using Mediatr (in Application layer)
• FluentValidation (for validation in the Application and Presentation)
• Entity Framework (data persistence in Infrastructure)
• Serilog for logging and Swashbuckle for OpenAPI specification generation