SteelReed

Search

Search posts, questions…

OOP & DesignQuestion 35 / 42

Junior

What is layered architecture? Package by layer or by feature?

Short answer

Layered architecture splits the app by technical responsibility: controller → service → repository, and each layer calls only the one right below. At the controller boundary, data in and out is a DTO, not a JPA entity.

Request DTOResponse DTOHTTP requestControllerService: business logicRepositoryDatabaseHTTP response

3 points to say:

  1. Controller → service → repository; layers are closed, no skipping (a controller never calls a repository directly).
  2. At the controller boundary use separate DTOs for request and response, never return JPA entities.
  3. Turn off open-in-view; prefer package-by-feature over package-by-layer.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.