Skip to content

BooksHub is a .NET 8 Web API for an online book library and store. It supports role-based access (Admin, Author, Subscriber), book management, subscriptions, reviews, favorites, and much more .

Notifications You must be signed in to change notification settings

Meltorky/Books.Hub

Repository files navigation

📚 BooksHub – .NET 8 Web API

.NET Version License Tests Architecture Status Coverage

BooksHub is a .NET 8 Web API for an online book library and store. It supports role-based access (Admin, Author, Subscriber), book management, subscriptions, reviews, favorites, and much more — following Clean Architecture best practices.

✅ Swagger docs available at https://bookshub.tryasp.net/


✨ Features

  • 🔐 JWT Authentication with Refresh Tokens
  • 🧑 Admin, Author, and Subscriber roles
  • ✍️ Admin can manage categories, books, authors (living and historic)
  • 📚 Author accounts can create Author Profiles to publish their books
  • 👥 Subscribers can:
    • Subscribe to author profiles
    • Add books to favorites
    • Purchase books
    • Review books
  • 📦 Global exception handling & request rate limiting
  • 🧪 Full unit testing with xUnit, FakeItEasy, FluentAssertions
  • 📜 Swagger UI enabled
  • 🧠 Middleware profiling and execution timing
  • 🛡️ Role seeding and default Admin user
  • 🧩 Modular and extensible with SOLID, DRY, KISS, YAGNI principles

🧱 Tech Stack

Layer Technologies
Backend .NET 8 Web API, Entity Framework Core, SQL Server
Authentication ASP.NET Core Identity, JWT (Bearer Tokens), Refresh Token Support
Architecture Clean Architecture (4-tier): API, Application, Domain, Infrastructure
Utilities Custom Mappers, Action Filters, Options Pattern, Middleware
Testing xUnit, FakeItEasy, FluentAssertions
Docs & Logs Swagger, Serilog

📁 Project Structure

BooksHub
│
├── BooksHub.API # Entry point, Controllers, Middleware, Swagger
├── BooksHub.Application # DTOs, Interfaces, Services, Business Logic
├── BooksHub.Domain # Core Entities, Enums, Contracts
├── BooksHub.Infrastructure # EF Core DbContext, Repositories, Identity, Configurations
└── BooksHub.Tests # Unit Tests for repositories, controllers and Middlewares

🚀 Getting Started

Prerequisites


🔧 Setup Instructions

  # 1. Clone the repository
  git clone https://github.com/your-username/BooksHub.git
  cd BooksHub
  
  # 2. Set connection string & JWT secret in appsettings.Development.json
  #    - "DefaultConnection"
  #    - "JWT:Key"
  
  # 3. Apply EF Core migrations
  dotnet ef database update --project BooksHub.Infrastructure
  
  # 4. Run the application
  dotnet run --project BooksHub.API

✅ Swagger docs available at https://bookshub.tryasp.net/


🔐 Authentication & Seeding

  • ✅ On first run:

    • AppRoles are seeded (Admin, Author, Subscriber)

    • Admin user is seeded (you can update email/password in the seeder)

    • Categories seeded via migration

  • JWT tokens issued on login

  • Refresh tokens handled via /auth/refresh-token endpoint


🧪 Testing

Run unit tests using:

  dotnet test
  • Frameworks: xUnit, FakeItEasy, FluentAssertions

  • Coverage: Middlewares, Repositories, Controllers


🧰 Extra Features

  • 🧠 Execution Time Filter: Tracks time taken by each controller action.

  • 🔥 Rate Limiting Middleware: Allows max 5 requests per 10 seconds per IP.

  • 💥 Global Exception Middleware: Catches and handles all unhandled exceptions.

  • 🧾 JWT & Image Options: Configured via IOptions.

  • 🖼️ Image Validation: Validates size and extension before upload.

  • 🧬 Custom AutoMapper Replacement: Lightweight object mapping.

  • 🔐 IdentitySeederExtension & JwtAuthenticationExtension: Simplifies startup logic.


Database Schema

erDiagram
    BaseEntity {
        int Id PK
        string Name
    }
    
    Author {
        int Id PK
        string Name
        string Nationality
        string Bio
        bool IsActive
        DateOnly DateOfBrith
        byte[] AuthorImage
        bool HaveAccount
        string ApplicationAuthorId FK
    }
    
    Book {
        int Id PK
        string Name
        string Description
        string Language
        double Rating
        DateOnly PublishedDate
        int PageCount
        double Price
        bool IsAvailable
        int TotalCopiesSold
        byte[] BookCover
        int AuthorId FK
    }
    
    Category {
        int Id PK
        string Name
    }
    
    BookCategory {
        int BookId PK_FK
        int CategoryId PK_FK
    }
    
    UserBook {
        int BookId PK_FK
        string UserId PK_FK
    }
    
    BookReview {
        int Id PK
        string UserId FK
        int BookId FK
        int Rating
        string Comment
        DateTime CreatedAt
    }
    
    AuthorSubscriber {
        int AuthorId PK_FK
        string SubscriberId PK_FK
    }
    
    ApplicationUser {
        string Id PK
        string UserName
        string Email
        string FirstName
        string LastName
        List FavouriteBooks
        List RefreshTokens
    }
    
    BaseEntity ||--o{ Author : inherits
    BaseEntity ||--o{ Book : inherits
    BaseEntity ||--o{ Category : inherits
    
    Author ||--o{ Book : "writes (1:N)"
    Author ||--o{ AuthorSubscriber : "has subscribers (1:N)"
    
    Book ||--o{ BookCategory : "has (1:N)"
    Category ||--o{ BookCategory : "contains (1:N)"
    
    Book ||--o{ UserBook : "owned by (1:N)"
    ApplicationUser ||--o{ UserBook : "owns (1:N)"
    
    Book ||--o{ BookReview : "receives (1:N)"
    ApplicationUser ||--o{ BookReview : "writes (1:N)"
    
    ApplicationUser ||--o{ AuthorSubscriber : "subscribes to (1:N)"
Loading

🧭 Roadmap

  • ✅ Backend API (current)

  • 🔄 Add CQRS support

  • 📦 Docker support for local development

  • ⚙️ CI/CD pipeline (GitHub Actions or Azure DevOps)

  • 🌐 Frontend (React or Next.js)


🖼️ Screenshots

Home Home Home Home Home Home Home


👤 Author

Mohamed Eltorky .NET Backend Developer 📫 Contact: [m.eltorky1014@gmail.com]

About

BooksHub is a .NET 8 Web API for an online book library and store. It supports role-based access (Admin, Author, Subscriber), book management, subscriptions, reviews, favorites, and much more .

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages