# codeurjc-daw-2024-25/webapp05 architecture

> Architecture diagram of the GitHub repository codeurjc-daw-2024-25/webapp05, 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/codeurjc-daw-2024-25/webapp05
- Repository: https://github.com/codeurjc-daw-2024-25/webapp05

## Overview

##### Project Components and Purpose
- Recognize that AlphaGym is a full-stack web application targeting a gym environment. Its primary purpose is to manage user profiles, offer personalized training and nutrition plans, enable comments on these plans, generate PDFs, and handle security (authentication/authorization with JWT and Spring Security).
- The README outlines both the web-based interfaces (templates, controllers for web navigation) and the REST APIs that expose business functionality as JSON endpoints. In addition, there is a clear separation of roles (anonymous, registered, admin) that affects how data is handled and which endpoints each user can access.

##### Main Components
a. Presentation Layer:
- Web controllers (@Controller) and template files (HTML pages, static resources like CSS, JS, images).
- REST API endpoints provided by @RestController classes (for Nutrition, Training, Comments, and User management).
b. Business/Service Layer:
- The service classes that implement business logic for entities (NutritionService, TrainingService, UserService, etc.).
c. Data Access Layer (Persistence):
- Spring Data repositories (UserRepository, NutritionRepository, TrainingRepository, etc.) managing CRUD operations with a MySQL database.
d. Domain Model:
- Entity classes such as User, Nutrition, Training, TrainingComment, NutritionComment, along with DTOs coming via mappers.
e. Security and Authentication:
- Security configuration setup (WebSecurityConfig, JWT filters, LoginController, and related security classes).
f. Integration Components:
- PDF generation for nutrition and training plans.
- External dependencies such as Docker containers (Dockerfile, docker-compose) for deployment and environment configuration.
g. API Documentation:

##### Relationships and Interactions
- Directional flows:
- From the client (browser or API consumer) to the Presentation Layer (web pages and REST endpoints).
- From Controllers to their respective Service classes where business logic is applied.
- From the Service layer to the Repository layer for CRUD operations with MySQL.
- From the Service layer back up to Controllers where responses (data, PDFs, error messages) are built.
- Additional flows such as the integration of security mechanisms where authentication requests pass through JWT filters and the Security configuration.
- API documentation consumption and Docker deployment where the application container interacts with external configuration (ports, environment variables).

##### Architectural Patterns and Design Principles
- Reinforce the Model-View-Controller (MVC) pattern present in the web controllers and view templates.
- The RESTful API design that exposes similar functionality nearly parallel to the MVC controllers.
- Separation of concerns is clearly seen in dividing responsibilities among controllers, services, repositories, and security classes.
- Use of DTOs and Mappers to decouple the entity model from external representations.

##### Technologies and Frameworks
- Java (version 21.0.5), Spring Boot (3.4.3) for the backend application.
- MySQL (8.0.33) for database management.
- Maven for build and dependency management.
- Docker for containerization and deployment.
- PDF generation libraries as part of the business logic.
- Frontend technologies include HTML/CSS/JavaScript.

## Diagram (Mermaid)

```mermaid
flowchart TB

    %% Client
    client["Client (Browser/API Consumer)"]:::clientStyle

    %% Presentation Layer Subgraph
    subgraph "Presentation Layer"
        web_ctrl["Web Controllers (@Controller)"]:::frontend
        rest_ctrl["REST Controllers (@RestController)"]:::frontend
        templates["HTML Templates"]:::frontend
        static["Static Assets"]:::frontend
    end

    %% Business/Service Layer Subgraph
    subgraph "Business/Service Layer"
        svc["Service Classes"]:::service
        pdf["PDF Generation Service"]:::service
    end

    %% Data Access Layer Subgraph
    subgraph "Data Access Layer"
        repo["Repository Classes"]:::repository
    end

    %% Domain Model Subgraph
    subgraph "Domain Model"
        entities["Entity Classes"]:::domain
        dtos["DTOs and Mappers"]:::domain
    end

    %% Security and Authentication Subgraph
    subgraph "Security"
        sec_conf["Security Configuration"]:::security
        jwt["JWT & Authentication"]:::security
    end

    %% Integration Components Subgraph
    subgraph "Integration Components"
        api_docs_html["API Docs (HTML)"]:::integration
        api_docs_yaml["API Docs (YAML)"]:::integration
        docker_compose["Docker Compose"]:::integration
        dockerfile["Dockerfile"]:::integration
    end

    %% Database Node
    mysql["MySQL Database"]:::database

    %% Connections
    client -->|"accesses"| web_ctrl
    client -->|"accesses"| rest_ctrl
    client -->|"authenticates"| jwt
    client -->|"views"| api_docs_html
    client -->|"views"| api_docs_yaml

    web_ctrl -->|"renders"| templates
    web_ctrl -->|"calls"| svc
    rest_ctrl -->|"calls"| svc

    svc -->|"invokes"| pdf
    svc -->|"uses"| repo
    svc -->|"manipulates"| entities
    svc -->|"maps data via"| dtos

    repo -->|"CRUD operations"| mysql

    web_ctrl -->|"securedBy"| sec_conf
    rest_ctrl -->|"securedBy"| sec_conf
    sec_conf -->|"utilizes"| jwt

    svc -->|"deployed via"| docker_compose
    svc -->|"deployed via"| dockerfile

    %% Styles
    classDef frontend fill:#9fdf9f,stroke:#333,stroke-width:2px;
    classDef service fill:#ff9f9f,stroke:#333,stroke-width:2px;
    classDef repository fill:#9fcfff,stroke:#333,stroke-width:2px;
    classDef domain fill:#fff59f,stroke:#333,stroke-width:2px;
    classDef security fill:#ffd699,stroke:#333,stroke-width:2px;
    classDef integration fill:#d3adf7,stroke:#333,stroke-width:2px;
    classDef clientStyle fill:#cccccc,stroke:#333,stroke-width:2px;
    classDef database fill:#cfe2f3,stroke:#333,stroke-width:2px;

    %% Click Events for Presentation Layer
    click web_ctrl "https://github.com/codeurjc-daw-2024-25/webapp05/tree/main/backend/src/main/java/es/codeurjc/daw/alphagym/controller/web"
    click rest_ctrl "https://github.com/codeurjc-daw-2024-25/webapp05/tree/main/backend/src/main/java/es/codeurjc/daw/alphagym/controller/rest"
    click templates "https://github.com/codeurjc-daw-2024-25/webapp05/tree/main/backend/src/main/resources/templates"
    click static "https://github.com/codeurjc-daw-2024-25/webapp05/tree/main/backend/src/main/resources/static"

    %% Click Events for Business/Service Layer
    click svc "https://github.com/codeurjc-daw-2024-25/webapp05/tree/main/backend/src/main/java/es/codeurjc/daw/alphagym/service"

    %% Click Events for Data Access Layer
    click repo "https://github.com/codeurjc-daw-2024-25/webapp05/tree/main/backend/src/main/java/es/codeurjc/daw/alphagym/repository"

    %% Click Events for Domain Model
    click entities "https://github.com/codeurjc-daw-2024-25/webapp05/tree/main/backend/src/main/java/es/codeurjc/daw/alphagym/model"
    click dtos "https://github.com/codeurjc-daw-2024-25/webapp05/tree/main/backend/src/main/java/es/codeurjc/daw/alphagym/dto"

    %% Click Events for Security
    click sec_conf "https://github.com/codeurjc-daw-2024-25/webapp05/tree/main/backend/src/main/java/es/codeurjc/daw/alphagym/security"
    click jwt "https://github.com/codeurjc-daw-2024-25/webapp05/tree/main/backend/src/main/java/es/codeurjc/daw/alphagym/security/jwt"

    %% Click Events for Integration Components
    click api_docs_html "https://github.com/codeurjc-daw-2024-25/webapp05/blob/main/api-docs/api-docs.html"
    click api_docs_yaml "https://github.com/codeurjc-daw-2024-25/webapp05/blob/main/api-docs/api-docs.yaml"
    click docker_compose "https://github.com/codeurjc-daw-2024-25/webapp05/blob/main/docker/Docker-compose.yml"
    click dockerfile "https://github.com/codeurjc-daw-2024-25/webapp05/tree/main/docker/Dockerfile"
```
