# hac1es/friendwithbooks-backend architecture

> Architecture diagram of the GitHub repository hac1es/friendwithbooks-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hac1es/friendwithbooks-backend
- Repository: https://github.com/hac1es/friendwithbooks-backend

## Overview

##### Project type and purpose
- This is a single‐project ASP.NET Core Web API backend (FriendwithBooksBackend) providing REST endpoints and real‐time chat for a “Friend with Books” application. Its controllers cover authentication, user profiles, book catalog, shopping cart, orders, payments, reviews, flash sales, and a SignalR chat hub.

##### File structure
- Top level:
- FriendwithBooksBackend.sln – Visual Studio solution
- Program.cs – application entry point
- Under FriendwithBooksBackend/:
- Controllers/ – HTTP API endpoints (AuthController, BookController, CartController, etc.)
- Hubs/ – SignalR Hub for real‐time chat (ChatHub.cs)
- Data/ – EF Core DbContext (DataContext.cs) and any DTOs
- Migrations/ – EF Core database migrations
- Models/ – Entity classes (Book, User, Order, Review, FlashSale, Transaction, etc.)
- Interfaces/ – Repository interfaces (IBookRepository, IUserRepository, etc.)
- Repositories/ – Concrete repository implementations using EF Core
- Services/ – Business logic and cross‐cutting services (CachingServices, ChatService, UserIDProvider)
- appsettings.json / appsettings.Development.json – configuration for database, caching, etc.

##### Detail
- Internal interactions (e.g., CartController → CartService → CartRepository → DataContext)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Client Apps"
        Clients["Web/Mobile Clients"]:::clients
    end

    subgraph "API Layer"
        AuthCtrl["AuthController"]:::controllers
        BookCtrl["BookController"]:::controllers
        CartCtrl["CartController"]:::controllers
        ChatCtrl["ChatController"]:::controllers
        HomeCtrl["HomeController"]:::controllers
        OrderCtrl["OrderController"]:::controllers
        PaymentCtrl["PaymentController"]:::controllers
        ProfileCtrl["ProfileController"]:::controllers
        AdminCtrl["AdminController"]:::controllers
        ChatHub["ChatHub (SignalR)"]:::controllers
    end

    subgraph "Business Layer"
        CachingSvc["CachingServices"]:::services
        ChatSvc["ChatService"]:::services
        UIDProvider["UserIDProvider"]:::services
    end

    subgraph "Data Access Layer"
        BookRepo["BookRepository"]:::dataAccess
        CategoryRepo["CategoryRepository"]:::dataAccess
        OrderRepo["OrderRepository"]:::dataAccess
        ReviewRepo["ReviewRepository"]:::dataAccess
        UserRepo["UserRepository"]:::dataAccess
        DataContext["DataContext"]:::dataAccess
    end

    subgraph "Database & Migrations"
        SQLDb["SQL Database"]:::db
        Migrations["EF Core Migrations"]:::db
    end

    subgraph "External Integrations"
        PaymentGW["Payment Gateway API"]:::external
        Redis["Redis Cache"]:::external
        Email["Email Provider"]:::external
        AuthProvider["Identity Provider"]:::external
    end

    Clients -->|"HTTP/HTTPS"| AuthCtrl
    Clients -->|"HTTP/HTTPS"| BookCtrl
    Clients -->|"HTTP/HTTPS"| CartCtrl
    Clients -->|"HTTP/HTTPS"| ChatCtrl
    Clients -->|"HTTP/HTTPS"| HomeCtrl
    Clients -->|"HTTP/HTTPS"| OrderCtrl
    Clients -->|"HTTP/HTTPS"| PaymentCtrl
    Clients -->|"HTTP/HTTPS"| ProfileCtrl
    Clients -->|"HTTP/HTTPS"| AdminCtrl
    Clients -->|"WebSocket/SignalR"| ChatHub

    AuthCtrl -->|uses| UIDProvider
    BookCtrl -->|uses| CachingSvc
    CartCtrl -->|uses| CachingSvc
    HomeCtrl -->|uses| CachingSvc
    OrderCtrl -->|uses| CachingSvc
    PaymentCtrl -->|uses| CachingSvc
    ProfileCtrl -->|uses| CachingSvc
    AdminCtrl -->|uses| CachingSvc
    ChatCtrl -->|uses| ChatSvc
    ChatHub -->|uses| ChatSvc

    CachingSvc -->|caches via| Redis
    ChatSvc -->|accesses| DataContext
    UIDProvider -->|resolves| UserRepo

    CachingSvc -->|wraps| BookRepo
    CachingSvc -->|wraps| CategoryRepo
    CachingSvc -->|wraps| OrderRepo
    CachingSvc -->|wraps| ReviewRepo
    CachingSvc -->|wraps| UserRepo

    BookRepo -->|uses| DataContext
    CategoryRepo -->|uses| DataContext
    OrderRepo -->|uses| DataContext
    ReviewRepo -->|uses| DataContext
    UserRepo -->|uses| DataContext

    DataContext -->|migrates with| Migrations
    DataContext -->|reads/writes| SQLDb

    PaymentCtrl -->|calls| PaymentGW
    CachingSvc -->|sends emails via| Email
    AuthCtrl -->|delegates auth to| AuthProvider

    classDef controllers fill:#f9f,stroke:#333,stroke-width:1px
    classDef services fill:#9f9,stroke:#333,stroke-width:1px
    classDef dataAccess fill:#ff9,stroke:#333,stroke-width:1px
    classDef db fill:#9ff,stroke:#333,stroke-width:1px
    classDef external fill:#f99,stroke:#333,stroke-width:1px
    classDef clients fill:#cff,stroke:#333,stroke-width:1px

    click AuthCtrl "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Controllers/AuthController.cs"
    click BookCtrl "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Controllers/BookController.cs"
    click CartCtrl "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Controllers/CartController.cs"
    click ChatCtrl "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Controllers/ChatController.cs"
    click HomeCtrl "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Controllers/HomeController.cs"
    click OrderCtrl "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Controllers/OrderController.cs"
    click PaymentCtrl "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Controllers/PaymentController.cs"
    click ProfileCtrl "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Controllers/ProfileController.cs"
    click AdminCtrl "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Controllers/AdminController.cs"
    click ChatHub "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Hubs/ChatHub.cs"
    click DataContext "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Data/DataContext.cs"
    click BookRepo "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Repositories/BookRepository.cs"
    click CategoryRepo "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Repositories/CategoryRepository.cs"
    click OrderRepo "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Repositories/OrderRepository.cs"
    click ReviewRepo "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Repositories/ReviewRepository.cs"
    click UserRepo "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Repositories/UserRepository.cs"
    click CachingSvc "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Services/CachingServices.cs"
    click ChatSvc "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Services/ChatService.cs"
    click UIDProvider "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/Services/UserIDProvider.cs"
    click SQLDb "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/appsettings.json"
    click Migrations "https://github.com/hac1es/friendwithbooks-backend/tree/master/FriendwithBooksBackend/Migrations"
    click PaymentGW "https://github.com/hac1es/friendwithbooks-backend/blob/master/FriendwithBooksBackend/appsettings.json"
```
