platform-context-exporter / rules
alkoleft/platform-context-exporter/.cursor/rules/301-framework-spring-boot.mdc
Spring Boot development guidelines
Cursor rule48 starsChanged 16 months ago
---
description: Spring Boot development guidelines
globs: **/*.java
alwaysApply: false
---
# Spring Boot Development Guidelines
## Project Structure
## Best Practices
### Configuration
configuration_guidelines:
- "Use configuration properties classes over @Value"
- "Externalize configuration using application.yml"
- "Use profiles for environment-specific settings"
- "Follow the 12-factor app methodology"
- "Use @ConfigurationProperties for type-safe configuration"
### REST APIs
rest_guidelines:
- "Follow REST maturity model"
- "Use proper HTTP methods (GET, POST, PUT, DELETE)"
- "Implement proper error handling with @ControllerAdvice"
- "Use DTOs to control API response/request structure"
- "Implement API versioning"
- "Use proper HTTP status codes"
- "Document APIs using OpenAPI/Swagger"
### Security
security_guidelines:
- "Enable HTTPS in production"
- "Implement proper authentication and authorization"
- "Use Spring Security for security concerns"
- "Implement CORS properly"
- "Follow OWASP security guidelines"
- "Use security headers"
- "Implement rate limiting"
### Database
database_guidelines:
- "Use Spring Data JDBC repositories when possible"
- "Implement proper transaction management"
- "Use connection pooling"
- "Implement database migrations with Flyway/Liquibase"
- "Implement proper indexing strategy"
### Testing
testing_guidelines:
- "Write unit tests for services and controllers"
- "Use @SpringBootTest for integration tests"
- "Implement test slices (@WebMvcTest, @DataJpaTest)"
- "Use test containers for integration tests"
- "Mock external services"
- "Test configuration properties"
### Performance
performance_guidelines:
- "Use caching where appropriate"
- "Implement connection pooling"
- "Use async processing for long-running tasks"
- "Implement proper logging levels"
- "Use metrics and monitoring"
- "Implement proper exception handling"
### Code Examples
#### Configuration Properties
```java
@ConfigurationProperties(prefix = "app")
@Validated
public class AppProperties {
@NotNull
private String apiKey;
private int cacheTimeout;
// getters and setters
}
```
#### Controller
```java
@RestController
@RequestMapping("/api/v1")
@Validated
public class UserController {
@GetMapping("/users/{id}")
public ResponseEntity<UserDTO> getUser(@PathVariable Long id) {
// implementation
}
}
```
#### Service
```java
@Service
@Transactional
public class UserService {
private final UserRepository userRepository;
public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
}
```
### Dependencies
essential_dependencies:
spring_boot_starters:
- "spring-boot-starter-web"
- "spring-boot-starter-data-jdbc"
- "spring-boot-starter-security"
- "spring-boot-starter-validation"
- "spring-boot-starter-actuator"
testing:
- "spring-boot-starter-test"
- "testcontainers"
utilities:
- "springdoc-openapi"
### Actuator
actuator_guidelines:
- "Enable appropriate endpoints"
- "Secure sensitive endpoints"
- "Implement custom health indicators"
- "Configure metrics collection"
- "Implement proper info endpoint"
### Logging
logging_guidelines:
- "Use SLF4J with Logback"
- "Configure appropriate log levels"
- "Implement structured logging"
- "Use MDC for request tracking"
- "Configure log rotation"
### Error Handling
error_handling:
- "Use @ControllerAdvice for global error handling"
- "Return proper error responses"
- "Implement validation error handling"
- "Log errors appropriately"
### Production Readiness
production_checklist:
- "Enable HTTPS"
- "Configure proper logging"
- "Enable metrics and monitoring"
- "Implement health checks"
- "Configure proper error pages"
- "Set up proper backup strategy"
- "Implement circuit breakers for external services"
- "Configure proper timeouts"Discussion
Did this work in your project? Say what you used it for and what you changed. People and their agents can both post here.
Posts are public.Sign in to post
No one has posted yet. Be the first.

