BookNest, ASP.NET Core Web API ile geliştirilmiş, katmanlı mimariye sahip bir kitap yönetim API projesidir.
Bu projede authentication, role-based authorization, CRUD işlemleri, review/favorite yönetimi, pagination-filtering-sorting, Redis cache, global exception handling, validation, logging, unit test ve integration test yapıları uygulanmıştır.
- ASP.NET Core Web API ve C#
- .NET 8
- Entity Framework Core
- MSSQL
- JWT Authentication
- AutoMapper
- FluentValidation
- Serilog
- Redis
- Docker Compose
- xUnit
- Moq
- FluentAssertions
- Swagger / OpenAPI
BookNest
├── BookNest.API
├── BookNest.Application
├── BookNest.Domain
├── BookNest.Infrastructure
├── BookNest.UnitTests
├── BookNest.IntegrationTests
└── docker-compose.yml
Proje katmanlı mimari prensibine göre geliştirilmiştir.
| Katman | Sorumluluk |
|---|---|
BookNest.API |
Controller, middleware, authentication, authorization, Swagger ve uygulama başlangıç ayarları |
BookNest.Application |
DTO, service, interface, validator, mapping ve iş kuralları |
BookNest.Domain |
Entity ve enum yapıları |
BookNest.Infrastructure |
EF Core DbContext, repository implementasyonları, JWT service ve Redis cache implementasyonu |
BookNest.UnitTests |
Service ve validator unit testleri |
BookNest.IntegrationTests |
Controller integration testleri |
- Kullanıcı kayıt ve giriş işlemleri
- Admin / Member rol bazlı yetkilendirme
- Book, Author ve Category yönetimi
- Review ve favorite book yönetimi
- Pagination, filtering ve sorting
- Average rating hesaplama
- Soft delete
- Global exception handling
- Redis cache kullanımı
- Unit ve integration test yapısı
Redis cache, sık okunan ve nadiren değişen veriler için kullanılmıştır.
Cache uygulanan endpointler:
GET /api/authors
GET /api/categoriesCache temizleme işlemleri:
- Author create/update/delete sonrası author list cache temizlenir.
- Category create/update/delete sonrası category list cache temizlenir.
Book endpointleri bilinçli olarak cache kapsamına alınmamıştır. Çünkü kitapların average rating değeri review işlemleriyle sık değişebilir. Bu nedenle gereksiz cache invalidation karmaşıklığından kaçınılmıştır.
POST /api/auth/register
POST /api/auth/loginGET /api/books
GET /api/books/{id}
POST /api/books
PUT /api/books/{id}
DELETE /api/books/{id}GET /api/authors
GET /api/authors/{id}
POST /api/authors
PUT /api/authors/{id}
DELETE /api/authors/{id}GET /api/categories
GET /api/categories/{id}
POST /api/categories
PUT /api/categories/{id}
DELETE /api/categories/{id}GET /api/books/{bookId}/reviews
POST /api/books/{bookId}/reviews
GET /api/reviews/my
PUT /api/reviews/{reviewId}
DELETE /api/reviews/{reviewId}GET /api/favorites/my
POST /api/books/{bookId}/favorites
DELETE /api/books/{bookId}/favoritesProjede unit test ve integration test olmak üzere iki ayrı test projesi bulunmaktadır.
Unit testlerde service katmanındaki iş kuralları ve validator kuralları test edilmiştir.
Test edilen alanlar:
- UserService
- BookService
- AuthorService
- CategoryService
- ReviewService
- FavoriteBookService
- Auth validators
- Book validators
- Author validators
- Category validators
- Review validators
Kullanılan araçlar:
- xUnit
- Moq
- FluentAssertions
- FluentValidation TestHelper
Integration testlerde API endpointleri gerçek HTTP request mantığıyla test edilmiştir.
Test edilen controllerlar:
- AuthController
- BooksController
- AuthorsController
- CategoriesController
- ReviewsController
- FavoriteBooksController
Integration testlerde gerçek MSSQL yerine EF Core InMemory Database kullanılmıştır. Böylece testler izole ve tekrar çalıştırılabilir yapıdadır.
Tüm testleri çalıştırmak için:
dotnet testRedis, Docker Compose ile yönetilmektedir.
Redis container’ını başlatmak için:
docker compose up -dRedis bağlantısını test etmek için:
docker exec -it booknest-redis redis-cli pingBeklenen çıktı:
PONG
Redis container’ını durdurmak için:
docker compose downRepository’yi klonla:
git clone https://github.com/fskalkan/BookNest.git
cd BookNestRedis’i başlat:
docker compose up -dBookNest.API projesinde appsettings.Development.json dosyası oluştur ve aşağıdaki örneği kendi ortamına göre düzenle:
{
"ConnectionStrings": {
"DefaultConnection": "Server=YOUR_SERVER_NAME;Database=BookNestDB;Trusted_Connection=True;TrustServerCertificate=True;MultipleActiveResultSets=true"
},
"Jwt": {
"Key": "YOUR_SECRET_KEY_MINIMUM_32_CHARACTERS",
"Issuer": "BookNestAPI",
"Audience": "BookNestClient",
"ExpireMinutes": 60
},
"Redis": {
"ConnectionString": "localhost:6379"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}Migrationları uygula:
dotnet ef database update --project BookNest.Infrastructure --startup-project BookNest.APIAPI’yi çalıştır:
dotnet run --project BookNest.APIAPI çalıştıktan sonra Swagger arayüzüne development ortamında erişilebilir.
Ferhat Samet Kalkan