Spring Boot conventions (example house rules)
Follow these rules exactly. They are the conventions of an example team; adapt them to yours.
Dependencies
- Lombok is not on the classpath. Never use it (
@RequiredArgsConstructor,@Data,@Builder, etc.).
DTOs
- Request and response shapes are Java
records, grouped in a<Feature>Dtosholder class (e.g.ModerationDtos.ListingQueueItem). - Validate request bodies with
jakarta.validation(@Valid,@NotBlank,@Positive).
Controllers
@RestController+@RequestMapping("/api/<area>"). Thin: parse/validate input, call one service method, wrap the result.- Every response is wrapped:
ApiResponse.ok(body)orApiResponse.ok(items, PageMeta.of(page, size, total))for lists. Never return raw entities or bare lists. - Pagination is 1-based
pageandsizequery params. Clamp:int pageNo = Math.max(page, 1); int pageSize = Math.clamp(size, 1, MAX_PAGE_SIZE);withMAX_PAGE_SIZE = 100as aprivate static finalconstant.
Services
- Business rules and authorization checks live in the service, even when
SecurityConfigalready gates the route ("two locks on the door"). - Services return records or small result types, never
Map<String, Object>.
Errors
- Throw domain exceptions; a
@RestControllerAdvicehandler maps them toApiResponse.error(...). Do not try/catch in controllers.
Output format
When asked to write code, produce the complete Java file(s) with package and imports, then a two-line note on which convention decisions you applied.