PrepZone Logo
PrepZone

Layered Architecture in Practice

Controller, service, domain, repository — who calls whom.

Why this matters

  • Layer responsibilities — detailed pointwise breakdown in the section below.
  • Dependency rule — detailed pointwise breakdown in the section below.
  • CampusOS booking service — detailed pointwise breakdown in the section below.
  • Thin controllers — detailed pointwise breakdown in the section below.
  • Production Java structure interviewers expect in backend LLD.
Dependency direction
Controller / FacadeHTTP or API entry
Serviceuse cases, orchestration
Domainentities, rules, invariants
Repositorypersistence port
Dependencies point inward — domain never imports infrastructure.

Overview

Controller, service, domain, repository — who calls whom. Study each section below in order — every list is interview-ready reference material.

Layer responsibilities

Points to cover

  • Definition — what Layer responsibilities means in one clear sentence
  • When to use — the force or smell that triggers this concept
  • CampusOS example — where this appears in parking, booking, or library modules
  • How to explain — pointwise bullets you can say aloud in an interview
  • Common mistake — what weak candidates do instead
  • Refactor move — one concrete change that improves the design

Dependency rule

Points to cover

  • Definition — what Dependency rule means in one clear sentence
  • When to use — the force or smell that triggers this concept
  • CampusOS example — where this appears in parking, booking, or library modules
  • How to explain — pointwise bullets you can say aloud in an interview
  • Common mistake — what weak candidates do instead
  • Refactor move — one concrete change that improves the design

CampusOS booking service

Points to cover

  • Definition — what CampusOS booking service means in one clear sentence
  • When to use — the force or smell that triggers this concept
  • CampusOS example — where this appears in parking, booking, or library modules
  • How to explain — pointwise bullets you can say aloud in an interview
  • Common mistake — what weak candidates do instead
  • Refactor move — one concrete change that improves the design

Thin controllers

Points to cover

  • Definition — what Thin controllers means in one clear sentence
  • When to use — the force or smell that triggers this concept
  • CampusOS example — where this appears in parking, booking, or library modules
  • How to explain — pointwise bullets you can say aloud in an interview
  • Common mistake — what weak candidates do instead
  • Refactor move — one concrete change that improves the design
Java
// CampusOS — apply "Layer responsibilities" on paper first, then in code
public final class LayeredArchitectureExample {
    // 1. Name entities from the problem statement
    // 2. Draw relationships before writing methods
    // 3. Introduce patterns only when a force appears
}

Quick recall

Everything you need if you only revisit this box.

  1. Layer responsibilities — review this slice before mock interviews.
  2. Dependency rule — review this slice before mock interviews.
  3. CampusOS booking service — review this slice before mock interviews.
  4. Thin controllers — review this slice before mock interviews.

Test yourself

Answer these before moving on — recall is what makes it stick.