.cursorrules Java Springboot Jpa

Java Spring Boot Development Guidelines

A set of best practices and instructions for developing robust and secure applications using Java Spring Boot 3 with Maven, focusing on SOLID principles and OWASP best practices.

Technology Stack

  • Framework: Java Spring Boot 3 with Maven
  • Dependencies: Spring Web, Spring Data JPA, Thymeleaf, Lombok, PostgreSQL driver
  • Java Version: Java 17

Application Logic Design

  • Request and response handling in RestController.
  • Database operations in ServiceImpl classes via Repositories.
  • Use DTOs for data transfer between layers.

Entities

  • Annotate with @Entity@Data, and proper validation annotations.
  • Use FetchType.LAZY for relationships.

Repository (DAO)

  • Annotate with @Repository, extend JpaRepository.
  • Use JPQL for queries and @EntityGraph for relationships.

Service

  • Implement logic in ServiceImpl classes.
  • Use @Transactional for multiple database operations.

Data Transfer Object (DTO)

  • Use record type unless specified otherwise.
  • Validate input parameters in the constructor.

RestController

  • Annotate with @RestController.
  • Use @RequestMapping and HTTP method annotations.
  • Return ResponseEntity<ApiResponse>.

ApiResponse Class

  • Standardized response format with success/error status and message.

GlobalExceptionHandler Class

  • Handles exceptions with standardized error responses.

Overview of .cursorrules prompt

This prompt outlines guidelines for developing robust and secure Java Spring Boot applications, emphasizing SOLID principles, OWASP best practices, and efficient layering of logic. It ensures that applications are maintainable, scalable, and secure by using Spring Data JPA for database operations and Thymeleaf for templating.

Updated: March 15, 2025
Guidelines for secure and maintainable Java Spring Boot development, following SOLID principles and OWASP best practices.
Usefull for: