Skip to content

Scalable Book Management API built with ASP.NET Core , following Clean Architecture, Domain-Driven Design (DDD), CQRS. Features JWT authentication, pagination, soft deletion, logging, validation pipelines, popularity score calculation, idempotent request handling. Built with SQL Server, EF Core, Quartz background jobs, and Polly retry mechanisms

Notifications You must be signed in to change notification settings

MrEshboboyev/book-management-api

Repository files navigation

📚 Book Management API – Scalable & Secure REST API 🚀

.NET 9 SQL Server CQRS Clean Architecture JWT Authentication

🎯 Overview

This Book Management API is a high-performance, scalable REST API built with ASP.NET Core and C#, implementing Clean Architecture, Domain-Driven Design (DDD), and CQRS. It supports CRUD operations, soft deletion, pagination, JWT authentication, popularity score calculation, and logging with validation pipelines.

Key Features:
Secure – JWT-based authentication with role-based authorization.
Efficient – Implements pagination, caching, and retry mechanisms.
Scalable – Built with CQRS, Event-Driven Architecture, and Outbox Pattern.
Reliable – Uses Quartz for background jobs and Polly for resiliency.


🏛️ Architecture & Design Patterns

This project follows Clean Architecture with Domain-Driven Design (DDD) principles:

📌 Domain Layer – Entities, Value Objects, Aggregates, and Domain Events.
📌 Application Layer – Commands, Queries, Services, and Event Handlers.
📌 Persistence Layer – EF Core, SQL Server, Interceptors, Repository implementations.
📌 Infrastructure Layer – Quartz Background Jobs, JWT, Idempotence.
📌 Presentation Layer – ASP.NET Core Web API with Swagger Documentation.

🔹 Key Patterns & Technologies Used

🔹 CQRS – Segregates commands (writes) and queries (reads).
🔹 Outbox Pattern – Ensures reliable event-driven architecture.
🔹 Rich Domain Model – Encapsulates behavior within entities.
🔹 Retry Mechanism (Polly) – Ensures reliability for external calls.
🔹 Idempotence – Prevents duplicate API requests.
🔹 Logging & Validation Pipelines – Ensures clean, validated, and logged API requests.
🔹 Global Exception Handling Middleware – Centralized error handling.


🛠️ Technologies & Tools

  • Framework – ASP.NET Core 8 / 9 Web API
  • Database – SQL Server, EF Core
  • Caching & Resiliency – Polly for retry mechanism
  • Background Jobs – Quartz.NET
  • Security – JWT-based authentication and permission-based authorization
  • API Documentation – Swagger / OpenAPI
  • Logging & Monitoring – Serilog
  • Validation – FluentValidation
  • Dependency Injection – Built-in .NET DI container

📖 Functional Features

1️⃣ CRUD Operations

Add Books – Supports single & bulk inserts.
Update Books – Modify book details with proper validation.
Soft Delete Books – Books can be restored if needed.
Retrieve Books – Fetch books by popularity (most-viewed first) with pagination.
Get Book Details – Includes real-time popularity score calculation.

2️⃣ Popularity Score Calculation

📌 Formula:

Popularity Score = (BookViews * 0.5) + (YearsSincePublished * 2)

📌 How it works:

  • BookViews – Counts the number of times a book’s details are retrieved.
  • YearsSincePublished – Older books receive a smaller score boost.
  • Live Computation – Popularity is calculated on the fly (not stored in DB).

3️⃣ Security & Authentication

JWT-based authentication – Secures all API endpoints.
Role-based authorization – Restricts access based on user permissions.

4️⃣ Pagination & Filtering

Retrieve books in order of popularity with pagination support.


🚀 Getting Started

📌 Prerequisites

.NET 9 SDK
SQL Server
Docker (optional for running SQL Server container)

Step 1: Clone the Repository

git clone https://github.com/MrEshboboyev/book-management-api.git
cd book-management-api

Step 2: Configure Database

Set up SQL Server and update connection strings in appsettings.json:

"ConnectionStrings": {
  "SqlServerDatabase": "Server=localhost;Database=BookManagement_DB;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True;"
}

Step 3: Run Database Migrations

dotnet ef database update

Step 4: Run the Application

dotnet run --project src/BookManagement.App

🔗 API Endpoints

Auth:

Method Endpoint Description
POST /api/auth/login Logs in a user by validating their credentials and generating a token.
POST /api/auth/register Registers a new user by creating their account with the provided details.

Users:

Method Endpoint Description
GET /api/users Retrieves the details of a current user.

Books:

Method Endpoint Description
POST /api/books Adds a new book.
POST /api/books/bulk Adds multiple books in bulk.
PUT /api/books/{id:guid} Updates an existing book.
DELETE /api/books/{id:guid} Soft delete a book
DELETE /api/books/bulk Soft deletes multiple books in bulk
GET /api/books Retrieve books by popularity (paginated)
GET /api/books/{id} Retrieves the details of a book by its unique identifier & popularity score

🧪 Testing

Unit Tests

Run unit tests for validation, application layer, and controllers:

dotnet test

Manual API Testing

📌 Use Postman or any REST client to:
Register/Login → Obtain a JWT Token
Add Books/api/books
Retrieve Books/api/books?PageNumber=1&PageSize=10
Get Book Details/api/books/{id} (track popularity score)


🎯 Why Use This Project?

Enterprise-Grade Architecture – Clean, scalable, and maintainable.
Performance-Oriented – Optimized with CQRS, caching, and indexing.
Security-First Approach – Uses JWT authentication and role-based access.
Ready for Production – Implements industry best practices.


📜 License

This project is licensed under the MIT License. See LICENSE for details.


📞 Contact

For feedback, contributions, or questions:
📧 Email: mreshboboyev@gmail.com

💻 GitHub: MrEshboboyev


🚀 Build high-performance, scalable APIs with .NET! Clone the repo & start coding today!

About

Scalable Book Management API built with ASP.NET Core , following Clean Architecture, Domain-Driven Design (DDD), CQRS. Features JWT authentication, pagination, soft deletion, logging, validation pipelines, popularity score calculation, idempotent request handling. Built with SQL Server, EF Core, Quartz background jobs, and Polly retry mechanisms

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages