Build and maintain Spring Boot financial management systems with JWT auth, transaction tracking, Brazilian market integration, and RESTful APIs following enterprise best practices.
Expert guidance for building enterprise-grade financial management applications with Spring Boot 3.x, focusing on transaction management, Brazilian market integration, and secure RESTful API design.
1. **Dependency Injection**: Use constructor injection over field injection
2. **Validation**: Apply `@Valid` annotations for request validation
3. **Exception Handling**: Implement `@ControllerAdvice` for centralized error handling
4. **RESTful Design**: Follow REST principles with proper HTTP methods and status codes
5. **Modern Java**: Leverage Java 21 features (records for DTOs, pattern matching)
- Controllers: `*.controller`
- Services: `*.service`
- Repositories: `*.repository`
- DTOs: `*.dto`
- Entities: `*.model`
- Config: `shared.config`
**CRITICAL**: Always use `BigDecimal` for monetary values, never `double` or `float`.
```java
// Correct
BigDecimal amount = new BigDecimal("150.75");
// Wrong
double amount = 150.75;
```
Use descriptive commit messages with scope:
```
feat(transactions): add transaction reconciliation
fix(auth): resolve JWT token expiration issue
docs(api): update OpenAPI specifications
test(goals): add integration tests for goal tracking
refactor(service): extract common validation logic
```
Commit in logical units by module, scope, or feature.
```java
@Test
void shouldThrowExceptionWhenTransactionAmountIsNegative() {
// Test implementation
}
```
#### RESTful Endpoints
```java
@RestController
@RequestMapping("/api/v1/transactions")
public class TransactionController {
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public TransactionResponse createTransaction(@Valid @RequestBody TransactionRequest request) {
// Implementation
}
@GetMapping
public Page<TransactionResponse> listTransactions(
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "20") int size
) {
// Implementation
}
}
```
1. **Never hardcode secrets**: Use environment variables or Spring's `@ConfigurationProperties`
2. **Input Validation**: Validate all user inputs with Bean Validation annotations
3. **Authentication**: Implement JWT-based authentication with proper token expiration
4. **Authorization**: Use method-level security with `@PreAuthorize` where needed
5. **CORS**: Configure CORS properly for frontend integration
6. **HTTPS**: Enforce HTTPS in production environments
Implement centralized error handling:
```java
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(EntityNotFoundException.class)
public ResponseEntity<ErrorResponse> handleNotFound(EntityNotFoundException ex) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(new ErrorResponse(ex.getMessage()));
}
}
```
1. **API Rate Limits**: Implement rate limiting for external market data APIs
2. **Data Validation**: Validate market data (stocks, FIIs) before storing
3. **Caching**: Cache market data with appropriate TTL
4. **Error Handling**: Handle external API failures gracefully with retry mechanisms
5. **Currency**: Handle Brazilian Real (BRL) conversions properly
```dockerfile
FROM gradle:8-jdk21 AS build
WORKDIR /app
COPY . .
RUN gradle clean build -x test
FROM eclipse-temurin:21-jre-alpine
WORKDIR /app
COPY --from=build /app/build/libs/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
```
1. **Database Queries**: Optimize with proper indexes and JPA fetch strategies
2. **Pagination**: Always paginate large datasets
3. **Caching**: Use Spring Cache abstraction for frequently accessed data
4. **Async Processing**: Use `@Async` for long-running tasks
5. **Connection Pooling**: Configure HikariCP for optimal performance
Integrate these tools into your build pipeline:
```java
private static final Logger log = LoggerFactory.getLogger(TransactionService.class);
public void processTransaction(Transaction transaction) {
log.info("Processing transaction: id={}, amount={}", transaction.getId(), transaction.getAmount());
try {
// Business logic
log.debug("Transaction processed successfully");
} catch (Exception e) {
log.error("Failed to process transaction: id={}", transaction.getId(), e);
throw new TransactionProcessingException("Transaction processing failed", e);
}
}
```
Enable Spring Boot Actuator endpoints:
```yaml
management:
endpoints:
web:
exposure:
include: health,metrics,info
endpoint:
health:
show-details: always
```
1. **README.md**: Keep project setup and overview current
2. **CHANGELOG.md**: Document all significant changes
3. **OpenAPI**: Annotate all endpoints with `@Operation`, `@ApiResponse`
4. **JavaDoc**: Add JavaDoc for complex business logic
1. **Audit Trails**: Log all financial transactions with timestamps and user context
2. **Reconciliation**: Implement proper transaction reconciliation logic
3. **Categories**: Validate transaction categories against predefined enums
4. **Boundaries**: Use `@Transactional` with proper isolation levels
5. **Validation**: Always validate transaction amounts (no negative values unless explicitly allowed)
1. Have rollback SQL scripts ready for migrations
2. Tag stable releases in Git
3. Document incident procedures in `INCIDENT_RESPONSE.md`
4. Monitor application health dashboards during deployments
---
**Remember**: These guidelines prioritize security, maintainability, and performance for financial applications. Adapt as needed while maintaining core principles of transactional integrity and data security.
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/spring-boot-finance-management/raw