An open API service indexing awesome lists of open source software.

https://github.com/mreshboboyev/book-management-api

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
https://github.com/mreshboboyev/book-management-api

asp-net-core-web-api clean-architecture cqrs ddd exception-handling idempotence logging outbox-pattern permission-based-authorization polly retry-mechanism rich-domain-model

Last synced: 6 months ago
JSON representation

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

Awesome Lists containing this project

README

          

# ๐Ÿ“š Book Management API โ€“ Scalable & Secure REST API ๐Ÿš€

![.NET 9](https://img.shields.io/badge/.NET%209-blue?style=for-the-badge)
![SQL Server](https://img.shields.io/badge/SQL%20Server-%F0%9F%93%9A-red?style=for-the-badge)
![CQRS](https://img.shields.io/badge/CQRS-%E2%9C%85-green?style=for-the-badge)
![Clean Architecture](https://img.shields.io/badge/Clean%20Architecture-%F0%9F%9A%80-purple?style=for-the-badge)
![JWT Authentication](https://img.shields.io/badge/JWT%20Authentication-%F0%9F%94%92-yellow?style=for-the-badge)

## ๐ŸŽฏ 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](https://dotnet.microsoft.com/download/dotnet/9.0)
โœ… [SQL Server](https://www.microsoft.com/en-us/sql-server/sql-server-downloads)
โœ… [Docker](https://www.docker.com/) (optional for running SQL Server container)

### **Step 1: Clone the Repository**
```bash
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`:
```json
"ConnectionStrings": {
"SqlServerDatabase": "Server=localhost;Database=BookManagement_DB;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True;"
}
```

### **Step 3: Run Database Migrations**
```bash
dotnet ef database update
```

### **Step 4: Run the Application**
```bash
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:
```bash
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](LICENSE) for details.

---

## ๐Ÿ“ž Contact

For feedback, contributions, or questions:
๐Ÿ“ง **Email**: mreshboboyev@gmail.com

๐Ÿ’ป **GitHub**: [MrEshboboyev](https://github.com/MrEshboboyev)

---

๐Ÿš€ **Build high-performance, scalable APIs with .NET!** Clone the repo & start coding today!