# hongphat167/treadingplatform architecture

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

- Interactive diagram: https://gitdiagram.com/hongphat167/treadingplatform
- Repository: https://github.com/hongphat167/treadingplatform

## Overview

##### Main Components
- Front-Facing API Layer: Represent the REST controllers (AssetController, AuthController, CoinController, OrderController, PaymentController, etc.) that handle HTTP requests.
- Business Logic Layer: Show the service layer (e.g., CoinService, OrderService, UserService, etc.) and their implementing classes. This layer encapsulates the core business logic.
- Data Persistence: Include the repository layer (e.g., CoinRepository, OrderRepository, WalletRepository, etc.) which will connect to the underlying databases (even if not explicitly shown, assume a relational or NoSQL database based on Spring Boot practices).
- Security and Configuration Modules:
- Configuration components (AppConfig, JwtConstant, JwtProvider, JwtTokenValidator, OpenApiConfig, VnPayConfig) that set up application settings and security.
- Two-Factor Authentication components (TwoFactorAuth, TwoFactorOTP, TwoFactorOtpService, TwoFactorOtpServiceImpl) that are part of the authentication flow.
- External Services: Highlight external integrations (such as VnPay for payment processing and EmailService for notifications). Include any API integrations that are handled via configuration.
- Utilities: Represent utility classes (like IpUtils and OtpUtils) which support various functionalities.

- Client Request → REST controllers (API layer)
- REST controllers → Service layer (business logic)
- Service layer → Repository layer (data persistence)
- Service layer ← Utility classes and Config modules (for authentication, third-party integrations, etc.)
- How controllers interact with the authentication modules (JWT and two-factor) for securing the endpoints, and how external service configurations (VnPay) integrate with business logic.
- Optionally, include the build and deployment aspect (Gradle, Docker-compose) as peripheral components showing Continuous Integration/Deployment pipelines or container orchestration.

##### Architectural Patterns & Design Principles
- Layered Architecture: Clearly indicate separated concerns (Presentation, Business, Data).
- Security Integration: Demonstrate the authentication and authorization flow (JWT providers, validators, and two-factor authentication) as distinct yet connecting components.
- Extensibility: Show how external integrations (e.g., payment gateways) plug into the main system via dedicated configuration and service classes.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Presentation Layer
    subgraph "Presentation Layer (API Layer)"
        APIControllers["REST Controllers"]:::apiLayer
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        Services["Services & Implementations"]:::business
        subgraph "Two-Factor Authentication"
            TwoFAModel["2FA Model"]:::twofa
            TwoFAService["TwoFactorOtpService"]:::twofa
            TwoFAServiceImpl["TwoFactorOtpServiceImpl"]:::twofa
        end
        ExternalEmail["Email Service"]:::external
        Utilities["Utilities"]:::utility
    end

    %% Data Persistence Layer
    subgraph "Data Persistence Layer"
        Repositories["Repositories"]:::repository
    end

    %% Security & Configuration
    subgraph "Security & Config"
        Security["Security & Config Modules"]:::config
        VnPayConfig["VnPay Config"]:::config
    end

    %% Build & Deployment
    subgraph "Build & Deployment"
        GradleBuild["Gradle Build & Gradlew"]:::build
        DockerCompose["Docker Compose"]:::build
    end

    %% Interactions
    Client["Client"]:::external

    Client -->|"HTTP_Request"| APIControllers
    APIControllers -->|"Service_Call"| Services
    Services -->|"DB_Query"| Repositories

    APIControllers -->|"Auth_Verify"| Security
    Services -->|"JWT_Validation"| Security

    Services -->|"2FA_Process"| TwoFAModel
    Services -->|"2FA_Process"| TwoFAService
    Services -->|"2FA_Process"| TwoFAServiceImpl

    Services -->|"Notification"| ExternalEmail
    Security -->|"Payment_Config"| VnPayConfig

    Services -->|"Utility_Usage"| Utilities

    %% Build & Deployment interacts externally
    GradleBuild ---|"Build_Process"| Services
    DockerCompose ---|"Deployment"| Services

    %% Click Events
    click APIControllers "https://github.com/hongphat167/treadingplatform/tree/main/treadingplatform_BE/coin/src/main/java/com/treading/coin/controller"
    click Services "https://github.com/hongphat167/treadingplatform/tree/main/treadingplatform_BE/coin/src/main/java/com/treading/coin/service"
    click TwoFAServiceImpl "https://github.com/hongphat167/treadingplatform/tree/main/treadingplatform_BE/coin/src/main/java/com/treading/coin/service/impl"
    click Repositories "https://github.com/hongphat167/treadingplatform/tree/main/treadingplatform_BE/coin/src/main/java/com/treading/coin/repository"
    click Security "https://github.com/hongphat167/treadingplatform/tree/main/treadingplatform_BE/coin/src/main/java/com/treading/coin/config"
    click TwoFAModel "https://github.com/hongphat167/treadingplatform/tree/main/treadingplatform_BE/coin/src/main/java/com/treading/coin/model"
    click TwoFAService "https://github.com/hongphat167/treadingplatform/tree/main/treadingplatform_BE/coin/src/main/java/com/treading/coin/service"
    click ExternalEmail "https://github.com/hongphat167/treadingplatform/blob/main/treadingplatform_BE/coin/src/main/java/com/treading/coin/service/EmailService.java"
    click VnPayConfig "https://github.com/hongphat167/treadingplatform/tree/main/treadingplatform_BE/coin/src/main/java/com/treading/coin/config/VnPayConfig"
    click Utilities "https://github.com/hongphat167/treadingplatform/tree/main/treadingplatform_BE/coin/src/main/java/com/treading/coin/utils"
    click GradleBuild "https://github.com/hongphat167/treadingplatform/blob/main/treadingplatform_BE/coin/build.gradle"
    click DockerCompose "https://github.com/hongphat167/treadingplatform/blob/main/treadingplatform_BE/coin/docker-compose.yml"

    %% Styles
    classDef apiLayer fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef business fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef repository fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef config fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef twofa fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef utility fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef build fill:#E6E6FA,stroke:#000,stroke-width:2px;
    classDef external fill:#FFFFE0,stroke:#000,stroke-width:2px;
```
