Junior — Middle
Can you explain the concept of hexagonal architecture and its main principles?
sobes.tech AI
Answer from AI
Hexagonal architecture (or Ports and Adapters) is an approach to application design that separates business logic from external dependencies.
Main principles:
- The core of the architecture is the business logic (the core), independent of external systems.
- Around the core, there are ports — interfaces through which the core interacts with the external world.
- Adapters implement these ports and provide connections to databases, UI, external services.
This allows easy replacement of external components without changing the business logic and simplifies testing.
Example:
- The core defines an interface for data storage (port).
- An adapter implements this interface, for example, through a database.
- When changing the database, only the adapter changes, the core remains unchanged.