# hienhaobn/tutorials-spring-boot-3 architecture

> Architecture diagram of the GitHub repository hienhaobn/tutorials-spring-boot-3, 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/hienhaobn/tutorials-spring-boot-3
- Repository: https://github.com/hienhaobn/tutorials-spring-boot-3

## Overview

##### Main Components
- Hello Spring Boot Service:
– This is a basic Spring Boot application (located in the hello-spring-boot directory).
– Contains a main entry point (HelloSpringBootApplication.java) and at least one controller (HelloSpringController.java) handling simple endpoints.
- Identity Service:
– This service (in the identity-service directory) is more feature-rich.
– It handles authentication, user, role, and permission management.
– It is structured into distinct layers such as configuration (e.g. SecurityConfig, JwtAuthenticationEntryPoint, ApplicationInitConfig), controllers (AuthenticationController, PermissionController, RoleController, UserController), service layer (AuthenticationService, PermissionService, RoleService, UserService), data access (repositories for User, Role, and Permission) and exception handling (GlobalExceptionHandler, custom exceptions).
– It employs DTOs (data transfer objects) and mappers to convert between entity representations and API responses.

##### Architectural Layers and Interactions
- For each Spring Boot application, identify the standard layers:
– Presentation Layer: Controllers managing REST endpoints.
– Business Logic Layer: Service classes containing the core logic.
– Data Access Layer: Repositories interacting with the database (even if not explicitly mentioned, Spring Data JPA is likely used given the standard structure).
– Configuration & Security: Identity Service contains several configuration classes for JWT-based authentication and general security setup.
– Exception Handling: Centralized error handling within Identity Service.
- Data Flow:
– A client sends HTTP requests to the respective controller endpoints.
– Controllers invoke service methods.
– Services interact with repositories to perform CRUD operations and validation.
– In Identity Service, requests may pass through security filters (configured in SecurityConfig and JwtAuthenticationEntryPoint) ensuring only authenticated and authorized requests are processed.

##### Architectural Patterns or Design Principles
- Both services follow Spring Boot’s layered architecture, commonly seen in MVC applications.
- The Identity Service in particular employs elements of the microservices design pattern where each service is self-contained and structured by components (controllers, services, repositories) with clear separation of concerns.
- Utilization of DTOs and mappers exemplifies the pattern of decoupling internal database models from external API representations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client("Client/Consumer"):::client

    %% Hello Spring Boot Service Subgraph
    subgraph "Hello Spring Boot Service"
        HAPP("HelloSpringBootApplication"):::app
        HCTRL("HelloSpringController"):::controller
        HRES("Application Resources"):::resource
        Client -->|"calls"| HCTRL
        HAPP -->|"starts"| HCTRL
        HCTRL -->|"loads"| HRES
    end

    %% Identity Service Subgraph
    subgraph "Identity Service"
        %% Configuration Layer
        subgraph "Configuration"
            IAPP("IdentityServiceApplication"):::app
            AIC("ApplicationInitConfig"):::config
            SEC("SecurityConfig"):::config
            JWT("JwtAuthenticationEntryPoint"):::config
            IAPP -->|"init config"| AIC
            IAPP -->|"configures"| SEC
            IAPP -->|"sets entry"| JWT
        end

        %% Controllers Layer
        subgraph "Controllers"
            AUTHCTRL("AuthenticationController"):::controller
            PERMCTRL("PermissionController"):::controller
            ROLECTRL("RoleController"):::controller
            UCTRL("UserController"):::controller
            Client -->|"calls"| AUTHCTRL
            Client -->|"calls"| PERMCTRL
            Client -->|"calls"| ROLECTRL
            Client -->|"calls"| UCTRL
        end

        %% Services Layer
        subgraph "Services"
            AUTHSERV("AuthenticationService"):::service
            PERMSERV("PermissionService"):::service
            ROLESERV("RoleService"):::service
            USERSERV("UserService"):::service
        end

        %% Data Access / Repositories Layer
        subgraph "Repositories"
            PERMREP("PermissionRepository"):::repository
            ROLEREP("RoleRepository"):::repository
            USERREP("UserRepository"):::repository
        end

        %% Domain Models / Entities
        subgraph "Domain Models"
            ENTITY_PERMISSION("Permission"):::entity
            ENTITY_ROLE("Role"):::entity
            ENTITY_USER("User"):::entity
        end

        %% DTOs
        subgraph "DTOs"
            DTO_REQ("Request DTOs"):::dto
            DTO_RESP("Response DTOs"):::dto
        end

        %% Mappers
        subgraph "Mappers"
            PERMMAP("PermissionMapper"):::mapper
            ROLEMAP("RoleMapper"):::mapper
            USERMAP("UserMapper"):::mapper
        end

        %% Exception Handling
        subgraph "Exception Handling"
            GEXH("GlobalExceptionHandler"):::exception
            APPEX("AppException & ErrorCode"):::exception
        end

        %% Application Resources
        subgraph "Application Resources"
            IRES("Application Configuration"):::resource
        end

        %% Internal Connections in Identity Service
        %% Controllers to Services
        AUTHCTRL -->|"calls"| AUTHSERV
        PERMCTRL -->|"calls"| PERMSERV
        ROLECTRL -->|"calls"| ROLESERV
        UCTRL -->|"calls"| USERSERV

        %% Services to Repositories
        AUTHSERV -->|"fetches"| USERREP
        PERMSERV -->|"fetches"| PERMREP
        ROLESERV -->|"fetches"| ROLEREP
        USERSERV -->|"fetches"| USERREP

        %% Repositories to Domain Models
        PERMREP -->|"maps to"| ENTITY_PERMISSION
        ROLEREP -->|"maps to"| ENTITY_ROLE
        USERREP -->|"maps to"| ENTITY_USER

        %% Controllers interaction with DTOs
        AUTHCTRL -->|"transfers"| DTO_REQ
        AUTHCTRL -->|"transfers"| DTO_RESP
        UCTRL -->|"transfers"| DTO_REQ
        UCTRL -->|"transfers"| DTO_RESP

        %% Services interaction with Mappers
        AUTHSERV -->|"uses"| PERMMAP
        PERMSERV -->|"uses"| PERMMAP
        ROLESERV -->|"uses"| ROLEMAP
        USERSERV -->|"uses"| USERMAP

        %% Security: Configuration impacts Controllers
        SEC -->|"secures"| AUTHCTRL
        SEC -->|"secures"| PERMCTRL
        SEC -->|"secures"| ROLECTRL
        SEC -->|"secures"| UCTRL

        %% Exception handling for Controllers
        AUTHCTRL -->|"handles errors"| GEXH
        PERMCTRL -->|"handles errors"| GEXH
        ROLECTRL -->|"handles errors"| GEXH
        UCTRL -->|"handles errors"| GEXH

        %% Application Resources linked to Main Application
        IAPP -->|"loads"| IRES
    end

    %% Click Events
    click HAPP "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/hello-spring-boot/src/main/java/com/hami/hello_spring_boot/HelloSpringBootApplication.java"
    click HCTRL "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/hello-spring-boot/src/main/java/com/hami/hello_spring_boot/controller/HelloSpringController.java"
    click HRES "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/hello-spring-boot/src/main/resources/application.properties"
    click IAPP "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/IdentityServiceApplication.java"
    click AIC "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/configuration/ApplicationInitConfig.java"
    click SEC "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/configuration/SecurityConfig.java"
    click JWT "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/configuration/JwtAuthenticationEntryPoint.java"
    click AUTHCTRL "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/controller/AuthenticationController.java"
    click PERMCTRL "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/controller/PermissionController.java"
    click ROLECTRL "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/controller/RoleController.java"
    click UCTRL "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/controller/UserController.java"
    click AUTHSERV "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/service/AuthenticationService.java"
    click PERMSERV "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/service/PermissionService.java"
    click ROLESERV "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/service/RoleService.java"
    click USERSERV "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/service/UserService.java"
    click PERMREP "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/repository/PermissionRepository.java"
    click ROLEREP "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/repository/RoleRepository.java"
    click USERREP "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/repository/UserRepository.java"
    click ENTITY_PERMISSION "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/entity/Permission.java"
    click ENTITY_ROLE "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/entity/Role.java"
    click ENTITY_USER "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/entity/User.java"
    click PERMMAP "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/mapper/PermissionMapper.java"
    click ROLEMAP "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/mapper/RoleMapper.java"
    click USERMAP "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/mapper/UserMapper.java"
    click GEXH "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/exception/GlobalExceptionHandler.java"
    click APPEX "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/exception/AppException.java"
    click APPEX "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/java/com/hami/identity_service/exception/ErrorCode.java"
    click IRES "https://github.com/hienhaobn/tutorials-spring-boot-3/blob/main/identity-service/src/main/resources/application.yaml"
    click DTO_REQ "https://github.com/hienhaobn/tutorials-spring-boot-3/tree/main/identity-service/src/main/java/com/hami/identity_service/dto/request/"
    click DTO_RESP "https://github.com/hienhaobn/tutorials-spring-boot-3/tree/main/identity-service/src/main/java/com/hami/identity_service/dto/response/"

    %% Styles
    classDef client fill:#f9c,stroke:#333,stroke-width:2px;
    classDef app fill:#bbf,stroke:#333,stroke-width:2px;
    classDef controller fill:#bfb,stroke:#333,stroke-width:2px;
    classDef service fill:#ffe,stroke:#333,stroke-width:2px;
    classDef repository fill:#fab,stroke:#333,stroke-width:2px;
    classDef entity fill:#dfe,stroke:#333,stroke-width:2px;
    classDef config fill:#cff,stroke:#333,stroke-width:2px;
    classDef dto fill:#fcf,stroke:#333,stroke-width:2px;
    classDef mapper fill:#ffd,stroke:#333,stroke-width:2px;
    classDef exception fill:#fdd,stroke:#333,stroke-width:2px;
    classDef resource fill:#def,stroke:#333,stroke-width:2px;
```
