# eudycss/jwt-springtboot-psql architecture

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

- Interactive diagram: https://gitdiagram.com/eudycss/jwt-springtboot-psql
- Repository: https://github.com/eudycss/jwt-springtboot-psql

## Overview

##### Main Components
a. Client/External System: Represents the users or tools (like Postman) interacting with REST endpoints.
b. API Gateway / HTTP Layer: The endpoints exposed by the application (AuthController, TestController) that handle registration, login, and protected resource access.
c. Security Module: Contains the Spring Security configuration, JWT utilities (AuthTokenFilter, JwtUtils, AuthEntryPointJwt) and service implementations (UserDetailsServiceImpl, UserDetailsImpl). This module manages authentication, processes JWT tokens, and enforces role-based access control.
d. Business Logic & Data Access:
- Controllers that handle input and output.
- The service layer (in this case, even though explicit “service” packages are minimal, the security/services package plays that role).
- Repositories (UserRepository, RoleRepository) to access the underlying database.
- Models (User, Role, ERole) representing data entities.
e. Database: Notice that the README mentions the use of H2 (in-memory for testing) and PostgreSQL for production. Illustrate database interactions accordingly.
f. Configuration: Components like OpenApiConfig and application.properties imply configuration management for API docs and application settings.

##### Relationships and Interactions
- That the API endpoints invoke Security components to authenticate and authorize requests.
- That once authenticated, controllers interact with repositories to perform CRUD operations on the database (users and roles).
- JWT flow, starting with login requests that result in a JWT token, then subsequent requests containing the token being validated via the JWT utility and filter chain before reaching protected resources.
- Data flow between the authentication endpoints and the security services.

##### Architectural and Design Patterns
- Layered Architecture: Separate presentation (controllers), business logic (service/security layer), and data access (repositories).
- Security with JWT: Emphasize how the authentication process is decoupled from the core business logic.
- REST API Design: Clear endpoints for authentication and role-based resource access.

##### Relevant Technologies and Frameworks
- Spring Boot as the application foundation.
- Spring Security for authentication and authorization.
- JWT (JSON Web Tokens) management components.
- H2 and PostgreSQL as the database solutions.
- Maven as the build tool (as seen in pom.xml).

## Diagram (Mermaid)

```mermaid
graph TD
    Client["Client/External System"]:::client

    subgraph "API Gateway/HTTP Layer"
        AuthController["AuthController"]:::api
        TestController["TestController"]:::api
    end

    subgraph "Payload Definitions"
        LoginRequest["LoginRequest"]:::payload
        SignupRequest["SignupRequest"]:::payload
        JwtResponse["JwtResponse"]:::payload
        MessageResponse["MessageResponse"]:::payload
    end

    subgraph "Security Module"
        WebSecurityConfig["WebSecurityConfig"]:::security
        AuthEntryPointJwt["AuthEntryPointJwt"]:::security
        AuthTokenFilter["AuthTokenFilter"]:::security
        JwtUtils["JwtUtils"]:::security
        UserDetailsServiceImpl["UserDetailsServiceImpl"]:::security
        UserDetailsImpl["UserDetailsImpl"]:::security
    end

    subgraph "Business Logic & Data Access"
        subgraph "Models"
            ERole["ERole"]:::business
            Role["Role"]:::business
            User["User"]:::business
        end
        subgraph "Repositories"
            RoleRepository["RoleRepository"]:::business
            UserRepository["UserRepository"]:::business
        end
    end

    subgraph "Configuration Management"
        OpenAPIConfig["OpenApiConfig"]:::config
        AppSettings["AppSettings"]:::config
    end

    subgraph "Application Bootstrap"
        SpringBootJwtAuthApplication["SpringBootJwtAuthApplication"]:::bootstrap
        DatabaseInitializer["DatabaseInitializer"]:::bootstrap
    end

    Database["Database (H2 & PostgreSQL)"]:::database

    %% Connections from Client to API Endpoints
    Client -->|"HTTP_Request"| AuthController
    Client -->|"HTTP_Request"| TestController

    %% API Endpoints interaction with Payload Definitions
    AuthController -->|"handles"| LoginRequest
    AuthController -->|"handles"| SignupRequest
    AuthController -->|"returns"| JwtResponse
    AuthController -->|"returns"| MessageResponse

    %% API Endpoints interaction with Security Module
    AuthController -->|"auth_process"| WebSecurityConfig
    TestController -->|"JWT_validation"| AuthTokenFilter

    %% Security Module internal flow
    WebSecurityConfig -->|"loads_userDetails"| UserDetailsServiceImpl
    AuthTokenFilter -->|"utilizes"| JwtUtils

    %% Security Module and Business Logic flow
    UserDetailsServiceImpl -->|"accesses"| UserRepository
    UserDetailsServiceImpl -->|"accesses"| RoleRepository

    %% Business Logic to Database
    RoleRepository -->|"DB_Query"| Database
    UserRepository -->|"DB_Query"| Database

    %% Application Bootstrap configuration
    SpringBootJwtAuthApplication -->|"starts"| AuthController
    SpringBootJwtAuthApplication -->|"starts"| WebSecurityConfig
    SpringBootJwtAuthApplication -->|"configures_API_docs"| OpenAPIConfig
    SpringBootJwtAuthApplication -->|"loads_settings"| AppSettings

    DatabaseInitializer -->|"initializes"| Database

    %% Class Definitions for colors
    classDef client fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef api fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef payload fill:#FFDEAD,stroke:#000,stroke-width:1px;
    classDef security fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef business fill:#FFFF99,stroke:#000,stroke-width:1px;
    classDef config fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef bootstrap fill:#D8BFD8,stroke:#000,stroke-width:1px;
    classDef database fill:#D3D3D3,stroke:#000,stroke-width:1px;

click AuthController "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/controllers/AuthController.java"
click TestController "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/controllers/TestController.java"
click WebSecurityConfig "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/security/WebSecurityConfig.java"
click AuthEntryPointJwt "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/security/jwt/AuthEntryPointJwt.java"
click AuthTokenFilter "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/security/jwt/AuthTokenFilter.java"
click JwtUtils "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/security/jwt/JwtUtils.java"
click UserDetailsServiceImpl "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/security/services/UserDetailsServiceImpl.java"
click UserDetailsImpl "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/security/services/UserDetailsImpl.java"
click ERole "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/models/ERole.java"
click Role "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/models/Role.java"
click User "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/models/User.java"
click RoleRepository "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/repository/RoleRepository.java"
click UserRepository "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/repository/UserRepository.java"
click LoginRequest "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/payload/request/LoginRequest.java"
click SignupRequest "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/payload/request/SignupRequest.java"
click JwtResponse "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/payload/response/JwtResponse.java"
click MessageResponse "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/payload/response/MessageResponse.java"
click OpenAPIConfig "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/config/OpenApiConfig.java"
click AppSettings "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/resources/application.properties"
click SpringBootJwtAuthApplication "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/SpringBootJwtAuthApplication.java"
click DatabaseInitializer "https://github.com/eudycss/jwt-springtboot-psql/blob/main/src/main/java/com/example/auth/DatabaseInitializer.java"
```
