# fm39hz/library architecture

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

- Interactive diagram: https://gitdiagram.com/fm39hz/library
- Repository: https://github.com/fm39hz/library

## Overview

##### High-Level Components

a) Client Layer (External)
- Incoming HTTP requests
- Potential client applications (web, mobile)

b) API Layer
- REST Controllers (AuthenticationController, BookController, etc.)
- Security Filter Chain (JwtAuthenticationFilter)

c) Service Layer
- Core Business Logic
- By modules (book, author, user, subscription, etc.)
- Payment Integration (VNPay)

d) Data Access Layer
- Repositories
- Database Connection

e) External Services
- VNPay Payment Gateway

##### Detailed Component Breakdown

Create modules/components for:

a) Authentication & Security
- SecurityConfig
- JwtTokenProvider
- CustomAuthenticationManager
- User Management

b) Core Library Modules
- Books Management
- Authors Management
- Publishers Management
- Records Management
- Subscriptions Management

c) Payment System
- Payment Service Factory
- VNPay Integration
- Invoice Management

##### Key Relationships to Highlight

- Security Filter → Controllers (authentication flow)
- Controllers → Services → Repositories
- Payment Service Factory → VNPay Service
- Subscription Factory → Subscription Service
- User → Subscription → Invoice relationships

##### Specific Implementation Details

Architectural patterns:
- Factory Pattern (PaymentServiceFactory, SubscriptionFactory)
- Repository Pattern (All *Repository interfaces)
- Service Layer Pattern (All *Service interfaces and implementations)
- DTO Pattern (Request/Response DTOs)

##### Additional Elements

Include:
- Configuration components (DatabaseConfig, SecurityConfig, VnPayConfig)
- Exception handling flow
- Aspect-oriented programming components (UserIdAspect)

##### Technical Stack Indicators

Show:
- Spring Boot framework
- Spring Security
- JPA/Hibernate
- MySQL/PostgreSQL (based on library.sql)
- JWT Authentication

##### Deployment Context

Include:
- Docker container boundaries (based on Dockerfile and docker-compose.yml)
- Database container
- Application container

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef client fill:#E1F5FE,stroke:#01579B
    classDef api fill:#E8F5E9,stroke:#1B5E20
    classDef service fill:#FFF3E0,stroke:#E65100
    classDef data fill:#EFEBE9,stroke:#3E2723
    classDef external fill:#F3E5F5,stroke:#4A148C
    classDef security fill:#E8EAF6,stroke:#1A237E
    classDef config fill:#FAFAFA,stroke:#424242

    %% Client Layer
    Client["Client Applications"]:::client

    %% API Layer
    subgraph API
        AuthController["Authentication Controller"]:::api
        BookController["Book Controller"]:::api
        UserController["User Controller"]:::api
        PaymentController["Payment Controller"]:::api
    end

    %% Security Layer
    subgraph Security
        SecurityConfig["Security Config"]:::security
        JwtFilter["JWT Filter"]:::security
        JwtProvider["JWT Provider"]:::security
    end
    click SecurityConfig "https://github.com/fm39hz/library/blob/master/src/main/java/com/huce/library/configuration/SecurityConfig.java"
    click JwtFilter "https://github.com/fm39hz/library/blob/master/src/main/java/com/huce/library/module/jwt/JwtAuthenticationFilter.java"
    click JwtProvider "https://github.com/fm39hz/library/blob/master/src/main/java/com/huce/library/module/jwt/JwtTokenProvider.java"

    %% Service Layer
    subgraph Services
        AuthService["Authentication Service"]:::service
        BookService["Book Service"]:::service
        AuthorService["Author Service"]:::service
        PublisherService["Publisher Service"]:::service
        UserService["User Service"]:::service
        RecordService["Record Service"]:::service
        SubscriptionService["Subscription Service"]:::service
        PaymentService["Payment Service"]:::service
        InvoiceService["Invoice Service"]:::service
    end
    click AuthService "https://github.com/fm39hz/library/tree/master/src/main/java/com/huce/library/module/authentication"
    click BookService "https://github.com/fm39hz/library/tree/master/src/main/java/com/huce/library/module/book"
    click AuthorService "https://github.com/fm39hz/library/tree/master/src/main/java/com/huce/library/module/author"
    click PublisherService "https://github.com/fm39hz/library/tree/master/src/main/java/com/huce/library/module/publisher"
    click UserService "https://github.com/fm39hz/library/tree/master/src/main/java/com/huce/library/module/user"
    click RecordService "https://github.com/fm39hz/library/tree/master/src/main/java/com/huce/library/module/record"
    click SubscriptionService "https://github.com/fm39hz/library/tree/master/src/main/java/com/huce/library/module/subscription"
    click PaymentService "https://github.com/fm39hz/library/tree/master/src/main/java/com/huce/library/module/payment"
    click InvoiceService "https://github.com/fm39hz/library/tree/master/src/main/java/com/huce/library/module/invoice"

    %% Factories
    subgraph Factories
        PaymentFactory["Payment Service Factory"]:::service
        SubFactory["Subscription Factory"]:::service
    end
    click PaymentFactory "https://github.com/fm39hz/library/tree/master/src/main/java/com/huce/library/module/payment"
    click SubFactory "https://github.com/fm39hz/library/blob/master/src/main/java/com/huce/library/module/subscription/SubscriptionFactory.java"

    %% Data Access Layer
    subgraph Repositories
        BookRepo["Book Repository"]:::data
        AuthorRepo["Author Repository"]:::data
        UserRepo["User Repository"]:::data
        RecordRepo["Record Repository"]:::data
        SubRepo["Subscription Repository"]:::data
        InvoiceRepo["Invoice Repository"]:::data
    end

    %% Database
    Database[(Database)]:::data
    click Database "https://github.com/fm39hz/library/blob/master/db/library.sql"

    %% External Services
    VNPay["VNPay Payment Gateway"]:::external
    click VNPay "https://github.com/fm39hz/library/tree/master/src/main/java/com/huce/library/module/payment/vnpay"

    %% Configuration
    subgraph Config
        DbConfig["Database Config"]:::config
        VNPayConfig["VNPay Config"]:::config
    end
    click DbConfig "https://github.com/fm39hz/library/blob/master/src/main/java/com/huce/library/configuration/DatabaseConfig.java"
    click VNPayConfig "https://github.com/fm39hz/library/blob/master/src/main/java/com/huce/library/configuration/VnPayConfig.java"

    %% Exception Handling
    ExceptionHandler["Exception Handler"]:::config
    click ExceptionHandler "https://github.com/fm39hz/library/tree/master/src/main/java/com/huce/library/exception"

    %% Relationships
    Client --> SecurityConfig
    SecurityConfig --> JwtFilter
    JwtFilter --> JwtProvider
    JwtFilter --> AuthController
    
    AuthController --> AuthService
    BookController --> BookService
    UserController --> UserService
    PaymentController --> PaymentService
    
    PaymentService --> PaymentFactory
    PaymentFactory --> VNPay
    SubscriptionService --> SubFactory
    
    BookService --> BookRepo
    AuthorService --> AuthorRepo
    UserService --> UserRepo
    RecordService --> RecordRepo
    SubscriptionService --> SubRepo
    InvoiceService --> InvoiceRepo
    
    BookRepo --> Database
    AuthorRepo --> Database
    UserRepo --> Database
    RecordRepo --> Database
    SubRepo --> Database
    InvoiceRepo --> Database
    
    DbConfig --> Database
    VNPayConfig --> VNPay
```
