liveBook · Manning

Downward dependency rule

As explained in Grokking Software Architecture

The Downward Dependency Rule requires dependencies between architectural layers to point only toward lower-level layers and never upward.

Think of layers as a chain of command: higher layers give work to lower layers, not the other way around. The downward dependency rule keeps source-code dependencies pointing down, helping prevent tangled, hard-to-maintain code. section 4.3

A common stack runs from Presentation to Application, Domain, and Infrastructure. In the strict form of the rule, each layer depends only on the adjacent layer below it; jumping over a layer is also a violation. section 4.11 section 4.3.2

Figure 4.4 The lower layers only accept tasks from the upper layers; they don’t assign them. Data can flow both ways, though.

Commands move down the stack, but result data can return upward without creating an upward source-code dependency. section 4.3 section 4.6.1

Two tempting shortcuts

A repository that directly updates a UI status label creates an upward dependency. Instead, it can return a result to the application service, which decides how to notify the presentation layer. A product controller that calls the database directly skips layers: it might bypass product filters or permission checks, and database changes can make the UI brittle. section 4.3.2

Shared needs such as logging, security, and caching cut across layers. Depending on abstractions, such as an ILogger interface, and using dependency inversion helps make these services available without tangling the layers. section 4.11 section 4.6.1

For a larger compiled application, separate projects can enforce the boundary: let Application reference Domain, but omit the reverse reference. An attempt to use a controller from Domain then fails to compile. The tradeoff is that a traditional downward stack still points core logic toward infrastructure; other architectural approaches explore reversing that relationship. section 4.4.2 section 4.9.4

How Grokking Software Architecture covers it

How deep it goes
Defines strict adjacent-layer dependencies, distinguishes commands from returned data, and demonstrates violations and project-reference enforcement.
Examples
Uses a repository updating a UI label and a product controller calling a database to illustrate violations.
What you can do after
Apply it by checking dependency directions, spotting layer-skipping shortcuts, and routing results through the application service.
How it connects
Connects layered architecture with separation of concerns, cross-cutting concerns, and dependency inversion.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.