# pedrohenriqueveiga/desafio architecture

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

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

## Overview

##### Main Components

a) External Layer:
- Client/Consumer Layer (showing REST endpoints)
- File Upload Interface (for data_1.txt/data_2.txt processing)

b) Application Core:
- REST Controllers Layer
- Use Cases/Interactor Layer
- Service Layer
- Repository Layer
- Database Layer (H2 in-memory)

##### Architectural Patterns to Highlight

The project follows Clean Architecture principles with clear separation of concerns:
- API Layer (Controllers, DTOs)
- Domain Layer (Entities, Repository interfaces)
- Implementation Layer (Concrete implementations)
- Infrastructure Layer (Exception handling, configurations)

##### Component Relationships

**[External Clients] → [REST Controllers]**
- ↓
**[DTOs] ←----------→ [Use Cases/Interactors]**
- ↓
**[Service Layer] ←-→ [Gateway Interfaces]**
- ↓
**[Repository Implementation] → [Database]**

##### Specific Elements

a) Controllers:
- QuoteController (POST /v1/quote/process, GET /v1/quote/search)
- AspectRestController (for logging/monitoring)

b) Core Components:
- CreateQuoteInteractor
- QuoteServiceGateway
- FileService
- QuoteRepositoryGateway

c) Data Flow:
- File Input Processing
- Quote Entity Mapping
- Data Aggregation
- Response Formation

##### Technical Details to Highlight

- Java 17 environment
- Spring Boot framework
- H2 Database
- Maven build system

##### Infrastructure Layer (Configurations, Exception Handling)

Annotations for:
- File processing patterns
- Data transformation rules
- Validation points
- Error handling paths

Remember to:
- Keep components aligned with the package structure
- Clear dependency directions
- Notes for critical business rules

This will provide a clear visualization of how the quote processing system works, from file input through to response generation, while maintaining the clean architecture principles evident in the codebase.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External
        Client[Client Applications]
        FileUpload[File Upload Interface]:::file
    end

    subgraph API_Layer
        RC["REST Controllers"]:::controller
        AL["Aspect Logging"]:::controller
        click RC "https://github.com/pedrohenriqueveiga/desafio/blob/master/src/main/java/br/com/magalu/desafio/api/resource/QuoteController.java"
        click AL "https://github.com/pedrohenriqueveiga/desafio/blob/master/src/main/java/br/com/magalu/desafio/AspectRestController.java"
    end

    subgraph Business_Layer
        DTOs["DTOs Layer"]:::dto
        UC["Use Cases/Interactors"]:::usecase
        GI["Gateway Interfaces"]:::gateway
        click DTOs "https://github.com/pedrohenriqueveiga/desafio/tree/master/src/main/java/br/com/magalu/desafio/api/dto"
        click UC "https://github.com/pedrohenriqueveiga/desafio/blob/master/src/main/java/br/com/magalu/desafio/api/usecases/CreateQuoteInteractor.java"
        click GI "https://github.com/pedrohenriqueveiga/desafio/blob/master/src/main/java/br/com/magalu/desafio/api/gateways/QuoteGateway.java"
    end

    subgraph Service_Layer
        FS["File Service"]:::service
        QS["Quote Service Gateway"]:::service
        QM["Quote Entity Mapper"]:::service
        click FS "https://github.com/pedrohenriqueveiga/desafio/blob/master/src/main/java/br/com/magalu/desafio/implementation/service/FileService.java"
        click QS "https://github.com/pedrohenriqueveiga/desafio/blob/master/src/main/java/br/com/magalu/desafio/implementation/service/QuoteServiceGateway.java"
        click QM "https://github.com/pedrohenriqueveiga/desafio/blob/master/src/main/java/br/com/magalu/desafio/implementation/service/QuoteEntityMapper.java"
    end

    subgraph Data_Layer
        DE["Domain Entities"]:::entity
        RI["Repository Interface"]:::repo
        RImpl["Repository Implementation"]:::repo
        DB[(H2 Database)]:::db
        click DE "https://github.com/pedrohenriqueveiga/desafio/blob/master/src/main/java/br/com/magalu/desafio/domain/entity/QuoteEntity.java"
        click RI "https://github.com/pedrohenriqueveiga/desafio/blob/master/src/main/java/br/com/magalu/desafio/domain/repository/QuoteRepository.java"
        click RImpl "https://github.com/pedrohenriqueveiga/desafio/blob/master/src/main/java/br/com/magalu/desafio/implementation/persistence/QuoteRepositoryGateway.java"
    end

    subgraph Infrastructure
        EH["Exception Handling"]:::infra
        Config["Configuration"]:::infra
        FP["File Processing"]:::infra
        click EH "https://github.com/pedrohenriqueveiga/desafio/tree/master/src/main/java/br/com/magalu/desafio/infra/exceptions"
        click Config "https://github.com/pedrohenriqueveiga/desafio/blob/master/src/main/java/br/com/magalu/desafio/api/config/QuoteConfig.java"
        click FP "https://github.com/pedrohenriqueveiga/desafio/blob/master/src/main/resources/data_1.txt"
    end

    Client --> RC
    FileUpload --> FP
    FP --> FS
    RC --> AL
    RC --> DTOs
    DTOs --> UC
    UC --> GI
    GI --> QS
    QS --> QM
    QM --> DE
    QS --> RI
    RI --> RImpl
    RImpl --> DB
    EH -.-> RC
    Config -.-> QS

    classDef controller fill:#2196F3,stroke:#1565C0,color:white
    classDef dto fill:#4CAF50,stroke:#2E7D32,color:white
    classDef usecase fill:#4CAF50,stroke:#2E7D32,color:white
    classDef service fill:#4CAF50,stroke:#2E7D32,color:white
    classDef entity fill:#FFC107,stroke:#FFA000,color:black
    classDef repo fill:#FFC107,stroke:#FFA000,color:black
    classDef db fill:#FFC107,stroke:#FFA000,color:black
    classDef infra fill:#9E9E9E,stroke:#616161,color:white
    classDef file fill:#2196F3,stroke:#1565C0,color:white
    classDef gateway fill:#4CAF50,stroke:#2E7D32,color:white

    subgraph Legend
        L1[External Interfaces]:::file
        L2[Business Logic]:::usecase
        L3[Data Access]:::repo
        L4[Infrastructure]:::infra
    end
```
