# chicong1001/tranining architecture

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

- Interactive diagram: https://gitdiagram.com/chicong1001/tranining
- Repository: https://github.com/chicong1001/tranining

## Overview

##### Project Type and Purpose
- It is a web application (likely a REST API) focused on "use management" (i.e., user management) given the package naming and inclusion of controllers like AuthController, FileController, and UserController.
- The project appears to handle authentication (with security configurations and JWT filters), user registration, and file handling, making it a full-stack backend service managing user data.

##### File Structure
- Top-level files and directories (pom.xml, mvnw, mvnw.cmd, .mvn) indicate it’s a Maven-managed Java project.
- The src/main/java tree is organized by feature and logical grouping under package "com.training.use_management". Within this package, there are directories for:
- config (SecurityConfig.java) – for configuring security settings.
- controller – which exposes endpoints for authentication, file operations, and user-related actions.
- dto – subdivided into requestDTO and responseDTO, likely for structuring API request and response payloads.
- entity – containing models like User, Role, and RoleName.
- exception – handling global exceptions.
- repository – which implies use of Spring Data or similar for persisting user and role entities.
- security – managing JWT security aspects with JwtAuthenticationFilter and JwtUtil.
- service – business logic layers such as AuthService, UserService, etc.
- utils – helper classes for password and validation utilities.
- Also, src/main/resources holds application.properties for configuration, and a test directory structure exists under src/test.

##### Readme Insights
- The README is minimal, simply titled "# tranining". Although it doesn’t provide architecture details, the naming and directory structure already indicate that the focus is on user management with security and file handling.

- Break the system into the following main components:
a. API Layer:
- Controllers (AuthController, UserController, FileController): Expose REST endpoints.
b. Business Logic Layer:
- Services (AuthService, UserService, CustomUserDetailsService, FileService): Implement business rules, token generation and validations.
c. Data Access Layer:
- Repositories (UserRepository, RoleRepository): Handle database CRUD operations.
d. Domain/Entity Layer:
- Domain models (User, Role, RoleName) representing business data.
e. Security Component:
- SecurityConfig, JwtAuthenticationFilter, JwtUtil: Manage authentication and authorization through JWT.
f. Utility and Cross-cutting Concerns:
- Utility classes (PasswordUtil, ValidationUtil).
g. Exception Handling:
- GlobalExceptionhandler: Centralized error handling mechanism.
- Controllers interact with Services.
- Services use Repositories for data persistence.
- Security components are invoked by both the controllers and services to ensure secure access.
- The entity layer is the data model shared between repositories and services.
- Utilities can be invoked wherever needed to validate inputs or encrypt passwords.

##### Architectural Patterns and Design Principles
- The project uses the layered (MVC-like) architecture: Separation of concerns between controllers, services, and repositories.
- It makes use of security best practices with JWT-based authentication and custom security configurations.
- The use of DTOs illustrates the emphasis on separating internal domain objects from external representations (API contracts).

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Client
    Client["Client"]:::external

    %% API Layer
    subgraph "API Layer"
        AC["AuthController"]:::api
        UC["UserController"]:::api
        FC["FileController"]:::api
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        AS["AuthService"]:::service
        US["UserService"]:::service
        CUDS["CustomUserDetailsService"]:::service
        FS["FileService"]:::service
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        UR["UserRepository"]:::repository
        RR["RoleRepository"]:::repository
    end

    %% Domain Layer
    subgraph "Domain Layer"
        U["User"]:::domain
        R["Role"]:::domain
        RN["RoleName"]:::domain
    end

    %% Security Component
    subgraph "Security Component"
        SC["SecurityConfig"]:::security
        JAF["JwtAuthenticationFilter"]:::security
        JU["JwtUtil"]:::security
    end

    %% Utility Layer
    subgraph "Utility Layer"
        PU["PasswordUtil"]:::utility
        VU["ValidationUtil"]:::utility
    end

    %% Exception Handling
    subgraph "Exception Handling"
        GE["GlobalExceptionhandler"]:::exception
    end

    %% DTOs
    subgraph "DTOs"
        LR["LoginRequest"]:::dto
        RRQ["RegisterRequest"]:::dto
        UP["UserProfileDTO"]:::dto
        UI["UserInfo"]:::dto
    end

    %% Configuration
    subgraph "Configuration"
        AP["Application Properties"]:::config
    end

    %% Connections from Client to API Layer
    Client -->|"RESTrequest"| AC
    Client -->|"RESTrequest"| UC
    Client -->|"RESTrequest"| FC

    %% Controllers calling Services
    AC -->|"calls"| AS
    UC -->|"calls"| US
    FC -->|"calls"| FS

    %% Services invoking additional Business Logic
    AS -->|"validates"| VU
    AS -->|"encrypts"| PU
    US -->|"validates"| VU
    US -->|"encrypts"| PU
    CUDS -->|"fetches"| UR

    %% Services using Repositories
    AS -->|"uses"| UR
    AS -->|"uses"| RR
    US -->|"uses"| UR
    FS -->|"calls"| UR

    %% Repositories output domain objects
    UR -->|"returns"| U
    RR -->|"returns"| R
    R -->|"defines"| RN

    %% Security interactions
    SC --> JAF
    SC --> JU
    AC -.->|"securedBy"| JAF
    UC -.->|"securedBy"| JAF
    FC -.->|"securedBy"| JAF

    %% Controllers use DTOs for data transfer
    AC -.->|"DTOinOut"| LR
    AC -.->|"DTOinOut"| RRQ
    UC -.->|"DTOinOut"| UP
    UC -.->|"DTOinOut"| UI

    %% Controllers connected to Exception Handling
    AC --> GE
    UC --> GE
    FC --> GE

    %% Configuration used by Security Component
    AP --> SC

    %% Styles
    classDef external fill:#f96,stroke:#333,stroke-width:2px;
    classDef api fill:#9fd,stroke:#333,stroke-width:2px;
    classDef service fill:#afa,stroke:#333,stroke-width:2px;
    classDef repository fill:#ff9,stroke:#333,stroke-width:2px;
    classDef domain fill:#cff,stroke:#333,stroke-width:2px;
    classDef security fill:#f99,stroke:#333,stroke-width:2px;
    classDef utility fill:#fcf,stroke:#333,stroke-width:2px;
    classDef exception fill:#ccc,stroke:#333,stroke-width:2px;
    classDef dto fill:#cdf,stroke:#333,stroke-width:2px;
    classDef config fill:#ddf,stroke:#333,stroke-width:2px;

    %% Click Events for API Layer
    click AC "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/controller/AuthController.java"
    click UC "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/controller/UserController.java"
    click FC "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/controller/FileController.java"

    %% Click Events for Business Logic Layer
    click AS "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/service/AuthService.java"
    click US "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/service/UserService.java"
    click CUDS "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/service/CustomUserDetailsService.java"
    click FS "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/service/FileService.java"

    %% Click Events for Data Access Layer
    click UR "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/repository/UserRepository.java"
    click RR "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/repository/RoleRepository.java"

    %% Click Events for Domain Layer
    click U "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/entity/User.java"
    click R "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/entity/Role.java"
    click RN "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/entity/RoleName.java"

    %% Click Events for Security Component
    click SC "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/config/SecurityConfig.java"
    click JAF "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/security/JwtAuthenticationFilter.java"
    click JU "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/security/JwtUtil.java"

    %% Click Events for Utility Layer
    click PU "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/utils/PasswordUtil.java"
    click VU "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/utils/ValidationUtil.java"

    %% Click Event for Exception Handling
    click GE "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/exception/GlobalExceptionhandler.java"

    %% Click Events for DTOs
    click LR "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/dto/requestDTO/LoginRequest.java"
    click RRQ "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/dto/requestDTO/RegisterRequest.java"
    click UP "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/dto/responseDTO/UserProfileDTO.java"
    click UI "https://github.com/chicong1001/tranining/blob/main/src/main/java/com/training/use_management/dto/UserInfo.java"

    %% Click Event for Configuration
    click AP "https://github.com/chicong1001/tranining/blob/main/src/main/resources/application.properties"
```
