Vertical Slices of Clean Architecture
As your project grows in size and complexity the natural need should be to decouple parts of the application.
- Why decouple?
- What are the different layers in clean architecture?
- How do we define the components within each layer?
- How do we develop and test each layer?
- How do we develop vertical slices?
Why decouple?
Decouple: separate, disengage or dissociate.
When components are strongly decoupled, the interference between components and the teams working on them is avoided.
What are the different layers we can use to decouple?
It’s up to you and your team to decide what these layers should be. When this decision is made you need to look at development, testing, and deployment. We decide on these layers based on what will(not might) change over time. This might be database technologies, libraries, user interfaces, API endpoints, external services, etc.
So a good starting point would be the following system layers:
- Data(API Services, DB, etc),
- Domain (Business rules), and
- Presentation(UI, API Endpoints, CLI commands, etc).
How do we define the components within each layer?
As we work on the project we would like the features to be developed and deployed in isolation or vertical slices
Use cases are narrow vertical slices that cut through the horizontal layers of the system: Clean Architecture by Robert C. Martin
These vertical slices touch many horizontal layers, UI, Use Case, Repository, DataSource.
How do we develop and test each layer?
Decoupling the horizontal layers with interfaces prevents interference between vertical slices and most importantly helps separate development tasks. The UI (Presentation) team cannot affect the team that focuses on the Domain business rules. The Database team (Data) does not need to know about the UI or Business Logic.
Software testing is an integral part of the software development process. Every software application comprises several components. To make software work seamlessly, it is important that every component works in tandem with one another. In other words, there should be effective communication between each of these components. The connection between the different components is termed the interface and the purpose of interface testing is to ensure that each component of the software application works in tandem and there is no gap in communication whatsoever.
Interface testing is a form of software testing that verifies the functionality of the software application interface.
How can we develop vertical slices?
Horizontal layers or system layers and vertical slices (dashed lines) are shown here for a couple of use cases or features. Each horizontal layer is separated decoupled and enforced by interfaces.
We also need to indicate how different teams(wearing different hats or actual teams), can work on and deploy decoupled parts of the system independently.
In this way, the whole team can focus on completing one vertical slice of the application without the fear of interfering with other teams.
In conclusion:
So long as the layers and use cases are decoupled, the architecture of the system will support the organization of the teams, irrespective of whether they are organized as feature teams, component teams, layer teams, or some other variation to achieve the goal of development and deployment in isolation.