s9n-devops-agent 2.0.13 → 2.0.18-dev.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/House_Rules_Contracts/API_CONTRACT.md +612 -0
- package/House_Rules_Contracts/DATABASE_SCHEMA_CONTRACT.md +373 -0
- package/House_Rules_Contracts/DEVOPS_AGENT_INSTRUCTIONS.md +743 -0
- package/House_Rules_Contracts/FEATURES_CONTRACT.md +655 -0
- package/House_Rules_Contracts/INFRA_CONTRACT.md +638 -0
- package/House_Rules_Contracts/README.md +671 -0
- package/House_Rules_Contracts/SQL_CONTRACT.json +346 -0
- package/House_Rules_Contracts/THIRD_PARTY_INTEGRATIONS.md +604 -0
- package/bin/cs-devops-agent +20 -2
- package/houserules.md +1412 -0
- package/houserules_structured.md +1442 -0
- package/package.json +6 -2
- package/scripts/generate-ai-commit.js +135 -0
- package/scripts/local-install.sh +42 -0
- package/src/agent-chat.js +457 -0
- package/src/credentials-manager.js +1 -1
- package/src/cs-devops-agent-worker.js +84 -4
- package/src/house-rules-manager.js +4 -14
- package/src/instruction-formatter.js +9 -1
- package/src/session-coordinator.js +170 -15
- package/src/setup-cs-devops-agent.js +214 -236
- package/src/worktree-manager.js +2 -1
- package/start-devops-session.sh +9 -2
|
@@ -0,0 +1,612 @@
|
|
|
1
|
+
# API Contract Schema
|
|
2
|
+
|
|
3
|
+
**Last Updated:** 2024-12-02
|
|
4
|
+
**Version:** 1.0.0
|
|
5
|
+
**Status:** Initial Template
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Purpose
|
|
10
|
+
|
|
11
|
+
This contract documents **all API endpoints** in the project. Coding agents **MUST check this file before creating new endpoints** to:
|
|
12
|
+
- Reuse existing endpoints
|
|
13
|
+
- Maintain consistent API design
|
|
14
|
+
- Avoid duplicate functionality
|
|
15
|
+
- Ensure backward compatibility
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Change Log
|
|
20
|
+
|
|
21
|
+
| Date | Version | Agent/Author | Changes | Impact |
|
|
22
|
+
|------|---------|--------------|---------|--------|
|
|
23
|
+
| 2024-12-02 | 1.0.0 | DevOps Agent | Initial template creation | N/A - Template only |
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## API Overview
|
|
28
|
+
|
|
29
|
+
### Base Configuration
|
|
30
|
+
|
|
31
|
+
| Property | Value | Notes |
|
|
32
|
+
|----------|-------|-------|
|
|
33
|
+
| **Base URL** | `https://api.example.com` | Production environment |
|
|
34
|
+
| **API Version** | `v1` | Current stable version |
|
|
35
|
+
| **Protocol** | HTTPS | TLS 1.2+ required |
|
|
36
|
+
| **Authentication** | Bearer Token / JWT | OAuth 2.0 compatible |
|
|
37
|
+
| **Rate Limiting** | 1000 req/hour per user | Configurable per endpoint |
|
|
38
|
+
| **Default Format** | JSON | Accept: application/json |
|
|
39
|
+
|
|
40
|
+
### Versioning Strategy
|
|
41
|
+
|
|
42
|
+
- **URL Versioning:** `/api/v1/`, `/api/v2/`
|
|
43
|
+
- **Breaking Changes:** Require new version
|
|
44
|
+
- **Deprecation Period:** 6 months minimum
|
|
45
|
+
- **Sunset Headers:** `Sunset: <date>` for deprecated endpoints
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Authentication & Authorization
|
|
50
|
+
|
|
51
|
+
### Authentication Methods
|
|
52
|
+
|
|
53
|
+
#### 1. JWT Bearer Token
|
|
54
|
+
```http
|
|
55
|
+
Authorization: Bearer <jwt_token>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Token Structure:**
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"sub": "user_id",
|
|
62
|
+
"email": "user@example.com",
|
|
63
|
+
"role": "admin|user|guest",
|
|
64
|
+
"iat": 1234567890,
|
|
65
|
+
"exp": 1234571490
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### 2. API Key (For Service-to-Service)
|
|
70
|
+
```http
|
|
71
|
+
X-API-Key: <api_key>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Authorization Roles
|
|
75
|
+
|
|
76
|
+
| Role | Permissions | Description |
|
|
77
|
+
|------|-------------|-------------|
|
|
78
|
+
| `guest` | Read public data | Unauthenticated users |
|
|
79
|
+
| `user` | Read/Write own data | Authenticated users |
|
|
80
|
+
| `admin` | Full access | System administrators |
|
|
81
|
+
| `service` | Backend operations | Service accounts |
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Endpoints
|
|
86
|
+
|
|
87
|
+
### Endpoint Template
|
|
88
|
+
|
|
89
|
+
#### `[METHOD] /api/v1/resource/{id}`
|
|
90
|
+
|
|
91
|
+
**Added:** [YYYY-MM-DD]
|
|
92
|
+
**Last Modified:** [YYYY-MM-DD]
|
|
93
|
+
**Status:** `active` | `deprecated` | `beta`
|
|
94
|
+
**Deprecation Date:** [YYYY-MM-DD] *(if applicable)*
|
|
95
|
+
|
|
96
|
+
**Description:**
|
|
97
|
+
[What this endpoint does]
|
|
98
|
+
|
|
99
|
+
**Authentication Required:** YES/NO
|
|
100
|
+
**Required Roles:** `[role1, role2]`
|
|
101
|
+
**Rate Limit:** [e.g., 100 req/min]
|
|
102
|
+
|
|
103
|
+
**Request:**
|
|
104
|
+
|
|
105
|
+
```http
|
|
106
|
+
[METHOD] /api/v1/resource/{id}
|
|
107
|
+
Content-Type: application/json
|
|
108
|
+
Authorization: Bearer <token>
|
|
109
|
+
|
|
110
|
+
{
|
|
111
|
+
"field": "value"
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Path Parameters:**
|
|
116
|
+
|
|
117
|
+
| Parameter | Type | Required | Description | Example |
|
|
118
|
+
|-----------|------|----------|-------------|---------|
|
|
119
|
+
| `id` | integer | YES | Resource identifier | `123` |
|
|
120
|
+
|
|
121
|
+
**Query Parameters:**
|
|
122
|
+
|
|
123
|
+
| Parameter | Type | Required | Default | Description | Example |
|
|
124
|
+
|-----------|------|----------|---------|-------------|---------|
|
|
125
|
+
| `filter` | string | NO | `null` | Filter criteria | `active` |
|
|
126
|
+
| `limit` | integer | NO | `20` | Results per page | `50` |
|
|
127
|
+
| `offset` | integer | NO | `0` | Pagination offset | `100` |
|
|
128
|
+
|
|
129
|
+
**Request Body Schema:**
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"field1": "string (required, max 255 chars)",
|
|
134
|
+
"field2": "integer (optional, min 0)",
|
|
135
|
+
"nested": {
|
|
136
|
+
"subfield": "boolean (required)"
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Response:**
|
|
142
|
+
|
|
143
|
+
**Success Response (200 OK):**
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"success": true,
|
|
147
|
+
"data": {
|
|
148
|
+
"id": 123,
|
|
149
|
+
"field1": "value",
|
|
150
|
+
"created_at": "2024-12-02T10:00:00Z"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Error Responses:**
|
|
156
|
+
|
|
157
|
+
| Status Code | Description | Response Body |
|
|
158
|
+
|-------------|-------------|---------------|
|
|
159
|
+
| 400 | Bad Request - Invalid input | `{"success": false, "error": "Validation failed", "details": [...]}` |
|
|
160
|
+
| 401 | Unauthorized - Missing/invalid token | `{"success": false, "error": "Authentication required"}` |
|
|
161
|
+
| 403 | Forbidden - Insufficient permissions | `{"success": false, "error": "Access denied"}` |
|
|
162
|
+
| 404 | Not Found - Resource doesn't exist | `{"success": false, "error": "Resource not found"}` |
|
|
163
|
+
| 429 | Too Many Requests - Rate limit exceeded | `{"success": false, "error": "Rate limit exceeded", "retry_after": 60}` |
|
|
164
|
+
| 500 | Internal Server Error | `{"success": false, "error": "Internal server error"}` |
|
|
165
|
+
|
|
166
|
+
**Implementation Details:**
|
|
167
|
+
|
|
168
|
+
- **Controller:** `src/api/controllers/ResourceController.js`
|
|
169
|
+
- **Service:** `src/services/ResourceService.js`
|
|
170
|
+
- **Database Tables:** `resources`, `resource_metadata`
|
|
171
|
+
- **SQL Queries Used:** `get_resource_by_id`, `update_resource`
|
|
172
|
+
- **3rd Party Integrations:** None / `[service_name]`
|
|
173
|
+
|
|
174
|
+
**Dependencies:**
|
|
175
|
+
|
|
176
|
+
- **Requires:** `[other_endpoints_this_calls]`
|
|
177
|
+
- **Called By:** `[endpoints_that_call_this]`
|
|
178
|
+
|
|
179
|
+
**Performance Notes:**
|
|
180
|
+
|
|
181
|
+
- Average response time: 50ms
|
|
182
|
+
- Database queries: 2 (with indexes)
|
|
183
|
+
- Caching: Redis, 5min TTL
|
|
184
|
+
|
|
185
|
+
**Security Notes:**
|
|
186
|
+
|
|
187
|
+
- Input validation: Joi schema
|
|
188
|
+
- SQL injection: Parameterized queries
|
|
189
|
+
- XSS protection: Output sanitization
|
|
190
|
+
- CSRF: Not applicable (stateless API)
|
|
191
|
+
|
|
192
|
+
**Examples:**
|
|
193
|
+
|
|
194
|
+
**Example 1: Get user by ID**
|
|
195
|
+
```bash
|
|
196
|
+
curl -X GET "https://api.example.com/api/v1/users/123" \
|
|
197
|
+
-H "Authorization: Bearer eyJhbGc..."
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**Example 2: Update user profile**
|
|
201
|
+
```bash
|
|
202
|
+
curl -X PUT "https://api.example.com/api/v1/users/123" \
|
|
203
|
+
-H "Authorization: Bearer eyJhbGc..." \
|
|
204
|
+
-H "Content-Type: application/json" \
|
|
205
|
+
-d '{"username": "new_name", "email": "new@example.com"}'
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
**Testing:**
|
|
209
|
+
|
|
210
|
+
- Unit tests: `test_cases/api/users.test.js`
|
|
211
|
+
- Integration tests: `test_cases/integration/user_api.test.js`
|
|
212
|
+
- Coverage: 95%
|
|
213
|
+
|
|
214
|
+
**Changelog:**
|
|
215
|
+
|
|
216
|
+
| Date | Version | Changes | Breaking |
|
|
217
|
+
|------|---------|---------|----------|
|
|
218
|
+
| 2024-01-15 | 1.0.0 | Initial creation | N/A |
|
|
219
|
+
| 2024-02-10 | 1.1.0 | Added `filter` query param | NO |
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Example Endpoints
|
|
224
|
+
|
|
225
|
+
<!-- ======================================================================= -->
|
|
226
|
+
<!-- NOTE: The following is an EXAMPLE ONLY. Do not treat as real API. -->
|
|
227
|
+
<!-- ======================================================================= -->
|
|
228
|
+
|
|
229
|
+
### User Management
|
|
230
|
+
|
|
231
|
+
#### `GET /api/v1/users/{id}`
|
|
232
|
+
|
|
233
|
+
**Added:** 2024-01-15
|
|
234
|
+
**Last Modified:** 2024-01-15
|
|
235
|
+
**Status:** `active`
|
|
236
|
+
|
|
237
|
+
**Description:**
|
|
238
|
+
Retrieves a single user by ID. Returns public profile information.
|
|
239
|
+
|
|
240
|
+
**Authentication Required:** YES
|
|
241
|
+
**Required Roles:** `user`, `admin`
|
|
242
|
+
**Rate Limit:** 100 req/min
|
|
243
|
+
|
|
244
|
+
**Path Parameters:**
|
|
245
|
+
|
|
246
|
+
| Parameter | Type | Required | Description | Example |
|
|
247
|
+
|-----------|------|----------|-------------|---------|
|
|
248
|
+
| `id` | integer | YES | User ID | `123` |
|
|
249
|
+
|
|
250
|
+
**Response:**
|
|
251
|
+
|
|
252
|
+
**Success (200 OK):**
|
|
253
|
+
```json
|
|
254
|
+
{
|
|
255
|
+
"success": true,
|
|
256
|
+
"data": {
|
|
257
|
+
"id": 123,
|
|
258
|
+
"username": "john_doe",
|
|
259
|
+
"email": "john@example.com",
|
|
260
|
+
"is_active": true,
|
|
261
|
+
"created_at": "2024-01-15T10:00:00Z"
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
**Implementation:**
|
|
267
|
+
- **Controller:** `src/api/controllers/UserController.js::getUser()`
|
|
268
|
+
- **Service:** `src/services/UserService.js::getUserById()`
|
|
269
|
+
- **SQL Query:** `get_user_by_id` (from SQL_CONTRACT.json)
|
|
270
|
+
- **Database Tables:** `users`
|
|
271
|
+
|
|
272
|
+
**Performance:** Avg 20ms, uses `idx_users_id` index
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
#### `POST /api/v1/users`
|
|
277
|
+
|
|
278
|
+
**Added:** 2024-01-15
|
|
279
|
+
**Last Modified:** 2024-01-15
|
|
280
|
+
**Status:** `active`
|
|
281
|
+
|
|
282
|
+
**Description:**
|
|
283
|
+
Creates a new user account. Sends verification email.
|
|
284
|
+
|
|
285
|
+
**Authentication Required:** NO (public registration)
|
|
286
|
+
**Required Roles:** N/A
|
|
287
|
+
**Rate Limit:** 10 req/hour per IP
|
|
288
|
+
|
|
289
|
+
**Request Body:**
|
|
290
|
+
|
|
291
|
+
```json
|
|
292
|
+
{
|
|
293
|
+
"email": "newuser@example.com",
|
|
294
|
+
"password": "SecurePass123!",
|
|
295
|
+
"username": "new_user"
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
**Validation Rules:**
|
|
300
|
+
- `email`: Valid email format, unique
|
|
301
|
+
- `password`: Min 8 chars, 1 uppercase, 1 number, 1 special char
|
|
302
|
+
- `username`: 3-30 chars, alphanumeric + underscore, unique
|
|
303
|
+
|
|
304
|
+
**Response:**
|
|
305
|
+
|
|
306
|
+
**Success (201 Created):**
|
|
307
|
+
```json
|
|
308
|
+
{
|
|
309
|
+
"success": true,
|
|
310
|
+
"data": {
|
|
311
|
+
"id": 124,
|
|
312
|
+
"username": "new_user",
|
|
313
|
+
"email": "newuser@example.com",
|
|
314
|
+
"created_at": "2024-12-02T10:00:00Z"
|
|
315
|
+
},
|
|
316
|
+
"message": "Verification email sent"
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
**Implementation:**
|
|
321
|
+
- **Controller:** `src/api/controllers/UserController.js::createUser()`
|
|
322
|
+
- **Service:** `src/services/UserService.js::registerUser()`
|
|
323
|
+
- **SQL Query:** `insert_user` (from SQL_CONTRACT.json)
|
|
324
|
+
- **Database Tables:** `users`
|
|
325
|
+
- **3rd Party:** SendGrid (email verification)
|
|
326
|
+
|
|
327
|
+
**Security:**
|
|
328
|
+
- Password hashed with bcrypt (cost factor 10)
|
|
329
|
+
- Email verification required before activation
|
|
330
|
+
- Rate limiting prevents spam registrations
|
|
331
|
+
|
|
332
|
+
---
|
|
333
|
+
|
|
334
|
+
### Authentication
|
|
335
|
+
|
|
336
|
+
#### `POST /api/v1/auth/login`
|
|
337
|
+
|
|
338
|
+
**Added:** 2024-01-15
|
|
339
|
+
**Last Modified:** 2024-01-15
|
|
340
|
+
**Status:** `active`
|
|
341
|
+
|
|
342
|
+
**Description:**
|
|
343
|
+
Authenticates user and returns JWT token.
|
|
344
|
+
|
|
345
|
+
**Authentication Required:** NO
|
|
346
|
+
**Rate Limit:** 5 req/min per IP
|
|
347
|
+
|
|
348
|
+
**Request Body:**
|
|
349
|
+
|
|
350
|
+
```json
|
|
351
|
+
{
|
|
352
|
+
"email": "user@example.com",
|
|
353
|
+
"password": "password123"
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
**Response:**
|
|
358
|
+
|
|
359
|
+
**Success (200 OK):**
|
|
360
|
+
```json
|
|
361
|
+
{
|
|
362
|
+
"success": true,
|
|
363
|
+
"data": {
|
|
364
|
+
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
|
365
|
+
"expires_at": "2024-12-03T10:00:00Z",
|
|
366
|
+
"user": {
|
|
367
|
+
"id": 123,
|
|
368
|
+
"username": "john_doe",
|
|
369
|
+
"email": "user@example.com"
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
**Error (401 Unauthorized):**
|
|
376
|
+
```json
|
|
377
|
+
{
|
|
378
|
+
"success": false,
|
|
379
|
+
"error": "Invalid email or password"
|
|
380
|
+
}
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
**Implementation:**
|
|
384
|
+
- **Controller:** `src/api/controllers/AuthController.js::login()`
|
|
385
|
+
- **Service:** `src/services/AuthService.js::authenticate()`
|
|
386
|
+
- **SQL Query:** `get_user_by_email` (from SQL_CONTRACT.json)
|
|
387
|
+
- **Database Tables:** `users`
|
|
388
|
+
|
|
389
|
+
**Security:**
|
|
390
|
+
- Password comparison using bcrypt
|
|
391
|
+
- Failed login attempts logged
|
|
392
|
+
- Account lockout after 5 failed attempts (15min)
|
|
393
|
+
- JWT signed with HS256, 24h expiration
|
|
394
|
+
|
|
395
|
+
---
|
|
396
|
+
|
|
397
|
+
## API Design Patterns
|
|
398
|
+
|
|
399
|
+
### Standard Response Format
|
|
400
|
+
|
|
401
|
+
**Success Response:**
|
|
402
|
+
```json
|
|
403
|
+
{
|
|
404
|
+
"success": true,
|
|
405
|
+
"data": { ... },
|
|
406
|
+
"message": "Optional success message",
|
|
407
|
+
"meta": {
|
|
408
|
+
"timestamp": "2024-12-02T10:00:00Z",
|
|
409
|
+
"request_id": "uuid"
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
**Error Response:**
|
|
415
|
+
```json
|
|
416
|
+
{
|
|
417
|
+
"success": false,
|
|
418
|
+
"error": "Error message",
|
|
419
|
+
"details": [ ... ],
|
|
420
|
+
"meta": {
|
|
421
|
+
"timestamp": "2024-12-02T10:00:00Z",
|
|
422
|
+
"request_id": "uuid"
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
### Pagination
|
|
428
|
+
|
|
429
|
+
**Request:**
|
|
430
|
+
```http
|
|
431
|
+
GET /api/v1/resources?limit=20&offset=0
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
**Response:**
|
|
435
|
+
```json
|
|
436
|
+
{
|
|
437
|
+
"success": true,
|
|
438
|
+
"data": [ ... ],
|
|
439
|
+
"pagination": {
|
|
440
|
+
"total": 150,
|
|
441
|
+
"limit": 20,
|
|
442
|
+
"offset": 0,
|
|
443
|
+
"has_more": true
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
### Filtering & Sorting
|
|
449
|
+
|
|
450
|
+
**Request:**
|
|
451
|
+
```http
|
|
452
|
+
GET /api/v1/resources?filter[status]=active&sort=-created_at
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
**Supported Operators:**
|
|
456
|
+
- `filter[field]=value` - Exact match
|
|
457
|
+
- `filter[field][gt]=value` - Greater than
|
|
458
|
+
- `filter[field][lt]=value` - Less than
|
|
459
|
+
- `filter[field][in]=val1,val2` - In array
|
|
460
|
+
- `sort=field` - Ascending
|
|
461
|
+
- `sort=-field` - Descending
|
|
462
|
+
|
|
463
|
+
---
|
|
464
|
+
|
|
465
|
+
## Endpoint Categories
|
|
466
|
+
|
|
467
|
+
### User Management
|
|
468
|
+
- `GET /api/v1/users/{id}` - Get user by ID
|
|
469
|
+
- `POST /api/v1/users` - Create user
|
|
470
|
+
- `PUT /api/v1/users/{id}` - Update user
|
|
471
|
+
- `DELETE /api/v1/users/{id}` - Delete user
|
|
472
|
+
- `GET /api/v1/users` - List users (admin only)
|
|
473
|
+
|
|
474
|
+
### Authentication
|
|
475
|
+
- `POST /api/v1/auth/login` - User login
|
|
476
|
+
- `POST /api/v1/auth/logout` - User logout
|
|
477
|
+
- `POST /api/v1/auth/refresh` - Refresh token
|
|
478
|
+
- `POST /api/v1/auth/forgot-password` - Password reset request
|
|
479
|
+
- `POST /api/v1/auth/reset-password` - Reset password
|
|
480
|
+
|
|
481
|
+
### Resources (Example)
|
|
482
|
+
- `GET /api/v1/resources` - List resources
|
|
483
|
+
- `GET /api/v1/resources/{id}` - Get resource
|
|
484
|
+
- `POST /api/v1/resources` - Create resource
|
|
485
|
+
- `PUT /api/v1/resources/{id}` - Update resource
|
|
486
|
+
- `DELETE /api/v1/resources/{id}` - Delete resource
|
|
487
|
+
|
|
488
|
+
---
|
|
489
|
+
|
|
490
|
+
## Breaking Change Protocol
|
|
491
|
+
|
|
492
|
+
### Before Creating/Modifying Endpoints:
|
|
493
|
+
|
|
494
|
+
1. **Check existing endpoints** - Search this contract for similar functionality
|
|
495
|
+
2. **Reuse if possible** - Use existing endpoints instead of creating new ones
|
|
496
|
+
3. **Combine endpoints** - Consider using existing endpoints together
|
|
497
|
+
4. **Plan backward compatibility** - Add optional parameters, don't remove required ones
|
|
498
|
+
5. **Version if breaking** - Create new version if changes are breaking
|
|
499
|
+
6. **Update this contract** - Document all changes with date and impact
|
|
500
|
+
7. **Update SQL_CONTRACT.json** - If endpoint uses new/modified queries
|
|
501
|
+
8. **Update DATABASE_SCHEMA_CONTRACT.md** - If endpoint uses new tables
|
|
502
|
+
|
|
503
|
+
### Breaking vs Non-Breaking Changes
|
|
504
|
+
|
|
505
|
+
**Breaking Changes (require new version):**
|
|
506
|
+
- Removing endpoints
|
|
507
|
+
- Removing required parameters
|
|
508
|
+
- Changing parameter types
|
|
509
|
+
- Changing response structure
|
|
510
|
+
- Changing authentication requirements
|
|
511
|
+
- Removing response fields
|
|
512
|
+
|
|
513
|
+
**Non-Breaking Changes (safe to add):**
|
|
514
|
+
- Adding new endpoints
|
|
515
|
+
- Adding optional parameters
|
|
516
|
+
- Adding new response fields
|
|
517
|
+
- Adding new error codes
|
|
518
|
+
- Improving performance
|
|
519
|
+
|
|
520
|
+
---
|
|
521
|
+
|
|
522
|
+
## Notes for Coding Agents
|
|
523
|
+
|
|
524
|
+
### CRITICAL RULES:
|
|
525
|
+
|
|
526
|
+
1. **ALWAYS read this contract before creating new endpoints**
|
|
527
|
+
2. **SEARCH for existing endpoints** that might serve the same purpose
|
|
528
|
+
3. **REUSE existing endpoints** by combining them if possible
|
|
529
|
+
4. **NEVER duplicate functionality** - extend existing endpoints instead
|
|
530
|
+
5. **UPDATE this contract immediately** after creating/modifying endpoints
|
|
531
|
+
6. **INCREMENT version number** for any API changes
|
|
532
|
+
7. **ADD changelog entry** with date, version, changes, and breaking status
|
|
533
|
+
8. **CROSS-REFERENCE SQL_CONTRACT.json** for queries used
|
|
534
|
+
9. **VERIFY DATABASE_SCHEMA_CONTRACT.md** for table structures
|
|
535
|
+
10. **DOCUMENT all parameters, responses, and errors** thoroughly
|
|
536
|
+
|
|
537
|
+
### Workflow:
|
|
538
|
+
|
|
539
|
+
```
|
|
540
|
+
1. Read API_CONTRACT.md
|
|
541
|
+
2. Search for existing endpoints by category and functionality
|
|
542
|
+
3. If exact match found, use it (document usage in your module)
|
|
543
|
+
4. If similar endpoint found, consider:
|
|
544
|
+
- Adding optional parameters to existing endpoint
|
|
545
|
+
- Combining multiple existing endpoints
|
|
546
|
+
- Creating new endpoint only if truly different
|
|
547
|
+
5. If creating new endpoint:
|
|
548
|
+
- Follow the template structure
|
|
549
|
+
- Document all details (auth, params, responses, errors)
|
|
550
|
+
- Add implementation details (controller, service, SQL)
|
|
551
|
+
- Cross-reference SQL_CONTRACT.json and DATABASE_SCHEMA_CONTRACT.md
|
|
552
|
+
- Add examples and test cases
|
|
553
|
+
6. Update changelog and version number
|
|
554
|
+
7. Commit with proper documentation
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
### Search Tips:
|
|
558
|
+
|
|
559
|
+
- Search by HTTP method (GET, POST, PUT, DELETE)
|
|
560
|
+
- Search by resource name (users, products, orders)
|
|
561
|
+
- Search by category (User Management, Authentication)
|
|
562
|
+
- Search by functionality (login, create, update, list)
|
|
563
|
+
- Check "Called By" and "Requires" to understand endpoint relationships
|
|
564
|
+
|
|
565
|
+
---
|
|
566
|
+
|
|
567
|
+
## Initial Population Instructions
|
|
568
|
+
|
|
569
|
+
**For DevOps Agent / Coding Agents:**
|
|
570
|
+
|
|
571
|
+
When populating this template for the first time:
|
|
572
|
+
|
|
573
|
+
1. **Scan codebase for route definitions:**
|
|
574
|
+
- Express: `app.get()`, `router.post()`, etc.
|
|
575
|
+
- FastAPI: `@app.get()`, `@router.post()`, etc.
|
|
576
|
+
- Flask: `@app.route()`, `@blueprint.route()`, etc.
|
|
577
|
+
- Django: `path()`, `url()` in urls.py
|
|
578
|
+
|
|
579
|
+
2. **Extract endpoint information:**
|
|
580
|
+
- HTTP method and path
|
|
581
|
+
- Controller/handler function
|
|
582
|
+
- Request parameters and body schema
|
|
583
|
+
- Response format
|
|
584
|
+
- Authentication/authorization requirements
|
|
585
|
+
|
|
586
|
+
3. **Document implementation details:**
|
|
587
|
+
- Which services/functions are called
|
|
588
|
+
- Which SQL queries are used (reference SQL_CONTRACT.json)
|
|
589
|
+
- Which database tables are accessed
|
|
590
|
+
- Which 3rd party services are integrated
|
|
591
|
+
|
|
592
|
+
4. **Add metadata:**
|
|
593
|
+
- Creation date
|
|
594
|
+
- Rate limits
|
|
595
|
+
- Performance characteristics
|
|
596
|
+
- Security considerations
|
|
597
|
+
|
|
598
|
+
5. **Categorize endpoints:**
|
|
599
|
+
- Group by resource type
|
|
600
|
+
- Tag by functionality
|
|
601
|
+
- Link related endpoints
|
|
602
|
+
|
|
603
|
+
**Search Patterns:**
|
|
604
|
+
- `app.get(`, `app.post(`, `app.put(`, `app.delete(`
|
|
605
|
+
- `router.get(`, `router.post(`, etc.
|
|
606
|
+
- `@app.route(`, `@router.route(`
|
|
607
|
+
- `@app.get(`, `@app.post(` (FastAPI)
|
|
608
|
+
- Route files: `**/routes/**`, `**/api/**`, `**/controllers/**`
|
|
609
|
+
|
|
610
|
+
---
|
|
611
|
+
|
|
612
|
+
*This contract is a living document. Update it with every API change.*
|