# phuclm-dev2302/read_online_books architecture

> Architecture diagram of the GitHub repository phuclm-dev2302/read_online_books, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/phuclm-dev2302/read_online_books
- Repository: https://github.com/phuclm-dev2302/read_online_books

## Overview

##### Main Components
- Front Controller Layer: Represent the REST controllers (e.g., AuthController, BookController, CategoryController, UserController, VipMembershipController) that expose endpoints to the client.
- Business / Service Layer: Show the service interfaces and their implementing classes (e.g., AuthService, BookService, BookmarkService, CategoryService, etc.) where the core application logic is processed.
- Data Access / Repository Layer: Include the repositories (e.g., AuthorRepository, BookRepository, BookmarkRepository, CategoryRepository) interacting with the database, along with the domain entities (e.g., Book, Author, User, VipMembership).
- Configuration Components: Illustrate the various configuration pieces such as:
- SecurityConfig and OAuth2LoginSuccessHandler for authentication and authorization.
- JWT configurations (JwtAuthenticationFilter, JwtProvider, etc.) for securing the API.
- Kafka configuration classes (KafkaConsumerConfig, KafkaProducerConfig) that integrate messaging into the system.
- WebSocketConfig and WebClientConfig for real-time communication and REST clients.
- RequestInterceptor and its config, which manage cross-component communication aspects.
- Exception Handling Module: Display how the application centralizes error handling (GlobalExceptionHandler and custom exceptions) to manage domain-specific errors.
- Resource and Template Layer: Indicate the resources (HTML templates for email functions) that are used for generating communication messages.
- External Integrations: Mark external systems like:
- A messaging broker (Kafka) that handles asynchronous message processing.
- Likely a database (implied by the existence of repository components) even if it isn’t explicitly shown in the file tree.
- Docker container configuration (docker-compose.yml) that bundles deployment dependencies.

##### Relationships and Interactions
- Service layer interacting with the repository layer by illustrating data flow from business logic to the data store.
- Integration with external services: illustrate the Kafka producers and consumers as separate nodes that interface with the service layer for event publishing and processing.
- Configuration components that act as cross-cutting concerns (e.g., Security, JWT management, WebSockets) that are wired into controllers and services.
- Email-related templates as part of the resource module that the system uses to send confirmations and password resets.

##### Important Architectural Patterns
- Layered Architecture (Controller → Service → Repository → Data): This separation of concerns helps modularize the business logic and data access.
- Integration of Asynchronous Messaging: The use of Kafka for inter-component communication (producer/consumer configurations).
- Security Best Practices: OAuth2, JWT, and exception handling reflect emphasis on secure API access.
- Configuration Management: The use of Spring Boot configuration files for setting up WebSocket, Interceptors, and other cross-cutting services.

## Diagram (Mermaid)

```mermaid
graph TD
    Client["Client Application"]:::client

    subgraph "Presentation Layer"
        Controller["REST Controllers"]:::present
    end

    subgraph "Business / Service Layer"
        ServiceInterfaces["Service Interfaces"]:::service
        ServiceImpl["Service Implementations"]:::service
    end

    subgraph "Data Access / Repository Layer"
        Repositories["Repositories"]:::repository
        Entities["Domain Entities"]:::repository
    end

    subgraph "Configuration Components"
        SecurityConfig["SecurityConfig"]:::config
        OAuth2LoginSuccess["OAuth2LoginSuccessHandler"]:::config
        JwtAuthFilter["JwtAuthenticationFilter"]:::config
        JwtProperties["JwtProperties"]:::config
        JwtProvider["JwtProvider"]:::config
        KafkaConsumerConfig["KafkaConsumerConfig"]:::config
        KafkaProducerConfig["KafkaProducerConfig"]:::config
        WebSocketConfig["WebSocketConfig"]:::config
        WebClientConfig["WebClientConfig"]:::config
        RequestInterceptor["RequestInterceptor"]:::config
        RequestInterceptorConfig["RequestInterceptorConfig"]:::config
        WebConfig["WebConfig"]:::config
        OpenAPIConfig["OpenAPIConfig"]:::config
    end

    subgraph "Exception Handling Module"
        GlobalExceptionHandler["GlobalExceptionHandler"]:::exception
        CustomExceptions["Custom Exceptions"]:::exception
    end

    subgraph "Resource and Template Layer"
        EmailTemplates["Email Templates & HTML Resources"]:::resource
    end

    subgraph "External Integrations"
        KafkaBroker["Kafka Broker"]:::external
        Database["Database"]:::external
        DockerCompose["docker-compose.yml"]:::external
    end

    %% Flow Connections
    Client -->|"requests"| Controller
    Controller -->|"calls"| ServiceInterfaces
    ServiceInterfaces -->|"implementedBy"| ServiceImpl
    ServiceInterfaces -->|"calls"| Repositories
    Repositories -->|"queries"| Database
    ServiceImpl -->|"persistsData"| Repositories
    ServiceImpl -->|"sendsEmail"| EmailTemplates

    %% Security and Exception Integration
    Controller -->|"securedBy"| SecurityConfig
    SecurityConfig -->|"uses"| OAuth2LoginSuccess
    Controller -->|"filteredBy"| JwtAuthFilter
    JwtAuthFilter -->|"configuredBy"| JwtProperties
    JwtAuthFilter -->|"uses"| JwtProvider
    Controller -->|"handledBy"| GlobalExceptionHandler

    %% Kafka Integration
    ServiceImpl -->|"publishesEvent"| KafkaProducerConfig
    KafkaProducerConfig -->|"publishesTo"| KafkaBroker
    KafkaBroker -->|"deliversTo"| KafkaConsumerConfig
    KafkaConsumerConfig -->|"processesEvent"| ServiceImpl

    %% Additional Configuration Connections
    ServiceImpl -->|"intercepts"| RequestInterceptor
    RequestInterceptor -->|"configuredBy"| RequestInterceptorConfig
    Controller -->|"configuredBy"| WebConfig
    Controller -->|"realTimeVia"| WebSocketConfig
    Controller -->|"restClient"| WebClientConfig
    ServiceImpl -->|"docsVia"| OpenAPIConfig

    %% Click Events
    click Controller "https://github.com/phuclm-dev2302/read_online_books/tree/main/src/main/java/com/example/read_book_online/controller"
    click ServiceInterfaces "https://github.com/phuclm-dev2302/read_online_books/tree/main/src/main/java/com/example/read_book_online/service"
    click ServiceImpl "https://github.com/phuclm-dev2302/read_online_books/tree/main/src/main/java/com/example/read_book_online/service/impl"
    click Repositories "https://github.com/phuclm-dev2302/read_online_books/tree/main/src/main/java/com/example/read_book_online/repository"
    click Entities "https://github.com/phuclm-dev2302/read_online_books/tree/main/src/main/java/com/example/read_book_online/entity"
    click SecurityConfig "https://github.com/phuclm-dev2302/read_online_books/blob/main/src/main/java/com/example/read_book_online/config/SecurityConfig.java"
    click OAuth2LoginSuccess "https://github.com/phuclm-dev2302/read_online_books/blob/main/src/main/java/com/example/read_book_online/config/OAuth2LoginSuccessHandler.java"
    click JwtAuthFilter "https://github.com/phuclm-dev2302/read_online_books/blob/main/src/main/java/com/example/read_book_online/jwtconfig/JwtAuthenticationFilter.java"
    click JwtProperties "https://github.com/phuclm-dev2302/read_online_books/blob/main/src/main/java/com/example/read_book_online/jwtconfig/JwtProperties.java"
    click JwtProvider "https://github.com/phuclm-dev2302/read_online_books/blob/main/src/main/java/com/example/read_book_online/jwtconfig/JwtProvider.java"
    click KafkaConsumerConfig "https://github.com/phuclm-dev2302/read_online_books/blob/main/src/main/java/com/example/read_book_online/config/KafkaConsumerConfig.java"
    click KafkaProducerConfig "https://github.com/phuclm-dev2302/read_online_books/blob/main/src/main/java/com/example/read_book_online/config/KafkaProducerConfig.java"
    click WebSocketConfig "https://github.com/phuclm-dev2302/read_online_books/blob/main/src/main/java/com/example/read_book_online/config/WebSocketConfig.java"
    click WebClientConfig "https://github.com/phuclm-dev2302/read_online_books/blob/main/src/main/java/com/example/read_book_online/config/WebClientConfig.java"
    click RequestInterceptor "https://github.com/phuclm-dev2302/read_online_books/blob/main/src/main/java/com/example/read_book_online/config/RequestInterceptor.java"
    click RequestInterceptorConfig "https://github.com/phuclm-dev2302/read_online_books/blob/main/src/main/java/com/example/read_book_online/config/RequestInterceptorConfig.java"
    click WebConfig "https://github.com/phuclm-dev2302/read_online_books/blob/main/src/main/java/com/example/read_book_online/config/WebConfig.java"
    click OpenAPIConfig "https://github.com/phuclm-dev2302/read_online_books/blob/main/src/main/java/com/example/read_book_online/config/OpenAPIConfig.java"
    click GlobalExceptionHandler "https://github.com/phuclm-dev2302/read_online_books/blob/main/src/main/java/com/example/read_book_online/config/exception/GlobalExceptionHandler.java"
    click CustomExceptions "https://github.com/phuclm-dev2302/read_online_books/tree/main/src/main/java/com/example/read_book_online/config/exception"
    click EmailTemplates "https://github.com/phuclm-dev2302/read_online_books/tree/main/src/main/resources/templates"
    click DockerCompose "https://github.com/phuclm-dev2302/read_online_books/blob/main/docker-compose.yml"

    %% Style Classes
    classDef present fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef service fill:#C8E6C9,stroke:#1B5E20,stroke-width:2px;
    classDef repository fill:#FFF9C4,stroke:#F57F17,stroke-width:2px;
    classDef config fill:#F8BBD0,stroke:#880E4F,stroke-width:2px;
    classDef exception fill:#FFCDD2,stroke:#B71C1C,stroke-width:2px;
    classDef resource fill:#D1C4E9,stroke:#4A148C,stroke-width:2px;
    classDef external fill:#CFD8DC,stroke:#37474F,stroke-width:2px;
    classDef client fill:#E1BEE7,stroke:#6A1B9A,stroke-width:2px;
```
