# sergiocp21/yourfitnessjourney architecture

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

- Interactive diagram: https://gitdiagram.com/sergiocp21/yourfitnessjourney
- Repository: https://github.com/sergiocp21/yourfitnessjourney

## Overview

##### Main Components
a. Frontend:
- Located in the "Frontend" directory.
- Contains a React-based application (using Vite as suggested by the "vite.config.js" file) with components for login, home view, authentication (e.g., AuthContext, AuthProvider), and general UI elements like headers and footers.

b. Backend:
- Found inside the "Backend/backend" directory.
- A Java Spring Boot application built with Maven (note the "pom.xml" and Maven wrapper files).
- Organized using a layered architecture pattern with clear subdivisions:
i. Controller: REST controllers (e.g., UserController) that handle incoming HTTP requests.
ii. Model: Domain entities (e.g., Exercise, Routine, User, RoutineExercise, UserRoutine).
iii. Repository: Interfaces (e.g., IExerciseRepository, IUserRepository, etc.) to abstract data persistence.
iv. Service: Business logic layer (e.g., UserService).
v. Security: JWT-based authentication components (JwtConfig, JwtUtils, SecurityConfig).

c. Database:
- Represented by the "BaseDatos.sql" file. This likely contains the SQL schema and possible seed data for the relational database supporting the backend.

##### Relationships and Data Flow
- The Frontend (React application) is the interface for the end-user which communicates with the Backend through RESTful API calls.
- The Backend receives HTTP requests via its controllers, processes business logic in the service layer, persists and retrieves data via repository interfaces, and secures endpoints using JWT-based security.
- The Database acts as the persistent store for all the application's data and is accessed by the backend.
- Security components (JWT utilities and configuration) are used as an intermediary layer ensuring that the data flow between the frontend and backend is properly authenticated and authorized.

##### Architectural Patterns and Technologies
- Layered (or n-tier) architecture in the backend to separate concerns (presentation, business logic, data access, and security).
- RESTful API design for communication between the frontend and backend.
- JWT-based authentication and authorization to secure endpoints.
- Use of modern Java frameworks (Spring Boot) for the backend and modern JavaScript frameworks (React with Vite) for the frontend.
- Maven as the build and dependency management tool for the Java backend.
- SQL-based database (as indicated by the BaseDatos.sql file).

a. Frontend Block:

b. Backend Block:
- Controller Layer (handling HTTP requests).
- Service Layer (processing business logic).
- Repository Layer (data access).
- Security Module (JWT utilities and configuration).

c. Database Block:

d. Security Component:
- Optionally, highlight the JWT Security module as a separate (or embedded) component in the backend to indicate that every request going to the backend undergoes security checks.

##### Final Practical Steps
- Decompose the Backend into its major layers (Controller, Service, Repository, Security).
- Clearly denote how the Frontend communicates with the Backend (via API calls) and how the Backend interfaces with the Database.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Components
    subgraph "Client Side"
        ReactFrontend["React Frontend"]:::frontend
        AuthModule["Auth Module"]:::frontend
        UIComponents["UI Components"]:::frontend
        AuthModule --> ReactFrontend
        UIComponents --> ReactFrontend
    end

    %% Backend Components
    subgraph "REST API Backend"
        BackendMain["Main Application"]:::backend
        subgraph "Controller Layer"
            UserController["UserController"]:::controller
        end
        subgraph "Service Layer"
            UserService["UserService"]:::service
        end
        subgraph "Repository Layer"
            Repositories["Repositories"]:::repository
        end
        subgraph "Security Module"
            JWTSecurity["JWT Security Module"]:::security
        end
    end

    %% Database
    Database["Relational Database"]:::database

    %% Data Flow Connections
    ReactFrontend -->|"API_call"| UserController
    UserController -->|"calls"| UserService
    UserService -->|"accesses"| Repositories
    Repositories -->|"queries"| Database
    UserController ---|"secured_by"| JWTSecurity

    %% Click Events
    click ReactFrontend "https://github.com/sergiocp21/yourfitnessjourney/tree/main/Frontend/"
    click AuthModule "https://github.com/sergiocp21/yourfitnessjourney/tree/main/Frontend/src/Auth/"
    click UIComponents "https://github.com/sergiocp21/yourfitnessjourney/tree/main/Frontend/src/components/"
    click BackendMain "https://github.com/sergiocp21/yourfitnessjourney/blob/main/Backend/backend/BackendApplication.java"
    click UserController "https://github.com/sergiocp21/yourfitnessjourney/tree/main/Backend/backend/src/main/java/com/your_fitness_journey/backend/Controller/"
    click UserService "https://github.com/sergiocp21/yourfitnessjourney/tree/main/Backend/backend/src/main/java/com/your_fitness_journey/backend/Service/"
    click Repositories "https://github.com/sergiocp21/yourfitnessjourney/tree/main/Backend/backend/src/main/java/com/your_fitness_journey/backend/Repository/"
    click JWTSecurity "https://github.com/sergiocp21/yourfitnessjourney/tree/main/Backend/backend/src/main/java/com/your_fitness_journey/backend/Security/"
    click Database "https://github.com/sergiocp21/yourfitnessjourney/blob/main/BaseDatos.sql"

    %% Styles
    classDef frontend fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef backend fill:#C1E1C1,stroke:#333,stroke-width:2px;
    classDef controller fill:#FFF5BA,stroke:#333,stroke-width:2px;
    classDef service fill:#FFD1DC,stroke:#333,stroke-width:2px;
    classDef repository fill:#F7D6AE,stroke:#333,stroke-width:2px;
    classDef security fill:#E2B1F2,stroke:#333,stroke-width:2px;
    classDef database fill:#F7AEC7,stroke:#333,stroke-width:2px;
```
