Dependency Rule in Clean Architecture
Source code dependencies must always point inward - toward the domain and use cases, never outward.
This means that inner layers (like your domain entities and use cases) should never depend on outer layers (like the UI, frameworks, or databases).
A dependency exists whenever your code:
- imports a class
- calls a method
- references a concrete implementation
- requires a framework to compile
So if your domain imports:
- Spring annotations ❌
- ORM entities ❌
- REST controllers ❌
You’ve already broken the rule.
The outer layers can depend on inner ones - but not the other way around.
Why? Because the core business logic should not care how it’s presented or where data is stored.
------
Join 5,400+ engineers: journal.optivem.com
#cleanarchitecture #softwaredevelopment #optivem