Awesome-omni-skill modern-java-backend-playbook
Enforces backend Java/Quarkus project standards including architecture layers, design patterns, code reuse, Lombok, TDD, exception handling, and modern Java features. Use this skill when writing, modifying, or reviewing Java backend code with Quarkus, Panache, Hibernate, Jakarta EE, or microservices architecture.
git clone https://github.com/diegosouzapw/awesome-omni-skill
T=$(mktemp -d) && git clone --depth=1 https://github.com/diegosouzapw/awesome-omni-skill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/development/modern-java-backend-playbook" ~/.claude/skills/diegosouzapw-awesome-omni-skill-modern-java-backend-playbook-4b53c3 && rm -rf "$T"
skills/development/modern-java-backend-playbook/SKILL.mdJava Backend - Project Standards & Patterns
You are a senior Java backend developer working on a microservices ecosystem built with Quarkus and Java. Before writing or modifying code, analyze the project's
pom.xml or build.gradle to identify the exact Java and Quarkus versions in use, then apply the best practices and features available for those versions. You MUST follow all the conventions and patterns described below when writing, modifying, or reviewing code. These are non-negotiable project standards.
1. Core Principles
1.1 Code Reuse
- NEVER reinvent the wheel. Before writing new logic, check if a solution already exists in:
- The current project's utility classes (e.g.,
,QueryUtils
,DateUtils
,FileUtils
)JwtUtil - Panache's built-in methods (
,findByIdOptional
,find
,list
,persist
,delete
,count
)pageCount - Libraries already in the project (Apache Commons, MapStruct, Lombok, Jackson, etc.)
- Java standard library methods (Stream API,
,List.of()
,Map.of()
,Optional
methods)String
- The current project's utility classes (e.g.,
- When a utility or helper already exists, use it. Do not create duplicate logic.
1.2 Design Patterns
Apply these patterns consistently:
- SOLID - Single Responsibility, Open/Closed, Liskov, Interface Segregation, Dependency Inversion
- Service Layer - All business logic lives in Services, NEVER in Resources or Repositories
- Repository Pattern - Data access only, SQL/HQL queries here, no business logic
- DTO Pattern - DTOs for API input/output, Entities for persistence. Never expose Entities directly
- Dependency Injection - Constructor injection via Lombok
. NEVER use@AllArgsConstructor@Inject - Facade - Orchestrate multiple services when needed
- Factory Method / Builder - Use Lombok
for complex object creation@Builder - Strategy - Use when multiple algorithms/behaviors need to be interchangeable
- Template Method - Use for shared algorithm structures with varying steps
- MVC - Resources (controllers) handle HTTP, Services handle logic, Repositories handle data
1.3 Modern Java Features - USE THEM
Always check the Java version in
pom.xml / build.gradle and prefer modern features available for that version:
- Records - For immutable DTOs, value objects, and simple data carriers where appropriate
- Stream API - For collection transformations. Prefer
over manual loopsstream().map().toList()
,List.of()
,Map.of()
- For immutable collectionsSet.of()- Type inference (
) - Use in local variables when the type is obvious from the right-hand sidevar - Text Blocks (
) - For multi-line strings, SQL queries, JSON templates""" - Switch Expressions - Use
syntax with yield when appropriate-> - Pattern Matching for
- Useinstanceof
instead of castingif (obj instanceof String s) - Pattern Matching for
- Use typed patterns in switch when applicableswitch - Sealed classes - Use for restricted hierarchies when applicable
- String methods - Use
,.strip()
,.isBlank()
, etc..formatted() - Virtual Threads - Use when beneficial for I/O-bound concurrent operations
2. Architecture & Package Structure
Every microservice follows this package structure:
├── resources/ # REST endpoints (JAX-RS Resources) ├── service/ # Service interfaces │ └── impl/ # Service implementations ├── repository/ # Panache repositories (data access + queries) ├── dto/ # Data Transfer Objects (request/response) ├── entities/ # JPA entities │ ├── enums/ # Enum types used by entities │ └── converters/ # JPA attribute converters ├── exceptions/ # Custom exceptions (BusinessException, etc.) │ └── providers/ # ExceptionMapper implementations ├── config/ # Configuration classes │ ├── interceptors/ # Filters, interceptors (LoggingFilter, TokenHeadersFactory) │ └── validators/ # Custom constraint validators ├── annotations/ # Custom annotations (@OpComparison, @ValidCNS, etc.) ├── clients/ # REST client interfaces (@RegisterRestClient) ├── mapper/ # MapStruct mappers (when used) ├── util/ # Utility classes (QueryUtils, DateUtils, JwtUtil, etc.) ├── health/ # Health check implementations ├── startup/ # Application startup hooks └── concurrency/ # Interceptors and listeners for async operations
Rules:
- Separate files correctly into their packages/modules
- Do NOT mix concerns: a Service does not belong in
, a query does not belong inresources/service/ - One class per file. Name the file exactly as the class name.
3. Resource Layer (Controllers)
Resources are thin HTTP controllers. They delegate ALL logic to Services.
@AllArgsConstructor @Authenticated @Path("/v1/products") public class ProductResources { private ProductService productService; @GET @Operation(summary = "List all products") public Response findByFilters(@BeanParam ProductFilter filter, @BeanParam Pageable pageable) { return Response.ok(productService.findByFilters(filter, pageable)).build(); } @POST @Operation(summary = "Create a new product") public Response create(@Valid Product product, @Context UriInfo uriInfo) throws BusinessException { var created = productService.create(product); var uri = uriInfo.getAbsolutePathBuilder().path(created.getId().toString()).build(); return Response.created(uri).entity(created).build(); } @DELETE @Path("{id}") @Operation(summary = "Delete a product") public Response delete(@PathParam("id") Long id) throws BusinessException { productService.deleteById(id); return Response.ok().build(); } }
Rules:
for constructor injection (NEVER@AllArgsConstructor
)@Inject
for secured endpoints@Authenticated
on request body DTOs for Hibernate Validator constraint validation@Valid
for query filters and pagination@BeanParam
for OpenAPI documentation@Operation(summary = "...")- Resources return
objectsResponse - NO business logic in Resources - only delegation to Services
- Use
annotations from Hibernate Validator directly on DTOs to avoid duplicate validation logic@Valid
4. Service Layer
Services contain ALL business logic. They follow the interface + implementation pattern.
Service Interface
public interface ProductService { PageResponse<Product> findByFilters(ProductFilter filter, Pageable pageable); List<Product> findByCategoryId(Long categoryId); Product create(Product product) throws BusinessException; void deleteById(Long id) throws BusinessException; }
Service Implementation
@AllArgsConstructor @ApplicationScoped public class ProductServiceImpl implements ProductService { private final ProductRepository productRepository; @Override @Transactional(rollbackOn = Exception.class) public Product create(Product product) throws BusinessException { var existingProduct = productRepository.findByCode(product.getCode()); if (existingProduct.isPresent()) { throw new BusinessException("Product already exists with code: " + product.getCode()); } var entity = product.toEntity(); productRepository.persist(entity); return Product.fromEntity(entity); } @Override @Transactional(rollbackOn = Exception.class) public void deleteById(Long id) throws BusinessException { var entity = this.findByIdInternal(id); productRepository.delete(entity); } protected ProductEntity findByIdInternal(Long id) throws BusinessException { return productRepository.findByIdOptional(id) .orElseThrow(() -> new BusinessException("Product not found")); } }
Rules:
for constructor injection (NEVER@AllArgsConstructor
)@Inject
as the default scope@ApplicationScoped
for write operations@Transactional(rollbackOn = Exception.class)- ALL business logic lives here, NOT in Resources or Repositories
- NO SQL/HQL in Services - queries belong in Repositories
- Throw
for business rule violationsBusinessException - Use
for not-found casesfindByIdOptional(...).orElseThrow(() -> new BusinessException(...)) - Use
for local variables when the type is obviousvar - Use
for internal entity lookup reused across methodsprotected findByIdInternal(...)
5. Repository Layer
Repositories handle ALL data access using Panache.
@ApplicationScoped public class ProductRepository implements PanacheRepository<ProductEntity> { public List<ProductEntity> findByCategoryId(Long categoryId) { return list("SELECT p FROM ProductEntity p WHERE p.category.id = ?1", categoryId); } public Optional<ProductEntity> findByCode(String code) { return find("code = ?1", code).firstResultOptional(); } public PanacheQuery<ProductEntity> find(String whereClause, Pageable pageable, Map<String, Object> params) { var baseQuery = "FROM ProductEntity p"; var fullQuery = whereClause != null && !whereClause.isBlank() ? baseQuery + " WHERE " + whereClause : baseQuery; return find(fullQuery, pageable.getSortOrder(), params); } }
Rules:
- Extends
PanacheRepository<EntityType> @ApplicationScoped- ALL SQL/HQL queries live here
- Reuse Panache built-in methods whenever possible (
,findByIdOptional
,find
,list
,persist
)delete - Return
for single-result queries that may not find dataOptional<T> - Return
for paginated queriesPanacheQuery<T>
6. DTO Layer
DTOs are the bridge between API and Entity layers.
@Data @Builder(toBuilder = true) @NoArgsConstructor @AllArgsConstructor @RegisterForReflection public class Product { private Long id; @NotBlank(message = "Name is required") private String name; @NotNull(message = "Category is required") private Long categoryId; private String description; public static Product fromEntity(ProductEntity entity) { return Product.builder() .id(entity.getId()) .name(entity.getName()) .categoryId(entity.getCategoryId()) .description(entity.getDescription()) .build(); } public ProductEntity toEntity() { return ProductEntity.builder() .id(this.id) .name(this.name) .categoryId(this.categoryId) .description(this.description) .build(); } public static List<Product> toDtoList(List<ProductEntity> entityList) { return entityList.stream().map(Product::fromEntity).toList(); } public static List<ProductEntity> toEntityList(List<Product> dtoList) { return dtoList.stream().map(Product::toEntity).toList(); } }
Rules:
- Use Lombok:
,@Data
,@Builder
,@NoArgsConstructor@AllArgsConstructor
for GraalVM native image support@RegisterForReflection
when appropriate@JsonInclude(JsonInclude.Include.NON_NULL)- Validation annotations from Hibernate Validator:
,@NotNull
,@NotBlank
,@NotEmpty
,@Size
,@Min
,@Max
,@Email
, etc.@Pattern - Place validation constraints on DTO fields, NOT in Service logic (avoids duplicate validation)
- Static
method for entity-to-DTO conversionfromEntity(Entity) - Instance
method for DTO-to-entity conversiontoEntity() - Static
for bulk conversion using streamstoDtoList(List<Entity>) - Static
for bulk conversion using streamstoEntityList(List<DTO>) - Use
for fields with default values@Builder.Default
Filter DTOs
@Data @Builder @AllArgsConstructor @NoArgsConstructor @RegisterForReflection public class ProductFilter { @QueryParam("name") @OpComparison(operator = "LIKE") private String name; @QueryParam("isActive") @OpComparison private Boolean isActive; }
Pagination DTOs
Use the standard
Pageable and PageResponse<T> classes already in the project.
7. Entity Layer
@Entity @Table(name = "product") @Data @Builder @AllArgsConstructor @NoArgsConstructor public class ProductEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private Long id; @Column(name = "name") private String name; @Column(name = "code") private String code; @Column(name = "category_id") private Long categoryId; @Column(name = "description") private String description; @Column(name = "is_active") private Boolean isActive; @Column(name = "date_created") private LocalDateTime dateCreated; }
Rules:
- Use Lombok:
(or@Data
/@Getter
for entities with relationships to avoid hashCode issues),@Setter
,@Builder
,@AllArgsConstructor@NoArgsConstructor
and@Entity@Table(name = "table_name")
with@Id@GeneratedValue(strategy = GenerationType.IDENTITY)
for all fields@Column(name = "column_name")
for enum fields@Enumerated(EnumType.STRING)- Enums go in the
packageentities.enums - Entity class names end with
suffix (e.g.,Entity
)ProductEntity
8. Exception Handling
Custom Exceptions
@RegisterForReflection public class BusinessException extends Exception { public BusinessException(String message) { super(message); } public BusinessException(String message, Throwable cause) { super(message, cause); } }
Problem Response Model
@Getter @RegisterForReflection public class Problem { private final int status; private final OffsetDateTime timestamp; private final String title; private final String detail; private final List<ProblemObject> messages; public Problem(int status, String title, String detail) { this.status = status; this.timestamp = OffsetDateTime.now(); this.title = title; this.detail = detail; this.messages = new ArrayList<>(); } public void addMessage(String field, String message) { this.messages.add(new ProblemObject(field, message)); } }
ProblemObject (field-level error detail)
@RegisterForReflection public record ProblemObject(String name, String message) { }
ProblemBuilder (centralized Response building)
Use
ProblemBuilder to avoid repeating Response.status().entity().type().build() in every provider:
public final class ProblemBuilder { private ProblemBuilder() {} public static Response build(int status, String title, String detail) { Problem problem = new Problem(status, title, detail); return Response.status(status) .entity(problem) .type(MediaType.APPLICATION_JSON) .build(); } public static Response build(Problem problem) { return Response.status(problem.getStatus()) .entity(problem) .type(MediaType.APPLICATION_JSON) .build(); } }
ExceptionMapper Providers
Each provider creates a
Problem with the appropriate status/title and delegates to ProblemBuilder:
@Provider public class BusinessExceptionProvider implements ExceptionMapper<BusinessException> { @Override public Response toResponse(BusinessException e) { Problem problem = new Problem(422, "Business rule violation", e.getMessage()); return ProblemBuilder.build(problem); } }
@Provider public class ConstraintViolationExceptionProvider implements ExceptionMapper<ConstraintViolationException> { @Override public Response toResponse(ConstraintViolationException e) { var problem = new Problem(400, "Invalid request data", "One or more fields are invalid."); e.getConstraintViolations().forEach(v -> problem.addMessage( lastFieldName(v.getPropertyPath().iterator()), v.getMessage() ) ); return ProblemBuilder.build(problem); } private String lastFieldName(Iterator<Path.Node> nodes) { Path.Node last = null; while (nodes.hasNext()) { last = nodes.next(); } return last != null ? last.getName() : null; } }
Global Exception Provider (fallback)
Always create a
GlobalExceptionProvider to catch any unhandled exception:
@Provider public class GlobalExceptionProvider implements ExceptionMapper<Throwable> { @Override public Response toResponse(Throwable e) { Problem problem = new Problem(500, "Error", e.getMessage()); return ProblemBuilder.build(problem); } }
Rules:
- ALWAYS map exceptions properly to return treated errors to the end user
- Use
with a single generic constructor (Problem
,status
,title
) — do NOT create one constructor per exception typedetail - Use
to centralize Response building — providers should NEVER build the Response manuallyProblemBuilder - Use
as aProblemObject
for field-level error detailsrecord - Use
to attach field-level messages (e.g., inProblem.addMessage()
)ConstraintViolationExceptionProvider - Use
for business rule violations (status 422)BusinessException - ALWAYS create a
forGlobalExceptionProvider
as a fallback for unhandled exceptionsThrowable - Create specific
classes implementing@Provider
in theExceptionMapper<T>
package for each exception type that needs custom handlingexceptions.providers - Verify that exceptions make architectural sense in their context. For example, do NOT throw a
inside a configuration class — use appropriate exception types for the layerBusinessException - Handle at minimum:
,BusinessException
,ConstraintViolationException
(global fallback)Throwable
9. Dependency Injection
// CORRECT - Constructor injection via Lombok @AllArgsConstructor @ApplicationScoped public class MyServiceImpl implements MyService { private final MyRepository myRepository; private final JwtUtil jwtUtil; }
// WRONG - NEVER do this @ApplicationScoped public class MyServiceImpl implements MyService { @Inject // NEVER use @Inject MyRepository myRepository; }
Rules:
- ALWAYS use constructor injection via
@AllArgsConstructor - NEVER use
for field injection@Inject - Mark injected fields as
when possibleprivate final - This applies to Resources, Services, Repositories, Config classes, and any CDI bean
10. Validation
Use Hibernate Validator constraint annotations directly on DTO fields:
@Data @Builder public class CreateUserRequest { @NotBlank(message = "O nome e obrigatorio") private String name; @NotNull(message = "O email e obrigatorio") @Email(message = "Email invalido") private String email; @Size(min = 11, max = 11, message = "CPF deve ter 11 digitos") private String cpf; }
Then use
@Valid in the Resource:
@POST public Response create(@Valid CreateUserRequest request) throws BusinessException { return Response.ok(service.create(request)).build(); }
Rules:
- Place constraints on DTO fields:
,@NotNull
,@NotBlank
,@NotEmpty
,@Size
,@Min
,@Max
,@Email@Pattern - Use
on the request body parameter in the Resource@Valid - Do NOT duplicate validation in the Service that is already handled by constraints
- Create custom validators (in
) when built-in constraints are insufficientconfig.validators
11. Constants
Define constants at the top of the class where they are used:
public class Pageable { private static final int DEFAULT_PAGE = 0; private static final int DEFAULT_SIZE = 10; private static final int MAX_SORT_COLUMNS = 5; private static final Pattern SORT_COLUMN_PATTERN = Pattern.compile("^[A-Za-z][A-Za-z0-9_.]{0,63}$"); // ... rest of the class }
Rules:
- Constants go at the TOP of the class, before fields and methods
- Use
for class-internal constantsprivate static final - Use
only when constants need to be sharedpublic static final - Use
for namingALL_CAPS_SNAKE_CASE - For utility classes with only static methods, add a private constructor to prevent instantiation
- Evaluate whether constants should live in the class or in a dedicated constants class. If a class accumulates too many constants or they are shared across multiple classes, consider moving them to a dedicated utility class (e.g.,
,AppConstants
) in theErrorMessages
package to keep the original class focused and readableutil
12. Lombok Usage
Use Lombok to eliminate boilerplate:
| Annotation | Usage |
|---|---|
| DTOs, Entities (generates getters, setters, equals, hashCode, toString) |
/ | Entities with relationships (to avoid hashCode issues) |
| DTOs, Entities, complex objects |
| When you need to copy and modify objects |
| Constructor injection in ALL CDI beans |
| Required by JPA entities and Jackson deserialization |
| When only fields need injection |
Rules:
- ALWAYS use Lombok to avoid boilerplate code
- NEVER write getters/setters/constructors manually if Lombok can generate them
- Use
for object construction in DTOs and Entities@Builder
13. Testing (TDD)
Apply TDD: write tests FIRST or alongside implementation to guarantee testability.
Unit Test Pattern
@QuarkusTest @TestProfile(NoDatabaseTestProfile.class) class ProductServiceImplTest { @InjectMock ProductRepository repository; AutoCloseable closeable; ProductServiceImpl service; @BeforeEach void initMocks() { closeable = MockitoAnnotations.openMocks(this); service = new ProductServiceImpl(repository); } @AfterEach void tearDown() throws Exception { closeable.close(); } @Test void givenValidProduct_WhenCreate_ThenReturnCreatedProduct() { // GIVEN var product = MockProduct.newProduct(); doAnswer(invocation -> { ProductEntity entity = invocation.getArgument(0); entity.setId(1L); return entity; }).when(repository).persist(any(ProductEntity.class)); // WHEN var result = service.create(product); // THEN assertNotNull(result); assertEquals(1L, result.getId()); verify(repository).persist(any(ProductEntity.class)); } @Test void givenNonExistentId_WhenFindById_ThenThrowBusinessException() { // GIVEN when(repository.findByIdOptional(1L)).thenReturn(Optional.empty()); // THEN var exception = assertThrows(BusinessException.class, () -> service.findById(1L)); assertEquals("Product not found", exception.getMessage()); } }
Integration Test Pattern
@QuarkusTest @TestHTTPResource class ProductResourcesIT { @Test void givenValidRequest_WhenCreateProduct_ThenReturn201() { given() .contentType(ContentType.JSON) .body(/* request body */) .when() .post("/v1/products") .then() .statusCode(201); } }
Rules:
- Test naming:
givenContext_WhenAction_ThenExpectedResult - Use GIVEN / WHEN / THEN comments to structure tests
for all tests@QuarkusTest
for unit tests that don't need a database@TestProfile(NoDatabaseTestProfile.class)
or@InjectMock
for mocking Panache repositories@InjectSpy- Use
inMockitoAnnotations.openMocks(this)@BeforeEach - Close mocks in
@AfterEach - Create mock factory classes (e.g.,
) for test dataMockField.newField() - Use
for integration testsrest-assured - Use
for database integration testsTestContainers - Test both success and failure paths
14. Technology Stack Reference
Always check the project's
pom.xml or build.gradle to identify the exact versions in use. Apply best practices for those versions.
| Technology | Purpose |
|---|---|
| Java | Language (check / for version) |
| Quarkus | Framework (check / for version) |
| Hibernate ORM + Panache | ORM / Data Access |
| Flyway | Database Migrations |
| SQL Server (MSSQL) | Database |
| Keycloak / OIDC | Authentication |
| Lombok | Code Generation |
| MapStruct | Object Mapping (when used) |
| Jackson | JSON Serialization |
| Hibernate Validator | Bean Validation |
| SmallRye OpenAPI | API Documentation |
| OpenTelemetry | Distributed Tracing |
| SmallRye Health | Health Checks |
| SmallRye Fault Tolerance | Resilience |
| AWS S3 | Object Storage |
| JUnit 5 + Mockito | Testing |
| TestContainers | Integration Testing |
| REST Assured | API Testing |
| JaCoCo | Code Coverage |
15. File Formatting
- Leave exactly ONE blank line at the end of every file
- Use 4 spaces for indentation (no tabs)
- Follow Java standard formatting conventions
- Organize imports: java., jakarta., third-party, project-internal
16. REST Client Pattern
Use
configKey to decouple the configuration from the fully qualified class name:
@RegisterRestClient(configKey = "user-api") @Path("/v1/users") public interface UserClient { @GET @Path("/{id}") UserResponse findById(@PathParam("id") Long id); }
Configuration in
application.properties:
quarkus.rest-client.user-api.url=${BACKEND_USER_URL}
Rules:
- Always use
inconfigKey
instead of referencing the full class path@RegisterRestClient(configKey = "...") - The
should be a short, descriptive kebab-case name (e.g.,configKey
,user-api
,product-api
)notification-api
17. Configuration Pattern
# Use environment variables with defaults quarkus.datasource.username=${DATASOURCE_USERNAME} quarkus.datasource.password=${DATASOURCE_PASSWORD} quarkus.datasource.jdbc.url=jdbc:sqlserver://${DATASOURCE_HOST:localhost}:1433;databaseName=${DATASOURCE_DB_NAME} # Profile-specific configuration %dev.quarkus.log.level=INFO %prod.quarkus.datasource.jdbc.min-size=${DATASOURCE_MIN_SIZE:2} %prod.quarkus.datasource.jdbc.max-size=${DATASOURCE_MAX_SIZE:10}
Rules:
- Use environment variable placeholders
with sensible defaults${VAR_NAME}${VAR_NAME:default} - Use Quarkus profiles (
,%dev.
,%test.
) for environment-specific config%prod. - NEVER hardcode secrets or credentials
18. Explicit this
Keyword Usage
thisUse
this. explicitly in specific contexts to improve code readability, especially in void methods where there is no return value to guide the reader through the flow.
When to use this.
this.In void methods calling other methods of the same class:
@Override public void updateStatusAndOverview(Long productSolicitationId, Long statusId, Long requestSummaryId) throws BusinessException { this.updateStatus(productSolicitationId, statusId, requestSummaryId, true); } @Override public void deleteById(Long id) throws BusinessException { var entity = this.findByIdInternal(id); productRepository.delete(entity); }
In void update methods on DTOs/Requests — accessing own fields with
:this.
public void updateUserEntity(UserEntity entity) { Optional.ofNullable(this.getName()).ifPresent(entity::setName); Optional.ofNullable(this.getEmail()).ifPresent(entity::setEmail); Optional.ofNullable(this.getPhone()).ifPresent(entity::setPhone); Optional.ofNullable(this.getDateOfBirth()).ifPresent(entity::setDateOfBirth); if (this.getRole() != null) { entity.setRole(RoleType.fromString(this.getRole())); } }
In constructors — field assignment (already standard in the project):
public Problem(BusinessException e) { this.status = 422; this.timestamp = OffsetDateTime.now(); this.title = "Business"; this.detail = e.getLocalizedMessage(); }
In
and copy methods — accessing own fields in builders:toEntity()
public ProductEntity toEntity() { return ProductEntity.builder() .id(this.id) .name(this.name) .categoryId(this.categoryId) .description(this.description) .build(); }
When NOT to use this.
this.- In methods that return a value and the flow is already self-explanatory
- In simple one-liner delegations where the context is obvious
- Avoid adding
everywhere indiscriminately — use it only where it genuinely improves readabilitythis.
Rules:
- Use
in void methods when calling other methods of the same classthis. - Use
in void update methods on DTOs when accessing own fields/gettersthis. - Use
in constructors for field assignmentthis. - Use
inthis.
and copy methods when building from own fieldstoEntity() - Do NOT apply
blindly to all code — the goal is readability, not ceremonythis.
Summary Checklist
Before submitting any code, verify:
- Business logic is in the Service layer only
- SQL/HQL queries are in the Repository layer only
- Constructor injection via
(no@AllArgsConstructor
)@Inject - Validation constraints are on DTO fields with
in Resource@Valid - Exceptions are mapped with ExceptionMapper providers
- Exceptions make architectural sense in their context
- Lombok is used to avoid boilerplate
- DTOs have
,fromEntity()
,toEntity()
methodstoDtoList() - Modern Java features for the project's version are used (var, streams, records, switch expressions, pattern matching, etc.)
- Tests follow GIVEN/WHEN/THEN pattern
- Constants are at the top of the class
- Files are in the correct package
- Exactly one blank line at end of file
- Existing code and utilities are reused
-
is used in void methods, constructors,this.
, and update methods for readabilitytoEntity()