This project is a modular and scalable .NET 8 RESTful API built using Clean Architecture principles. It serves as a demo application for managing books, users, roles, and categories. It also includes features like auditing, validation, and scheduled background services.
- .NET 8
- Entity Framework Core (Code-First + SQLite)
- MediatR
- AutoMapper
- FluentValidation
- xUnit for testing
- Docker
BooksService
├── BooksService.Api --> Entry point (Controllers, Middleware, Program.cs)
├── BooksService.Application --> Business logic (Commands, Queries, Validators, Interfaces)
├── BooksService.Domain --> Domain models and exceptions
├── BooksService.Infrastructure --> Audit
├── BooksService.Persistence --> EF DbContext, Repositories, Decorators, Configuration
└── BooksService.Tests --> Unit tests (xUnit, Moq)
- User, Role, Book, Category entities with relationships
- Business validation methods in domain (e.g.
Category.EnsureDeletable())
- CQRS with MediatR (Commands/Handlers)
CreateUserCommandUpdateUserRoleCommandDeleteCategoryCommand
- DTOs and AutoMapper Profiles
- FluentValidation for input validation
- EF Core DbContext with SQLite
- Repository pattern + generic decorators:
AuditAddDecorator<TEntity>AuditUpdateDecorator<TEntity>AuditDeleteDecorator<TEntity>
- Seeding of sample data (Users, Roles, Books, Categories)
- Controllers for Users, Books, etc.
- Swagger UI
- Global Exception Middleware
- API Response Models (PagedResponse, ErrorResponse, etc.)
AuditCleanupService: Deletes audit records older than 20 days
- xUnit used for testing command handlers
- Moq used for mocking dependencies
- Tests included for:
CreateUserCommandHandlerUpdateUserRoleCommandHandlerDeleteCategoryCommandHandler
- Dedicated
AuditLogstable - Tracks Create, Update, Delete actions via decorators
- Background cleanup service runs daily to delete old logs
- Dockerfile for the API
- SQLite database stored in the container file system
- Run the app:
dotnet run --project BooksService.Api- Dummy data is inserted on DB initialization only if the DB is newly created.
- Decorators are injected using interfaces like
IAddRepository<TEntity>,IUpdateRepository<TEntity>, etc.
This app demonstrates a solid Clean Architecture design with separation of concerns, testability, and scalability. It includes decorators, audit logging, background processing, and custom validation.