# 412139-chachagua/teg_mydiagrams_public architecture

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

- Interactive diagram: https://gitdiagram.com/412139-chachagua/teg_mydiagrams_public
- Repository: https://github.com/412139-chachagua/teg_mydiagrams_public

## Overview

##### Project type and purpose
- This is the backend of a full-stack digital version of the TEG board game. It exposes a REST API (Spring Boot) implementing game mechanics, user management, chat, and state persistence. Although there is no frontend code here, the system is intended to serve a separate client application (web or mobile).

##### File structure and README
- Top-level artifacts:
- pom.xml, mvnw → Java/Spring Boot build
- src/main/java → layered API (controllers, services, repositories, entities, DTOs)
- src/main/resources/application.properties → runtime configuration (DB connection, ports, etc.)
- scripts/BD_TEG.sql → initial database schema
- Layers follow a classic MVC/service/repository pattern with MapStruct mappers and SpringDoc (Swagger) for API docs.

##### Core architectural components
a. Client (web/mobile) – consumes REST endpoints and pushes/polls chat messages
b. API Layer (Controllers) – Spring MVC REST controllers (Ping, Usuario, Partida, Chat, etc.)
c. Business Layer (Services) – interfaces + impl packages encapsulate game logic, security, chat, DTO mapping
d. Data Layer (Repositories) – Spring Data JPA repositories for entities (Usuario, Partida, Mensaje, Pais, Turno, etc.)
e. Persistence Store – relational database (PostgreSQL or H2) defined via application.properties and initialized by BD_TEG.sql
f. Cross-cutting / Infra
- MapStruct (MappersConfig)
- Swagger/OpenAPI (SpringDocConfig)
- Authentication module (AutenticacionService)
- Logging, error handling (ErrorApi DTO)

##### Relationships and interactions
- Client → HTTP(S) → Controllers
- Controller methods delegate to Service interfaces
- Services orchestrate business rules, call Repositories, use Mappers to convert Entities ↔ DTOs
- Repositories ↔ Database
- ChatController ↔ ChatService may poll or publish messages (consider WebSocket or long-polling extension in future)

##### Architectural patterns / design principles
- Layered (Controller → Service → Repository)
- Dependency injection (Spring @Component, @Service, @Repository)
- Separation of concerns (DTO vs. Entity)
- Configuration externalized (application.properties)
- API documentation via OpenAPI / Swagger
- Use of MapStruct for mapping to reduce boilerplate

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    Client["Web/Mobile Client"]:::external
    DB["Database (PostgreSQL/H2)"]:::db

    %% Infra / Configurations
    subgraph "Infra / Config"
        MappersConfig["MappersConfig"]:::infra
        SpringDocConfig["SpringDocConfig"]:::infra
        ErrorApi["ErrorApi DTO"]:::infra
        AppProps["application.properties"]:::infra
        DBScript["BD_TEG.sql"]:::infra
    end

    %% Controllers Layer
    subgraph "API Layer (Controllers)"
        Controllers["Controllers Package"]:::controllers
    end

    %% Business Layer
    subgraph "Business Layer"
        ServiceIface["Services Interfaces Package"]:::services
        ServiceImpl["Services Implementations Package"]:::services
        AuthService["AutenticacionService"]:::services
        AuthServiceImpl["AutenticacionServiceImpl"]:::services
    end

    %% Data Layer
    subgraph "Data Layer"
        Repo["Repositories Package"]:::repository
        Entities["Entities Package"]:::repository
    end

    %% Relationships
    Client -->|"HTTP/HTTPS"| Controllers
    Controllers -->|"calls Service Interfaces"| ServiceIface
    ServiceIface -->|"implemented by"| ServiceImpl
    Controllers -->|"authentication calls"| AuthService
    AuthService -->|"implemented by"| AuthServiceImpl
    ServiceImpl -->|"CRUD operations"| Repo
    Repo -->|"SQL"| DB

    MappersConfig -.->|used by| Controllers
    MappersConfig -.->|used by| ServiceImpl
    SpringDocConfig -.->|documents| Controllers
    AppProps -.->|configures| DB
    DBScript -.->|initializes schema| DB

    %% Click Events
    click Controllers "https://github.com/412139-chachagua/teg_mydiagrams_public/tree/master/src/main/java/ar/edu/utn/frc/tup/piii/controllers/"
    click ServiceIface "https://github.com/412139-chachagua/teg_mydiagrams_public/tree/master/src/main/java/ar/edu/utn/frc/tup/piii/services/"
    click ServiceImpl "https://github.com/412139-chachagua/teg_mydiagrams_public/tree/master/src/main/java/ar/edu/utn/frc/tup/piii/services/impl/"
    click Repo "https://github.com/412139-chachagua/teg_mydiagrams_public/tree/master/src/main/java/ar/edu/utn/frc/tup/piii/model/repository/"
    click Entities "https://github.com/412139-chachagua/teg_mydiagrams_public/tree/master/src/main/java/ar/edu/utn/frc/tup/piii/model/entities/"
    click ErrorApi "https://github.com/412139-chachagua/teg_mydiagrams_public/blob/master/src/main/java/ar/edu/utn/frc/tup/piii/dtos/common/ErrorApi.java"
    click MappersConfig "https://github.com/412139-chachagua/teg_mydiagrams_public/blob/master/src/main/java/ar/edu/utn/frc/tup/piii/configs/MappersConfig.java"
    click SpringDocConfig "https://github.com/412139-chachagua/teg_mydiagrams_public/blob/master/src/main/java/ar/edu/utn/frc/tup/piii/configs/SpringDocConfig.java"
    click AuthService "https://github.com/412139-chachagua/teg_mydiagrams_public/blob/master/src/main/java/ar/edu/utn/frc/tup/piii/services/AutenticacionService.java"
    click AuthServiceImpl "https://github.com/412139-chachagua/teg_mydiagrams_public/blob/master/src/main/java/ar/edu/utn/frc/tup/piii/services/impl/AutenticacionServiceImpl.java"
    click DBScript "https://github.com/412139-chachagua/teg_mydiagrams_public/blob/master/scripts/BD_TEG.sql"
    click AppProps "https://github.com/412139-chachagua/teg_mydiagrams_public/blob/master/src/main/resources/application.properties"

    %% Styles
    classDef external fill:#f2f2f2,stroke:#333,stroke-width:1px
    classDef db fill:#d9ead3,stroke:#6aa84f,stroke-width:1px
    classDef infra fill:#eeeeee,stroke:#999999,stroke-width:1px
    classDef controllers fill:#cfe2f3,stroke:#2e75b6,stroke-width:1px
    classDef services fill:#d9d2e9,stroke:#674ea7,stroke-width:1px
    classDef repository fill:#fce5cd,stroke:#e69138,stroke-width:1px
```
