This project implements a RESTful API for a personal blog, developed following Clean Architecture principles and SOLID practices. The project serves as a reference implementation for .NET applications requiring a robust and well-structured architecture.
The project is structured in layers following Clean Architecture principles:
-
Domain Layer: Contains domain entities, business rules, and repository interfaces
- Implements Aggregate Root pattern for transaction management
- Uses Value Objects for immutable concept encapsulation
- Defines repository contracts through interfaces
-
Application Layer: Implements application use cases
- Uses CQRS pattern with MediatR for command and query separation
- Implements validation through FluentValidation
- Defines DTOs for data transfer between layers
-
Infrastructure Layer: Provides concrete implementations of defined interfaces
- Implements Repository pattern for data access
- Uses Entity Framework Core for ORM
- Implements Unit of Work pattern for transaction management
- Provides dependency injection configurations
-
API Layer: Presentation layer
- Implements RESTful endpoints
- Uses .NET 8 minimal APIs
- Defines API contracts through DTOs
- .NET 8.0: Main framework
- Entity Framework Core: ORM for data access
- MediatR: CQRS pattern implementation
- FluentValidation: Command and query validation
- Docker: Application containerization
- SQL Server: Main database
- NUnit: Testing framework
- Moq: Mocking framework for tests
- Bogus: Fake data generation for tests
src/
├── API/ # Presentation layer
│ └── Endpoints/ # RESTful endpoints
├── Application/ # Use cases and interfaces
│ ├── Articles/ # Article use cases
│ │ ├── Commands/ # Commands (write)
│ │ ├── Queries/ # Queries (read)
│ │ └── Services/ # Application services
│ └── Common/ # Shared components
├── Domain/ # Entities and business rules
│ ├── Articles/ # Article domain
│ │ ├── Entities/ # Entities
│ │ ├── ValueObjects/# Value objects
│ │ └── Repositories/# Repository interfaces
│ └── Shared/ # Shared components
├── Infrastructure/ # Concrete implementations
│ ├── Configuration/ # Configurations
│ ├── Domain/ # Domain implementations
│ ├── Persistence/ # Data access
│ └── UnitOfWork/ # UoW implementation
└── Tests/ # Unit and integration tests
├── Application/ # Use case tests
└── Domain/ # Domain tests
The project implements comprehensive test coverage:
- Unit Tests: Using NUnit and Moq
- Domain Tests: Business rule validation
- Application Tests: Use case validation
- Report Generation: Using Coverlet and ReportGenerator
To run tests:
dotnet testTo generate coverage report:
./Coverage-report.sh- .NET 8.0 SDK
- SQL Server (or SQLite for development)
- Docker (optional)
- Clone the repository:
git clone [REPOSITORY_URL]-
Configure connection string in
appsettings.json -
Restore dependencies:
dotnet restore- Run migrations:
dotnet ef database update --project src/Infrastructure --startup-project src/API- Run the project:
dotnet run --project src/API- Build the image:
docker build -t blog-api .- Run the container:
docker run -p 5000:80 blog-api- C# naming conventions
- SOLID principles implementation
- API and complex method documentation
- Validation across all layers
- Consistent exception handling
The project is configured for:
- Automated builds
- Test execution
- Coverage report generation
- Docker containerization
This project is licensed under the MIT License - see the LICENSE file for details.
- Alberth - Initial work