liveBook · Manning

Layer skipping

As explained in Grokking Software Architecture

Layer skipping is a dependency shortcut in which a component bypasses one or more intervening architectural layers.

Layer skipping happens when a component bypasses an intervening layer—for example, when a presentation component calls the database directly instead of going through the service layer. section 4.3.2

The tempting shortcut

A product controller that queries a SQL repository directly may skip service rules such as filtering discontinued products or checking permissions. It also ties the UI to the database choice, making a later change harder. section 4.3.2

Listing 4.3 Violating Downward Dependency (Skipping Layers)
// Presentation Layer (Controller)
public class ProductController : Controller
{
    private SqlProductRepository _repo = new SqlProductRepository(); #A
 
    public IActionResult GetAll()
    {
        var products = _repo.GetProductsSql(); #B
        return View(products);
    }
}

See a controller querying a SQL repository directly, bypassing the intervening layer. section 4.3.2

Keep dependencies flowing downward through adjacent layers. The application layer can coordinate the work and return data upward; it need not make infrastructure call the UI. section 4.3.2

How Grokking Software Architecture covers it

How deep it goes
Traces a direct database call from the UI to lost logic, security risks, and brittleness, without giving a refactoring procedure.
Examples
Uses a product controller that queries a SQL repository directly and notes filtering, permissions, and database-change risks.
What you can do after
Evaluate whether a component bypasses intermediate layers and recognize the resulting logic, security, and maintenance risks.
How it connects
Connects layer skipping to layered architecture, downward dependency, and the application and service layers.

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.