# dws-2025/project-grupo-r-2 architecture

> Architecture diagram of the GitHub repository dws-2025/project-grupo-r-2, 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/dws-2025/project-grupo-r-2
- Repository: https://github.com/dws-2025/project-grupo-r-2

## Overview

##### Main Components
- Frontend Client:
- Web user interface built using Thymeleaf templates (HTML files under src/main/resources/templates) and static assets (CSS, JavaScript, images).
- Additional details for the static resources (styles.css, market.js, etc.) which support dynamic client-side interactions.

- Backend Application (Spring Boot):
- Controllers: Separate groups within the project for web controllers (e.g., WebController, LoginController, AdminController, MarketController, MembershipsController) that handle page requests, and REST controllers (e.g., CombatClassRestController, MembershipRestController, ProductRestController, UserRestController, and LoginRestController under the auth package) for API requests.
- Service Layer: Components that include business logic for each entity (UserService, MembershipService, CombatClassService, ProductService, ImageService) and possibly additional services like UserLoginService.
- Repository Layer: Interfaces that abstract data persistence operations (e.g., UserRepository, MembershipRepository, CombatClassRepository, ProductRepository).
- Domain Model & DTOs: Entities (User, Membership, CombatClass, Product) showcasing business data; related DTO objects for data transfer; and mappers to convert between entity and DTO representations.

- Security Module:
- JWT-based authentication and authorization handled by classes in the security and security/jwt packages, including configuration, filters, token providers, and handlers.
- CSRF handling and other security-specific configurations.

- Database:
- Although the specific type isn’t detailed, DatabaseInitializer and the pom.xml configuration imply that a relational database (or similar) is used with an ORM like JPA/Hibernate.

##### Relationships and Data Flow
- How the frontend interacts with the backend. For example, user actions (such as login, product purchase, membership subscription) are sent as HTTP requests to the respective controllers.
- Controllers delegate operations to the service layer.
- Services interact with repositories to perform CRUD operations on the database.
- Bidirectional relationships:
- The relationship between Users, Memberships, Products, and Combat Classes as laid out in the README.
- That a User can have multiple products and a subscription to a membership, while a membership is associated with one combat class (which can be part of several memberships).
- Integration of the JWT-based security mechanism filtering requests between the client and backend resources, ensuring secure access based on user roles (Admin vs. Regular User).

##### Architectural Patterns and Technologies
- Layered (MVC) pattern:
- Controllers handle HTTP requests.
- Services embed business logic.
- Repositories interact with the database.
- Use of Data Transfer Objects (DTOs) for decoupling domain models from external interfaces.
- Optionally, mention the integration testing (files under src/test) used to ensure the correctness of the application.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Client"
        FE1("Templates"):::frontend
        FE2("Static Assets"):::frontend
    end

    %% Security Module
    subgraph "Security Module"
        SEC1("Security Config"):::security
        SEC2("JWT Components"):::security
    end

    %% Backend Controllers
    subgraph "Controllers"
        CTRL1("Web Controllers"):::controller
        CTRL2("REST Controllers"):::controller
    end

    %% Service Layer
    SVC("Service Layer"):::service

    %% Domain Model & DTOs
    subgraph "Domain & DTOs"
        DM("Domain Models"):::model
        DTO("DTOs"):::model
        MP("Mappers"):::model
    end

    %% Repository Layer
    REP("Repository Layer"):::repository

    %% Database Initialization
    DBI("Database Initialization"):::repository

    %% Database
    DB("Database"):::database

    %% Connections
    FE1 -->|"authenticates"| SEC1
    FE2 -->|"authenticates"| SEC1

    SEC1 -->|"secures"| CTRL1
    SEC1 -->|"secures"| CTRL2
    SEC2 -->|"handles_token"| CTRL2

    CTRL1 -->|"calls"| SVC
    CTRL2 -->|"calls"| SVC

    SVC -->|"uses"| REP

    SVC -->|"maps"| DM
    DM -->|"converts_to"| DTO
    DTO -->|"mapped_by"| MP
    MP -->|"returns_to"| SVC

    REP -->|"persists_to"| DB

    DBI -->|"initializes"| DB

    %% Click Events
    click FE1 "https://github.com/dws-2025/project-grupo-r-2/tree/main/SpartanWrath/src/main/resources/templates"
    click FE2 "https://github.com/dws-2025/project-grupo-r-2/tree/main/SpartanWrath/src/main/resources/static"
    click CTRL1 "https://github.com/dws-2025/project-grupo-r-2/tree/main/SpartanWrath/src/main/java/com/spartanwrath/controller"
    click CTRL2 "https://github.com/dws-2025/project-grupo-r-2/tree/main/SpartanWrath/src/main/java/com/spartanwrath/restController"
    click SVC "https://github.com/dws-2025/project-grupo-r-2/tree/main/SpartanWrath/src/main/java/com/spartanwrath/service"
    click REP "https://github.com/dws-2025/project-grupo-r-2/tree/main/SpartanWrath/src/main/java/com/spartanwrath/repository"
    click DM "https://github.com/dws-2025/project-grupo-r-2/tree/main/SpartanWrath/src/main/java/com/spartanwrath/model"
    click DTO "https://github.com/dws-2025/project-grupo-r-2/tree/main/SpartanWrath/src/main/java/com/spartanwrath/dto"
    click MP "https://github.com/dws-2025/project-grupo-r-2/tree/main/SpartanWrath/src/main/java/com/spartanwrath/mappers"
    click SEC1 "https://github.com/dws-2025/project-grupo-r-2/tree/main/SpartanWrath/src/main/java/com/spartanwrath/security"
    click SEC2 "https://github.com/dws-2025/project-grupo-r-2/tree/main/SpartanWrath/src/main/java/com/spartanwrath/security/jwt"
    click DBI "https://github.com/dws-2025/project-grupo-r-2/blob/main/SpartanWrath/src/main/java/com/spartanwrath/config/DatabaseInitializer.java"

    %% Styles
    classDef frontend fill:#FFDD57,stroke:#333,stroke-width:2px;
    classDef controller fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef service fill:#C8E6C9,stroke:#333,stroke-width:2px;
    classDef repository fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef model fill:#D7BDE2,stroke:#333,stroke-width:2px;
    classDef security fill:#F5B7B1,stroke:#333,stroke-width:2px;
    classDef database fill:#FADBD8,stroke:#333,stroke-width:2px,stroke-dasharray: 5, 5;
```
