Hexagonal Architecture

Hexagonal Architecture is an architectural style that emphasizes separation of concerns and modularity in software applications. It is also known as Ports and Adapters.

Hexagonal Architecture

Hexagonal Architecture

Hexagonal Architecture is based on the idea of dividing the application into different segments, each with its own responsibilities and dependencies. The core of the application is the domain, which contains abstractions in the form of service/repository interfaces, the business logic and domain objects. The domain is surrounded by one or more adapters, concretions of the interfaces, which handle user interactions, data access, and any other external dependencies. The adapters integrate with the domain through ports, which are abstract interfaces that define the services provided by the domain. The ports are thus implemented by the adapters, which provide the necessary translations and mappings to the external systems and frameworks.

The architecture of interfaces/ports and adapters is following the dependency inversion principle (DIP). Adapters are allowed to depend on the domain, but not the other way around. Adapters are also not allowed to depend on each other. There can be multiple adapters for a single port. This is useful for unit testing the domain, without having to mock external dependencies. You can just pick another adapter with, for example, in-memory storage. Multiple adapters for a single port follow the Liskov substitution principe (LSP). In the final application, the selection of adapters can be made via dependency injection, typically by utilizing environment variables.

Dependencies

Dependencies

By using Hexagonal Architecture, the Fractal Framework promotes modularity, testability, and flexibility in software applications. It allows developers to separate concerns and dependencies, making it easier to modify or replace individual components without affecting the rest of the system. It also provides a clear separation between the business logic and the infrastructure, making it easier to test and maintain the application over time.

Overall, Hexagonal Architecture is a powerful tool for building robust and maintainable software applications, and the Fractal Framework makes it easy to implement this architecture in practice.