Model reference
Reference Figure: The Complete MVC Application
All four layers in one view: the web layer, the controller layer, the service layer and the data layer, with the direction of dependency between them.
A generated application is a stack of four layers. Each layer has one job and depends only on the layer below it. The clear direction of dependency is what makes the application testable and easy to extend.
The layers
- View and UI layer. JSP pages and tags that render data and collect input.
- Controller layer. Request handling, binding, validation and view selection.
- Service layer. Transactions, business rules and calls to repositories.
- Data layer. Entity types, repositories and named queries.
Why the stack matters
Because the layers only point downward, a change in the data layer does not force a change in the web layer. A new view can be added without touching the database. A service can be tested with a stub repository, and a controller can be tested with a stub service. Each test stays small and fast.
Use this figure as a map when you open an unfamiliar generated project. Start at the view, follow the controller, then read the service and the repository. The code will match the stack almost every time.