You can see in the diagram that all dependencies in the standard three-tier architecture go to the database. That means that abstraction and dependency don’t match. Logically, the business layer should be the center of the app, but it isn’t, as dependencies go towards the database.

The business layer knows about the database and it shouldn’t. It should be the other way around. Whereas in clean architecture, dependencies go to the business (inner) layer and abstraction also rises towards the business layer, so they match nicely.

This is important because abstraction is the theory and dependencies are the practice. Abstraction is the logical layout of the app, and dependencies are how it is actually composed together. In clean architecture these two match up, while in the standard three-tier architecture they don’t; and this can quickly lead to all kinds of logical inconsistencies and mess if you aren’t careful.

III. Communication between layers

Now that we have divided our app into the modules, nicely separated everything, put business logic in the center of our app and implementation details in the outskirts, everything looks great. But you’ve probably quickly run into an interesting problem.

If your UI is an implementation detail, the internet is an implementation detail, and business logic is in between, how the heck can we fetch the data from the internet, pass it through the business logic and then send it to the screen?

Business logic is in the middle and should mediate between the internet and the UI, but it doesn’t even know that those two guys exist. This is a question of communication and data flow.

We would like the data to be able to flow from the outer layers to the inner ones and vice versa, but the dependency rule doesn’t allow that. Let’s strip that down to the simplest example.

We have only two layers, the green one and the red one. The green one is outer and knows about the red one, and the red one is inner and knows only about itself. We want the data to flow from the green one to the red one and back to the green one. The solution has already been hinted at before and is shown in the following diagram: