# jonathanm2ndoza/hexagonal-architecture-ddd architecture

> Architecture diagram of the GitHub repository jonathanm2ndoza/hexagonal-architecture-ddd, 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/jonathanm2ndoza/hexagonal-architecture-ddd
- Repository: https://github.com/jonathanm2ndoza/hexagonal-architecture-ddd

## Overview

##### Main Components
- Microservices: Represent each service (Customer, Order, Product) as separate containers or modules.
- Layers within each Microservice:
- Application Layer: Contains the REST and SOAP adapters (e.g., controllers, request/response mappings) in packages such as “application/rest” and “application/soap”. This layer is responsible for receiving external inputs.
- Domain Layer: Includes domain models, use-case interfaces (ports), and business logic implementations (services). Look at packages under “domain” or “domain/model”, “domain/ports”, and “domain/services”. This is the central, technology-agnostic part of each microservice.
- Infrastructure Layer: Contains the adapters that implement external interactions like databases (MongoDB and PostgreSQL), message brokers, and security aspects. Observe the “infrastructure/databases”, “infrastructure/messagebroker”, and “infrastructure/security” packages.

##### Component Relationships and Data Flow
- Each microservice’s Application layer receives requests, which are then forwarded to the Domain layer through inbound ports.
- The Domain layer, which encapsulates the core business logic, interacts with outbound ports that represent dependencies like data persistence or messaging.
- The Infrastructure layer implements these outbound ports as adapters. For example, Customer uses MongoDB adapters (such as CreateCustomerAdapter, DeleteCustomerAdapter) and PostgreSQL adapters can be seen in the Order context.

##### Architectural Patterns and Design Principles
- Hexagonal (Ports and Adapters) Architecture: Emphasize that the Domain is at the center, isolated by the ports (interfaces) through which the Application and Infrastructure layers interact.
- Domain-Driven Design (DDD): Each service’s domain layer models its business concepts explicitly. The bounded contexts are clear (Customer, Order, Product).
- Use cases are implemented as services in the Domain layer and exposed via REST/SOAP endpoints in the Application layer.

##### Relevant Technologies and Frameworks
- Spring Boot: Indicate that each microservice is built on Spring Boot as the backbone of application startup and dependency management.
- Databases: Note the usage of MongoDB (commonly for document storage in Customer and Product) and PostgreSQL (used in Order and in some Product infrastructures).
- Message Broker: Show the adapters for messagebroker integration, which help in asynchronous communication between services.
- Additional libraries: Components for security (e.g., PasswordEncodeAdapter) and cross-cutting concerns (e.g., custom exception handlers) should be included.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Customer Microservice
    subgraph "Customer Microservice"
        Cust_App("Application Layer: REST & SOAP"):::appStyle
        Cust_Dom("Domain Layer: Business Logic & Use Cases"):::domainStyle
        Cust_Infra("Infrastructure Layer: MongoDB Adapters"):::infraStyle
        Cust_App -->|"calls"| Cust_Dom
        Cust_Dom -->|"invokes"| Cust_Infra
    end

    %% Order Microservice
    subgraph "Order Microservice"
        Order_App("Application Layer: REST Controllers"):::appStyle
        Order_Dom("Domain Layer: Order Use Cases"):::domainStyle
        Order_Infra("Infrastructure Layer: PostgreSQL & Message Broker"):::infraStyle
        Order_Config("Configuration"):::infraStyle
        Order_App -->|"calls"| Order_Dom
        Order_Dom -->|"invokes"| Order_Infra
        Order_Infra -->|"uses"| Order_Config
    end

    %% Product Microservice
    subgraph "Product Microservice"
        Prod_App("Application Layer"):::appStyle
        Prod_Dom("Domain Layer"):::domainStyle
        Prod_Infra("Infrastructure Layer: MongoDB/PostgreSQL Adapters"):::infraStyle
        Prod_App -->|"calls"| Prod_Dom
        Prod_Dom -->|"invokes"| Prod_Infra
    end

    %% External Systems
    MongoDB(("MongoDB")):::externalStyle
    PostgreSQL(("PostgreSQL")):::externalStyle
    MessageBroker(("Message Broker")):::externalStyle

    %% Infrastructure to External Systems Connections
    Cust_Infra -->|"reads/writes"| MongoDB
    Order_Infra -->|"reads/writes"| PostgreSQL
    Order_Infra -->|"publishes"| MessageBroker
    Prod_Infra -->|"reads/writes"| MongoDB
    Prod_Infra -->|"reads/writes"| PostgreSQL

    %% Inter-Microservice Interaction
    Order_Dom -->|"fetchesCustomerData"| Cust_Dom

    %% Click Events for Component Mapping
    click Cust_App "https://github.com/jonathanm2ndoza/hexagonal-architecture-ddd/tree/master/Customer/src/main/java/com/jmendoza/swa/hexagonal/customer/application"
    click Cust_Dom "https://github.com/jonathanm2ndoza/hexagonal-architecture-ddd/tree/master/Customer/src/main/java/com/jmendoza/swa/hexagonal/customer/domain"
    click Cust_Infra "https://github.com/jonathanm2ndoza/hexagonal-architecture-ddd/tree/master/Customer/src/main/java/com/jmendoza/swa/hexagonal/customer/infrastructure"
    click Order_App "https://github.com/jonathanm2ndoza/hexagonal-architecture-ddd/tree/master/Order/application/src/main/java/com/jmendoza/swa/hexagonal/application/rest"
    click Order_Dom "https://github.com/jonathanm2ndoza/hexagonal-architecture-ddd/tree/master/Order/domain/src/main/java/com/jmendoza/swa/hexagonal/domain"
    click Order_Infra "https://github.com/jonathanm2ndoza/hexagonal-architecture-ddd/tree/master/Order/infrastructure/src/main/java/com/jmendoza/swa/hexagonal/infrastracture"
    click Order_Config "https://github.com/jonathanm2ndoza/hexagonal-architecture-ddd/tree/master/Order/configuration/src/main/java/com/jmendoza/swa/hexagonal/configuration"
    click Prod_App "https://github.com/jonathanm2ndoza/hexagonal-architecture-ddd/tree/master/Product/src/main/java/com/jmendoza/swa/hexagonal/product/application"
    click Prod_Dom "https://github.com/jonathanm2ndoza/hexagonal-architecture-ddd/tree/master/Product/src/main/java/com/jmendoza/swa/hexagonal/product/domain"
    click Prod_Infra "https://github.com/jonathanm2ndoza/hexagonal-architecture-ddd/tree/master/Product/src/main/java/com/jmendoza/swa/hexagonal/product/infrastructure"

    %% Styles
    classDef appStyle fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef domainStyle fill:#A9DFBF,stroke:#145A32,stroke-width:2px;
    classDef infraStyle fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef externalStyle fill:#D6EAF8,stroke:#2874A6,stroke-width:2px;
```
