Loading...
Loading...
Enterprise Java development skill covering Spring ecosystem, microservices, design patterns, performance optimization, and Java best practices. Use this skill when building enterprise Java applications, working with Spring Boot, implementing microservices, or need guidance on Java architecture and performance tuning.
npx skill4agent add projanvil/mindforge enterprise-javapackage com.example.{module}.{layer};
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.{Annotation};
import org.springframework.transaction.annotation.Transactional;
/**
* {Class purpose and responsibility}
*
* <p>Key features:
* <ul>
* <li>Feature 1</li>
* <li>Feature 2</li>
* </ul>
*
* @author Enterprise Java Developer
* @since {Version}
*/
@Slf4j
@RequiredArgsConstructor
@{Annotation}
public class {ClassName} {
private final Dependency dependency;
/**
* {Method purpose}
*
* @param param parameter description
* @return return value description
* @throws BusinessException when business rules violated
*/
@Transactional(rollbackFor = Exception.class)
public Result methodName(Param param) {
log.info("Method started, param: {}", param);
try {
// 1. Validate input
validateParam(param);
// 2. Execute business logic
Result result = executeBusinessLogic(param);
// 3. Return result
log.info("Method completed successfully");
return result;
} catch (BusinessException e) {
log.error("Business error: {}", e.getMessage(), e);
throw e;
} catch (Exception e) {
log.error("System error occurred", e);
throw new SystemException("Unexpected error", e);
}
}
private void validateParam(Param param) {
if (param == null) {
throw new IllegalArgumentException("Param cannot be null");
}
// Additional validations...
}
private Result executeBusinessLogic(Param param) {
// Implementation...
return new Result();
}
}controller/ - HTTP endpoints, request/response handling
├── dto/ - Data Transfer Objects
└── vo/ - View Objects
service/ - Business logic, orchestration
├── impl/ - Service implementations
repository/ - Data access layer
├── entity/ - JPA entities
└── mapper/ - MyBatis mappers
domain/ - Domain models (DDD)
├── model/ - Domain objects
├── service/ - Domain services
└── event/ - Domain events
config/ - Configuration classes
exception/ - Custom exceptions
util/ - Utility classes
constant/ - Constants and enums## Code Review Summary
### ✅ Strengths
- Point 1
- Point 2
### ⚠️ Issues Found
#### Critical
1. **Issue Title**
- **Location**: Class.method():line
- **Problem**: Description
- **Impact**: Why this matters
- **Solution**: How to fix
#### Major
...
#### Minor
...
### 💡 Suggestions
- Suggestion 1
- Suggestion 2
### 📝 Refactored Code
```java
// Improved version
### 2. Architecture Design Request
When designing architecture:
#### Gather Requirements
- Functional requirements
- Non-functional requirements (scalability, availability, performance)
- Constraints (budget, timeline, team size)
#### Design Approach
1. **High-Level Architecture**: Components and their interactions
2. **Data Flow**: How data moves through the system
3. **Technology Stack**: Justified selections
4. **Scalability Strategy**: How to handle growth
5. **Resilience**: Failure handling and recovery
**Output Format:**[Component A] --> [Component B]
[Component B] --> [Component C]// Key entities
### 3. Performance Optimization Request
When optimizing performance:
#### Analysis Steps
1. **Identify Bottleneck**: Where is the slowdown?
2. **Measure Impact**: How severe is it?
3. **Root Cause**: Why is it happening?
4. **Solution Options**: Multiple approaches
5. **Recommendation**: Best approach with reasoning
**Output Format:**// Before
public List<User> getUsersWithOrders() {
List<User> users = userRepository.findAll();
users.forEach(user -> user.getOrders().size()); // N queries
return users;
}
// After
public List<User> getUsersWithOrders() {
return userRepository.findAllWithOrders(); // 1 query
}
// Repository
@Query("SELECT u FROM User u LEFT JOIN FETCH u.orders")
List<User> findAllWithOrders();@Cacheable(value = "users", key = "#userId")
public User getUser(Long userId) {
return userRepository.findById(userId)
.orElseThrow(() -> new UserNotFoundException(userId));
}
### 4. Problem Diagnosis Request
When diagnosing production issues:
#### Investigation Process
1. **Symptoms**: What's observed
2. **Logs Analysis**: Error messages and stack traces
3. **Hypothesis**: Possible causes
4. **Verification**: How to confirm
5. **Solution**: Fix and prevention
**Output Format:**java.lang.OutOfMemoryError: Java heap space
at ArrayList.grow()
at OrderService.exportAllOrders()exportAllOrders()// Problematic code
public List<Order> exportAllOrders() {
return orderRepository.findAll(); // Loads 1M+ records
}-Xmx4g -Xms4gpublic void exportAllOrders(OutputStream output) {
int pageSize = 1000;
int page = 0;
Page<Order> orderPage;
do {
orderPage = orderRepository.findAll(
PageRequest.of(page++, pageSize)
);
writeToStream(orderPage.getContent(), output);
} while (orderPage.hasNext());
}@Scheduled(fixedRate = 60000)
public void checkMemoryUsage() {
MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
long used = memoryBean.getHeapMemoryUsage().getUsed();
long max = memoryBean.getHeapMemoryUsage().getMax();
if (used > max * 0.8) {
log.warn("High memory usage: {}%", (used * 100 / max));
}
}
## Best Practices You Always Apply
### Exception Handling
```java
// ❌ Bad
try {
service.process();
} catch (Exception e) {
e.printStackTrace();
}
// ✅ Good
try {
service.process();
} catch (BusinessException e) {
log.warn("Business validation failed: {}", e.getMessage());
throw e;
} catch (Exception e) {
log.error("Unexpected error in process", e);
throw new SystemException("Processing failed", e);
}// ❌ Bad
public String getUserName(User user) {
return user.getName();
}
// ✅ Good
public String getUserName(User user) {
return Optional.ofNullable(user)
.map(User::getName)
.orElse("Unknown");
}// ❌ Bad
InputStream is = new FileInputStream(file);
// forgot to close
// ✅ Good
try (InputStream is = new FileInputStream(file)) {
// use stream
} // automatically closed// ❌ Bad
private static final String API_URL = "http://api.example.com";
// ✅ Good
@Value("${api.url}")
private String apiUrl;// ❌ Bad
System.out.println("User: " + user);
log.debug("Processing order: " + order.getId());
// ✅ Good
log.info("User operation started, userId: {}", user.getId());
log.debug("Processing order, orderId: {}", order.getId());// ❌ Wrong: Transaction in loop
public void updateUsers(List<User> users) {
for (User user : users) {
updateUser(user); // Each call opens/closes transaction
}
}
// ✅ Correct: Single transaction
@Transactional
public void updateUsers(List<User> users) {
for (User user : users) {
userRepository.save(user);
}
}// ❌ LazyInitializationException
@Transactional
public User getUser(Long id) {
return userRepository.findById(id).orElse(null);
}
// Later: user.getOrders() fails - no session
// ✅ Fetch needed data
@Transactional
public User getUserWithOrders(Long id) {
return userRepository.findByIdWithOrders(id).orElse(null);
}// ❌ Stale cache after update
@Cacheable("users")
public User getUser(Long id) { ... }
public void updateUser(User user) {
userRepository.save(user);
// Cache still has old data!
}
// ✅ Invalidate cache
@CacheEvict(value = "users", key = "#user.id")
public void updateUser(User user) {
userRepository.save(user);
}