Spring Framework· 30 min

Spring Application Architecture

Organize controllers, services, repositories, domain objects, configuration, and cross-cutting concerns.

Java interview lesson
Question 18 · Not reviewed

Spring · design

Can you explain this clearly in an interview?

Use the strong answer as your reference, explain it aloud in your own words, then choose how soon you want to review it again.

Interview prompt

Spring Application Architecture

Explain it aloud in your own words

Strong answer

A maintainable Spring service separates transport, application orchestration, domain behavior, and persistence. Controllers translate HTTP; services coordinate use cases; repositories handle storage. DTOs protect the API contract from leaking persistence models.

Key points

  • Keep controllers thin and validation explicit.
  • Transactions should surround a business use case, not arbitrary controller code.
  • Domain rules should remain testable without starting the entire framework.
  • Avoid turning every class into a Spring bean without a reason.

Interviewer looks for

Give a concrete request flow from controller to database and identify where validation, authorization, and transaction boundaries live.

Java example

1@RestController
2@RequestMapping("/orders")
3class OrderController {
4  private final OrderService service;
5  // Map request DTO -> service command -> response DTO.
6}

Topic interview questions

Revise this topic like an interviewer

These questions are tied to this lesson. Read each question aloud, then compare your explanation with the strong answer.

5 questions
Q1Basic

What responsibilities belong in a controller, service, and repository?

Strong answer

A controller translates transport concerns, a service coordinates an application use case and transaction boundary, and a repository handles persistence. Keeping these responsibilities separate improves testability and change isolation.

Q2Intermediate

Why use DTOs instead of exposing JPA entities directly?

Strong answer

DTOs keep the external API contract independent from persistence shape, prevent accidental field exposure, and avoid lazy-loading or serialization surprises. They also allow request and response models to evolve separately.

Q3Intermediate

Where should domain rules live?

Strong answer

Rules that define valid business behavior should live in domain objects or application services, not in controllers or persistence adapters. They should be testable without requiring a web server or database.

Q4Intermediate

What makes a transaction boundary too broad?

Strong answer

A transaction that includes slow network calls, file processing, or unrelated work holds locks and connections longer than necessary. Keep the boundary around the smallest coherent unit that must commit together.

Q5Intermediate

How should a service handle validation and authorization?

Strong answer

Validate shape and basic constraints at the input boundary, then enforce business invariants in the application or domain layer. Authorization should be explicit and checked against the target resource and requested action.

How well do you know this?

Your review choice is saved locally and synced to your learner profile when signed in.