@mytechtoday/augment-extensions 0.1.0 → 0.1.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.
Files changed (102) hide show
  1. package/AGENTS.md +83 -3
  2. package/README.md +6 -5
  3. package/augment-extensions/coding-standards/python/README.md +44 -0
  4. package/augment-extensions/coding-standards/python/module.json +26 -0
  5. package/augment-extensions/coding-standards/python/rules/best-practices.md +232 -0
  6. package/augment-extensions/coding-standards/python/rules/code-organization.md +220 -0
  7. package/augment-extensions/coding-standards/python/rules/error-handling.md +221 -0
  8. package/augment-extensions/coding-standards/python/rules/naming-conventions.md +172 -0
  9. package/augment-extensions/coding-standards/python/rules/type-hints.md +188 -0
  10. package/augment-extensions/coding-standards/react/README.md +45 -0
  11. package/augment-extensions/coding-standards/react/module.json +27 -0
  12. package/augment-extensions/coding-standards/react/rules/component-patterns.md +214 -0
  13. package/augment-extensions/coding-standards/react/rules/hooks-best-practices.md +235 -0
  14. package/augment-extensions/coding-standards/react/rules/performance.md +300 -0
  15. package/augment-extensions/coding-standards/react/rules/state-management.md +265 -0
  16. package/augment-extensions/coding-standards/react/rules/typescript-react.md +271 -0
  17. package/augment-extensions/domain-rules/api-design/README.md +41 -0
  18. package/augment-extensions/domain-rules/api-design/module.json +27 -0
  19. package/augment-extensions/domain-rules/api-design/rules/authentication.md +263 -0
  20. package/augment-extensions/domain-rules/api-design/rules/documentation.md +395 -0
  21. package/augment-extensions/domain-rules/api-design/rules/error-handling.md +290 -0
  22. package/augment-extensions/domain-rules/api-design/rules/graphql-api.md +313 -0
  23. package/augment-extensions/domain-rules/api-design/rules/rest-api.md +214 -0
  24. package/augment-extensions/domain-rules/api-design/rules/versioning.md +268 -0
  25. package/augment-extensions/domain-rules/security/README.md +41 -0
  26. package/augment-extensions/domain-rules/security/module.json +28 -0
  27. package/augment-extensions/domain-rules/security/rules/authentication-security.md +361 -0
  28. package/augment-extensions/domain-rules/security/rules/encryption.md +208 -0
  29. package/augment-extensions/domain-rules/security/rules/input-validation.md +294 -0
  30. package/augment-extensions/domain-rules/security/rules/owasp-top-10.md +339 -0
  31. package/augment-extensions/domain-rules/security/rules/secure-coding.md +293 -0
  32. package/augment-extensions/domain-rules/security/rules/web-security.md +268 -0
  33. package/augment-extensions/examples/design-patterns/README.md +37 -0
  34. package/augment-extensions/examples/design-patterns/examples/behavioral-patterns.md +370 -0
  35. package/augment-extensions/examples/design-patterns/examples/creational-patterns.md +250 -0
  36. package/augment-extensions/examples/design-patterns/examples/structural-patterns.md +264 -0
  37. package/augment-extensions/examples/design-patterns/module.json +27 -0
  38. package/{modules → augment-extensions}/workflows/beads/examples/complete-workflow-example.md +5 -5
  39. package/{modules → augment-extensions}/workflows/beads/rules/file-format.md +45 -1
  40. package/{modules → augment-extensions}/workflows/beads/rules/workflow.md +41 -0
  41. package/{modules → augment-extensions}/workflows/openspec/examples/complete-change-example.md +14 -0
  42. package/{modules → augment-extensions}/workflows/openspec/rules/spec-format.md +44 -1
  43. package/{modules → augment-extensions}/workflows/openspec/rules/workflow.md +25 -0
  44. package/cli/dist/cli.js +64 -0
  45. package/cli/dist/cli.js.map +1 -1
  46. package/cli/dist/commands/coord.d.ts +30 -0
  47. package/cli/dist/commands/coord.d.ts.map +1 -0
  48. package/cli/dist/commands/coord.js +150 -0
  49. package/cli/dist/commands/coord.js.map +1 -0
  50. package/cli/dist/commands/link.js +1 -1
  51. package/cli/dist/commands/link.js.map +1 -1
  52. package/cli/dist/commands/list.js +1 -1
  53. package/cli/dist/commands/list.js.map +1 -1
  54. package/cli/dist/commands/search.d.ts.map +1 -1
  55. package/cli/dist/commands/search.js +107 -5
  56. package/cli/dist/commands/search.js.map +1 -1
  57. package/cli/dist/commands/show.js +1 -1
  58. package/cli/dist/commands/show.js.map +1 -1
  59. package/cli/dist/commands/sync.d.ts +26 -0
  60. package/cli/dist/commands/sync.d.ts.map +1 -0
  61. package/cli/dist/commands/sync.js +106 -0
  62. package/cli/dist/commands/sync.js.map +1 -0
  63. package/cli/dist/commands/update.d.ts.map +1 -1
  64. package/cli/dist/commands/update.js +132 -7
  65. package/cli/dist/commands/update.js.map +1 -1
  66. package/cli/dist/utils/auto-sync.d.ts +34 -0
  67. package/cli/dist/utils/auto-sync.d.ts.map +1 -0
  68. package/cli/dist/utils/auto-sync.js +172 -0
  69. package/cli/dist/utils/auto-sync.js.map +1 -0
  70. package/cli/dist/utils/beads-sync.d.ts +51 -0
  71. package/cli/dist/utils/beads-sync.d.ts.map +1 -0
  72. package/cli/dist/utils/beads-sync.js +171 -0
  73. package/cli/dist/utils/beads-sync.js.map +1 -0
  74. package/cli/dist/utils/coordination-queries.d.ts +79 -0
  75. package/cli/dist/utils/coordination-queries.d.ts.map +1 -0
  76. package/cli/dist/utils/coordination-queries.js +155 -0
  77. package/cli/dist/utils/coordination-queries.js.map +1 -0
  78. package/cli/dist/utils/file-tracking.d.ts +42 -0
  79. package/cli/dist/utils/file-tracking.d.ts.map +1 -0
  80. package/cli/dist/utils/file-tracking.js +155 -0
  81. package/cli/dist/utils/file-tracking.js.map +1 -0
  82. package/cli/dist/utils/migrate.d.ts +25 -0
  83. package/cli/dist/utils/migrate.d.ts.map +1 -0
  84. package/cli/dist/utils/migrate.js +204 -0
  85. package/cli/dist/utils/migrate.js.map +1 -0
  86. package/cli/dist/utils/openspec-sync.d.ts +48 -0
  87. package/cli/dist/utils/openspec-sync.d.ts.map +1 -0
  88. package/cli/dist/utils/openspec-sync.js +167 -0
  89. package/cli/dist/utils/openspec-sync.js.map +1 -0
  90. package/{MODULES.md → modules.md} +1 -1
  91. package/package.json +9 -7
  92. /package/{modules → augment-extensions}/coding-standards/typescript/README.md +0 -0
  93. /package/{modules → augment-extensions}/coding-standards/typescript/module.json +0 -0
  94. /package/{modules → augment-extensions}/coding-standards/typescript/rules/naming-conventions.md +0 -0
  95. /package/{modules → augment-extensions}/workflows/beads/README.md +0 -0
  96. /package/{modules → augment-extensions}/workflows/beads/module.json +0 -0
  97. /package/{modules → augment-extensions}/workflows/beads/rules/best-practices.md +0 -0
  98. /package/{modules → augment-extensions}/workflows/beads/rules/manual-setup.md +0 -0
  99. /package/{modules → augment-extensions}/workflows/openspec/README.md +0 -0
  100. /package/{modules → augment-extensions}/workflows/openspec/module.json +0 -0
  101. /package/{modules → augment-extensions}/workflows/openspec/rules/best-practices.md +0 -0
  102. /package/{modules → augment-extensions}/workflows/openspec/rules/manual-setup.md +0 -0
@@ -0,0 +1,395 @@
1
+ # API Documentation
2
+
3
+ Best practices for documenting APIs effectively.
4
+
5
+ ## OpenAPI/Swagger (Recommended)
6
+
7
+ Use OpenAPI specification for REST APIs.
8
+
9
+ ```yaml
10
+ # openapi.yaml
11
+ openapi: 3.0.0
12
+ info:
13
+ title: User API
14
+ version: 1.0.0
15
+ description: API for managing users
16
+ contact:
17
+ email: api@example.com
18
+ license:
19
+ name: MIT
20
+
21
+ servers:
22
+ - url: https://api.example.com/v1
23
+ description: Production
24
+ - url: https://staging-api.example.com/v1
25
+ description: Staging
26
+
27
+ paths:
28
+ /users:
29
+ get:
30
+ summary: List users
31
+ description: Retrieve a paginated list of users
32
+ tags:
33
+ - Users
34
+ parameters:
35
+ - name: page
36
+ in: query
37
+ schema:
38
+ type: integer
39
+ default: 1
40
+ - name: limit
41
+ in: query
42
+ schema:
43
+ type: integer
44
+ default: 20
45
+ maximum: 100
46
+ responses:
47
+ '200':
48
+ description: Successful response
49
+ content:
50
+ application/json:
51
+ schema:
52
+ $ref: '#/components/schemas/UserList'
53
+ '401':
54
+ $ref: '#/components/responses/Unauthorized'
55
+
56
+ post:
57
+ summary: Create user
58
+ description: Create a new user
59
+ tags:
60
+ - Users
61
+ requestBody:
62
+ required: true
63
+ content:
64
+ application/json:
65
+ schema:
66
+ $ref: '#/components/schemas/CreateUserRequest'
67
+ responses:
68
+ '201':
69
+ description: User created
70
+ content:
71
+ application/json:
72
+ schema:
73
+ $ref: '#/components/schemas/User'
74
+ '422':
75
+ $ref: '#/components/responses/ValidationError'
76
+
77
+ components:
78
+ schemas:
79
+ User:
80
+ type: object
81
+ properties:
82
+ id:
83
+ type: string
84
+ example: "123"
85
+ name:
86
+ type: string
87
+ example: "John Doe"
88
+ email:
89
+ type: string
90
+ format: email
91
+ example: "john@example.com"
92
+ createdAt:
93
+ type: string
94
+ format: date-time
95
+
96
+ CreateUserRequest:
97
+ type: object
98
+ required:
99
+ - name
100
+ - email
101
+ properties:
102
+ name:
103
+ type: string
104
+ minLength: 1
105
+ maxLength: 100
106
+ email:
107
+ type: string
108
+ format: email
109
+
110
+ UserList:
111
+ type: object
112
+ properties:
113
+ data:
114
+ type: array
115
+ items:
116
+ $ref: '#/components/schemas/User'
117
+ meta:
118
+ $ref: '#/components/schemas/PaginationMeta'
119
+
120
+ responses:
121
+ Unauthorized:
122
+ description: Authentication required
123
+ content:
124
+ application/json:
125
+ schema:
126
+ $ref: '#/components/schemas/Error'
127
+
128
+ ValidationError:
129
+ description: Validation failed
130
+ content:
131
+ application/json:
132
+ schema:
133
+ $ref: '#/components/schemas/ValidationError'
134
+
135
+ securitySchemes:
136
+ bearerAuth:
137
+ type: http
138
+ scheme: bearer
139
+ bearerFormat: JWT
140
+
141
+ security:
142
+ - bearerAuth: []
143
+ ```
144
+
145
+ ## GraphQL Documentation
146
+
147
+ Use schema descriptions and tools like GraphQL Playground.
148
+
149
+ ```graphql
150
+ """
151
+ Represents a user in the system
152
+ """
153
+ type User {
154
+ """
155
+ Unique identifier for the user
156
+ """
157
+ id: ID!
158
+
159
+ """
160
+ User's full name
161
+ """
162
+ name: String!
163
+
164
+ """
165
+ User's email address (must be unique)
166
+ """
167
+ email: String!
168
+
169
+ """
170
+ User's role in the system
171
+ """
172
+ role: UserRole!
173
+
174
+ """
175
+ Timestamp when the user was created
176
+ """
177
+ createdAt: DateTime!
178
+ }
179
+
180
+ """
181
+ Available user roles
182
+ """
183
+ enum UserRole {
184
+ """
185
+ Administrator with full access
186
+ """
187
+ ADMIN
188
+
189
+ """
190
+ Regular user with limited access
191
+ """
192
+ USER
193
+ }
194
+
195
+ type Query {
196
+ """
197
+ Retrieve a single user by ID
198
+
199
+ Returns null if user not found
200
+ """
201
+ user(
202
+ """
203
+ The unique identifier of the user
204
+ """
205
+ id: ID!
206
+ ): User
207
+
208
+ """
209
+ List all users with optional filtering
210
+
211
+ Supports pagination using cursor-based approach
212
+ """
213
+ users(
214
+ """
215
+ Filter by user role
216
+ """
217
+ role: UserRole
218
+
219
+ """
220
+ Number of users to return (max 100)
221
+ """
222
+ first: Int = 20
223
+
224
+ """
225
+ Cursor for pagination
226
+ """
227
+ after: String
228
+ ): UserConnection!
229
+ }
230
+ ```
231
+
232
+ ## README Documentation
233
+
234
+ Provide comprehensive README for API.
235
+
236
+ ```markdown
237
+ # User API
238
+
239
+ REST API for managing users.
240
+
241
+ ## Base URL
242
+
243
+ ```
244
+ Production: https://api.example.com/v1
245
+ Staging: https://staging-api.example.com/v1
246
+ ```
247
+
248
+ ## Authentication
249
+
250
+ All endpoints require authentication using JWT tokens.
251
+
252
+ ```bash
253
+ # Login to get token
254
+ curl -X POST https://api.example.com/v1/auth/login \
255
+ -H "Content-Type: application/json" \
256
+ -d '{"email": "user@example.com", "password": "secret"}'
257
+
258
+ # Use token in requests
259
+ curl https://api.example.com/v1/users \
260
+ -H "Authorization: Bearer YOUR_TOKEN"
261
+ ```
262
+
263
+ ## Endpoints
264
+
265
+ ### List Users
266
+
267
+ ```
268
+ GET /users
269
+ ```
270
+
271
+ Query Parameters:
272
+ - `page` (integer, default: 1) - Page number
273
+ - `limit` (integer, default: 20, max: 100) - Items per page
274
+ - `role` (string) - Filter by role (admin, user)
275
+
276
+ Response:
277
+ ```json
278
+ {
279
+ "data": [
280
+ {
281
+ "id": "123",
282
+ "name": "John Doe",
283
+ "email": "john@example.com"
284
+ }
285
+ ],
286
+ "meta": {
287
+ "total": 100,
288
+ "page": 1,
289
+ "limit": 20
290
+ }
291
+ }
292
+ ```
293
+
294
+ ## Error Handling
295
+
296
+ All errors follow this format:
297
+
298
+ ```json
299
+ {
300
+ "error": {
301
+ "code": "ERROR_CODE",
302
+ "message": "Human-readable message"
303
+ }
304
+ }
305
+ ```
306
+
307
+ Common error codes:
308
+ - `VALIDATION_ERROR` (422) - Invalid input
309
+ - `UNAUTHORIZED` (401) - Authentication required
310
+ - `FORBIDDEN` (403) - Insufficient permissions
311
+ - `NOT_FOUND` (404) - Resource not found
312
+
313
+ ## Rate Limiting
314
+
315
+ - 1000 requests per hour per API key
316
+ - Rate limit info in response headers:
317
+ - `X-RateLimit-Limit`
318
+ - `X-RateLimit-Remaining`
319
+ - `X-RateLimit-Reset`
320
+
321
+ ## Versioning
322
+
323
+ API is versioned in the URL: `/v1/`, `/v2/`, etc.
324
+
325
+ Current version: v1
326
+
327
+ ## SDKs
328
+
329
+ - JavaScript: `npm install @example/api-client`
330
+ - Python: `pip install example-api-client`
331
+
332
+ ## Support
333
+
334
+ - Documentation: https://docs.example.com
335
+ - Email: api@example.com
336
+ - GitHub: https://github.com/example/api
337
+ ```
338
+
339
+ ## Code Examples
340
+
341
+ Provide examples in multiple languages.
342
+
343
+ ```markdown
344
+ ## Examples
345
+
346
+ ### JavaScript
347
+
348
+ ```javascript
349
+ const response = await fetch('https://api.example.com/v1/users', {
350
+ headers: {
351
+ 'Authorization': `Bearer ${token}`,
352
+ 'Content-Type': 'application/json'
353
+ }
354
+ });
355
+ const users = await response.json();
356
+ ```
357
+
358
+ ### Python
359
+
360
+ ```python
361
+ import requests
362
+
363
+ response = requests.get(
364
+ 'https://api.example.com/v1/users',
365
+ headers={'Authorization': f'Bearer {token}'}
366
+ )
367
+ users = response.json()
368
+ ```
369
+
370
+ ### cURL
371
+
372
+ ```bash
373
+ curl https://api.example.com/v1/users \
374
+ -H "Authorization: Bearer YOUR_TOKEN"
375
+ ```
376
+ ```
377
+
378
+ ## Best Practices
379
+
380
+ 1. **Use OpenAPI** - For REST APIs
381
+ 2. **Use schema descriptions** - For GraphQL
382
+ 3. **Provide examples** - In multiple languages
383
+ 4. **Document errors** - List all error codes
384
+ 5. **Include authentication** - How to authenticate
385
+ 6. **Show rate limits** - Document limits
386
+ 7. **Version documentation** - Docs for each version
387
+ 8. **Interactive docs** - Swagger UI, GraphQL Playground
388
+ 9. **Keep updated** - Sync with code
389
+ 10. **Provide SDKs** - Client libraries
390
+ 11. **Include changelog** - Document changes
391
+ 12. **Add tutorials** - Getting started guides
392
+ 13. **Show use cases** - Common scenarios
393
+ 14. **Document webhooks** - If applicable
394
+ 15. **Provide support** - Contact information
395
+
@@ -0,0 +1,290 @@
1
+ # API Error Handling
2
+
3
+ Best practices for handling and communicating errors in APIs.
4
+
5
+ ## Error Response Structure
6
+
7
+ Use consistent error response format.
8
+
9
+ ```json
10
+ // Good - Comprehensive error response
11
+ {
12
+ "error": {
13
+ "code": "VALIDATION_ERROR",
14
+ "message": "Validation failed for one or more fields",
15
+ "details": [
16
+ {
17
+ "field": "email",
18
+ "message": "Email is required",
19
+ "code": "REQUIRED_FIELD"
20
+ },
21
+ {
22
+ "field": "age",
23
+ "message": "Age must be at least 18",
24
+ "code": "MIN_VALUE",
25
+ "value": 15,
26
+ "constraint": 18
27
+ }
28
+ ],
29
+ "timestamp": "2024-01-21T10:00:00Z",
30
+ "path": "/api/v1/users",
31
+ "requestId": "req_abc123"
32
+ }
33
+ }
34
+
35
+ // Good - Simple error
36
+ {
37
+ "error": {
38
+ "code": "NOT_FOUND",
39
+ "message": "User not found",
40
+ "timestamp": "2024-01-21T10:00:00Z",
41
+ "requestId": "req_abc123"
42
+ }
43
+ }
44
+ ```
45
+
46
+ ## HTTP Status Codes
47
+
48
+ Use appropriate status codes for different error types.
49
+
50
+ ```
51
+ # Client Errors (4xx)
52
+ 400 Bad Request - Malformed request syntax
53
+ 401 Unauthorized - Authentication required or failed
54
+ 403 Forbidden - Authenticated but not authorized
55
+ 404 Not Found - Resource doesn't exist
56
+ 405 Method Not Allowed - HTTP method not supported
57
+ 409 Conflict - Resource conflict (e.g., duplicate)
58
+ 410 Gone - Resource permanently deleted
59
+ 422 Unprocessable Entity - Validation errors
60
+ 429 Too Many Requests - Rate limit exceeded
61
+
62
+ # Server Errors (5xx)
63
+ 500 Internal Server Error - Unexpected server error
64
+ 502 Bad Gateway - Invalid response from upstream
65
+ 503 Service Unavailable - Server temporarily unavailable
66
+ 504 Gateway Timeout - Upstream server timeout
67
+ ```
68
+
69
+ ## Error Codes
70
+
71
+ Define machine-readable error codes.
72
+
73
+ ```typescript
74
+ // Good - Enum of error codes
75
+ enum ErrorCode {
76
+ // Validation errors (4xx)
77
+ VALIDATION_ERROR = 'VALIDATION_ERROR',
78
+ REQUIRED_FIELD = 'REQUIRED_FIELD',
79
+ INVALID_FORMAT = 'INVALID_FORMAT',
80
+ MIN_LENGTH = 'MIN_LENGTH',
81
+ MAX_LENGTH = 'MAX_LENGTH',
82
+
83
+ // Authentication errors (401)
84
+ INVALID_CREDENTIALS = 'INVALID_CREDENTIALS',
85
+ TOKEN_EXPIRED = 'TOKEN_EXPIRED',
86
+ TOKEN_INVALID = 'TOKEN_INVALID',
87
+
88
+ // Authorization errors (403)
89
+ INSUFFICIENT_PERMISSIONS = 'INSUFFICIENT_PERMISSIONS',
90
+ RESOURCE_FORBIDDEN = 'RESOURCE_FORBIDDEN',
91
+
92
+ // Not found errors (404)
93
+ RESOURCE_NOT_FOUND = 'RESOURCE_NOT_FOUND',
94
+ ENDPOINT_NOT_FOUND = 'ENDPOINT_NOT_FOUND',
95
+
96
+ // Conflict errors (409)
97
+ DUPLICATE_RESOURCE = 'DUPLICATE_RESOURCE',
98
+ RESOURCE_CONFLICT = 'RESOURCE_CONFLICT',
99
+
100
+ // Rate limiting (429)
101
+ RATE_LIMIT_EXCEEDED = 'RATE_LIMIT_EXCEEDED',
102
+
103
+ // Server errors (5xx)
104
+ INTERNAL_ERROR = 'INTERNAL_ERROR',
105
+ DATABASE_ERROR = 'DATABASE_ERROR',
106
+ EXTERNAL_SERVICE_ERROR = 'EXTERNAL_SERVICE_ERROR'
107
+ }
108
+ ```
109
+
110
+ ## Validation Errors
111
+
112
+ Provide detailed validation error information.
113
+
114
+ ```json
115
+ // Good - Field-level validation errors
116
+ {
117
+ "error": {
118
+ "code": "VALIDATION_ERROR",
119
+ "message": "Validation failed",
120
+ "details": [
121
+ {
122
+ "field": "email",
123
+ "message": "Email must be a valid email address",
124
+ "code": "INVALID_FORMAT",
125
+ "value": "not-an-email"
126
+ },
127
+ {
128
+ "field": "password",
129
+ "message": "Password must be at least 8 characters",
130
+ "code": "MIN_LENGTH",
131
+ "value": "***",
132
+ "constraint": 8
133
+ },
134
+ {
135
+ "field": "age",
136
+ "message": "Age must be between 18 and 120",
137
+ "code": "OUT_OF_RANGE",
138
+ "value": 150,
139
+ "min": 18,
140
+ "max": 120
141
+ }
142
+ ]
143
+ }
144
+ }
145
+ ```
146
+
147
+ ## Authentication Errors
148
+
149
+ Handle authentication failures clearly.
150
+
151
+ ```json
152
+ // 401 Unauthorized - Invalid credentials
153
+ {
154
+ "error": {
155
+ "code": "INVALID_CREDENTIALS",
156
+ "message": "Invalid email or password",
157
+ "timestamp": "2024-01-21T10:00:00Z"
158
+ }
159
+ }
160
+
161
+ // 401 Unauthorized - Token expired
162
+ {
163
+ "error": {
164
+ "code": "TOKEN_EXPIRED",
165
+ "message": "Access token has expired",
166
+ "expiredAt": "2024-01-21T09:00:00Z",
167
+ "hint": "Use refresh token to obtain a new access token"
168
+ }
169
+ }
170
+
171
+ // 401 Unauthorized - Invalid token
172
+ {
173
+ "error": {
174
+ "code": "TOKEN_INVALID",
175
+ "message": "Invalid or malformed access token"
176
+ }
177
+ }
178
+ ```
179
+
180
+ ## Authorization Errors
181
+
182
+ Communicate permission issues.
183
+
184
+ ```json
185
+ // 403 Forbidden - Insufficient permissions
186
+ {
187
+ "error": {
188
+ "code": "INSUFFICIENT_PERMISSIONS",
189
+ "message": "You don't have permission to perform this action",
190
+ "requiredPermission": "write:users",
191
+ "userPermissions": ["read:users"]
192
+ }
193
+ }
194
+
195
+ // 403 Forbidden - Resource forbidden
196
+ {
197
+ "error": {
198
+ "code": "RESOURCE_FORBIDDEN",
199
+ "message": "You don't have access to this resource"
200
+ }
201
+ }
202
+ ```
203
+
204
+ ## Not Found Errors
205
+
206
+ Distinguish between different types of "not found".
207
+
208
+ ```json
209
+ // 404 Not Found - Resource
210
+ {
211
+ "error": {
212
+ "code": "RESOURCE_NOT_FOUND",
213
+ "message": "User not found",
214
+ "resourceType": "User",
215
+ "resourceId": "123"
216
+ }
217
+ }
218
+
219
+ // 404 Not Found - Endpoint
220
+ {
221
+ "error": {
222
+ "code": "ENDPOINT_NOT_FOUND",
223
+ "message": "The requested endpoint does not exist",
224
+ "path": "/api/v1/invalid-endpoint"
225
+ }
226
+ }
227
+ ```
228
+
229
+ ## Rate Limiting Errors
230
+
231
+ Provide retry information.
232
+
233
+ ```json
234
+ // 429 Too Many Requests
235
+ {
236
+ "error": {
237
+ "code": "RATE_LIMIT_EXCEEDED",
238
+ "message": "Too many requests. Please try again later.",
239
+ "limit": 1000,
240
+ "remaining": 0,
241
+ "resetAt": "2024-01-21T11:00:00Z",
242
+ "retryAfter": 3600
243
+ }
244
+ }
245
+ ```
246
+
247
+ ## Server Errors
248
+
249
+ Handle internal errors gracefully.
250
+
251
+ ```json
252
+ // 500 Internal Server Error
253
+ {
254
+ "error": {
255
+ "code": "INTERNAL_ERROR",
256
+ "message": "An unexpected error occurred. Please try again later.",
257
+ "requestId": "req_abc123",
258
+ "timestamp": "2024-01-21T10:00:00Z"
259
+ }
260
+ }
261
+
262
+ // Don't expose internal details in production
263
+ // Bad - Exposing stack trace
264
+ {
265
+ "error": {
266
+ "message": "Database connection failed",
267
+ "stack": "Error: connect ECONNREFUSED...", // ❌ Don't expose
268
+ "query": "SELECT * FROM users WHERE..." // ❌ Don't expose
269
+ }
270
+ }
271
+ ```
272
+
273
+ ## Best Practices
274
+
275
+ 1. **Use consistent format** - Same structure for all errors
276
+ 2. **Use proper status codes** - Match HTTP semantics
277
+ 3. **Provide error codes** - Machine-readable codes
278
+ 4. **Include helpful messages** - Human-readable descriptions
279
+ 5. **Field-level errors** - For validation failures
280
+ 6. **Include request ID** - For debugging and support
281
+ 7. **Include timestamp** - When error occurred
282
+ 8. **Don't expose internals** - Hide stack traces in production
283
+ 9. **Log errors** - Server-side logging for debugging
284
+ 10. **Document errors** - List possible error codes
285
+ 11. **Localize messages** - Support multiple languages
286
+ 12. **Provide hints** - Suggest how to fix the error
287
+ 13. **Rate limit info** - Include retry information
288
+ 14. **Validate early** - Fail fast on invalid input
289
+ 15. **Monitor errors** - Track error rates and types
290
+