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

Layer Responsibilities and Boundaries

Defining what each layer should and shouldn't do, and how to enforce boundaries between them.

Layer Responsibilities and Boundaries

What you'll learn: How to define clear responsibilities for each architectural layer and enforce the boundaries between them.

In a layered architecture, each layer should have a well-defined job and know nothing about layers above it—only about the layer directly below. Think of it like a hotel: the kitchen doesn't need to know who's dining upstairs; it just receives orders from the waitstaff and prepares food. The waitstaff doesn't care how the food is cooked; they just deliver what comes out.

Defining Layer Responsibilities

Each layer should own a specific concern:

  • Presentation Layer: Handle user interaction, display logic, input validation for format (not business rules)
  • Business/Application Layer: Execute business rules, orchestrate workflows, enforce domain logic
  • Data Layer: Persist and retrieve data, manage transactions, handle database-specific concerns

A layer should never skip levels. Your presentation shouldn't directly call the database—that violates the boundary and creates tight coupling.

Enforcing Boundaries

Boundaries prevent chaos. Without them, code becomes a tangled mess where UI logic sneaks into database queries, or business rules hide in view templates.

Enforcement techniques:

  • Dependency rules: Layer N can only depend on Layer N-1
  • Interface contracts: Define explicit APIs between layers
  • Package/module organization: Physical separation makes violations obvious
  • Code reviews: Catch boundary violations before they merge
  • Architecture tests: Automated checks that fail if a layer imports from the wrong place

When a layer needs information from above, use dependency inversion—pass it down as a parameter or callback rather than reaching upward.

Key Takeaway: Clear layer responsibilities and enforced boundaries prevent architectural erosion, making your system easier to understand, test, and modify. Each layer should do one job well and respect the layers around it.