# eltonarmelini/tu-cancha architecture

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

- Interactive diagram: https://gitdiagram.com/eltonarmelini/tu-cancha
- Repository: https://github.com/eltonarmelini/tu-cancha

## Overview

1. Frontend: A React-based client that handles the user interface and communicates with the backend via REST.
2. Backend: A Spring Boot application, employing Spring Security with JWT for authentication/authorization, and structured with controllers, services, repositories, and data transfer objects (DTOs) to handle business logic (e.g., user management, reservations, and notifications via email).
3. Infrastructure & Deployment: Docker is used in both the frontend and backend (with respective Dockerfiles and docker-compose configurations). Deployment infrastructure utilizes AWS EC2, with Ansible scripts for orchestration, and continuous integration/deployment is automated via GitLab CI/CD.

A. Main Components and Their Relationships:
- Frontend Component:
- Represented as the React application.
- Subcomponents (pages, components, context providers) symbolizing UI elements like Home, Booking, Detail pages plus admin functionality.
- That it interacts with the backend via REST API calls.
- Backend Component:
- Spring Boot application.
- Layered architecture:
▸ Controller Layer: Shows endpoints for authentication (AuthController), reservations, pitches, ratings, etc.
▸ Service Layer: Include key services like UserService, ReservationService, PitchService, etc.
▸ Security & Configuration: Components for JWT validation (JwtTokenValidator, JwtUtils), Spring Security, S3 configuration, and model mapping.
- Database Layer:
- External Services:
- Email Service: Integration with Mailtrap for email notifications.
- AWS S3: For image uploads/storage.
- Infrastructure & CI/CD:
- Docker & Docker-Compose: Emphasize containerization with separate Dockerfiles for frontend and backend.
- Deployment: Show AWS EC2 as the hosting target and Ansible for configuration/deployment management.
- Pipeline: GitLab CI/CD for automated testing, building, and deployment.

B. Architectural Patterns and Design Principles:
- Layered Architecture: Separate controllers, services, repositories, and utility layers.
- Microservice-Inspired Separation (even if monolithic in code organization): Separate frontend and backend services.
- RESTful API communications: Indicate clear interactions between the frontend and backend.
- Secure Authentication: Highlight the use of Spring Security and JWT for secure access.
- Containerization & Orchestration: Use Docker containers and deployment automation.

- Clear Labels: For each component (e.g., “React Frontend”, “Spring Boot API”, “Database”, “Mail Service”, “AWS S3 Storage”, “Docker”, “Ansible Deployment”, “GitLab CI/CD Pipeline”).
- Use another distinct style for external integrations (Mailtrap, AWS S3).
- Technology Annotations: Next to each component, annotate key technologies (e.g., “React”, “Spring Boot”, “JWT”, “Docker”, “Ansible”, “GitLab CI/CD”).

- For a Full-Stack Application like TU Cancha:
- Decoupling between the frontend client and backend API.
- How authentication is managed (JWT tokens exchanged between the frontend and Spring Security).
- A depiction of deployment processes: local development (via docker-compose) versus production deployment (AWS EC2 and Ansible).
- Detail the internal backend structure:
- For Infrastructure, detail how GitLab CI/CD integrates with the Docker build process to deploy containers onto AWS.

- How the Frontend makes REST API calls to the Backend.
- How the Backend accesses the Database.
- How the Backend communicates with Mailtrap and AWS S3 for emails and file storage.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend (React)"
        F1["React Frontend\n(React)"]:::frontend
        FP["Pages"]:::frontend
        FC["Components"]:::frontend
        CFP["Context Providers"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Spring Boot API)"
        BEntry["ReservaTuCanchaBackendApplication"]:::backend
        subgraph "Controller Layer"
            BC["Controllers\n(AuthController, PitchController, etc.)"]:::backend
        end
        subgraph "Service Layer"
            BS["Core Services\n(User, Reservation, Pitch, etc.)"]:::backend
            ESI["IEmailService"]:::backend
            ESI_Impl["EmailServiceImplementation"]:::backend
        end
        subgraph "Repository Layer"
            BR["JPA Repositories"]:::backend
        end
        subgraph "DTO Layer"
            BDTOReq["Request DTOs"]:::backend
            BDTORes["Response DTOs"]:::backend
        end
        subgraph "Security & Config"
            SC["SecurityConfig"]:::backend
            JT["JwtTokenValidator"]:::backend
            JU["JwtUtils"]:::backend
            S3["S3Config"]:::backend
            MM["ModelMapperConfig"]:::backend
            ACFG["Application.yml"]:::backend
            DL["DataLoader"]:::backend
        end
    end

    %% Database Layer
    subgraph "Database"
        DB["Database\n(MySQL/PostgreSQL)"]:::database
    end

    %% External Services
    subgraph "External Services"
        Mail["Mail Service\n(Mailtrap)"]:::external
        S3Ext["AWS S3 Storage"]:::external
    end

    %% Infrastructure & Deployment
    subgraph "Infrastructure & Deployment"
        Docker["Docker & docker-compose"]:::infra
        Ansible["Ansible Deployment"]:::infra
        CICD["GitLab CI/CD Pipeline"]:::infra
    end

    %% Connections
    F1 -->|"RESTAPI"| BEntry
    FP --- F1
    FC --- F1
    CFP --- F1

    BEntry -->|"initializes"| BC
    BC -->|"calls"| BS
    BC -->|"transfers"| BDTOReq
    BC -->|"transfers"| BDTORes
    BS -->|"queries"| BR
    BS -->|"delegates-email"| ESI
    BS -->|"delegates-email"| ESI_Impl

    BR -->|"persists"| DB

    SC --- BEntry
    JT --- BEntry
    JU --- BEntry
    S3 --- BEntry
    MM --- BEntry
    ACFG --- BEntry
    DL --- BEntry

    ESI -->|"defines"| ESI_Impl

    BS -->|"notifies"| Mail
    S3 --- S3Ext

    %% Infrastructure connections
    F1 -->|"containerized"| Docker
    BEntry -->|"containerized"| Docker
    Docker -->|"CI triggers"| CICD
    CICD -->|"deploys via"| Ansible

    %% Click Events for Frontend
    click F1 "https://github.com/eltonarmelini/tu-cancha/tree/main/frontend/"
    click FP "https://github.com/eltonarmelini/tu-cancha/tree/main/frontend/src/Pages"
    click FC "https://github.com/eltonarmelini/tu-cancha/tree/main/frontend/src/components"
    click CFP "https://github.com/eltonarmelini/tu-cancha/tree/main/frontend/src/context"

    %% Click Events for Backend Entry
    click BEntry "https://github.com/eltonarmelini/tu-cancha/blob/main/backend/src/main/java/com/reservatucancha/backend/rtc_backend/ReservaTuCanchaBackendApplication.java"
    click BC "https://github.com/eltonarmelini/tu-cancha/tree/main/backend/src/main/java/com/reservatucancha/backend/rtc_backend/controller"
    click BS "https://github.com/eltonarmelini/tu-cancha/tree/main/backend/src/main/java/com/reservatucancha/backend/rtc_backend/service"
    click BR "https://github.com/eltonarmelini/tu-cancha/tree/main/backend/src/main/java/com/reservatucancha/backend/rtc_backend/repository"
    click BDTOReq "https://github.com/eltonarmelini/tu-cancha/tree/main/backend/src/main/java/com/reservatucancha/backend/rtc_backend/dto/request"
    click BDTORes "https://github.com/eltonarmelini/tu-cancha/tree/main/backend/src/main/java/com/reservatucancha/backend/rtc_backend/dto/response"
    click SC "https://github.com/eltonarmelini/tu-cancha/blob/main/backend/src/main/java/com/reservatucancha/backend/rtc_backend/config/SecurityConfig.java"
    click JT "https://github.com/eltonarmelini/tu-cancha/blob/main/backend/src/main/java/com/reservatucancha/backend/rtc_backend/config/filter/JwtTokenValidator.java"
    click JU "https://github.com/eltonarmelini/tu-cancha/blob/main/backend/src/main/java/com/reservatucancha/backend/rtc_backend/utils/JwtUtils.java"
    click S3 "https://github.com/eltonarmelini/tu-cancha/blob/main/backend/src/main/java/com/reservatucancha/backend/rtc_backend/config/S3Config.java"
    click MM "https://github.com/eltonarmelini/tu-cancha/blob/main/backend/src/main/java/com/reservatucancha/backend/rtc_backend/config/ModelMapperConfig.java"
    click ACFG "https://github.com/eltonarmelini/tu-cancha/blob/main/backend/src/main/resources/application.yml"
    click DL "https://github.com/eltonarmelini/tu-cancha/blob/main/backend/src/main/java/com/reservatucancha/backend/rtc_backend/bootstrap/DataLoader.java"
    click ESI "https://github.com/eltonarmelini/tu-cancha/blob/main/backend/src/main/java/com/reservatucancha/backend/rtc_backend/service/IEmailService.java"
    click ESI_Impl "https://github.com/eltonarmelini/tu-cancha/blob/main/backend/src/main/java/com/reservatucancha/backend/rtc_backend/service/implementation/EmailServiceImplementation.java"

    %% Click Events for Infrastructure
    click Ansible "https://github.com/eltonarmelini/tu-cancha/tree/main/backend/deploy/"
    click CICD "https://github.com/eltonarmelini/tu-cancha/blob/main/backend/.gitlab-ci.yml"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef backend fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef database fill:#F9E79F,stroke:#D4AC0D,stroke-width:2px;
    classDef external fill:#FADBD8,stroke:#E74C3C,stroke-width:2px;
    classDef infra fill:#D6EAF8,stroke:#3498DB,stroke-width:2px;
```
