# dalmaponce/practicas-underc0de-appsorteo architecture

> Architecture diagram of the GitHub repository dalmaponce/practicas-underc0de-appsorteo, 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/dalmaponce/practicas-underc0de-appsorteo
- Repository: https://github.com/dalmaponce/practicas-underc0de-appsorteo

## Overview

##### Project Type and Purpose
- This is a full-stack application developed as a practice project for performing random draws (sorteos).
- The frontend is a simple interface built with HTML, CSS, and JavaScript that allows users to create events and input participants and prizes.
- The backend is built with Spring Boot (Java) and exposes RESTful endpoints for managing events, participants, and prizes. It interacts with a MySQL database for persistence.

##### Main Components
a. Frontend:
- UI Elements (HTML pages such as index.html and formulario.html).
- CSS & JS files for styling and interaction (CSS files, formulario.js, fuction.js).
- This layer is responsible for capturing user input and sending requests to the backend API.
b. Backend:
- API Layer built with Spring Boot (see controller packages: EventoController, ParticipanteController, PremioController).
- Business Logic layer (service classes: EventoService, ParticipanteService, PremioService).
- Data Access layer (repository interfaces: IEventoRepository, IParticipanteRepository, IPremioRepository).
- Exception handling and configuration modules (advice package, config package).
c. Database:
- MySQL database (as specified in the README) where data for events, participants, prizes, and historical event data are stored.
d. External Dependencies:
- Maven (for dependency management) and Java 17.
- Spring Data JPA is used to abstract database interactions.

##### Relationships and Interactions
- The Frontend sends HTTP requests (likely via AJAX/Fetch) to the Backend’s REST API endpoints.
- The Backend processes these requests:
- Controllers interpret requests and delegate tasks to services.
- The Service layer implements business logic (handling creation of events, managing participants/prizes, executing the random lottery).
- The Repository layer communicates with the MySQL database via Spring Data JPA.
- Data flows from the frontend to the backend and back, with the database acting as persistence storage.

##### Important Architectural Patterns & Design Principles
- Layered Architecture: Separation between the presentation layer (frontend), business logic (backend services), and data access (repositories).
- RESTful API design: Endpoints such as POST /evento, GET /evento/historial, etc., outlining standard resource operations.
- Exception and validation management using dedicated advice and config packages.
- Use of Data Transfer Objects (DTOs) to decouple domain entities from API data representations.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["Frontend UI"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        CT["Spring Boot Controllers"]:::backendController
        SR["Business Services"]:::backendService
        RP["Data Repositories"]:::backendRepository
        EX["Exception Handling & Validation"]:::backendAdvice
        CF["Configuration"]:::backendConfig
    end

    %% Database Layer
    DB["MySQL Database"]:::database

    %% Data Flow Arrows
    FE -->|"HTTP Request"| CT
    CT -->|"Delegates"| SR
    SR -->|"Queries/Saves"| RP
    RP -->|"Data Persistence"| DB

    DB -->|"Data Result"| RP
    RP -->|"Return Data"| SR
    SR -->|"Response"| CT
    CT -->|"HTTP Response"| FE

    %% Additional Backend Interactions
    CT -->|"Error Handling"| EX
    CT -->|"Uses"| CF

    %% Click Events
    click FE "https://github.com/dalmaponce/practicas-underc0de-appsorteo/tree/main/Frontend"
    click CT "https://github.com/dalmaponce/practicas-underc0de-appsorteo/tree/main/backend/src/main/java/org/underc0de/backend/controller"
    click SR "https://github.com/dalmaponce/practicas-underc0de-appsorteo/tree/main/backend/src/main/java/org/underc0de/backend/service"
    click RP "https://github.com/dalmaponce/practicas-underc0de-appsorteo/tree/main/backend/src/main/java/org/underc0de/backend/repository"
    click EX "https://github.com/dalmaponce/practicas-underc0de-appsorteo/tree/main/backend/src/main/java/org/underc0de/backend/advice"
    click CF "https://github.com/dalmaponce/practicas-underc0de-appsorteo/tree/main/backend/src/main/java/org/underc0de/backend/config"

    %% Style Definitions
    classDef frontend fill:#ADD8E6,stroke:#0000FF,stroke-width:2px;
    classDef backendController fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef backendService fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef backendRepository fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef backendAdvice fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef backendConfig fill:#FFA07A,stroke:#CD5C5C,stroke-width:2px;
    classDef database fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px;
```
