aw-spec-cli 0.1.10 → 0.1.11
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/assets/.appweaver/ORCH-DIALECT.md +17 -5
- package/assets/.appweaver/orchestrator/README.md +1 -1
- package/assets/.appweaver/orchestrator/adapters/claude_agent_sdk.py +2 -2
- package/assets/.appweaver/orchestrator/adapters/google_antigravity.py +28 -6
- package/assets/.appweaver/orchestrator/modules/delta-spec.orch.yaml +13 -1
- package/assets/.appweaver/orchestrator/orchestrator.py +126 -39
- package/assets/.appweaver/orchestrator/workflows/aw-spec-adopt.orch.yaml +5 -0
- package/assets/.appweaver/orchestrator/workflows/aw-spec-characterize.orch.yaml +1 -0
- package/assets/.appweaver/orchestrator/workflows/aw-spec-onboard.orch.yaml +1 -0
- package/assets/.appweaver/orchestrator/workflows/aw-spec-specify.orch.yaml +888 -141
- package/assets/.appweaver/scripts/bash/aw-spec-actions.sh +826 -16
- package/assets/.appweaver/scripts/powershell/aw-spec-actions.ps1 +780 -12
- package/assets/.appweaver/stack-profiles/java-spring.json +3 -3
- package/assets/.appweaver/templates/spec-template.md +73 -62
- package/assets/.appweaver/templates/story-template.md +107 -0
- package/assets/guardrails/technology/java-spring/ai-rules.md +505 -0
- package/assets/guardrails/technology/java-spring/api-versioning.md +782 -0
- package/assets/guardrails/technology/java-spring/authorization.md +618 -0
- package/assets/guardrails/technology/java-spring/clean-architecture.md +960 -0
- package/assets/guardrails/technology/java-spring/coding-standards.md +821 -0
- package/assets/guardrails/technology/java-spring/dependency-policy.md +91 -0
- package/assets/guardrails/technology/java-spring/domain-driven-design.md +467 -0
- package/assets/guardrails/technology/java-spring/domain_abstraction.md +424 -0
- package/assets/guardrails/technology/java-spring/folder-structure.md +1537 -0
- package/assets/guardrails/technology/java-spring/global_exception_handler.md +247 -0
- package/assets/guardrails/technology/java-spring/logging.md +215 -0
- package/assets/guardrails/technology/java-spring/modular-monolith.md +77 -0
- package/assets/guardrails/technology/java-spring/persistence.md +316 -0
- package/assets/guardrails/technology/java-spring/problem_details.md +98 -0
- package/assets/guardrails/technology/java-spring/result_mapping.md +48 -0
- package/assets/guardrails/technology/java-spring/technology-constitution.md +168 -0
- package/assets/guardrails/technology/java-spring/testing.md +601 -0
- package/assets/guardrails/technology/java-spring/zero-trust.md +210 -0
- package/dist/index.js +0 -0
- package/dist/utils/config.d.ts +22 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +76 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/copy-assets.d.ts.map +1 -1
- package/dist/utils/copy-assets.js +4 -11
- package/dist/utils/copy-assets.js.map +1 -1
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +11 -7
- package/dist/utils/paths.js.map +1 -1
- package/package.json +2 -1
- package/assets/guardrails/technology/java-spring/README.md +0 -62
- package/dist/commands/update.d.ts +0 -3
- package/dist/commands/update.d.ts.map +0 -1
- package/dist/commands/update.js +0 -142
- package/dist/commands/update.js.map +0 -1
- package/dist/utils/manifest.d.ts +0 -31
- package/dist/utils/manifest.d.ts.map +0 -1
- package/dist/utils/manifest.js +0 -91
- package/dist/utils/manifest.js.map +0 -1
- package/dist/utils/update-engine.d.ts +0 -52
- package/dist/utils/update-engine.d.ts.map +0 -1
- package/dist/utils/update-engine.js +0 -203
- package/dist/utils/update-engine.js.map +0 -1
|
@@ -0,0 +1,821 @@
|
|
|
1
|
+
# Java Coding Standards
|
|
2
|
+
|
|
3
|
+
> Pure technology (domain-agnostic).
|
|
4
|
+
>
|
|
5
|
+
> Defines generic Java coding and implementation standards for AppWeaver applications.
|
|
6
|
+
>
|
|
7
|
+
> See also: `dependency-policy.md`, `ai-rules.md`.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 1. Java Version
|
|
12
|
+
|
|
13
|
+
- The project MUST use the Java version defined by its active build configuration.
|
|
14
|
+
|
|
15
|
+
- Java 21 SHOULD be the default AppWeaver Java baseline unless the project explicitly defines another supported version.
|
|
16
|
+
|
|
17
|
+
- The configured Java version MUST be consistent across:
|
|
18
|
+
- local development;
|
|
19
|
+
- build configuration;
|
|
20
|
+
- CI;
|
|
21
|
+
- testing;
|
|
22
|
+
- deployment.
|
|
23
|
+
|
|
24
|
+
- Production code MUST NOT depend on APIs introduced in a newer Java version than the configured project version.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 2. Naming Conventions
|
|
29
|
+
|
|
30
|
+
### Packages
|
|
31
|
+
|
|
32
|
+
- Package names MUST use lowercase characters.
|
|
33
|
+
|
|
34
|
+
- Package names MUST follow standard Java naming conventions.
|
|
35
|
+
|
|
36
|
+
### Classes and Interfaces
|
|
37
|
+
|
|
38
|
+
- Classes, interfaces, records, enums, and annotations MUST use `PascalCase`.
|
|
39
|
+
|
|
40
|
+
Examples:
|
|
41
|
+
|
|
42
|
+
```text
|
|
43
|
+
Booking
|
|
44
|
+
CreateBookingUseCase
|
|
45
|
+
BookingResponse
|
|
46
|
+
BookingStatus
|
|
47
|
+
````
|
|
48
|
+
|
|
49
|
+
### Methods and Variables
|
|
50
|
+
|
|
51
|
+
* Methods, fields, parameters, and local variables MUST use `camelCase`.
|
|
52
|
+
|
|
53
|
+
Examples:
|
|
54
|
+
|
|
55
|
+
```text
|
|
56
|
+
createBooking()
|
|
57
|
+
bookingId
|
|
58
|
+
customerName
|
|
59
|
+
flightNumber
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Constants
|
|
63
|
+
|
|
64
|
+
* Constants MUST use `UPPER_SNAKE_CASE`.
|
|
65
|
+
|
|
66
|
+
Example:
|
|
67
|
+
|
|
68
|
+
```java
|
|
69
|
+
private static final int MAX_RETRY_COUNT = 3;
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Boolean Names
|
|
73
|
+
|
|
74
|
+
Boolean variables and methods SHOULD use meaningful prefixes such as:
|
|
75
|
+
|
|
76
|
+
```text
|
|
77
|
+
is
|
|
78
|
+
has
|
|
79
|
+
can
|
|
80
|
+
should
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Examples:
|
|
84
|
+
|
|
85
|
+
```text
|
|
86
|
+
isActive
|
|
87
|
+
hasPermission
|
|
88
|
+
canRetry
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 3. Type Safety
|
|
94
|
+
|
|
95
|
+
* Production code MUST be type-safe.
|
|
96
|
+
|
|
97
|
+
* Raw types are forbidden.
|
|
98
|
+
|
|
99
|
+
* Unchecked casts SHOULD be avoided.
|
|
100
|
+
|
|
101
|
+
* Unchecked compiler warnings SHOULD be eliminated.
|
|
102
|
+
|
|
103
|
+
* Generic collections MUST specify their element type.
|
|
104
|
+
|
|
105
|
+
Incorrect:
|
|
106
|
+
|
|
107
|
+
```java
|
|
108
|
+
List items;
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Correct:
|
|
112
|
+
|
|
113
|
+
```java
|
|
114
|
+
List<String> items;
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
* `Object` SHOULD NOT be used when a more specific type can express the contract.
|
|
118
|
+
|
|
119
|
+
* Type casts SHOULD be minimized.
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## 4. Optional
|
|
124
|
+
|
|
125
|
+
* `Optional` MAY be used as a return type when absence is a meaningful result.
|
|
126
|
+
|
|
127
|
+
Example:
|
|
128
|
+
|
|
129
|
+
```java
|
|
130
|
+
Optional<Booking> findBooking(BookingId id);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
* `Optional` SHOULD NOT normally be used for:
|
|
134
|
+
|
|
135
|
+
* method parameters;
|
|
136
|
+
* entity fields;
|
|
137
|
+
* DTO fields;
|
|
138
|
+
* command fields;
|
|
139
|
+
* query fields.
|
|
140
|
+
|
|
141
|
+
* `Optional` MUST NOT be used merely to avoid handling `null`.
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## 5. Immutability
|
|
146
|
+
|
|
147
|
+
* Immutable objects SHOULD be preferred where practical.
|
|
148
|
+
|
|
149
|
+
* Mutable state MUST be minimized.
|
|
150
|
+
|
|
151
|
+
* Fields that do not change after construction SHOULD be declared `final`.
|
|
152
|
+
|
|
153
|
+
* Constructor-injected dependencies SHOULD be stored in `final` fields.
|
|
154
|
+
|
|
155
|
+
* Static mutable state is forbidden unless explicitly justified and proven safe.
|
|
156
|
+
|
|
157
|
+
* Public APIs SHOULD avoid exposing mutable internal collections.
|
|
158
|
+
|
|
159
|
+
Prefer:
|
|
160
|
+
|
|
161
|
+
```java
|
|
162
|
+
public List<String> names() {
|
|
163
|
+
return List.copyOf(names);
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
over exposing a mutable internal collection directly.
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## 6. Java Records
|
|
172
|
+
|
|
173
|
+
Java records SHOULD be used for immutable data carriers where appropriate.
|
|
174
|
+
|
|
175
|
+
Suitable use cases include:
|
|
176
|
+
|
|
177
|
+
* API request/response models;
|
|
178
|
+
* commands;
|
|
179
|
+
* queries;
|
|
180
|
+
* immutable results;
|
|
181
|
+
* simple value objects;
|
|
182
|
+
* configuration data.
|
|
183
|
+
|
|
184
|
+
Records SHOULD NOT be used when the object requires substantial mutable state or lifecycle behavior.
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## 7. Collections
|
|
189
|
+
|
|
190
|
+
* Use the most appropriate collection type for the required behavior.
|
|
191
|
+
|
|
192
|
+
Examples:
|
|
193
|
+
|
|
194
|
+
```text
|
|
195
|
+
List → ordered collection
|
|
196
|
+
Set → unique elements
|
|
197
|
+
Map → key/value lookup
|
|
198
|
+
Queue → processing order
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
* Do not expose mutable internal collections unnecessarily.
|
|
202
|
+
|
|
203
|
+
* Prefer immutable collection factories when mutation is not required:
|
|
204
|
+
|
|
205
|
+
```java
|
|
206
|
+
List.of(...)
|
|
207
|
+
Set.of(...)
|
|
208
|
+
Map.of(...)
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
* Avoid unnecessary conversions between collection types.
|
|
212
|
+
|
|
213
|
+
* Collection operations SHOULD remain readable rather than using unnecessarily complex streams.
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## 8. Strings
|
|
218
|
+
|
|
219
|
+
* Use `String` for textual data.
|
|
220
|
+
|
|
221
|
+
* Avoid unnecessary string concatenation in loops.
|
|
222
|
+
|
|
223
|
+
* Use `StringBuilder` when repeated mutable string construction is required.
|
|
224
|
+
|
|
225
|
+
* Use text blocks for large multiline string literals where they improve readability.
|
|
226
|
+
|
|
227
|
+
* String comparisons MUST use value comparison:
|
|
228
|
+
|
|
229
|
+
```java
|
|
230
|
+
if ("ACTIVE".equals(status)) {
|
|
231
|
+
...
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
or:
|
|
236
|
+
|
|
237
|
+
```java
|
|
238
|
+
if (status.equals("ACTIVE")) {
|
|
239
|
+
...
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
when nullability is guaranteed.
|
|
244
|
+
|
|
245
|
+
Do not use:
|
|
246
|
+
|
|
247
|
+
```java
|
|
248
|
+
status == "ACTIVE"
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
for string value comparison.
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## 9. Null Handling
|
|
256
|
+
|
|
257
|
+
* Nullability MUST be intentional.
|
|
258
|
+
|
|
259
|
+
* Methods SHOULD avoid returning `null` when a meaningful empty representation exists.
|
|
260
|
+
|
|
261
|
+
Examples:
|
|
262
|
+
|
|
263
|
+
```text
|
|
264
|
+
Optional<T>
|
|
265
|
+
empty collection
|
|
266
|
+
empty result
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
* `null` MUST NOT be silently propagated through multiple layers.
|
|
270
|
+
|
|
271
|
+
* Null checks SHOULD occur at the appropriate boundary.
|
|
272
|
+
|
|
273
|
+
* `Objects.requireNonNull()` MAY be used when null is an invalid programmer input.
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
## 10. Exception Handling
|
|
278
|
+
|
|
279
|
+
* Exceptions MUST represent meaningful failure conditions.
|
|
280
|
+
|
|
281
|
+
* Exceptions MUST NOT be used for normal control flow.
|
|
282
|
+
|
|
283
|
+
* Catch blocks MUST NOT silently swallow exceptions.
|
|
284
|
+
|
|
285
|
+
Incorrect:
|
|
286
|
+
|
|
287
|
+
```java
|
|
288
|
+
try {
|
|
289
|
+
process();
|
|
290
|
+
} catch (Exception ignored) {
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
* Exceptions MUST be handled, translated, rethrown, or propagated appropriately.
|
|
295
|
+
|
|
296
|
+
* When wrapping an exception, the original cause MUST be preserved.
|
|
297
|
+
|
|
298
|
+
Example:
|
|
299
|
+
|
|
300
|
+
```java
|
|
301
|
+
throw new ProcessingException("Unable to process booking", cause);
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
* Catch the most specific exception type that can be handled.
|
|
305
|
+
|
|
306
|
+
Avoid unnecessarily broad catches such as:
|
|
307
|
+
|
|
308
|
+
```java
|
|
309
|
+
catch (Exception e)
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
unless centralized error handling genuinely requires it.
|
|
313
|
+
|
|
314
|
+
* Error messages MUST NOT contain secrets, credentials, tokens, or sensitive information.
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
## 11. Resource Management
|
|
319
|
+
|
|
320
|
+
Resources that implement `AutoCloseable` MUST normally use try-with-resources.
|
|
321
|
+
|
|
322
|
+
Preferred:
|
|
323
|
+
|
|
324
|
+
```java
|
|
325
|
+
try (InputStream input = resource.getInputStream()) {
|
|
326
|
+
// ...
|
|
327
|
+
}
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
Avoid manually managing resource closure when try-with-resources is applicable.
|
|
331
|
+
|
|
332
|
+
Resources such as:
|
|
333
|
+
|
|
334
|
+
* streams;
|
|
335
|
+
* readers;
|
|
336
|
+
* writers;
|
|
337
|
+
* JDBC resources;
|
|
338
|
+
* files;
|
|
339
|
+
|
|
340
|
+
MUST be closed appropriately.
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
## 12. Date and Time
|
|
345
|
+
|
|
346
|
+
* Use the `java.time` API for new development.
|
|
347
|
+
|
|
348
|
+
Preferred types include:
|
|
349
|
+
|
|
350
|
+
```text
|
|
351
|
+
Instant
|
|
352
|
+
LocalDate
|
|
353
|
+
LocalDateTime
|
|
354
|
+
OffsetDateTime
|
|
355
|
+
ZonedDateTime
|
|
356
|
+
Duration
|
|
357
|
+
Period
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
* Avoid legacy date/time APIs such as:
|
|
361
|
+
|
|
362
|
+
```text
|
|
363
|
+
java.util.Date
|
|
364
|
+
java.util.Calendar
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
for new code unless required for interoperability.
|
|
368
|
+
|
|
369
|
+
* The correct temporal type MUST be selected according to the meaning of the value.
|
|
370
|
+
|
|
371
|
+
Examples:
|
|
372
|
+
|
|
373
|
+
```text
|
|
374
|
+
LocalDate → date without time
|
|
375
|
+
Instant → point in time
|
|
376
|
+
Duration → elapsed time
|
|
377
|
+
Period → calendar-based amount
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
* Time-zone assumptions MUST be explicit where relevant.
|
|
381
|
+
|
|
382
|
+
---
|
|
383
|
+
|
|
384
|
+
## 13. Equality and Hashing
|
|
385
|
+
|
|
386
|
+
Classes that define value-based equality MUST implement `equals()` and `hashCode()` consistently.
|
|
387
|
+
|
|
388
|
+
The following contract MUST be preserved:
|
|
389
|
+
|
|
390
|
+
```text
|
|
391
|
+
a.equals(b) == true
|
|
392
|
+
↓
|
|
393
|
+
a.hashCode() == b.hashCode()
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
* `equals()` MUST be reflexive, symmetric, transitive, consistent, and false for `null`.
|
|
397
|
+
|
|
398
|
+
* Mutable fields that participate in `hashCode()` SHOULD be avoided.
|
|
399
|
+
|
|
400
|
+
* Java records SHOULD be preferred for simple immutable value-based data where appropriate.
|
|
401
|
+
|
|
402
|
+
---
|
|
403
|
+
|
|
404
|
+
## 14. Enums
|
|
405
|
+
|
|
406
|
+
* Enums SHOULD be used when a value has a fixed, known set of states.
|
|
407
|
+
|
|
408
|
+
Example:
|
|
409
|
+
|
|
410
|
+
```java
|
|
411
|
+
public enum BookingStatus {
|
|
412
|
+
CREATED,
|
|
413
|
+
CONFIRMED,
|
|
414
|
+
CANCELLED
|
|
415
|
+
}
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
* Do not use arbitrary strings when an enum provides a stable domain-independent representation.
|
|
419
|
+
|
|
420
|
+
* Enum names MUST use `UPPER_SNAKE_CASE`.
|
|
421
|
+
|
|
422
|
+
* Business behavior MAY be placed in an enum when it is cohesive and improves clarity.
|
|
423
|
+
|
|
424
|
+
---
|
|
425
|
+
|
|
426
|
+
## 15. Switch Expressions
|
|
427
|
+
|
|
428
|
+
Modern Java language features SHOULD be used when they improve clarity.
|
|
429
|
+
|
|
430
|
+
Prefer switch expressions where appropriate:
|
|
431
|
+
|
|
432
|
+
```java
|
|
433
|
+
String description = switch (status) {
|
|
434
|
+
case CREATED -> "Booking created";
|
|
435
|
+
case CONFIRMED -> "Booking confirmed";
|
|
436
|
+
case CANCELLED -> "Booking cancelled";
|
|
437
|
+
};
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
Avoid unnecessary legacy switch patterns when the modern syntax provides clearer behavior.
|
|
441
|
+
|
|
442
|
+
---
|
|
443
|
+
|
|
444
|
+
## 16. Streams and Lambdas
|
|
445
|
+
|
|
446
|
+
Streams SHOULD be used when they improve readability and express collection transformations clearly.
|
|
447
|
+
|
|
448
|
+
Example:
|
|
449
|
+
|
|
450
|
+
```java
|
|
451
|
+
List<String> names = bookings.stream()
|
|
452
|
+
.map(Booking::customerName)
|
|
453
|
+
.toList();
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
Streams SHOULD NOT be used when a simple loop is clearer.
|
|
457
|
+
|
|
458
|
+
Avoid:
|
|
459
|
+
|
|
460
|
+
* deeply nested stream pipelines;
|
|
461
|
+
* side effects inside stream operations;
|
|
462
|
+
* difficult-to-debug functional chains;
|
|
463
|
+
* unnecessary stream creation.
|
|
464
|
+
|
|
465
|
+
Stream operations SHOULD preferably remain side-effect free.
|
|
466
|
+
|
|
467
|
+
---
|
|
468
|
+
|
|
469
|
+
## 17. Method Design
|
|
470
|
+
|
|
471
|
+
Methods SHOULD:
|
|
472
|
+
|
|
473
|
+
* have one clear responsibility;
|
|
474
|
+
* use meaningful names;
|
|
475
|
+
* have a small and understandable parameter list;
|
|
476
|
+
* avoid unnecessary side effects;
|
|
477
|
+
* return meaningful results.
|
|
478
|
+
|
|
479
|
+
Methods with many parameters SHOULD be reviewed for a clearer parameter object when appropriate.
|
|
480
|
+
|
|
481
|
+
Methods MUST NOT be artificially split into numerous trivial methods merely to reduce line count.
|
|
482
|
+
|
|
483
|
+
---
|
|
484
|
+
|
|
485
|
+
## 18. Class Design
|
|
486
|
+
|
|
487
|
+
Classes SHOULD have a clear responsibility.
|
|
488
|
+
|
|
489
|
+
Classes SHOULD NOT become large collections of unrelated functionality.
|
|
490
|
+
|
|
491
|
+
Avoid classes that:
|
|
492
|
+
|
|
493
|
+
* contain unrelated utility methods;
|
|
494
|
+
* maintain excessive mutable state;
|
|
495
|
+
* expose unnecessary internal state;
|
|
496
|
+
* perform unrelated operations.
|
|
497
|
+
|
|
498
|
+
Inheritance SHOULD be used only when a genuine substitutable relationship exists.
|
|
499
|
+
|
|
500
|
+
Composition SHOULD generally be preferred over inheritance when it provides clearer design.
|
|
501
|
+
|
|
502
|
+
---
|
|
503
|
+
|
|
504
|
+
## 19. Visibility
|
|
505
|
+
|
|
506
|
+
* Use the narrowest visibility required.
|
|
507
|
+
|
|
508
|
+
* Fields SHOULD generally be `private`.
|
|
509
|
+
|
|
510
|
+
* Avoid unnecessary `public` methods and classes.
|
|
511
|
+
|
|
512
|
+
* Package-private visibility MAY be used when functionality is intended only for the package.
|
|
513
|
+
|
|
514
|
+
* Public APIs SHOULD expose only what consumers actually require.
|
|
515
|
+
|
|
516
|
+
---
|
|
517
|
+
|
|
518
|
+
## 20. Static State
|
|
519
|
+
|
|
520
|
+
* Static constants are allowed.
|
|
521
|
+
|
|
522
|
+
Example:
|
|
523
|
+
|
|
524
|
+
```java
|
|
525
|
+
private static final String DEFAULT_STATUS = "ACTIVE";
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
* Static mutable state is forbidden unless explicitly justified.
|
|
529
|
+
|
|
530
|
+
* Static service locators are forbidden.
|
|
531
|
+
|
|
532
|
+
* Global mutable caches MUST have an explicit lifecycle and concurrency strategy.
|
|
533
|
+
|
|
534
|
+
---
|
|
535
|
+
|
|
536
|
+
## 21. Reflection
|
|
537
|
+
|
|
538
|
+
* Reflection MUST NOT be used for normal application logic unless there is a genuine requirement.
|
|
539
|
+
|
|
540
|
+
* Framework-required reflection MAY be used.
|
|
541
|
+
|
|
542
|
+
* New reflection-based infrastructure MUST have an explicit justification.
|
|
543
|
+
|
|
544
|
+
* Reflection MUST NOT be introduced merely to avoid writing straightforward Java code.
|
|
545
|
+
|
|
546
|
+
---
|
|
547
|
+
|
|
548
|
+
## 22. Concurrency
|
|
549
|
+
|
|
550
|
+
* Shared mutable state SHOULD be avoided.
|
|
551
|
+
|
|
552
|
+
* Concurrent code MUST have an explicit thread-safety strategy.
|
|
553
|
+
|
|
554
|
+
* Blocking operations MUST NOT be performed on event-loop or reactive threads.
|
|
555
|
+
|
|
556
|
+
* Threads MUST NOT be created manually without an explicit lifecycle and ownership strategy.
|
|
557
|
+
|
|
558
|
+
* Executors SHOULD be managed by the application's configured execution infrastructure.
|
|
559
|
+
|
|
560
|
+
* When asynchronous processing is used, the following SHOULD be considered explicitly:
|
|
561
|
+
|
|
562
|
+
* timeout;
|
|
563
|
+
* cancellation;
|
|
564
|
+
* exception handling;
|
|
565
|
+
* resource limits;
|
|
566
|
+
* thread safety;
|
|
567
|
+
* context propagation.
|
|
568
|
+
|
|
569
|
+
---
|
|
570
|
+
|
|
571
|
+
## 23. Virtual Threads
|
|
572
|
+
|
|
573
|
+
Virtual threads MAY be used when appropriate for blocking I/O workloads.
|
|
574
|
+
|
|
575
|
+
They MUST NOT be introduced automatically.
|
|
576
|
+
|
|
577
|
+
Before using virtual threads, the application SHOULD consider:
|
|
578
|
+
|
|
579
|
+
* blocking dependencies;
|
|
580
|
+
* database connection pool limits;
|
|
581
|
+
* external service limits;
|
|
582
|
+
* thread-local usage;
|
|
583
|
+
* context propagation;
|
|
584
|
+
* observability.
|
|
585
|
+
|
|
586
|
+
The use of virtual threads MUST remain consistent with the project's runtime configuration.
|
|
587
|
+
|
|
588
|
+
---
|
|
589
|
+
|
|
590
|
+
## 24. Logging
|
|
591
|
+
|
|
592
|
+
Logging MUST follow the application's logging standards.
|
|
593
|
+
|
|
594
|
+
Production code MUST NOT log:
|
|
595
|
+
|
|
596
|
+
* passwords;
|
|
597
|
+
* credentials;
|
|
598
|
+
* access tokens;
|
|
599
|
+
* refresh tokens;
|
|
600
|
+
* API keys;
|
|
601
|
+
* secrets;
|
|
602
|
+
* payment card information;
|
|
603
|
+
* sensitive personal information.
|
|
604
|
+
|
|
605
|
+
Logs SHOULD contain useful diagnostic context without exposing sensitive data.
|
|
606
|
+
|
|
607
|
+
Logging MUST NOT replace proper exception handling.
|
|
608
|
+
|
|
609
|
+
---
|
|
610
|
+
|
|
611
|
+
## 25. Time and Randomness
|
|
612
|
+
|
|
613
|
+
Code that depends on current time or randomness SHOULD remain testable.
|
|
614
|
+
|
|
615
|
+
Direct use of:
|
|
616
|
+
|
|
617
|
+
```java
|
|
618
|
+
Instant.now()
|
|
619
|
+
UUID.randomUUID()
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
is permitted when appropriate.
|
|
623
|
+
|
|
624
|
+
Where deterministic testing requires control over time or randomness, an appropriate abstraction MAY be introduced.
|
|
625
|
+
|
|
626
|
+
Abstractions MUST NOT be introduced merely because they are theoretically possible.
|
|
627
|
+
|
|
628
|
+
---
|
|
629
|
+
|
|
630
|
+
## 26. Comments
|
|
631
|
+
|
|
632
|
+
Comments SHOULD explain intent where the code cannot reasonably express it.
|
|
633
|
+
|
|
634
|
+
Comments SHOULD NOT:
|
|
635
|
+
|
|
636
|
+
* restate obvious code;
|
|
637
|
+
* describe syntax;
|
|
638
|
+
* contain outdated implementation details;
|
|
639
|
+
* replace meaningful naming.
|
|
640
|
+
|
|
641
|
+
Commented-out production code MUST be removed before merge.
|
|
642
|
+
|
|
643
|
+
TODO comments SHOULD identify a genuine follow-up requirement and MUST NOT be used as a substitute for completing required work.
|
|
644
|
+
|
|
645
|
+
---
|
|
646
|
+
|
|
647
|
+
## 27. Documentation
|
|
648
|
+
|
|
649
|
+
Public APIs SHOULD be documented where their behavior is not self-explanatory.
|
|
650
|
+
|
|
651
|
+
Non-obvious implementation decisions MAY be documented.
|
|
652
|
+
|
|
653
|
+
Documentation SHOULD remain concise and accurate.
|
|
654
|
+
|
|
655
|
+
Documentation MUST be updated when public behavior changes.
|
|
656
|
+
|
|
657
|
+
---
|
|
658
|
+
|
|
659
|
+
## 28. Formatting
|
|
660
|
+
|
|
661
|
+
Code MUST follow the project's configured Java formatter.
|
|
662
|
+
|
|
663
|
+
Where no project-specific formatter exists, the team SHOULD adopt a single automated formatter.
|
|
664
|
+
|
|
665
|
+
Formatting MUST be automated where practical.
|
|
666
|
+
|
|
667
|
+
Developers SHOULD NOT spend review time debating formatting that can be enforced automatically.
|
|
668
|
+
|
|
669
|
+
---
|
|
670
|
+
|
|
671
|
+
## 29. Static Analysis
|
|
672
|
+
|
|
673
|
+
Static analysis SHOULD be enabled for production projects.
|
|
674
|
+
|
|
675
|
+
Where configured:
|
|
676
|
+
|
|
677
|
+
* compiler warnings SHOULD be treated seriously;
|
|
678
|
+
* unused imports MUST be removed;
|
|
679
|
+
* unreachable code MUST be removed;
|
|
680
|
+
* unsafe casts SHOULD be eliminated;
|
|
681
|
+
* obvious nullability issues SHOULD be addressed;
|
|
682
|
+
* code-quality violations MUST be resolved or explicitly justified.
|
|
683
|
+
|
|
684
|
+
The project's configured static-analysis tools are authoritative.
|
|
685
|
+
|
|
686
|
+
---
|
|
687
|
+
|
|
688
|
+
## 30. Dependencies
|
|
689
|
+
|
|
690
|
+
New dependencies MUST comply with the project's dependency policy.
|
|
691
|
+
|
|
692
|
+
Existing approved dependencies SHOULD be reused when they already provide the required capability.
|
|
693
|
+
|
|
694
|
+
New libraries MUST NOT be introduced merely for convenience when the Java standard library or an existing project dependency provides an adequate solution.
|
|
695
|
+
|
|
696
|
+
Unused dependencies MUST be removed.
|
|
697
|
+
|
|
698
|
+
Dependency selection MUST consider:
|
|
699
|
+
|
|
700
|
+
* maintenance;
|
|
701
|
+
* security;
|
|
702
|
+
* licensing;
|
|
703
|
+
* compatibility;
|
|
704
|
+
* project support;
|
|
705
|
+
* operational impact.
|
|
706
|
+
|
|
707
|
+
See:
|
|
708
|
+
|
|
709
|
+
```text
|
|
710
|
+
dependency-policy.md
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
---
|
|
714
|
+
|
|
715
|
+
## 31. Testing
|
|
716
|
+
|
|
717
|
+
Production code MUST be testable.
|
|
718
|
+
|
|
719
|
+
Tests SHOULD:
|
|
720
|
+
|
|
721
|
+
* be deterministic;
|
|
722
|
+
* be isolated;
|
|
723
|
+
* have clear names;
|
|
724
|
+
* test observable behavior;
|
|
725
|
+
* avoid unnecessary implementation coupling.
|
|
726
|
+
|
|
727
|
+
Unit tests SHOULD execute quickly and independently.
|
|
728
|
+
|
|
729
|
+
Integration tests SHOULD be used where behavior depends on:
|
|
730
|
+
|
|
731
|
+
* databases;
|
|
732
|
+
* frameworks;
|
|
733
|
+
* external services;
|
|
734
|
+
* messaging;
|
|
735
|
+
* infrastructure.
|
|
736
|
+
|
|
737
|
+
Tests MUST NOT depend on production infrastructure.
|
|
738
|
+
|
|
739
|
+
---
|
|
740
|
+
|
|
741
|
+
## 32. Forbidden Coding Patterns
|
|
742
|
+
|
|
743
|
+
The following are forbidden unless explicitly justified and approved:
|
|
744
|
+
|
|
745
|
+
1. Raw generic types.
|
|
746
|
+
|
|
747
|
+
2. Silent exception swallowing.
|
|
748
|
+
|
|
749
|
+
3. Hard-coded credentials, secrets, tokens, or API keys.
|
|
750
|
+
|
|
751
|
+
4. Logging secrets or protected sensitive data.
|
|
752
|
+
|
|
753
|
+
5. Unmanaged thread creation.
|
|
754
|
+
|
|
755
|
+
6. Unnecessary static mutable state.
|
|
756
|
+
|
|
757
|
+
7. Reflection for ordinary business/application logic.
|
|
758
|
+
|
|
759
|
+
8. `==` for String value comparison.
|
|
760
|
+
|
|
761
|
+
9. Legacy date/time APIs for new functionality without an interoperability requirement.
|
|
762
|
+
|
|
763
|
+
10. Commented-out production code.
|
|
764
|
+
|
|
765
|
+
11. Dead or unreachable production code.
|
|
766
|
+
|
|
767
|
+
12. Unused dependencies.
|
|
768
|
+
|
|
769
|
+
13. Catching broad exceptions when a specific exception can be handled.
|
|
770
|
+
|
|
771
|
+
14. Using exceptions as normal control flow.
|
|
772
|
+
|
|
773
|
+
15. Excessively complex stream pipelines when a simple loop is clearer.
|
|
774
|
+
|
|
775
|
+
16. Speculative abstractions introduced without a concrete requirement.
|
|
776
|
+
|
|
777
|
+
17. Duplicate utility implementations when an existing standard library or approved dependency already provides the required functionality.
|
|
778
|
+
|
|
779
|
+
---
|
|
780
|
+
|
|
781
|
+
## 33. Quality Gates
|
|
782
|
+
|
|
783
|
+
The project MUST comply with the quality gates defined by its active build and CI configuration.
|
|
784
|
+
|
|
785
|
+
Where configured:
|
|
786
|
+
|
|
787
|
+
* compilation MUST succeed;
|
|
788
|
+
* automated tests MUST pass;
|
|
789
|
+
* formatting checks MUST pass;
|
|
790
|
+
* static analysis MUST pass;
|
|
791
|
+
* dependency checks MUST pass;
|
|
792
|
+
* license checks MUST pass;
|
|
793
|
+
* security scanning MUST pass;
|
|
794
|
+
* configured code-quality thresholds MUST be satisfied.
|
|
795
|
+
|
|
796
|
+
The exact commands and tools MUST come from the project's build configuration.
|
|
797
|
+
|
|
798
|
+
This document does NOT mandate a specific build tool, database, testing framework, static-analysis tool, or CI platform.
|
|
799
|
+
|
|
800
|
+
---
|
|
801
|
+
|
|
802
|
+
## 34. Related Standards
|
|
803
|
+
|
|
804
|
+
See also:
|
|
805
|
+
|
|
806
|
+
* `dependency-policy.md`
|
|
807
|
+
* `ai-rules.md`
|
|
808
|
+
|
|
809
|
+
```
|
|
810
|
+
|
|
811
|
+
This version is intentionally **technology/coding focused only**. Architecture rules such as:
|
|
812
|
+
|
|
813
|
+
- `adapter/application/domain/infrastructure`
|
|
814
|
+
- Hexagonal Architecture
|
|
815
|
+
- Modular Monolith
|
|
816
|
+
- controller → use case
|
|
817
|
+
- persistence boundaries
|
|
818
|
+
- module boundaries
|
|
819
|
+
|
|
820
|
+
belong in `clean-architecture.md`, not here.
|
|
821
|
+
```
|