Course contentsShow
← Software Engineering
Lesson 1273 of 1,93338. Layered and Modular ArchitectureFree lesson

The Dependency Rule

Source code dependencies must point inward toward higher-level policies, never outward toward details.

The Dependency Rule

You'll learn: The one cardinal rule that keeps Clean Architecture clean: dependencies must always point inward toward business logic, never outward toward implementation details.

The Core Principle

The Dependency Rule states that source code dependencies must point inward in concentric circles of your architecture. Inner circles contain high-level business policies and domain logic. Outer circles contain low-level details like databases, frameworks, and UI. Code in inner circles cannot know anything about outer circles—no references to names, classes, functions, or any entity from outer layers.

Why This Matters

Think of your architecture like a castle with walls. The innermost keep holds your most valuable assets: your business rules. Each layer of walls protects it from the outside world. The Dependency Rule ensures that arrows of dependency—imports, references, function calls—always point toward the keep, never away from it.

This means:

  • Your business logic never imports from a database library
  • Your domain entities never reference a web framework
  • Your use cases never depend on UI components

Instead, outer layers depend on inner layers through abstractions (interfaces/ports). When the database needs to call business logic, we use dependency inversion: the inner layer defines an interface, and the outer layer implements it.

The Benefit

This rule gives you flexibility. You can swap databases, change frameworks, or redesign the UI without touching your core business logic. Your architecture becomes testable (inner layers test without databases) and maintainable (changes to details don't cascade inward).

Key Takeaway: The Dependency Rule ensures stability by making dependencies flow inward—high-level policy stays independent of low-level details, protecting your business logic from the volatility of implementation choices.