# samuel-cruz/desafio architecture

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

- Interactive diagram: https://gitdiagram.com/samuel-cruz/desafio
- Repository: https://github.com/samuel-cruz/desafio

## Overview

##### Project type and purpose
- This is a standalone back-end REST API built with Java 11 and Spring Boot.
- Its sole responsibility is to manage “Pessoa” (person) records: create, read, update, delete, with field validation and API versioning (v1/v2).

##### High-level architecture
- Client (e.g. front-end app or Swagger UI)
- Issues HTTP requests to the API endpoints.
- API Layer (Spring MVC Controllers)
- Versioned controllers under br.com.meta.controller.v1 and v2.
- They accept requests, invoke converters and services, and return DTOs.
- Conversion Layer
- BaseConverter + versioned converters transform between Entity ↔ DTO.
- Service Layer
- BaseService + PessoaService encapsulate business rules (validations, uniqueness checks).
- Repository Layer
- BaseRepository + PessoaRepository handle CRUD via Spring Data JPA.
- Persistence
- H2 in-memory (or file-based) database holds Pessoa table.
- Cross-cutting concerns
- Exception handling (CustomizedResponseEntityExceptionHandler)
- SecurityConfig (authentication/authorization if enabled)
- SwaggerConfig exposes API docs
- BaseWebMvcConfig for MVC customization
- Deployment
- Packaged via Maven, containerized with Dockerfile.

##### Relationships and data flow
- Client → Controller (v1/v2) → Converter → Service → Repository → H2 DB
- On responses, flow reverses: Repository → Service → Converter → Controller → Client
- Config classes bootstrap Spring context, Swagger UI, exception advice intercepts errors.

##### Key architectural patterns & principles
- Layered architecture (Controller → Service → Repository)
- DTO pattern to decouple API contract from persistence model
- API versioning via separate controller packages
- Centralized exception handling
- Dependency Injection via Spring Boot
- Containerization for consistent deployment

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client"
        Client["Client (Front-end)"]:::external
        Swagger["Swagger UI"]:::external
    end
    subgraph "Spring Boot Application"
        App["App.java"]:::app

        subgraph "Controller Layer"
            C3["BaseController"]:::controller
            C1["v1 PessoaController"]:::controller
            C2["v1 SourceGitController"]:::controller
            C4["v2 PessoaController"]:::controller
        end

        subgraph "Converter Layer"
            BConv["BaseConverter"]:::converter
            V1Conv["v1 PessoaConverter"]:::converter
            V2Conv["v2 PessoaConverter"]:::converter
        end

        subgraph "Service Layer"
            BServ["BaseService"]:::service
            PServ["PessoaService"]:::service
        end

        subgraph "Repository Layer"
            BRepo["BaseRepository"]:::repository
            PRepo["PessoaRepository"]:::repository
        end

        DB["H2 Database"]:::database

        subgraph "Configuration & Exception"
            Exc["CustomizedResponseEntityExceptionHandler"]:::config
            Sec["SecurityConfig"]:::config
            Swag["SwaggerConfig"]:::config
            MVC["BaseWebMvcConfig"]:::config
        end

        App --> C3
        App --> C1
        App --> C2
        App --> C4

        Client -->|"POST /v1/pessoa → PessoaDTO"| C1
        Swagger -->|"/swagger-ui.html"| Swag

        C1 -->|"toDTO() v1"| V1Conv
        C2 -->|"toDTO() base"| BConv
        C4 -->|"toDTO() v2"| V2Conv

        V1Conv -->|"validate & convert"| PServ
        V2Conv -->|"validate & convert"| PServ

        PServ -->|"save(entity)"| PRepo
        PRepo -->|"CRUD operations"| DB

        DB -->|"result set"| PRepo
        PRepo -->|"entity"| PServ

        PServ -->|"toDTO() base"| BConv
        BConv -->|"response DTO"| C1
        BConv -->|"response DTO"| C4

        Exc --> App
        Sec --> App
        Swag --> App
        MVC --> App
    end

    subgraph "Build & Deployment"
        Maven["pom.xml"]:::build
        Docker["Dockerfile"]:::build
    end
    Maven --> App
    App --> Docker

    click App "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/app/App.java"
    click C3 "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/controller/BaseController.java"
    click C1 "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/controller/v1/PessoaController.java"
    click C2 "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/controller/v1/SourceGitController.java"
    click C4 "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/controller/v2/PessoaController.java"
    click BConv "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/converter/BaseConverter.java"
    click V1Conv "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/converter/v1/PessoaConverter.java"
    click V2Conv "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/converter/v2/PessoaConverter.java"
    click BServ "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/service/BaseService.java"
    click PServ "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/service/PessoaService.java"
    click BRepo "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/repository/BaseRepository.java"
    click PRepo "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/repository/PessoaRepository.java"
    click BaseDTO "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/dto/BaseDTO.java"
    click DTOv1 "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/dto/v1/PessoaDTO.java"
    click DTOv2 "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/dto/v2/PessoaDTO.java"
    click BaseEntity "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/entity/BaseEntity.java"
    click PessoaEntity "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/entity/Pessoa.java"
    click Sexo "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/enumeradores/Sexo.java"
    click Exc "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/config/CustomizedResponseEntityExceptionHandler.java"
    click Sec "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/config/SecurityConfig.java"
    click Swag "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/config/SwaggerConfig.java"
    click MVC "https://github.com/samuel-cruz/desafio/blob/master/src/main/java/br/com/meta/config/BaseWebMvcConfig.java"
    click ExceptionsPackage "https://github.com/samuel-cruz/desafio/tree/master/src/main/java/br/com/meta/exceptions/"
    click Props "https://github.com/samuel-cruz/desafio/blob/master/src/main/resources/application.properties"
    click Messages "https://github.com/samuel-cruz/desafio/blob/master/src/main/resources/ValidationMessages.properties"
    click Maven "https://github.com/samuel-cruz/desafio/blob/master/pom.xml"
    click Docker "https://github.com/samuel-cruz/desafio/tree/master/Dockerfile"

    classDef external fill:#ffe4b3,stroke:#cc7a00;
    classDef app fill:#e3f2fd,stroke:#2196f3;
    classDef controller fill:#ffcccb,stroke:#e53935;
    classDef converter fill:#ffecb3,stroke:#fbc02d;
    classDef service fill:#c8e6c9,stroke:#43a047;
    classDef repository fill:#bbdefb,stroke:#1e88e5;
    classDef database fill:#d1c4e9,stroke:#5e35b1,shape:cylinder;
    classDef config fill:#f5f5f5,stroke:#9e9e9e,shape:component;
    classDef build fill:#d7ccc8,stroke:#6d4c41;
    class BaseDTO,DTOv1,DTOv2 dto;
    class BaseEntity,PessoaEntity,Sexo entity;
```
