A clean architecture boilerplate for .NET 8 WebAPI, designed for scalable, maintainable, and testable RESTful APIs. Includes PostgreSQL integration, localization, CQRS, and best practices for enterprise-grade solutions.
To start a new project using this boilerplate, follow these steps:
dotnet new kl-api -n YourProjectName
Replace
YourProjectNamewith your desired project name.
- .NET 8
- ASP.NET Core WebAPI
- PostgreSQL
- Clean Architecture (Core, Infrastructure, Host)
- CQRS Pattern
- Dependency Injection
- FluentValidation
- IStringLocalizer for localization
- Core: Domain and Application layers
- Infrastructure: Data access and external services
- Host: API and Function endpoints
- CQRS: Command and Query separation
- Dependency Injection: All interfaces in Application, implementations in Infrastructure
- Message keys in
MessageConstants.cs(PascalCase) - Translations in JSON files under
Localization(snake_case keys) - Language files:
en-US.json,fr-FR.json, etc. - Use
{0},{1}for placeholders - Retrieve messages via
IStringLocalizer
- Request DTOs: Suffix with
RequestDto - Response DTOs: Suffix with
ResponseDto - Standard HTTP methods for CRUD
- RESTful endpoint naming
- API versioning via
@VersionedApiControlleror@VersionNeutralApiController - Use
ProducesResponseTypefor responses - Validation attributes in RequestDto
- EnumDataType for enum validation
- Use
IRepository<T>for data operations - No direct DbContext usage for DML
- Entity table names: snake_case
- Use migrations for schema changes
- Migration command:
dotnet ef migrations add <migrationName> --project ../../Migrators/Migrators.PostgreSQL --context ApplicationDbContext -o Migrations/Application - Implement pagination via
PaginatedListAsync
- Controllers: Only call service methods
- Use partial classes for complex entities
- Organize code into:
- Controllers
- Services
- DTOs
- Models
- Specifications
- Validators
- Use FluentValidation
- Consistent error response format
- Proper exception handling and error messages
- Authentication and authorization
- HTTPS only
- Secure sensitive data
- XML comments for public APIs
- OpenAPI/Swagger standards
- Document complex logic
- Caching strategies
- Use async/await for I/O
- Optimize queries
- Pagination for large datasets
- Structured logging
- Appropriate log levels
- Monitoring and alerting
- SOLID principles
- Clean, maintainable code
- Design patterns
- DRY principle
- Proper naming and formatting