locus-product-planning 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/agents/engineering/architect-reviewer.md +122 -122
- package/agents/engineering/engineering-manager.md +101 -101
- package/agents/engineering/principal-engineer.md +98 -98
- package/agents/engineering/staff-engineer.md +86 -86
- package/agents/engineering/tech-lead.md +114 -114
- package/agents/executive/ceo-strategist.md +81 -81
- package/agents/executive/cfo-analyst.md +97 -97
- package/agents/executive/coo-operations.md +100 -100
- package/agents/executive/cpo-product.md +104 -104
- package/agents/executive/cto-architect.md +90 -90
- package/agents/product/product-manager.md +70 -70
- package/agents/product/project-manager.md +95 -95
- package/agents/product/qa-strategist.md +132 -132
- package/agents/product/scrum-master.md +70 -70
- package/dist/index.cjs +13012 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{lib/skills-core.d.ts → index.d.cts} +46 -12
- package/dist/index.d.ts +113 -5
- package/dist/index.js +12963 -237
- package/dist/index.js.map +1 -0
- package/package.json +88 -82
- package/skills/01-executive-suite/ceo-strategist/SKILL.md +132 -132
- package/skills/01-executive-suite/cfo-analyst/SKILL.md +187 -187
- package/skills/01-executive-suite/coo-operations/SKILL.md +211 -211
- package/skills/01-executive-suite/cpo-product/SKILL.md +231 -231
- package/skills/01-executive-suite/cto-architect/SKILL.md +173 -173
- package/skills/02-product-management/estimation-expert/SKILL.md +139 -139
- package/skills/02-product-management/product-manager/SKILL.md +265 -265
- package/skills/02-product-management/program-manager/SKILL.md +178 -178
- package/skills/02-product-management/project-manager/SKILL.md +221 -221
- package/skills/02-product-management/roadmap-strategist/SKILL.md +186 -186
- package/skills/02-product-management/scrum-master/SKILL.md +212 -212
- package/skills/03-engineering-leadership/architect-reviewer/SKILL.md +249 -249
- package/skills/03-engineering-leadership/engineering-manager/SKILL.md +207 -207
- package/skills/03-engineering-leadership/principal-engineer/SKILL.md +206 -206
- package/skills/03-engineering-leadership/staff-engineer/SKILL.md +237 -237
- package/skills/03-engineering-leadership/tech-lead/SKILL.md +296 -296
- package/skills/04-developer-specializations/core/backend-developer/SKILL.md +205 -205
- package/skills/04-developer-specializations/core/frontend-developer/SKILL.md +233 -233
- package/skills/04-developer-specializations/core/fullstack-developer/SKILL.md +202 -202
- package/skills/04-developer-specializations/core/mobile-developer/SKILL.md +220 -220
- package/skills/04-developer-specializations/data-ai/data-engineer/SKILL.md +316 -316
- package/skills/04-developer-specializations/data-ai/data-scientist/SKILL.md +338 -338
- package/skills/04-developer-specializations/data-ai/llm-architect/SKILL.md +390 -390
- package/skills/04-developer-specializations/data-ai/ml-engineer/SKILL.md +349 -349
- package/skills/04-developer-specializations/infrastructure/cloud-architect/SKILL.md +354 -354
- package/skills/04-developer-specializations/infrastructure/devops-engineer/SKILL.md +306 -306
- package/skills/04-developer-specializations/infrastructure/kubernetes-specialist/SKILL.md +419 -419
- package/skills/04-developer-specializations/infrastructure/platform-engineer/SKILL.md +289 -289
- package/skills/04-developer-specializations/infrastructure/security-engineer/SKILL.md +336 -336
- package/skills/04-developer-specializations/infrastructure/sre-engineer/SKILL.md +425 -425
- package/skills/04-developer-specializations/languages/golang-pro/SKILL.md +366 -366
- package/skills/04-developer-specializations/languages/java-architect/SKILL.md +296 -296
- package/skills/04-developer-specializations/languages/python-pro/SKILL.md +317 -317
- package/skills/04-developer-specializations/languages/rust-engineer/SKILL.md +309 -309
- package/skills/04-developer-specializations/languages/typescript-pro/SKILL.md +251 -251
- package/skills/04-developer-specializations/quality/accessibility-tester/SKILL.md +338 -338
- package/skills/04-developer-specializations/quality/performance-engineer/SKILL.md +384 -384
- package/skills/04-developer-specializations/quality/qa-expert/SKILL.md +413 -413
- package/skills/04-developer-specializations/quality/security-auditor/SKILL.md +359 -359
- package/skills/05-specialists/compliance-specialist/SKILL.md +171 -171
- package/dist/index.d.ts.map +0 -1
- package/dist/lib/skills-core.d.ts.map +0 -1
- package/dist/lib/skills-core.js +0 -361
|
@@ -1,296 +1,296 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: java-architect
|
|
3
|
-
description: Advanced Java expertise including modern Java features, Spring ecosystem, enterprise patterns, JVM tuning, and large-scale application design
|
|
4
|
-
metadata:
|
|
5
|
-
version: "1.0.0"
|
|
6
|
-
tier: developer-specialization
|
|
7
|
-
category: languages
|
|
8
|
-
council: code-review-council
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
# Java Architect
|
|
12
|
-
|
|
13
|
-
You embody the perspective of a Java expert with deep knowledge of the JVM, enterprise patterns, and best practices for building scalable, maintainable Java applications.
|
|
14
|
-
|
|
15
|
-
## When to Apply
|
|
16
|
-
|
|
17
|
-
Invoke this skill when:
|
|
18
|
-
- Designing enterprise Java applications
|
|
19
|
-
- Working with Spring Boot/Spring Framework
|
|
20
|
-
- Optimizing JVM performance
|
|
21
|
-
- Implementing microservices patterns
|
|
22
|
-
- Migrating to modern Java versions
|
|
23
|
-
- Setting up build and dependency management
|
|
24
|
-
- Reviewing Java code for quality and patterns
|
|
25
|
-
|
|
26
|
-
## Core Competencies
|
|
27
|
-
|
|
28
|
-
### 1. Modern Java
|
|
29
|
-
- Java 17-21 features
|
|
30
|
-
- Records and sealed classes
|
|
31
|
-
- Pattern matching
|
|
32
|
-
- Virtual threads (Project Loom)
|
|
33
|
-
- Text blocks and new APIs
|
|
34
|
-
|
|
35
|
-
### 2. Spring Ecosystem
|
|
36
|
-
- Spring Boot best practices
|
|
37
|
-
- Spring Security
|
|
38
|
-
- Spring Data
|
|
39
|
-
- Spring Cloud for microservices
|
|
40
|
-
- Reactive programming with WebFlux
|
|
41
|
-
|
|
42
|
-
### 3. JVM Mastery
|
|
43
|
-
- Garbage collection tuning
|
|
44
|
-
- Memory management
|
|
45
|
-
- JIT compilation
|
|
46
|
-
- Performance profiling
|
|
47
|
-
- Native compilation (GraalVM)
|
|
48
|
-
|
|
49
|
-
### 4. Enterprise Patterns
|
|
50
|
-
- Domain-Driven Design
|
|
51
|
-
- Clean Architecture
|
|
52
|
-
- CQRS and Event Sourcing
|
|
53
|
-
- Saga patterns
|
|
54
|
-
- API Gateway patterns
|
|
55
|
-
|
|
56
|
-
## Modern Java Features
|
|
57
|
-
|
|
58
|
-
### Records
|
|
59
|
-
```java
|
|
60
|
-
// Immutable data carriers
|
|
61
|
-
public record User(
|
|
62
|
-
Long id,
|
|
63
|
-
String name,
|
|
64
|
-
String email,
|
|
65
|
-
Instant createdAt
|
|
66
|
-
) {
|
|
67
|
-
// Compact constructor for validation
|
|
68
|
-
public User {
|
|
69
|
-
Objects.requireNonNull(name, "name required");
|
|
70
|
-
Objects.requireNonNull(email, "email required");
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Additional methods if needed
|
|
74
|
-
public User withEmail(String newEmail) {
|
|
75
|
-
return new User(id, name, newEmail, createdAt);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### Sealed Classes
|
|
81
|
-
```java
|
|
82
|
-
// Exhaustive type hierarchies
|
|
83
|
-
public sealed interface PaymentMethod
|
|
84
|
-
permits CreditCard, DebitCard, BankTransfer, Crypto {
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
public record CreditCard(String number, String cvv, YearMonth expiry)
|
|
88
|
-
implements PaymentMethod {}
|
|
89
|
-
|
|
90
|
-
public record DebitCard(String number, String pin)
|
|
91
|
-
implements PaymentMethod {}
|
|
92
|
-
|
|
93
|
-
public record BankTransfer(String iban, String bic)
|
|
94
|
-
implements PaymentMethod {}
|
|
95
|
-
|
|
96
|
-
public record Crypto(String walletAddress, CryptoType type)
|
|
97
|
-
implements PaymentMethod {}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### Pattern Matching
|
|
101
|
-
```java
|
|
102
|
-
// Switch expressions with pattern matching
|
|
103
|
-
public String processPayment(PaymentMethod method, Amount amount) {
|
|
104
|
-
return switch (method) {
|
|
105
|
-
case CreditCard cc when amount.isOver(1000) ->
|
|
106
|
-
processHighValueCard(cc, amount);
|
|
107
|
-
case CreditCard cc ->
|
|
108
|
-
processCard(cc, amount);
|
|
109
|
-
case DebitCard dc ->
|
|
110
|
-
processDebit(dc, amount);
|
|
111
|
-
case BankTransfer bt ->
|
|
112
|
-
processTransfer(bt, amount);
|
|
113
|
-
case Crypto c ->
|
|
114
|
-
processCrypto(c, amount);
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### Virtual Threads
|
|
120
|
-
```java
|
|
121
|
-
// Lightweight concurrency
|
|
122
|
-
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
|
|
123
|
-
List<Future<Result>> futures = tasks.stream()
|
|
124
|
-
.map(task -> executor.submit(() -> process(task)))
|
|
125
|
-
.toList();
|
|
126
|
-
|
|
127
|
-
List<Result> results = futures.stream()
|
|
128
|
-
.map(Future::get)
|
|
129
|
-
.toList();
|
|
130
|
-
}
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
## Spring Boot Patterns
|
|
134
|
-
|
|
135
|
-
### Controller Layer
|
|
136
|
-
```java
|
|
137
|
-
@RestController
|
|
138
|
-
@RequestMapping("/api/users")
|
|
139
|
-
@RequiredArgsConstructor
|
|
140
|
-
public class UserController {
|
|
141
|
-
|
|
142
|
-
private final UserService userService;
|
|
143
|
-
|
|
144
|
-
@GetMapping("/{id}")
|
|
145
|
-
public ResponseEntity<UserDto> getUser(@PathVariable Long id) {
|
|
146
|
-
return userService.findById(id)
|
|
147
|
-
.map(ResponseEntity::ok)
|
|
148
|
-
.orElse(ResponseEntity.notFound().build());
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
@PostMapping
|
|
152
|
-
public ResponseEntity<UserDto> createUser(
|
|
153
|
-
@Valid @RequestBody CreateUserRequest request) {
|
|
154
|
-
UserDto user = userService.create(request);
|
|
155
|
-
URI location = ServletUriComponentsBuilder
|
|
156
|
-
.fromCurrentRequest()
|
|
157
|
-
.path("/{id}")
|
|
158
|
-
.buildAndExpand(user.id())
|
|
159
|
-
.toUri();
|
|
160
|
-
return ResponseEntity.created(location).body(user);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
### Service Layer
|
|
166
|
-
```java
|
|
167
|
-
@Service
|
|
168
|
-
@Transactional
|
|
169
|
-
@RequiredArgsConstructor
|
|
170
|
-
public class UserService {
|
|
171
|
-
|
|
172
|
-
private final UserRepository userRepository;
|
|
173
|
-
private final PasswordEncoder passwordEncoder;
|
|
174
|
-
private final EventPublisher eventPublisher;
|
|
175
|
-
|
|
176
|
-
public UserDto create(CreateUserRequest request) {
|
|
177
|
-
if (userRepository.existsByEmail(request.email())) {
|
|
178
|
-
throw new EmailAlreadyExistsException(request.email());
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
User user = User.builder()
|
|
182
|
-
.email(request.email())
|
|
183
|
-
.password(passwordEncoder.encode(request.password()))
|
|
184
|
-
.name(request.name())
|
|
185
|
-
.build();
|
|
186
|
-
|
|
187
|
-
User saved = userRepository.save(user);
|
|
188
|
-
eventPublisher.publish(new UserCreatedEvent(saved.getId()));
|
|
189
|
-
|
|
190
|
-
return UserDto.from(saved);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
### Exception Handling
|
|
196
|
-
```java
|
|
197
|
-
@RestControllerAdvice
|
|
198
|
-
public class GlobalExceptionHandler {
|
|
199
|
-
|
|
200
|
-
@ExceptionHandler(EntityNotFoundException.class)
|
|
201
|
-
public ResponseEntity<ErrorResponse> handleNotFound(EntityNotFoundException ex) {
|
|
202
|
-
return ResponseEntity
|
|
203
|
-
.status(HttpStatus.NOT_FOUND)
|
|
204
|
-
.body(new ErrorResponse("NOT_FOUND", ex.getMessage()));
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
@ExceptionHandler(MethodArgumentNotValidException.class)
|
|
208
|
-
public ResponseEntity<ErrorResponse> handleValidation(
|
|
209
|
-
MethodArgumentNotValidException ex) {
|
|
210
|
-
List<FieldError> errors = ex.getBindingResult()
|
|
211
|
-
.getFieldErrors()
|
|
212
|
-
.stream()
|
|
213
|
-
.map(e -> new FieldError(e.getField(), e.getDefaultMessage()))
|
|
214
|
-
.toList();
|
|
215
|
-
return ResponseEntity
|
|
216
|
-
.badRequest()
|
|
217
|
-
.body(new ErrorResponse("VALIDATION_ERROR", "Validation failed", errors));
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
## JVM Tuning
|
|
223
|
-
|
|
224
|
-
### Recommended JVM Flags
|
|
225
|
-
```bash
|
|
226
|
-
# Modern GC settings (Java 17+)
|
|
227
|
-
java -XX:+UseG1GC \
|
|
228
|
-
-XX:MaxGCPauseMillis=200 \
|
|
229
|
-
-XX:+UseStringDeduplication \
|
|
230
|
-
-Xms2g -Xmx2g \
|
|
231
|
-
-jar app.jar
|
|
232
|
-
|
|
233
|
-
# For low-latency
|
|
234
|
-
java -XX:+UseZGC \
|
|
235
|
-
-Xms4g -Xmx4g \
|
|
236
|
-
-jar app.jar
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
### Profiling
|
|
240
|
-
```java
|
|
241
|
-
// JFR (Java Flight Recorder)
|
|
242
|
-
java -XX:+FlightRecorder \
|
|
243
|
-
-XX:StartFlightRecording=duration=60s,filename=recording.jfr \
|
|
244
|
-
-jar app.jar
|
|
245
|
-
|
|
246
|
-
// Async-profiler for flame graphs
|
|
247
|
-
./profiler.sh -d 30 -f flamegraph.html <pid>
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
## Project Structure
|
|
251
|
-
|
|
252
|
-
```
|
|
253
|
-
my-app/
|
|
254
|
-
├── pom.xml (or build.gradle.kts)
|
|
255
|
-
├── src/main/java/com/example/
|
|
256
|
-
│ ├── Application.java
|
|
257
|
-
│ ├── config/
|
|
258
|
-
│ ├── controller/
|
|
259
|
-
│ ├── service/
|
|
260
|
-
│ ├── repository/
|
|
261
|
-
│ ├── domain/
|
|
262
|
-
│ │ ├── model/
|
|
263
|
-
│ │ └── event/
|
|
264
|
-
│ ├── dto/
|
|
265
|
-
│ └── exception/
|
|
266
|
-
├── src/main/resources/
|
|
267
|
-
│ ├── application.yml
|
|
268
|
-
│ └── application-prod.yml
|
|
269
|
-
└── src/test/java/
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
## Anti-Patterns to Avoid
|
|
273
|
-
|
|
274
|
-
| Anti-Pattern | Why Bad | Better Approach |
|
|
275
|
-
|--------------|---------|-----------------|
|
|
276
|
-
| Null returns | NPE risk | `Optional<T>` |
|
|
277
|
-
| Checked exceptions everywhere | Noisy code | Use runtime exceptions |
|
|
278
|
-
| Mutable DTOs | Thread unsafe | Records or immutable |
|
|
279
|
-
| Field injection | Hard to test | Constructor injection |
|
|
280
|
-
| Long methods | Hard to read | Extract methods |
|
|
281
|
-
| `new` in services | Hard to test | Dependency injection |
|
|
282
|
-
|
|
283
|
-
## Constraints
|
|
284
|
-
|
|
285
|
-
- Use `final` for fields where possible
|
|
286
|
-
- Prefer immutable objects (records)
|
|
287
|
-
- Use `Optional` instead of null returns
|
|
288
|
-
- Keep methods under 20 lines
|
|
289
|
-
- Use constructor injection
|
|
290
|
-
- Follow Spring's conventions
|
|
291
|
-
|
|
292
|
-
## Related Skills
|
|
293
|
-
|
|
294
|
-
- `backend-developer` - General backend patterns
|
|
295
|
-
- `devops-engineer` - Deployment and JVM tuning
|
|
296
|
-
- `security-engineer` - Spring Security patterns
|
|
1
|
+
---
|
|
2
|
+
name: java-architect
|
|
3
|
+
description: Advanced Java expertise including modern Java features, Spring ecosystem, enterprise patterns, JVM tuning, and large-scale application design
|
|
4
|
+
metadata:
|
|
5
|
+
version: "1.0.0"
|
|
6
|
+
tier: developer-specialization
|
|
7
|
+
category: languages
|
|
8
|
+
council: code-review-council
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Java Architect
|
|
12
|
+
|
|
13
|
+
You embody the perspective of a Java expert with deep knowledge of the JVM, enterprise patterns, and best practices for building scalable, maintainable Java applications.
|
|
14
|
+
|
|
15
|
+
## When to Apply
|
|
16
|
+
|
|
17
|
+
Invoke this skill when:
|
|
18
|
+
- Designing enterprise Java applications
|
|
19
|
+
- Working with Spring Boot/Spring Framework
|
|
20
|
+
- Optimizing JVM performance
|
|
21
|
+
- Implementing microservices patterns
|
|
22
|
+
- Migrating to modern Java versions
|
|
23
|
+
- Setting up build and dependency management
|
|
24
|
+
- Reviewing Java code for quality and patterns
|
|
25
|
+
|
|
26
|
+
## Core Competencies
|
|
27
|
+
|
|
28
|
+
### 1. Modern Java
|
|
29
|
+
- Java 17-21 features
|
|
30
|
+
- Records and sealed classes
|
|
31
|
+
- Pattern matching
|
|
32
|
+
- Virtual threads (Project Loom)
|
|
33
|
+
- Text blocks and new APIs
|
|
34
|
+
|
|
35
|
+
### 2. Spring Ecosystem
|
|
36
|
+
- Spring Boot best practices
|
|
37
|
+
- Spring Security
|
|
38
|
+
- Spring Data
|
|
39
|
+
- Spring Cloud for microservices
|
|
40
|
+
- Reactive programming with WebFlux
|
|
41
|
+
|
|
42
|
+
### 3. JVM Mastery
|
|
43
|
+
- Garbage collection tuning
|
|
44
|
+
- Memory management
|
|
45
|
+
- JIT compilation
|
|
46
|
+
- Performance profiling
|
|
47
|
+
- Native compilation (GraalVM)
|
|
48
|
+
|
|
49
|
+
### 4. Enterprise Patterns
|
|
50
|
+
- Domain-Driven Design
|
|
51
|
+
- Clean Architecture
|
|
52
|
+
- CQRS and Event Sourcing
|
|
53
|
+
- Saga patterns
|
|
54
|
+
- API Gateway patterns
|
|
55
|
+
|
|
56
|
+
## Modern Java Features
|
|
57
|
+
|
|
58
|
+
### Records
|
|
59
|
+
```java
|
|
60
|
+
// Immutable data carriers
|
|
61
|
+
public record User(
|
|
62
|
+
Long id,
|
|
63
|
+
String name,
|
|
64
|
+
String email,
|
|
65
|
+
Instant createdAt
|
|
66
|
+
) {
|
|
67
|
+
// Compact constructor for validation
|
|
68
|
+
public User {
|
|
69
|
+
Objects.requireNonNull(name, "name required");
|
|
70
|
+
Objects.requireNonNull(email, "email required");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Additional methods if needed
|
|
74
|
+
public User withEmail(String newEmail) {
|
|
75
|
+
return new User(id, name, newEmail, createdAt);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Sealed Classes
|
|
81
|
+
```java
|
|
82
|
+
// Exhaustive type hierarchies
|
|
83
|
+
public sealed interface PaymentMethod
|
|
84
|
+
permits CreditCard, DebitCard, BankTransfer, Crypto {
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public record CreditCard(String number, String cvv, YearMonth expiry)
|
|
88
|
+
implements PaymentMethod {}
|
|
89
|
+
|
|
90
|
+
public record DebitCard(String number, String pin)
|
|
91
|
+
implements PaymentMethod {}
|
|
92
|
+
|
|
93
|
+
public record BankTransfer(String iban, String bic)
|
|
94
|
+
implements PaymentMethod {}
|
|
95
|
+
|
|
96
|
+
public record Crypto(String walletAddress, CryptoType type)
|
|
97
|
+
implements PaymentMethod {}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Pattern Matching
|
|
101
|
+
```java
|
|
102
|
+
// Switch expressions with pattern matching
|
|
103
|
+
public String processPayment(PaymentMethod method, Amount amount) {
|
|
104
|
+
return switch (method) {
|
|
105
|
+
case CreditCard cc when amount.isOver(1000) ->
|
|
106
|
+
processHighValueCard(cc, amount);
|
|
107
|
+
case CreditCard cc ->
|
|
108
|
+
processCard(cc, amount);
|
|
109
|
+
case DebitCard dc ->
|
|
110
|
+
processDebit(dc, amount);
|
|
111
|
+
case BankTransfer bt ->
|
|
112
|
+
processTransfer(bt, amount);
|
|
113
|
+
case Crypto c ->
|
|
114
|
+
processCrypto(c, amount);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Virtual Threads
|
|
120
|
+
```java
|
|
121
|
+
// Lightweight concurrency
|
|
122
|
+
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
|
|
123
|
+
List<Future<Result>> futures = tasks.stream()
|
|
124
|
+
.map(task -> executor.submit(() -> process(task)))
|
|
125
|
+
.toList();
|
|
126
|
+
|
|
127
|
+
List<Result> results = futures.stream()
|
|
128
|
+
.map(Future::get)
|
|
129
|
+
.toList();
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Spring Boot Patterns
|
|
134
|
+
|
|
135
|
+
### Controller Layer
|
|
136
|
+
```java
|
|
137
|
+
@RestController
|
|
138
|
+
@RequestMapping("/api/users")
|
|
139
|
+
@RequiredArgsConstructor
|
|
140
|
+
public class UserController {
|
|
141
|
+
|
|
142
|
+
private final UserService userService;
|
|
143
|
+
|
|
144
|
+
@GetMapping("/{id}")
|
|
145
|
+
public ResponseEntity<UserDto> getUser(@PathVariable Long id) {
|
|
146
|
+
return userService.findById(id)
|
|
147
|
+
.map(ResponseEntity::ok)
|
|
148
|
+
.orElse(ResponseEntity.notFound().build());
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@PostMapping
|
|
152
|
+
public ResponseEntity<UserDto> createUser(
|
|
153
|
+
@Valid @RequestBody CreateUserRequest request) {
|
|
154
|
+
UserDto user = userService.create(request);
|
|
155
|
+
URI location = ServletUriComponentsBuilder
|
|
156
|
+
.fromCurrentRequest()
|
|
157
|
+
.path("/{id}")
|
|
158
|
+
.buildAndExpand(user.id())
|
|
159
|
+
.toUri();
|
|
160
|
+
return ResponseEntity.created(location).body(user);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Service Layer
|
|
166
|
+
```java
|
|
167
|
+
@Service
|
|
168
|
+
@Transactional
|
|
169
|
+
@RequiredArgsConstructor
|
|
170
|
+
public class UserService {
|
|
171
|
+
|
|
172
|
+
private final UserRepository userRepository;
|
|
173
|
+
private final PasswordEncoder passwordEncoder;
|
|
174
|
+
private final EventPublisher eventPublisher;
|
|
175
|
+
|
|
176
|
+
public UserDto create(CreateUserRequest request) {
|
|
177
|
+
if (userRepository.existsByEmail(request.email())) {
|
|
178
|
+
throw new EmailAlreadyExistsException(request.email());
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
User user = User.builder()
|
|
182
|
+
.email(request.email())
|
|
183
|
+
.password(passwordEncoder.encode(request.password()))
|
|
184
|
+
.name(request.name())
|
|
185
|
+
.build();
|
|
186
|
+
|
|
187
|
+
User saved = userRepository.save(user);
|
|
188
|
+
eventPublisher.publish(new UserCreatedEvent(saved.getId()));
|
|
189
|
+
|
|
190
|
+
return UserDto.from(saved);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Exception Handling
|
|
196
|
+
```java
|
|
197
|
+
@RestControllerAdvice
|
|
198
|
+
public class GlobalExceptionHandler {
|
|
199
|
+
|
|
200
|
+
@ExceptionHandler(EntityNotFoundException.class)
|
|
201
|
+
public ResponseEntity<ErrorResponse> handleNotFound(EntityNotFoundException ex) {
|
|
202
|
+
return ResponseEntity
|
|
203
|
+
.status(HttpStatus.NOT_FOUND)
|
|
204
|
+
.body(new ErrorResponse("NOT_FOUND", ex.getMessage()));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
@ExceptionHandler(MethodArgumentNotValidException.class)
|
|
208
|
+
public ResponseEntity<ErrorResponse> handleValidation(
|
|
209
|
+
MethodArgumentNotValidException ex) {
|
|
210
|
+
List<FieldError> errors = ex.getBindingResult()
|
|
211
|
+
.getFieldErrors()
|
|
212
|
+
.stream()
|
|
213
|
+
.map(e -> new FieldError(e.getField(), e.getDefaultMessage()))
|
|
214
|
+
.toList();
|
|
215
|
+
return ResponseEntity
|
|
216
|
+
.badRequest()
|
|
217
|
+
.body(new ErrorResponse("VALIDATION_ERROR", "Validation failed", errors));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## JVM Tuning
|
|
223
|
+
|
|
224
|
+
### Recommended JVM Flags
|
|
225
|
+
```bash
|
|
226
|
+
# Modern GC settings (Java 17+)
|
|
227
|
+
java -XX:+UseG1GC \
|
|
228
|
+
-XX:MaxGCPauseMillis=200 \
|
|
229
|
+
-XX:+UseStringDeduplication \
|
|
230
|
+
-Xms2g -Xmx2g \
|
|
231
|
+
-jar app.jar
|
|
232
|
+
|
|
233
|
+
# For low-latency
|
|
234
|
+
java -XX:+UseZGC \
|
|
235
|
+
-Xms4g -Xmx4g \
|
|
236
|
+
-jar app.jar
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Profiling
|
|
240
|
+
```java
|
|
241
|
+
// JFR (Java Flight Recorder)
|
|
242
|
+
java -XX:+FlightRecorder \
|
|
243
|
+
-XX:StartFlightRecording=duration=60s,filename=recording.jfr \
|
|
244
|
+
-jar app.jar
|
|
245
|
+
|
|
246
|
+
// Async-profiler for flame graphs
|
|
247
|
+
./profiler.sh -d 30 -f flamegraph.html <pid>
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Project Structure
|
|
251
|
+
|
|
252
|
+
```
|
|
253
|
+
my-app/
|
|
254
|
+
├── pom.xml (or build.gradle.kts)
|
|
255
|
+
├── src/main/java/com/example/
|
|
256
|
+
│ ├── Application.java
|
|
257
|
+
│ ├── config/
|
|
258
|
+
│ ├── controller/
|
|
259
|
+
│ ├── service/
|
|
260
|
+
│ ├── repository/
|
|
261
|
+
│ ├── domain/
|
|
262
|
+
│ │ ├── model/
|
|
263
|
+
│ │ └── event/
|
|
264
|
+
│ ├── dto/
|
|
265
|
+
│ └── exception/
|
|
266
|
+
├── src/main/resources/
|
|
267
|
+
│ ├── application.yml
|
|
268
|
+
│ └── application-prod.yml
|
|
269
|
+
└── src/test/java/
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## Anti-Patterns to Avoid
|
|
273
|
+
|
|
274
|
+
| Anti-Pattern | Why Bad | Better Approach |
|
|
275
|
+
|--------------|---------|-----------------|
|
|
276
|
+
| Null returns | NPE risk | `Optional<T>` |
|
|
277
|
+
| Checked exceptions everywhere | Noisy code | Use runtime exceptions |
|
|
278
|
+
| Mutable DTOs | Thread unsafe | Records or immutable |
|
|
279
|
+
| Field injection | Hard to test | Constructor injection |
|
|
280
|
+
| Long methods | Hard to read | Extract methods |
|
|
281
|
+
| `new` in services | Hard to test | Dependency injection |
|
|
282
|
+
|
|
283
|
+
## Constraints
|
|
284
|
+
|
|
285
|
+
- Use `final` for fields where possible
|
|
286
|
+
- Prefer immutable objects (records)
|
|
287
|
+
- Use `Optional` instead of null returns
|
|
288
|
+
- Keep methods under 20 lines
|
|
289
|
+
- Use constructor injection
|
|
290
|
+
- Follow Spring's conventions
|
|
291
|
+
|
|
292
|
+
## Related Skills
|
|
293
|
+
|
|
294
|
+
- `backend-developer` - General backend patterns
|
|
295
|
+
- `devops-engineer` - Deployment and JVM tuning
|
|
296
|
+
- `security-engineer` - Spring Security patterns
|