# jeansupre/stardewvalleyprojectback architecture

> Architecture diagram of the GitHub repository jeansupre/stardewvalleyprojectback, 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/jeansupre/stardewvalleyprojectback
- Repository: https://github.com/jeansupre/stardewvalleyprojectback

## Overview

##### Main Components
a. API Controllers: Located in the “controller” package, with subcategories such as AdminController and AuthController (in the “publics” folder). These components handle inbound HTTP requests.
b. Service Layer: Splitting into interfaces (in service/interfaces) and implementations (in service/impl), these encapsulate business logic (e.g., AuthServiceImpl, AdminServiceImpl, JwtService).
c. Data Access Layer: Represented by repositories (in the “repository” package) interfacing with data persistence, handling entities such as Aldeano, Cultivo, Item, etc.
d. Data Transfer Objects (DTOs): In the “dto” package (e.g., for creating users, items, etc.) supporting data interchange between client and server.
e. Domain Models: In the “model” package, these are the application’s core entities (Aldeano, Categoria, Cultivo, etc.).
f. Security Module: The “security” package includes annotations and interceptors (e.g., JwtInterceptor) and related configurations ensuring JWT authentication.
g. Configuration: The “config” package and resources (application.properties, messages files) hold the environment setup, locale resolving, Swagger documentation, and web configurations.
h. Utility Components: In the “util” package (e.g., Constantes, ITools, Mensajes).

##### Relationships and Data Flow
- Clients call the API endpoints through the controllers.
- Controllers delegate requests to the service layer, which orchestrates business logic.
- The service layer interacts with the repository layer to perform CRUD operations on the domain models.
- Security interceptors (like JwtInterceptor) work on the request flow to enforce authentication/authorization before controllers get involved.
- Configuration components (e.g., Swagger, locale, web settings) ensure that the API is both well documented and tailored for internationalization.
- DTOs translate data between front-end requests and backend domain models, while Mapper interfaces ensure correct conversions.

##### Architectural Patterns and Design Principles
- Layered (n-tier) Architecture: Clearly separating controllers, services, and repositories.
- MVC (Model-View-Controller) principles: While this is primarily an API backend (without a traditional “view”), the controller-model separation follows MVC ideas.
- Security is implemented using interceptors and annotations, ensuring concerns of authentication are modular and cross-cutting.
- Integration with external tools/libraries is managed via Maven, which handles dependency management.

##### Relevant Technologies
- Java and Spring Boot framework patterns (configurations, MVC architecture)
- Maven for build and dependency management (pom.xml, mvnw scripts)
- Swagger for API documentation (SwaggerConfig)
- Internationalization (i18n) via locale resolvers and message properties files
- JWT based authentication via security interceptors.

##### Detail
- Avoid oversimplification – clearly denote sub-packages like “publics” under controllers and the separation of DTO and mappers.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Client Layer
    Client("Client (HTTP Request)"):::client

    %% Security Layer
    subgraph "Security Layer"
        JwtInterceptor("JWT Interceptor"):::security
        RequireJwt("RequireJwtVerification Annotation"):::security
    end

    %% Controller Layer
    subgraph "Controller Layer"
        AdminController("AdminController"):::controller
        AuthController("AuthController"):::controller
    end

    %% Service Layer
    subgraph "Service Layer"
        IAdminService("IAdminService"):::service
        IAuthService("IAuthService"):::service
        AdminServiceImpl("AdminServiceImpl"):::service
        AuthServiceImpl("AuthServiceImpl"):::service
        JwtService("JwtService"):::service
    end

    %% Repository Layer
    subgraph "Repository Layer"
        AldeanoRepo("IAldeanoRepository"):::repository
        ItemRepo("IItemRepository"):::repository
    end

    %% DTO and Domain Models
    subgraph "DTO & Domain"
        DTO("DTOs"):::dto
        Domain("Domain Models"):::domain
    end

    %% Configuration & Utility Components
    subgraph "Configuration & Utilities"
        CustomLocale("CustomLocaleResolver"):::config
        PrincipalConfig("PrincipalConfig"):::config
        SwaggerConfig("SwaggerConfig"):::config
        WebConfig("WebConfig"):::config
        Constantes("Constantes"):::utility
        ITools("ITools"):::utility
        Mensajes("Mensajes"):::utility
    end

    %% Data Flow arrows
    Client -->|"HTTP_Request"| JwtInterceptor
    JwtInterceptor -->|"Validates Request"| AuthController
    JwtInterceptor -->|"Validates Request"| AdminController
    %% Security annotation usage (applied to endpoints)
    RequireJwt --- JwtInterceptor

    %% Controllers delegate to Service Layer
    AuthController -->|"Executes auth logic"| IAuthService
    AdminController -->|"Executes admin logic"| IAdminService

    %% Service Layer implementation
    IAuthService -->|"Implemented by"| AuthServiceImpl
    IAdminService -->|"Implemented by"| AdminServiceImpl
    AuthServiceImpl -->|"Utilizes for token"| JwtService

    %% Service interactions with Repository Layer
    AdminServiceImpl -->|"CRUD operations"| AldeanoRepo
    AdminServiceImpl -->|"CRUD operations"| ItemRepo

    %% Controllers interact with DTOs
    AuthController -->|"Data conversion"| DTO
    AdminController -->|"Data conversion"| DTO

    %% Services map DTOs to Domain Models
    AuthServiceImpl -->|"Maps to"| Domain
    AdminServiceImpl -->|"Maps to"| Domain

    %% Repository retrieves Domain Models
    AldeanoRepo -->|"Returns"| Domain
    ItemRepo -->|"Returns"| Domain

    %% Utilities support Service and other layers
    AdminServiceImpl -->|"Uses"| Constantes
    AdminServiceImpl -->|"Uses"| ITools
    AdminServiceImpl -->|"Uses"| Mensajes

    %% Configuration supports overall API behavior
    Client --- CustomLocale
    Client --- SwaggerConfig
    Client --- WebConfig
    Client --- PrincipalConfig

    %% Click Events
    click AdminController "https://github.com/jeansupre/stardewvalleyprojectback/blob/main/src/main/java/com/jean/stardewvalleyapi/controller/AdminController.java"
    click AuthController "https://github.com/jeansupre/stardewvalleyprojectback/blob/main/src/main/java/com/jean/stardewvalleyapi/controller/publics/AuthController.java"
    click IAdminService "https://github.com/jeansupre/stardewvalleyprojectback/blob/main/src/main/java/com/jean/stardewvalleyapi/service/interfaces/IAdminService.java"
    click IAuthService "https://github.com/jeansupre/stardewvalleyprojectback/blob/main/src/main/java/com/jean/stardewvalleyapi/service/interfaces/IAuthService.java"
    click AdminServiceImpl "https://github.com/jeansupre/stardewvalleyprojectback/blob/main/src/main/java/com/jean/stardewvalleyapi/service/impl/AdminServiceImpl.java"
    click AuthServiceImpl "https://github.com/jeansupre/stardewvalleyprojectback/blob/main/src/main/java/com/jean/stardewvalleyapi/service/impl/AuthServiceImpl.java"
    click JwtService "https://github.com/jeansupre/stardewvalleyprojectback/blob/main/src/main/java/com/jean/stardewvalleyapi/service/impl/JwtService.java"
    click AldeanoRepo "https://github.com/jeansupre/stardewvalleyprojectback/blob/main/src/main/java/com/jean/stardewvalleyapi/repository/IAldeanoRepository.java"
    click ItemRepo "https://github.com/jeansupre/stardewvalleyprojectback/blob/main/src/main/java/com/jean/stardewvalleyapi/repository/IItemRepository.java"
    click JwtInterceptor "https://github.com/jeansupre/stardewvalleyprojectback/blob/main/src/main/java/com/jean/stardewvalleyapi/security/interceptors/JwtInterceptor.java"
    click RequireJwt "https://github.com/jeansupre/stardewvalleyprojectback/blob/main/src/main/java/com/jean/stardewvalleyapi/security/annotations/RequireJwtVerification.java"
    click CustomLocale "https://github.com/jeansupre/stardewvalleyprojectback/blob/main/src/main/java/com/jean/stardewvalleyapi/config/CustomLocaleResolver.java"
    click PrincipalConfig "https://github.com/jeansupre/stardewvalleyprojectback/blob/main/src/main/java/com/jean/stardewvalleyapi/config/PrincipalConfig.java"
    click SwaggerConfig "https://github.com/jeansupre/stardewvalleyprojectback/blob/main/src/main/java/com/jean/stardewvalleyapi/config/SwaggerConfig.java"
    click WebConfig "https://github.com/jeansupre/stardewvalleyprojectback/blob/main/src/main/java/com/jean/stardewvalleyapi/config/WebConfig.java"
    click Constantes "https://github.com/jeansupre/stardewvalleyprojectback/blob/main/src/main/java/com/jean/stardewvalleyapi/util/Constantes.java"
    click ITools "https://github.com/jeansupre/stardewvalleyprojectback/blob/main/src/main/java/com/jean/stardewvalleyapi/util/ITools.java"
    click Mensajes "https://github.com/jeansupre/stardewvalleyprojectback/blob/main/src/main/java/com/jean/stardewvalleyapi/util/Mensajes.java"

    %% Styles
    classDef client fill:#F6D8AE,stroke:#333,stroke-width:2px;
    classDef security fill:#F49AC2,stroke:#333,stroke-width:2px;
    classDef controller fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef service fill:#C2E7DA,stroke:#333,stroke-width:2px;
    classDef repository fill:#D7BDE2,stroke:#333,stroke-width:2px;
    classDef dto fill:#FFF79A,stroke:#333,stroke-width:2px;
    classDef domain fill:#C6E2FF,stroke:#333,stroke-width:2px;
    classDef config fill:#B3E5FC,stroke:#333,stroke-width:2px;
    classDef utility fill:#F0B27A,stroke:#333,stroke-width:2px;
```
