# wendermata/salescodingtest architecture

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

- Interactive diagram: https://gitdiagram.com/wendermata/salescodingtest
- Repository: https://github.com/wendermata/salescodingtest

## Overview

##### Main Layers and Components
- Presentation Layer (Web API):
- Represented by the "src/WebApi" folder.
- Contains controllers (e.g., ProductController and SalesController) which serve as the entry points for client requests.
- It sets up routes, calls application use cases, and returns responses via RESTful endpoints.
- Application Layer:
- Located in "src/Application".
- Contains the use cases, input/output models, mapping, validation, and helper utilities.
- Divided into use case groups (e.g., Product – Create, List, Remove, Update; Sale – Create, List, Cancel).
- Implements boundaries to external services such as the ViaCEP service for address lookup.
- Domain Layer:
- Present in "src/Domain".
- Encodes the Entities, Aggregates (like SaleAggregate), and repository interfaces that embody business rules.
- Reflects core business logic independent of any technology.
- Infrastructure Layer:
- Found in "src/Infra.Mongo".
- Implements data persistence using MongoDB.
- Provides concrete implementations of the repository interfaces declared in the Domain.
- Contains configuration settings and connection management related to MongoDB.
- Testing:
- The "tests" directory contains unit tests for the Application logic, Domain entities, and Web API controllers, ensuring functionality and separation of concerns.

##### Relationships and Data Flow
- Client calls are received by the WebApi controllers.
- Controllers invoke corresponding use cases present in the Application layer.
- Use cases perform business logic potentially calling domain services or validating business entities.
- When data persistence is needed, the Application layer abstracts repository calls; the Domain defines the interface while Infra.Mongo provides the concrete implementation.
- The ViaCEP boundary within the Application layer is an external service integration which fetches address data (or related details) to support the use cases.
- All layers strictly follow dependency inversion: The higher-level modules (Application, Domain) are decoupled from lower-level details (Infra.Mongo).

##### Architectural Patterns and Technologies
- Clean Architecture Division: Separate boundaries between WebApi (UI), Application, Domain, and Infrastructure.
- DDD: Use of Aggregates, Entities, and repositories.
- Mediator Pattern: Likely used in orchestrating use case handling (even if not explicitly shown, it’s mentioned in the README).
- Repository Pattern: Abstracts data access to MongoDB.
- Docker is used for containerization (Dockerfile, docker-compose.yml).
- The project utilizes specific libraries such as the ViaCEP service client, which is integrated under the Application layer.

##### Final Details
- Use clear labels for each component (e.g., "ProductController", "CreateProductUseCase", "Product Entity", "ProductRepository").
- Ovals for domain entities, and
- Optionally, mark the Docker container boundary to indicate the deployment environment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client Request"]:::client

    subgraph "Docker Container"
        subgraph "Presentation Layer (Web API)"
            PC["ProductController"]:::controller
            SC["SalesController"]:::controller
        end
        subgraph "Application Layer"
            PUC["Product Use Cases"]:::usecase
            SUC["Sale Use Cases"]:::usecase
            VCEP["ViaCEP Service"]:::service
            CU["Common Utilities"]:::helper
        end
        subgraph "Domain Layer"
            DL["Domain Entities & Repositories"]:::domain
        end
        subgraph "Infrastructure Layer"
            IM["MongoDB Repository"]:::database
        end
    end

    T["Tests"]:::test

    Client --> PC
    Client --> SC
    PC -->|"calls"| PUC
    SC -->|"calls"| SUC
    PUC -->|"executes"| DL
    SUC -->|"executes"| DL
    DL -->|"persists"| IM
    PUC -->|"integrates"| VCEP
    PUC -->|"utilizes"| CU
    SUC -->|"utilizes"| CU

    click PC "https://github.com/wendermata/salescodingtest/tree/main/src/WebApi/Controllers"
    click SC "https://github.com/wendermata/salescodingtest/tree/main/src/WebApi/Controllers"
    click PUC "https://github.com/wendermata/salescodingtest/tree/main/src/Application/UseCases/Product"
    click SUC "https://github.com/wendermata/salescodingtest/tree/main/src/Application/UseCases/Sale"
    click VCEP "https://github.com/wendermata/salescodingtest/tree/main/src/Application/Boundaries/Services/ViaCEP"
    click CU "https://github.com/wendermata/salescodingtest/tree/main/src/Application/Common"
    click DL "https://github.com/wendermata/salescodingtest/tree/main/src/Domain"
    click IM "https://github.com/wendermata/salescodingtest/blob/main/src/Infra.Mongo"
    click T "https://github.com/wendermata/salescodingtest/tree/main/tests"

    classDef client fill:#fefbd8,stroke:#333,stroke-width:2px;
    classDef controller fill:#ffcccb,stroke:#333,stroke-width:2px;
    classDef usecase fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef service fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef helper fill:#d3d3d3,stroke:#333,stroke-width:2px;
    classDef domain fill:#f0e68c,stroke:#333,stroke-width:2px;
    classDef database fill:#dda0dd,stroke:#333,stroke-width:2px;
    classDef test fill:#ffdab9,stroke:#333,stroke-width:2px;
```
