# manu-lopez/ecommerce-test architecture

> Architecture diagram of the GitHub repository manu-lopez/ecommerce-test, 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/manu-lopez/ecommerce-test
- Repository: https://github.com/manu-lopez/ecommerce-test

## Overview

- Client / API Consumer: Represent the external client (or users) that will send HTTP GET requests.
- API Gateway / Controller: Highlight the PriceController (along with the global exception handler, RestControllerExceptionHandler) that interfaces with incoming REST requests.
- Application Layer: Include the PriceService interface and implementation (PriceServiceImpl), DTO classes (like PriceDTO) and exception handling (PriceNotFoundException). This layer encapsulates business logic and orchestrates data flow between the controller and domain.
- Domain Layer: Mark domain objects such as PriceDO and BrandDO along with repository interfaces (PriceRepository). These represent the core business data and rules.
- External Systems/Database: Represent the underlying database system used by Spring Boot/JPA, connected through the repository adapter.

##### Separation of concerns and layered architecture
→ Presentation Layer: Where the REST endpoints and exception handlers exist.
→ Application Layer: Containing business services, DTOs, and the orchestrating logic.
→ Domain Layer: With core business models and repository interfaces.
→ Infrastructure Layer: Handling persistence, external frameworks (Spring Data JPA), and mappings.
- This separation reflects a clean architecture where business rules are isolated from external systems.

##### Technology and framework details
- That Maven is used for build management.
- Usage of JPA for data persistence and mapping (infrastructure repository classes and entity mapping).
- Mention that integration and unit tests (found under src/test) exist to validate the application and infrastructure components.

- Components like mappers and exception handlers are also shown, even if they are auxiliary, since they play a key role in converting data formats and handling errors.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    client("Client/API Consumer"):::external

    %% Presentation Layer
    subgraph "Presentation Layer"
        pc("PriceController"):::presentation
        exHandler("RestControllerExceptionHandler"):::presentation
    end

    %% Application Layer
    subgraph "Application Layer"
        psI("PriceService"):::application
        psImpl("PriceServiceImpl"):::application
        priceDTO("PriceDTO"):::application
        priceNotFound("PriceNotFoundException"):::application
        priceAppMapper("PriceApplicationMapper"):::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        priceDO("PriceDO"):::domain
        brandDO("BrandDO"):::domain
        priceRepo("PriceRepository"):::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        prAdapter("PriceRepositoryAdapter"):::infrastructure
        jpaPriceRepo("JpaPriceRepository"):::infrastructure
        pMapper("PriceMapper"):::infrastructure
        bMapper("BrandMapper"):::infrastructure
        pEntity("PriceEntity"):::infrastructure
        bEntity("BrandEntity"):::infrastructure
        pResponse("PriceResponse"):::infrastructure
        eResponse("ErrorResponse"):::infrastructure
    end

    %% External Systems/Configuration
    subgraph "External/Configuration"
        appConfig("Application Configuration"):::external
        dataSql("Data Initialization Script"):::external
        db("Database"):::external
    end

    %% Connections
    client -->|"HTTP_request"| pc
    pc -->|"delegates"| psImpl
    psI -.->|"implements"| psImpl
    psImpl -->|"orchestrates"| priceAppMapper
    psImpl -->|"fetches"| priceRepo
    priceAppMapper -->|"maps_to"| priceDTO
    priceRepo -->|"accessed_by"| prAdapter
    prAdapter -->|"calls"| jpaPriceRepo
    jpaPriceRepo -->|"queries"| db
    prAdapter -->|"uses_mapper"| pMapper
    pMapper -->|"maps_to"| pEntity
    pMapper -->|"maps_to"| bEntity
    exHandler -->|"error_response"| client
    jpaPriceRepo -->|"configured_by"| appConfig
    jpaPriceRepo -->|"returns"| pResponse
    exHandler -->|"formats"| eResponse

    %% Click Events
    click pc "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/java/ecommerce_test/ecommerce/infrastructure/controller/PriceController.java"
    click exHandler "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/java/ecommerce_test/ecommerce/infrastructure/controller/RestControllerExceptionHandler.java"
    click psI "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/java/ecommerce_test/ecommerce/application/service/PriceService.java"
    click psImpl "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/java/ecommerce_test/ecommerce/application/service/PriceServiceImpl.java"
    click priceDTO "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/java/ecommerce_test/ecommerce/application/dto/PriceDTO.java"
    click priceNotFound "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/java/ecommerce_test/ecommerce/application/exception/PriceNotFoundException.java"
    click priceAppMapper "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/java/ecommerce_test/ecommerce/application/mapper/PriceApplicationMapper.java"
    click priceDO "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/java/ecommerce_test/ecommerce/domain/PriceDO.java"
    click brandDO "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/java/ecommerce_test/ecommerce/domain/BrandDO.java"
    click priceRepo "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/java/ecommerce_test/ecommerce/domain/repository/PriceRepository.java"
    click prAdapter "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/java/ecommerce_test/ecommerce/infrastructure/repository/PriceRepositoryAdapter.java"
    click jpaPriceRepo "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/java/ecommerce_test/ecommerce/infrastructure/repository/JpaPriceRepository.java"
    click pMapper "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/java/ecommerce_test/ecommerce/infrastructure/mapper/PriceMapper.java"
    click bMapper "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/java/ecommerce_test/ecommerce/infrastructure/mapper/BrandMapper.java"
    click pEntity "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/java/ecommerce_test/ecommerce/infrastructure/entity/PriceEntity.java"
    click bEntity "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/java/ecommerce_test/ecommerce/infrastructure/entity/BrandEntity.java"
    click pResponse "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/java/ecommerce_test/ecommerce/infrastructure/response/PriceResponse.java"
    click eResponse "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/java/ecommerce_test/ecommerce/infrastructure/response/ErrorResponse.java"
    click appConfig "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/resources/application.properties"
    click dataSql "https://github.com/manu-lopez/ecommerce-test/blob/develop/src/main/resources/data.sql"

    %% Styles
    classDef external fill:#FAD7A0,stroke:#C0392B,stroke-width:2px;
    classDef presentation fill:#D6EAF8,stroke:#2874A6,stroke-width:2px;
    classDef application fill:#D5F5E3,stroke:#28B463,stroke-width:2px;
    classDef domain fill:#FCF3CF,stroke:#F1C40F,stroke-width:2px;
    classDef infrastructure fill:#F2D7D5,stroke:#922B21,stroke-width:2px;
```
