Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EliFuzz/8ab693db36ff33ead1445a43c3f0ef7e to your computer and use it in GitHub Desktop.
Save EliFuzz/8ab693db36ff33ead1445a43c3f0ef7e to your computer and use it in GitHub Desktop.
Comparison Table: Hexagonal, Clean, Onion, and Traditional Layered Architectures
Aspect Traditional Layered Architecture Clean Architecture Onion Architecture Hexagonal Architecture
Definition Divides the application into layers based on functionality, with each layer having dependencies on the layer below it Emphasizes separation of concerns and the use of SOLID principles for building scalable and maintainable software Similar to Hexagonal Architecture, it aims to decouple the application core from the infrastructure layers. However, it adds the concept of concentric layers Also known as Ports and Adapters Architecture, it focuses on separating the application core from the surrounding infrastructure layers
Dependency Flow Dependencies flow from higher-level layers to lower-level layers, with each layer depending on the layer directly below it The dependency flow is unidirectional, with higher-level layers depending on lower-level layers. Dependencies are not allowed to flow in the opposite direction Similar to Hexagonal Architecture, the dependency flow is inward, with the core defining interfaces and the adapters implementing them The flow of dependencies is inward, with the application core defining interfaces (ports) that are implemented by the adapters. The adapters depend on the interfaces defined by the core
Dependency Inversion Principle (DIP) Support May not explicitly enforce the DIP, leading to potentially tightly coupled dependencies between layers Emphasizes the DIP by using interfaces and dependency injection to invert dependencies, enabling higher-level layers to depend on abstractions defined by lower-level layers Supports the DIP by using interfaces to define dependencies between layers, allowing for the inversion of dependencies and loose coupling Strongly aligns with the DIP by relying on interfaces (ports) that are implemented by adapters, allowing the core to depend on abstractions
Deployment and Infrastructure May have tight coupling with the infrastructure, making it more difficult to adapt or switch deployment environments without impacting the entire system Is agnostic to the deployment and infrastructure details, allowing for easy adaptation to different environments Separates infrastructure concerns into outer layers, making it easier to adapt or switch to different deployment environments without affecting the core Abstracts away the infrastructure, making it easier to switch or adapt to different deployment environments without affecting the core
Flexibility and Adaptability Can be less flexible and adaptable due to tight coupling, making it harder to change or replace components without impacting other parts of the system Promotes flexibility and adaptability by enforcing separation of concerns, allowing for independent modification of layers without affecting others Provides flexibility and adaptability by separating concerns into layers, making it easier to change or replace components without affecting other layers Offers high flexibility and adaptability by isolating the core from external dependencies, making it easier to switch or upgrade components
Layering Philosophy Layers are organized vertically based on functionality, with each layer providing services to the layer above it Layers are organized based on business logic and responsibilities. Each layer has a clear purpose and can depend only on the layer below it Concentric layers approach: The innermost layer represents the core business logic and the outer layers handle infrastructure and frameworks Ports (interfaces) and Adapters (implementations) are the core elements. The application core is isolated from the external dependencies
Scalability and Maintainability Can be scalable and maintainable, but tight coupling between layers can make it more challenging to modify or add new features without affecting other parts of the system Promotes scalability and maintainability by enforcing separation of concerns and dependency inversion, making it easier to modify and add new features without impacting other parts of the system Aims to improve scalability and maintainability through its layered approach, allowing for easier modification and replacement of components without affecting other layers Enables scalability and maintainability by decoupling the application core from the infrastructure, allowing for easier modification and replacement of external dependencies
Testing and Isolation Can make testing more challenging due to tight coupling between layers, requiring more complex integration testing Advocates for testability by employing dependency inversion and interfaces, enabling mocking and unit testing of individual layers Emphasizes testability through the use of interfaces and dependency injection, allowing for isolated testing of the core business logic Promotes easier testing and isolation of the application core by using ports and adapters, allowing the core to be tested independently of the infrastructure
Use cases - project requires a simple and straightforward architecture
- project involves a small number of external integrations
- project requires a high degree of scalability
- project requires a high degree of maintainability and understandability
- project involves a large number of business rules and use cases
- project requires a high degree of testability
- project requires a high degree of flexibility and maintainability
- project involves a large number of complex business rules and domain logic
- project requires a high degree of testability
- project requires a high degree of testability and maintainability
- project involves a large number of external integrations, such as databases, file systems, or web services
- project requires a high degree of flexibility, such as the ability to switch from one technology to another
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment