An advanced ASP.NET Core Web API for managing a book library, demonstrating best practices in routing, middleware, caching, authorization, logging, documentation, testing, and performance.
- 📖 Complete Book Management - Create, read, update, and delete books with all details
- 👩💻 Author Tracking - Link books to authors with biographical information
- 🏷️ Category Organization - Assign multiple categories to books
- ⭐ Review System - Store and retrieve book reviews with ratings
- 🔍 Advanced Search - Find books by title, author, or description using LINQ
- 📊 Rating Analytics - Calculate average ratings across books
- 📘 API Documentation - Auto-generated Swagger/OpenAPI documentation
- Advanced Routing: Attribute routing, route constraints, and custom routes.
- Middleware & Filters: Custom request logging middleware and action logging filter.
- Caching: Response caching, in-memory caching, and distributed Redis caching.
- Role-Based Authorization: Restrict endpoints to roles (e.g., Admin for create/update/delete).
- Logging & Monitoring: Serilog integration, health check endpoint (
/health). - Automated Testing: xUnit and Moq for unit testing controllers and repositories.
- Performance Tuning: AsNoTracking, pagination, and profiling guidance.
- Pagination: All major endpoints support paginated responses with metadata (total count, page, size, total pages).
graph TD A[Controllers] --> B[Repositories] B --> C[DbContext] C --> D[(SQL Database)] subgraph "Data Models" E[Book] <--> F[Author] E <--> G[Category] E <--> H[Review] end | Entity | Description | Relations |
|---|---|---|
| 📕 Book | Core book information | Belongs to Author, Has many Categories, Has many Reviews |
| 👤 Author | Writer details with bio | Has many Books |
| 🏷️ Category | Genre classification | Has many Books |
| 💬 Review | User feedback and ratings | Belongs to Book |
- .NET 6.0 SDK or newer
- SQL Server (LocalDB or full version)
- Visual Studio / VS Code or preferred IDE
-
Clone & Navigate:
git clone https://github.com/NickiMash17/BookLibrarySystem.git cd BookLibrarySystem -
Restore Packages:
dotnet restore
-
Set Up Database:
dotnet ef database update
-
Launch the API:
dotnet run
-
Explore with Swagger:
https://localhost:7001/swagger/index.html
| Method | Endpoint | Description |
|---|---|---|
GET | /api/Books | 📋 List all books |
GET | /api/Books/{id} | 📕 Get book details |
GET | /api/Books/author/{id} | 👤 Get author's books |
GET | /api/Books/category/{id} | 🏷️ Get books by category |
GET | /api/Books/search?term={query} | 🔍 Search books |
GET | /api/Books/ratings | ⭐ Get books with ratings |
POST | /api/Books | ➕ Add new book |
PUT | /api/Books/{id} | 📝 Update book |
DELETE | /api/Books/{id} | 🗑️ Delete book |
BookLibrarySystem/ ├── 🎮 Controllers/ │ └── BooksController.cs ├── 💾 Data/ │ ├── BookLibraryContext.cs │ └── DbInitializer.cs ├── 📋 Models/ │ ├── Author.cs │ ├── Book.cs │ ├── BookCategory.cs │ ├── Category.cs │ └── Review.cs ├── 🔄 Repositories/ │ ├── BookRepository.cs │ └── IBookRepository.cs ├── 🔀 Migrations/ ├── ⚙️ appsettings.json └── 🚀 Program.cs - Repository Pattern - Separation of data access logic
- Dependency Injection - Built-in .NET Core DI container
- LINQ Query Objects - For complex database queries with strong typing
- Entity Framework Core - ORM for database operations
- OpenAPI/Swagger - For automatic API documentation and testing
// Get all books with ratings above 4.0 var highlyRatedBooks = await _context.Books .Include(b => b.Author) .Include(b => b.Reviews) .Where(b => b.Reviews.Average(r => r.Rating) >= 4.0) .ToListAsync();Contributions make the open-source community amazing! Follow these steps:
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add some AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ for book lovers and developers alike
⭐ Star this repository if you find it useful! ⭐