@corbat-tech/coding-standards-mcp 1.0.0
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 -0
- package/README.md +371 -0
- package/assets/demo.gif +0 -0
- package/dist/agent.d.ts +53 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +629 -0
- package/dist/agent.js.map +1 -0
- package/dist/cli/init.d.ts +3 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +651 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/config.d.ts +73 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +105 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -0
- package/dist/profiles.d.ts +39 -0
- package/dist/profiles.d.ts.map +1 -0
- package/dist/profiles.js +526 -0
- package/dist/profiles.js.map +1 -0
- package/dist/prompts-legacy.d.ts +25 -0
- package/dist/prompts-legacy.d.ts.map +1 -0
- package/dist/prompts-legacy.js +600 -0
- package/dist/prompts-legacy.js.map +1 -0
- package/dist/prompts-v2.d.ts +30 -0
- package/dist/prompts-v2.d.ts.map +1 -0
- package/dist/prompts-v2.js +310 -0
- package/dist/prompts-v2.js.map +1 -0
- package/dist/prompts.d.ts +30 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +310 -0
- package/dist/prompts.js.map +1 -0
- package/dist/resources.d.ts +18 -0
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +95 -0
- package/dist/resources.js.map +1 -0
- package/dist/tools-legacy.d.ts +196 -0
- package/dist/tools-legacy.d.ts.map +1 -0
- package/dist/tools-legacy.js +1230 -0
- package/dist/tools-legacy.js.map +1 -0
- package/dist/tools-v2.d.ts +92 -0
- package/dist/tools-v2.d.ts.map +1 -0
- package/dist/tools-v2.js +410 -0
- package/dist/tools-v2.js.map +1 -0
- package/dist/tools.d.ts +92 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +410 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +3054 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +515 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/retry.d.ts +44 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +74 -0
- package/dist/utils/retry.js.map +1 -0
- package/package.json +79 -0
- package/profiles/README.md +199 -0
- package/profiles/custom/.gitkeep +2 -0
- package/profiles/templates/_template.yaml +159 -0
- package/profiles/templates/angular.yaml +494 -0
- package/profiles/templates/java-spring-backend.yaml +512 -0
- package/profiles/templates/minimal.yaml +102 -0
- package/profiles/templates/nodejs.yaml +338 -0
- package/profiles/templates/python.yaml +340 -0
- package/profiles/templates/react.yaml +331 -0
- package/profiles/templates/vue.yaml +598 -0
- package/standards/architecture/ddd.md +173 -0
- package/standards/architecture/hexagonal.md +97 -0
- package/standards/cicd/github-actions.md +567 -0
- package/standards/clean-code/naming.md +175 -0
- package/standards/clean-code/principles.md +179 -0
- package/standards/containerization/dockerfile.md +419 -0
- package/standards/database/selection-guide.md +443 -0
- package/standards/documentation/guidelines.md +189 -0
- package/standards/event-driven/domain-events.md +527 -0
- package/standards/kubernetes/deployment.md +518 -0
- package/standards/observability/guidelines.md +665 -0
- package/standards/project-setup/initialization-checklist.md +650 -0
- package/standards/spring-boot/best-practices.md +598 -0
- package/standards/testing/guidelines.md +559 -0
- package/standards/workflow/llm-development-workflow.md +542 -0
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
# Database Selection Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This guide helps choose the right database technology based on your application requirements.
|
|
6
|
+
|
|
7
|
+
## Decision Matrix
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
┌─────────────────────────────────────────────────────────────────────────────┐
|
|
11
|
+
│ DATABASE SELECTION FLOWCHART │
|
|
12
|
+
├─────────────────────────────────────────────────────────────────────────────┤
|
|
13
|
+
│ │
|
|
14
|
+
│ Need ACID transactions? │
|
|
15
|
+
│ ├─ YES: Need complex queries/joins? │
|
|
16
|
+
│ │ ├─ YES: → PostgreSQL (default choice) │
|
|
17
|
+
│ │ └─ NO: High write throughput? │
|
|
18
|
+
│ │ ├─ YES: → PostgreSQL with partitioning │
|
|
19
|
+
│ │ └─ NO: → PostgreSQL │
|
|
20
|
+
│ │ │
|
|
21
|
+
│ └─ NO: What's the data model? │
|
|
22
|
+
│ ├─ Key-Value: → Redis │
|
|
23
|
+
│ ├─ Document: → MongoDB │
|
|
24
|
+
│ ├─ Time Series: → TimescaleDB or InfluxDB │
|
|
25
|
+
│ ├─ Graph: → Neo4j │
|
|
26
|
+
│ ├─ Search: → Elasticsearch │
|
|
27
|
+
│ └─ Wide Column: → Cassandra │
|
|
28
|
+
│ │
|
|
29
|
+
└─────────────────────────────────────────────────────────────────────────────┘
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Database Comparison
|
|
33
|
+
|
|
34
|
+
| Database | Best For | Not Good For | Scalability |
|
|
35
|
+
|----------|----------|--------------|-------------|
|
|
36
|
+
| **PostgreSQL** | OLTP, complex queries, JSON, full-text search | Extreme write scale | Vertical + Read replicas |
|
|
37
|
+
| **MySQL** | Web apps, read-heavy workloads | Complex queries | Vertical + Read replicas |
|
|
38
|
+
| **MongoDB** | Document storage, rapid prototyping | Complex transactions | Horizontal (sharding) |
|
|
39
|
+
| **Redis** | Caching, sessions, real-time data | Large data sets | Cluster mode |
|
|
40
|
+
| **Elasticsearch** | Full-text search, log analytics | Primary data store | Horizontal |
|
|
41
|
+
| **Cassandra** | High write throughput, time series | Complex queries | Horizontal |
|
|
42
|
+
| **DynamoDB** | Serverless, key-value | Complex queries, joins | Managed horizontal |
|
|
43
|
+
|
|
44
|
+
## PostgreSQL (Recommended Default)
|
|
45
|
+
|
|
46
|
+
PostgreSQL is the recommended default for most Spring Boot applications.
|
|
47
|
+
|
|
48
|
+
### Why PostgreSQL?
|
|
49
|
+
|
|
50
|
+
- **ACID compliant**: Full transaction support
|
|
51
|
+
- **Rich SQL support**: CTEs, window functions, complex joins
|
|
52
|
+
- **JSON support**: JSONB for document-like storage
|
|
53
|
+
- **Full-text search**: Built-in, no separate engine needed
|
|
54
|
+
- **Extensions**: PostGIS, pg_trgm, pgvector, etc.
|
|
55
|
+
- **Mature ecosystem**: Excellent Spring Data JPA support
|
|
56
|
+
- **Free and open source**: No licensing costs
|
|
57
|
+
|
|
58
|
+
### Spring Data JPA Configuration
|
|
59
|
+
|
|
60
|
+
```yaml
|
|
61
|
+
spring:
|
|
62
|
+
datasource:
|
|
63
|
+
url: jdbc:postgresql://localhost:5432/orderdb
|
|
64
|
+
username: ${DATABASE_USERNAME}
|
|
65
|
+
password: ${DATABASE_PASSWORD}
|
|
66
|
+
hikari:
|
|
67
|
+
maximum-pool-size: 10
|
|
68
|
+
minimum-idle: 5
|
|
69
|
+
connection-timeout: 30000
|
|
70
|
+
idle-timeout: 600000
|
|
71
|
+
max-lifetime: 1800000
|
|
72
|
+
|
|
73
|
+
jpa:
|
|
74
|
+
hibernate:
|
|
75
|
+
ddl-auto: validate
|
|
76
|
+
properties:
|
|
77
|
+
hibernate:
|
|
78
|
+
dialect: org.hibernate.dialect.PostgreSQLDialect
|
|
79
|
+
format_sql: true
|
|
80
|
+
open-in-view: false
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Dependencies
|
|
84
|
+
|
|
85
|
+
```xml
|
|
86
|
+
<dependency>
|
|
87
|
+
<groupId>org.springframework.boot</groupId>
|
|
88
|
+
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
|
89
|
+
</dependency>
|
|
90
|
+
<dependency>
|
|
91
|
+
<groupId>org.postgresql</groupId>
|
|
92
|
+
<artifactId>postgresql</artifactId>
|
|
93
|
+
<scope>runtime</scope>
|
|
94
|
+
</dependency>
|
|
95
|
+
<dependency>
|
|
96
|
+
<groupId>org.flywaydb</groupId>
|
|
97
|
+
<artifactId>flyway-core</artifactId>
|
|
98
|
+
</dependency>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Docker Compose
|
|
102
|
+
|
|
103
|
+
```yaml
|
|
104
|
+
postgres:
|
|
105
|
+
image: postgres:15-alpine
|
|
106
|
+
environment:
|
|
107
|
+
POSTGRES_DB: orderdb
|
|
108
|
+
POSTGRES_USER: postgres
|
|
109
|
+
POSTGRES_PASSWORD: postgres
|
|
110
|
+
ports:
|
|
111
|
+
- "5432:5432"
|
|
112
|
+
volumes:
|
|
113
|
+
- postgres-data:/var/lib/postgresql/data
|
|
114
|
+
healthcheck:
|
|
115
|
+
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
116
|
+
interval: 5s
|
|
117
|
+
timeout: 5s
|
|
118
|
+
retries: 5
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## MongoDB (Document Store)
|
|
122
|
+
|
|
123
|
+
Use when you need:
|
|
124
|
+
- Flexible schema
|
|
125
|
+
- Document-oriented data model
|
|
126
|
+
- Rapid prototyping
|
|
127
|
+
- Horizontal scaling
|
|
128
|
+
|
|
129
|
+
### Spring Data MongoDB Configuration
|
|
130
|
+
|
|
131
|
+
```yaml
|
|
132
|
+
spring:
|
|
133
|
+
data:
|
|
134
|
+
mongodb:
|
|
135
|
+
uri: mongodb://localhost:27017/orderdb
|
|
136
|
+
auto-index-creation: true
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Dependencies
|
|
140
|
+
|
|
141
|
+
```xml
|
|
142
|
+
<dependency>
|
|
143
|
+
<groupId>org.springframework.boot</groupId>
|
|
144
|
+
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
|
145
|
+
</dependency>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Repository Example
|
|
149
|
+
|
|
150
|
+
```java
|
|
151
|
+
@Document(collection = "orders")
|
|
152
|
+
public class Order {
|
|
153
|
+
@Id
|
|
154
|
+
private String id;
|
|
155
|
+
private String customerId;
|
|
156
|
+
private List<OrderLine> lines;
|
|
157
|
+
private Instant createdAt;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
public interface OrderRepository extends MongoRepository<Order, String> {
|
|
161
|
+
List<Order> findByCustomerId(String customerId);
|
|
162
|
+
|
|
163
|
+
@Query("{ 'lines.productId': ?0 }")
|
|
164
|
+
List<Order> findByProductId(String productId);
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Redis (Cache & Sessions)
|
|
169
|
+
|
|
170
|
+
Use for:
|
|
171
|
+
- Caching frequently accessed data
|
|
172
|
+
- Session storage
|
|
173
|
+
- Rate limiting
|
|
174
|
+
- Leaderboards
|
|
175
|
+
- Pub/Sub messaging
|
|
176
|
+
|
|
177
|
+
### Spring Data Redis Configuration
|
|
178
|
+
|
|
179
|
+
```yaml
|
|
180
|
+
spring:
|
|
181
|
+
data:
|
|
182
|
+
redis:
|
|
183
|
+
host: localhost
|
|
184
|
+
port: 6379
|
|
185
|
+
password: ${REDIS_PASSWORD:}
|
|
186
|
+
cache:
|
|
187
|
+
type: redis
|
|
188
|
+
redis:
|
|
189
|
+
time-to-live: 3600000
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Dependencies
|
|
193
|
+
|
|
194
|
+
```xml
|
|
195
|
+
<dependency>
|
|
196
|
+
<groupId>org.springframework.boot</groupId>
|
|
197
|
+
<artifactId>spring-boot-starter-data-redis</artifactId>
|
|
198
|
+
</dependency>
|
|
199
|
+
<dependency>
|
|
200
|
+
<groupId>org.springframework.boot</groupId>
|
|
201
|
+
<artifactId>spring-boot-starter-cache</artifactId>
|
|
202
|
+
</dependency>
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Caching Example
|
|
206
|
+
|
|
207
|
+
```java
|
|
208
|
+
@Service
|
|
209
|
+
@RequiredArgsConstructor
|
|
210
|
+
public class ProductService {
|
|
211
|
+
|
|
212
|
+
private final ProductRepository productRepository;
|
|
213
|
+
|
|
214
|
+
@Cacheable(value = "products", key = "#id")
|
|
215
|
+
public Product findById(String id) {
|
|
216
|
+
return productRepository.findById(id)
|
|
217
|
+
.orElseThrow(() -> new ProductNotFoundException(id));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
@CacheEvict(value = "products", key = "#product.id")
|
|
221
|
+
public Product save(Product product) {
|
|
222
|
+
return productRepository.save(product);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
@CacheEvict(value = "products", allEntries = true)
|
|
226
|
+
public void clearCache() {
|
|
227
|
+
// Clears all products from cache
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Elasticsearch (Search)
|
|
233
|
+
|
|
234
|
+
Use for:
|
|
235
|
+
- Full-text search
|
|
236
|
+
- Log analytics
|
|
237
|
+
- Complex search queries
|
|
238
|
+
- Autocomplete
|
|
239
|
+
|
|
240
|
+
### Spring Data Elasticsearch Configuration
|
|
241
|
+
|
|
242
|
+
```yaml
|
|
243
|
+
spring:
|
|
244
|
+
elasticsearch:
|
|
245
|
+
uris: http://localhost:9200
|
|
246
|
+
username: ${ELASTIC_USERNAME:}
|
|
247
|
+
password: ${ELASTIC_PASSWORD:}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Dependencies
|
|
251
|
+
|
|
252
|
+
```xml
|
|
253
|
+
<dependency>
|
|
254
|
+
<groupId>org.springframework.boot</groupId>
|
|
255
|
+
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
|
|
256
|
+
</dependency>
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Search Example
|
|
260
|
+
|
|
261
|
+
```java
|
|
262
|
+
@Document(indexName = "products")
|
|
263
|
+
public class ProductDocument {
|
|
264
|
+
@Id
|
|
265
|
+
private String id;
|
|
266
|
+
|
|
267
|
+
@Field(type = FieldType.Text, analyzer = "standard")
|
|
268
|
+
private String name;
|
|
269
|
+
|
|
270
|
+
@Field(type = FieldType.Text, analyzer = "standard")
|
|
271
|
+
private String description;
|
|
272
|
+
|
|
273
|
+
@Field(type = FieldType.Keyword)
|
|
274
|
+
private String category;
|
|
275
|
+
|
|
276
|
+
@Field(type = FieldType.Double)
|
|
277
|
+
private BigDecimal price;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
public interface ProductSearchRepository extends ElasticsearchRepository<ProductDocument, String> {
|
|
281
|
+
|
|
282
|
+
List<ProductDocument> findByNameContaining(String name);
|
|
283
|
+
|
|
284
|
+
@Query("{\"bool\": {\"must\": [{\"match\": {\"name\": \"?0\"}}]}}")
|
|
285
|
+
List<ProductDocument> searchByName(String name);
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
## Database Migrations with Flyway
|
|
290
|
+
|
|
291
|
+
### Configuration
|
|
292
|
+
|
|
293
|
+
```yaml
|
|
294
|
+
spring:
|
|
295
|
+
flyway:
|
|
296
|
+
enabled: true
|
|
297
|
+
locations: classpath:db/migration
|
|
298
|
+
baseline-on-migrate: true
|
|
299
|
+
validate-on-migrate: true
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### Migration File Naming
|
|
303
|
+
|
|
304
|
+
```
|
|
305
|
+
db/migration/
|
|
306
|
+
├── V1__create_orders_table.sql
|
|
307
|
+
├── V2__add_customer_id_index.sql
|
|
308
|
+
├── V3__create_order_lines_table.sql
|
|
309
|
+
└── V4__add_status_column.sql
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### Migration Example
|
|
313
|
+
|
|
314
|
+
```sql
|
|
315
|
+
-- V1__create_orders_table.sql
|
|
316
|
+
CREATE TABLE orders (
|
|
317
|
+
id VARCHAR(36) PRIMARY KEY,
|
|
318
|
+
customer_id VARCHAR(36) NOT NULL,
|
|
319
|
+
status VARCHAR(20) NOT NULL,
|
|
320
|
+
total_amount DECIMAL(19, 2) NOT NULL,
|
|
321
|
+
currency VARCHAR(3) NOT NULL DEFAULT 'USD',
|
|
322
|
+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
323
|
+
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
CREATE INDEX idx_orders_customer_id ON orders(customer_id);
|
|
327
|
+
CREATE INDEX idx_orders_status ON orders(status);
|
|
328
|
+
CREATE INDEX idx_orders_created_at ON orders(created_at);
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
## Multi-Database Strategy
|
|
332
|
+
|
|
333
|
+
For complex applications, combine databases:
|
|
334
|
+
|
|
335
|
+
```
|
|
336
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
337
|
+
│ MULTI-DATABASE ARCHITECTURE │
|
|
338
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
339
|
+
│ │
|
|
340
|
+
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
|
341
|
+
│ │ PostgreSQL │ │ Redis │ │Elasticsearch│ │
|
|
342
|
+
│ │ │ │ │ │ │ │
|
|
343
|
+
│ │ Primary │ │ Cache │ │ Search │ │
|
|
344
|
+
│ │ Data Store │ │ Sessions │ │ Index │ │
|
|
345
|
+
│ │ │ │ Rate Limit│ │ │ │
|
|
346
|
+
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
|
|
347
|
+
│ │ │ │ │
|
|
348
|
+
│ └──────────────────┼──────────────────┘ │
|
|
349
|
+
│ │ │
|
|
350
|
+
│ ┌───────▼───────┐ │
|
|
351
|
+
│ │ Spring Boot │ │
|
|
352
|
+
│ │ Application │ │
|
|
353
|
+
│ └───────────────┘ │
|
|
354
|
+
│ │
|
|
355
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### Configuration for Multiple Data Sources
|
|
359
|
+
|
|
360
|
+
```java
|
|
361
|
+
@Configuration
|
|
362
|
+
public class DataSourceConfig {
|
|
363
|
+
|
|
364
|
+
@Bean
|
|
365
|
+
@Primary
|
|
366
|
+
@ConfigurationProperties("spring.datasource.primary")
|
|
367
|
+
public DataSource primaryDataSource() {
|
|
368
|
+
return DataSourceBuilder.create().build();
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
@Bean
|
|
372
|
+
@ConfigurationProperties("spring.datasource.read-replica")
|
|
373
|
+
public DataSource readReplicaDataSource() {
|
|
374
|
+
return DataSourceBuilder.create().build();
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
## Performance Considerations
|
|
380
|
+
|
|
381
|
+
### Connection Pooling (HikariCP)
|
|
382
|
+
|
|
383
|
+
```yaml
|
|
384
|
+
spring:
|
|
385
|
+
datasource:
|
|
386
|
+
hikari:
|
|
387
|
+
maximum-pool-size: 10 # Recommended: 2 * CPU cores + disk spindles
|
|
388
|
+
minimum-idle: 5
|
|
389
|
+
connection-timeout: 30000 # 30 seconds
|
|
390
|
+
idle-timeout: 600000 # 10 minutes
|
|
391
|
+
max-lifetime: 1800000 # 30 minutes
|
|
392
|
+
leak-detection-threshold: 60000
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
### Indexing Strategy
|
|
396
|
+
|
|
397
|
+
```sql
|
|
398
|
+
-- Create indexes for frequent query patterns
|
|
399
|
+
CREATE INDEX idx_orders_customer_status ON orders(customer_id, status);
|
|
400
|
+
CREATE INDEX idx_orders_created_at_desc ON orders(created_at DESC);
|
|
401
|
+
|
|
402
|
+
-- Partial index for active orders
|
|
403
|
+
CREATE INDEX idx_active_orders ON orders(customer_id)
|
|
404
|
+
WHERE status IN ('PENDING', 'CONFIRMED');
|
|
405
|
+
|
|
406
|
+
-- GIN index for JSONB columns
|
|
407
|
+
CREATE INDEX idx_order_metadata ON orders USING GIN(metadata);
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
## Testing with Testcontainers
|
|
411
|
+
|
|
412
|
+
```java
|
|
413
|
+
@SpringBootTest
|
|
414
|
+
@Testcontainers
|
|
415
|
+
class OrderRepositoryIT {
|
|
416
|
+
|
|
417
|
+
@Container
|
|
418
|
+
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15-alpine")
|
|
419
|
+
.withDatabaseName("testdb")
|
|
420
|
+
.withUsername("test")
|
|
421
|
+
.withPassword("test");
|
|
422
|
+
|
|
423
|
+
@DynamicPropertySource
|
|
424
|
+
static void configureProperties(DynamicPropertyRegistry registry) {
|
|
425
|
+
registry.add("spring.datasource.url", postgres::getJdbcUrl);
|
|
426
|
+
registry.add("spring.datasource.username", postgres::getUsername);
|
|
427
|
+
registry.add("spring.datasource.password", postgres::getPassword);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
## Best Practices
|
|
433
|
+
|
|
434
|
+
1. **Start with PostgreSQL**: It handles most use cases well
|
|
435
|
+
2. **Add Redis for caching**: When you need to reduce database load
|
|
436
|
+
3. **Add Elasticsearch**: When you need advanced search capabilities
|
|
437
|
+
4. **Use connection pooling**: HikariCP is the default and recommended
|
|
438
|
+
5. **Always use migrations**: Flyway or Liquibase
|
|
439
|
+
6. **Index strategically**: Based on query patterns, not guessing
|
|
440
|
+
7. **Monitor performance**: Use pg_stat_statements, slow query logs
|
|
441
|
+
8. **Plan for scaling**: Read replicas, partitioning, or sharding
|
|
442
|
+
9. **Test with real databases**: Use Testcontainers in integration tests
|
|
443
|
+
10. **Secure connections**: Use SSL/TLS in production
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# Documentation Standards
|
|
2
|
+
|
|
3
|
+
## Principles
|
|
4
|
+
|
|
5
|
+
1. **Document everything you create** - All code, features, and changes must be documented
|
|
6
|
+
2. **Keep it concise** - Professional, to the point, complete but not extensive
|
|
7
|
+
3. **No redundancy** - Avoid copying code unnecessarily; reference it instead
|
|
8
|
+
4. **Always up-to-date** - Update docs when code changes
|
|
9
|
+
|
|
10
|
+
## README Style Guide
|
|
11
|
+
|
|
12
|
+
Follow the modern GitHub README pattern used by successful repositories:
|
|
13
|
+
|
|
14
|
+
### Header Structure
|
|
15
|
+
|
|
16
|
+
```markdown
|
|
17
|
+
<div align="center">
|
|
18
|
+
|
|
19
|
+
# 🔧 Project Name
|
|
20
|
+
|
|
21
|
+
### Short Description
|
|
22
|
+
|
|
23
|
+
*Tagline or value proposition*
|
|
24
|
+
|
|
25
|
+
<br>
|
|
26
|
+
|
|
27
|
+
[](link) [](link)
|
|
28
|
+
|
|
29
|
+
<br>
|
|
30
|
+
|
|
31
|
+
[Section 1](#section-1) · [Section 2](#section-2) · [Section 3](#section-3)
|
|
32
|
+
|
|
33
|
+
</div>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Section Guidelines
|
|
37
|
+
|
|
38
|
+
| Section | Purpose | Style |
|
|
39
|
+
|---------|---------|-------|
|
|
40
|
+
| **What is this?** | Brief explanation | 2-3 sentences max |
|
|
41
|
+
| **Quick Start** | Get running fast | Minimal steps, copy-paste ready |
|
|
42
|
+
| **Features** | Key capabilities | Bullet points or table |
|
|
43
|
+
| **Installation** | Setup instructions | Code blocks with comments |
|
|
44
|
+
| **Usage** | How to use | Examples with context |
|
|
45
|
+
| **Configuration** | Options available | Table format preferred |
|
|
46
|
+
| **API/Reference** | Technical details | Tables, concise descriptions |
|
|
47
|
+
| **Troubleshooting** | Common issues | Collapsible `<details>` sections |
|
|
48
|
+
| **Contributing** | How to help | Brief numbered steps |
|
|
49
|
+
|
|
50
|
+
### Best Practices
|
|
51
|
+
|
|
52
|
+
- **Use tables** for structured data (configs, options, comparisons)
|
|
53
|
+
- **Use collapsible sections** for detailed/optional content:
|
|
54
|
+
```markdown
|
|
55
|
+
<details>
|
|
56
|
+
<summary><b>Click to expand</b></summary>
|
|
57
|
+
|
|
58
|
+
Detailed content here...
|
|
59
|
+
|
|
60
|
+
</details>
|
|
61
|
+
```
|
|
62
|
+
- **Use badges** for status, version, license (shields.io)
|
|
63
|
+
- **Use diagrams** for architecture (ASCII in code blocks or Mermaid)
|
|
64
|
+
- **Link, don't duplicate** - Reference other docs instead of copying
|
|
65
|
+
|
|
66
|
+
## Code Documentation
|
|
67
|
+
|
|
68
|
+
### What to Document
|
|
69
|
+
|
|
70
|
+
| Element | Required | Format |
|
|
71
|
+
|---------|----------|--------|
|
|
72
|
+
| Public functions | Yes | JSDoc/docstring with params, return, example |
|
|
73
|
+
| Classes | Yes | Purpose, usage example |
|
|
74
|
+
| Complex logic | Yes | Inline comments explaining "why" |
|
|
75
|
+
| Config options | Yes | Type, default, description |
|
|
76
|
+
| API endpoints | Yes | Method, path, params, response |
|
|
77
|
+
|
|
78
|
+
### What NOT to Document
|
|
79
|
+
|
|
80
|
+
- Self-explanatory code (e.g., `getUserById(id)`)
|
|
81
|
+
- Implementation details that may change
|
|
82
|
+
- Obvious variable names
|
|
83
|
+
- Boilerplate code
|
|
84
|
+
|
|
85
|
+
### Comment Style
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
/**
|
|
89
|
+
* Calculates the total price with tax.
|
|
90
|
+
*
|
|
91
|
+
* @param price - Base price without tax
|
|
92
|
+
* @param taxRate - Tax rate as decimal (0.21 for 21%)
|
|
93
|
+
* @returns Total price including tax
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* calculateTotal(100, 0.21) // returns 121
|
|
97
|
+
*/
|
|
98
|
+
function calculateTotal(price: number, taxRate: number): number {
|
|
99
|
+
return price * (1 + taxRate);
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Documentation Review Cycle
|
|
104
|
+
|
|
105
|
+
**Every piece of documentation must go through 3 review iterations:**
|
|
106
|
+
|
|
107
|
+
### Iteration 1: Initial Draft
|
|
108
|
+
1. Write the documentation
|
|
109
|
+
2. Self-review for completeness
|
|
110
|
+
3. Rate it (1-10) with brief justification
|
|
111
|
+
4. Identify areas for improvement
|
|
112
|
+
|
|
113
|
+
### Iteration 2: Refinement
|
|
114
|
+
1. Address identified issues
|
|
115
|
+
2. Check for clarity and conciseness
|
|
116
|
+
3. Remove redundancies
|
|
117
|
+
4. Rate again and compare to previous
|
|
118
|
+
|
|
119
|
+
### Iteration 3: Polish
|
|
120
|
+
1. Final grammar and formatting check
|
|
121
|
+
2. Verify all links work
|
|
122
|
+
3. Ensure consistency with project style
|
|
123
|
+
4. Final rating (should be 8+)
|
|
124
|
+
|
|
125
|
+
### Rating Criteria
|
|
126
|
+
|
|
127
|
+
| Score | Meaning | Action |
|
|
128
|
+
|-------|---------|--------|
|
|
129
|
+
| 9-10 | Excellent | Ready to merge |
|
|
130
|
+
| 7-8 | Good | Minor improvements needed |
|
|
131
|
+
| 5-6 | Acceptable | Significant revision needed |
|
|
132
|
+
| 1-4 | Poor | Rewrite required |
|
|
133
|
+
|
|
134
|
+
### Review Checklist
|
|
135
|
+
|
|
136
|
+
- [ ] Is it complete? All features/changes documented?
|
|
137
|
+
- [ ] Is it concise? No unnecessary words or code?
|
|
138
|
+
- [ ] Is it clear? Would a new developer understand?
|
|
139
|
+
- [ ] Is it correct? Matches actual implementation?
|
|
140
|
+
- [ ] Is it consistent? Follows project style guide?
|
|
141
|
+
- [ ] Is it current? No outdated information?
|
|
142
|
+
|
|
143
|
+
## File Organization
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
docs/
|
|
147
|
+
├── README.md # Project overview (follows header style)
|
|
148
|
+
├── CONTRIBUTING.md # How to contribute
|
|
149
|
+
├── CHANGELOG.md # Version history
|
|
150
|
+
└── api/ # API documentation
|
|
151
|
+
└── endpoints.md
|
|
152
|
+
|
|
153
|
+
standards/ # Coding standards (this project)
|
|
154
|
+
├── documentation/
|
|
155
|
+
│ └── guidelines.md # This file
|
|
156
|
+
├── architecture/
|
|
157
|
+
└── testing/
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Changelog Format
|
|
161
|
+
|
|
162
|
+
Follow [Keep a Changelog](https://keepachangelog.com/):
|
|
163
|
+
|
|
164
|
+
```markdown
|
|
165
|
+
## [1.2.0] - 2026-01-15
|
|
166
|
+
|
|
167
|
+
### Added
|
|
168
|
+
- New feature X for Y purpose
|
|
169
|
+
|
|
170
|
+
### Changed
|
|
171
|
+
- Improved Z performance by 50%
|
|
172
|
+
|
|
173
|
+
### Fixed
|
|
174
|
+
- Bug where A caused B
|
|
175
|
+
|
|
176
|
+
### Removed
|
|
177
|
+
- Deprecated method C
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Summary
|
|
181
|
+
|
|
182
|
+
| Do | Don't |
|
|
183
|
+
|----|-------|
|
|
184
|
+
| Be concise and direct | Write walls of text |
|
|
185
|
+
| Use examples | Explain without showing |
|
|
186
|
+
| Keep docs with code | Separate docs repository |
|
|
187
|
+
| Update on every change | Let docs get stale |
|
|
188
|
+
| Review in 3 iterations | Ship first draft |
|
|
189
|
+
| Rate your own work | Skip self-review |
|