/HexagonalArchitecture

Hexagonal Architecture Sample

Primary LanguageC#

Hexagonal Architecture

  • .Net Core 8
  • Entity Framework Core 8
  • Swagger
  • MediatR
  • API Versioning
  • Exception Handling
  • Fluent Validation
  • Mapster
  • Testcontainers
  • Open Telemetry
    • Prometheus
    • Jaeger
    • Grafana
    • Loki

Hexagonal Architecture, also known as Ports and Adapters, is an architectural pattern that aims to create loosely coupled application components, making the system more maintainable and adaptable to change. The core idea is to separate the business logic from external systems (like databases, user interfaces, or APIs) through "ports" (interfaces) and "adapters" (implementations). This allows the application to be easily tested and extended, as changes to external systems do not impact the core business logic.

You can review the following diagram for a better understanding;

hexagonal-arch

  • Ports are interfaces that define how the application interacts with the outside world.

    • Driving Ports: Handle incoming requests and interactions from external sources.
    • Driven Ports: Define how the application communicates with external systems and services.
  • Adapters are components that implement the ports' interfaces and handle the actual communication between the application and external systems or users. They convert data between the application's internal format and the format required by the external systems.

  • Domain refers to the core business logic and rules of the application. It is the central part of the architecture, isolated from external concerns and interfaces.

  • Use Case defines a specific interaction or functionality that the application provides, focusing on how the application fulfills user requirements or business processes.

  • Infrastructure refers to the external systems and technologies that support the application, such as databases, messaging systems, APIs are used to implement driven ports.

  • Driving Side represents the external components or systems that initiate interactions with the application, such as users, external services or other systems that drive the application's behavior through the driving ports.

  • Driven Side consists of the external systems or services that the application interacts with, such as databases or third-party APIs are accessed through driven ports.

Domain-Driven Design (DDD) focuses on modeling complex software systems by aligning the design with the business domain, using concepts like entities, value objects, aggregates and domain events to create a shared understanding between developers and domain experts.