What does the "dependency rule" mean?
The Dependency Rule is the core principle of Clean Architecture that defines the direction of dependencies between the system's layers.
The essence of the rule
All dependencies point inward, toward the center of the architecture.
Inner layers (business logic) must know nothing about outer ones (infrastructure, UI, frameworks).
What it looks like
javascript
[ Frameworks & UI ]
↓
[ Interface Adapters ]
↓
[ Use Cases ]
↓
[ Entities ]- Code in an outer layer can call into an inner one.
- An inner layer must not depend on an outer one, only on abstractions (interfaces) defined within itself.
Example
- Allowed: a controller calls
CreateOrderUseCase. - Not allowed:
CreateOrderUseCaseusesDjango ORMorFlaskdirectly.
Instead, the use case calls the OrderRepository abstraction, and an adapter (an outer layer) implements that interface using a specific technology.
Why it matters
- Isolate business logic from frameworks.
- Make the system independent of external changes.
- Make testing and technology replacement easier.
Summary:
The Dependency Rule states that dependencies always point from details to abstractions, and from outer to inner, so the system's core stays stable, clean, and independent.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.