ai-spector 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 (63) hide show
  1. package/README.md +169 -0
  2. package/_templates/basic_design/db-design-template.md +177 -0
  3. package/_templates/basic_design/detail-api-template.md +278 -0
  4. package/_templates/basic_design/detail-screen-template.md +281 -0
  5. package/_templates/basic_design/list-api-template.md +130 -0
  6. package/_templates/basic_design/list-screen-template.md +242 -0
  7. package/_templates/detail_design/common/architecture-overview-template.md +302 -0
  8. package/_templates/detail_design/common/deployment-infrastructure-template.md +461 -0
  9. package/_templates/detail_design/common/error-handling-patterns-template.md +460 -0
  10. package/_templates/detail_design/common/integration-patterns-template.md +410 -0
  11. package/_templates/detail_design/common/performance-standards-template.md +406 -0
  12. package/_templates/detail_design/common/security-patterns-template.md +395 -0
  13. package/_templates/detail_design/feature-detail-design-template.md +773 -0
  14. package/_templates/detail_design/feature-list-template.md +39 -0
  15. package/_templates/srs/1-introduction.md +58 -0
  16. package/_templates/srs/2-overall-description.md +91 -0
  17. package/_templates/srs/3-use-case-detail-template.md +142 -0
  18. package/_templates/srs/3-use-cases.md +53 -0
  19. package/_templates/srs/4-system-feature-detail-template.md +131 -0
  20. package/_templates/srs/4-system-features-list-template.md +39 -0
  21. package/_templates/srs/5-data-requirements.md +59 -0
  22. package/_templates/srs/6-external-interfaces.md +56 -0
  23. package/_templates/srs/7-quality-attributes.md +74 -0
  24. package/_templates/srs/8-internationalization.md +36 -0
  25. package/_templates/srs/9-other-requirements.md +46 -0
  26. package/assets/cursor/commands/analyze.md +39 -0
  27. package/assets/cursor/commands/generate-detail-design.md +35 -0
  28. package/assets/cursor/commands/generate-srs.md +38 -0
  29. package/assets/cursor/skills/spec-writer/SKILL.md +33 -0
  30. package/assets/workflow/config/analyze.graphify.json +36 -0
  31. package/assets/workflow/config/completeness-rules.detail-design.json +57 -0
  32. package/assets/workflow/config/completeness-rules.srs.json +72 -0
  33. package/assets/workflow/config/dag.detail-design.json +64 -0
  34. package/assets/workflow/config/dag.srs.json +87 -0
  35. package/assets/workflow/state/state.template.json +26 -0
  36. package/assets/workflow/templates/basic_design/db-design-template.md +177 -0
  37. package/assets/workflow/templates/basic_design/detail-api-template.md +278 -0
  38. package/assets/workflow/templates/basic_design/detail-screen-template.md +281 -0
  39. package/assets/workflow/templates/basic_design/list-api-template.md +130 -0
  40. package/assets/workflow/templates/basic_design/list-screen-template.md +242 -0
  41. package/assets/workflow/templates/detail_design/common/architecture-overview-template.md +302 -0
  42. package/assets/workflow/templates/detail_design/common/deployment-infrastructure-template.md +461 -0
  43. package/assets/workflow/templates/detail_design/common/error-handling-patterns-template.md +460 -0
  44. package/assets/workflow/templates/detail_design/common/integration-patterns-template.md +410 -0
  45. package/assets/workflow/templates/detail_design/common/performance-standards-template.md +406 -0
  46. package/assets/workflow/templates/detail_design/common/security-patterns-template.md +395 -0
  47. package/assets/workflow/templates/detail_design/feature-detail-design-template.md +773 -0
  48. package/assets/workflow/templates/detail_design/feature-list-template.md +39 -0
  49. package/assets/workflow/templates/srs/1-introduction.md +58 -0
  50. package/assets/workflow/templates/srs/2-overall-description.md +91 -0
  51. package/assets/workflow/templates/srs/3-use-case-detail-template.md +142 -0
  52. package/assets/workflow/templates/srs/3-use-cases.md +53 -0
  53. package/assets/workflow/templates/srs/4-system-feature-detail-template.md +131 -0
  54. package/assets/workflow/templates/srs/4-system-features-list-template.md +39 -0
  55. package/assets/workflow/templates/srs/5-data-requirements.md +59 -0
  56. package/assets/workflow/templates/srs/6-external-interfaces.md +56 -0
  57. package/assets/workflow/templates/srs/7-quality-attributes.md +74 -0
  58. package/assets/workflow/templates/srs/8-internationalization.md +36 -0
  59. package/assets/workflow/templates/srs/9-other-requirements.md +46 -0
  60. package/bin/spec-writer.js +56 -0
  61. package/package.json +25 -0
  62. package/src/cli/helpers/fs.js +50 -0
  63. package/src/cli/init.js +178 -0
@@ -0,0 +1,410 @@
1
+ # Integration Patterns: <Project Name>
2
+
3
+ > This document defines common integration patterns, API integration standards, event-driven patterns, and third-party service integration approaches used across all features.
4
+
5
+ **Source Requirements:** SRS Section 6.2 (Software Interfaces)
6
+
7
+ ---
8
+
9
+ ## 1. Overview
10
+
11
+ **Purpose:**
12
+ > This document establishes integration patterns and standards that ensure consistent, reliable, and maintainable integrations across all features.
13
+
14
+ **Integration Principles:**
15
+ - Loose coupling
16
+ - Fault tolerance
17
+ - Idempotency
18
+ - Versioning
19
+ - Monitoring and observability
20
+
21
+ ---
22
+
23
+ ## 2. API Integration Patterns
24
+
25
+ ### 2.1 REST API Integration
26
+
27
+ **REST Principles:**
28
+ - Use standard HTTP methods (GET, POST, PUT, DELETE, PATCH)
29
+ - Use proper HTTP status codes
30
+ - Follow RESTful resource naming
31
+ - Support content negotiation
32
+ - Use HATEOAS when appropriate
33
+
34
+ **Request/Response Format:**
35
+ - Content-Type: `application/json`
36
+ - Accept: `application/json`
37
+ - Use consistent error response format
38
+ - Include request/response metadata
39
+
40
+ **Authentication:**
41
+ - Bearer token authentication
42
+ - API key authentication (for service-to-service)
43
+ - OAuth2 for third-party integrations
44
+
45
+ ### 2.2 GraphQL Integration
46
+
47
+ **When to Use:**
48
+ - Complex data requirements
49
+ - Need for flexible queries
50
+ - Multiple client types with different data needs
51
+
52
+ **Best Practices:**
53
+ - Use query complexity analysis
54
+ - Implement rate limiting
55
+ - Use data loaders to avoid N+1 queries
56
+ - Implement proper error handling
57
+
58
+ ### 2.3 gRPC Integration
59
+
60
+ **When to Use:**
61
+ - High-performance requirements
62
+ - Strong typing needed
63
+ - Microservices communication
64
+ - Streaming data
65
+
66
+ **Best Practices:**
67
+ - Define clear service contracts
68
+ - Use protocol buffers
69
+ - Implement proper error handling
70
+ - Monitor performance
71
+
72
+ ---
73
+
74
+ ## 3. Event-Driven Architecture
75
+
76
+ ### 3.1 Event Patterns
77
+
78
+ **Event Sourcing:**
79
+ - Store events as source of truth
80
+ - Rebuild state from events
81
+ - Enable audit trail
82
+ - Support time travel
83
+
84
+ **Pub/Sub Pattern:**
85
+ ```
86
+ Publisher → Message Queue → Subscribers
87
+ ```
88
+
89
+ **Event Streaming:**
90
+ - Use message brokers (Kafka, RabbitMQ)
91
+ - Support multiple consumers
92
+ - Ensure event ordering when needed
93
+ - Handle event replay
94
+
95
+ ### 3.2 Message Queue Patterns
96
+
97
+ **Queue Types:**
98
+ - **Point-to-point:** One producer, one consumer
99
+ - **Pub/Sub:** One producer, multiple consumers
100
+ - **Request/Reply:** Request-response pattern
101
+
102
+ **Message Format:**
103
+ ```json
104
+ {
105
+ "event_type": "user.created",
106
+ "event_id": "evt_123456789",
107
+ "timestamp": "2025-01-15T10:30:00Z",
108
+ "source": "user-service",
109
+ "data": {
110
+ "user_id": "user123",
111
+ "email": "user@example.com"
112
+ },
113
+ "metadata": {
114
+ "correlation_id": "corr_123",
115
+ "causation_id": "evt_123456788"
116
+ }
117
+ }
118
+ ```
119
+
120
+ **Message Properties:**
121
+ - **Idempotency:** Handle duplicate messages
122
+ - **Ordering:** Maintain message order when needed
123
+ - **Retry:** Automatic retry on failure
124
+ - **Dead Letter Queue:** Handle failed messages
125
+
126
+ ### 3.3 Event Types
127
+
128
+ **Domain Events:**
129
+ - `user.created`
130
+ - `user.updated`
131
+ - `order.placed`
132
+ - `payment.processed`
133
+
134
+ **Integration Events:**
135
+ - `external.service.notified`
136
+ - `sync.completed`
137
+ - `webhook.sent`
138
+
139
+ ---
140
+
141
+ ## 4. Third-Party Service Integration
142
+
143
+ ### 4.1 Integration Patterns
144
+
145
+ **API Gateway Pattern:**
146
+ - Single entry point for external services
147
+ - Centralized authentication
148
+ - Rate limiting and throttling
149
+ - Request/response transformation
150
+
151
+ **Adapter Pattern:**
152
+ - Wrap third-party APIs
153
+ - Abstract service differences
154
+ - Handle service-specific errors
155
+ - Provide consistent interface
156
+
157
+ **Circuit Breaker Pattern:**
158
+ - Protect against cascading failures
159
+ - Fail fast when service is down
160
+ - Automatic recovery testing
161
+ - Fallback mechanisms
162
+
163
+ ### 4.2 Webhook Integration
164
+
165
+ **Webhook Flow:**
166
+ ```
167
+ 1. Register webhook URL with third-party
168
+ 2. Third-party sends events to webhook URL
169
+ 3. Validate webhook signature
170
+ 4. Process webhook event
171
+ 5. Return acknowledgment
172
+ ```
173
+
174
+ **Webhook Security:**
175
+ - Verify webhook signatures
176
+ - Use HTTPS only
177
+ - Validate event source
178
+ - Implement idempotency
179
+
180
+ **Webhook Handling:**
181
+ - Handle duplicate events
182
+ - Process events asynchronously
183
+ - Retry failed webhooks
184
+ - Log all webhook events
185
+
186
+ ### 4.3 OAuth2 Integration
187
+
188
+ **OAuth2 Flows:**
189
+ - **Authorization Code:** For web applications
190
+ - **Client Credentials:** For service-to-service
191
+ - **Implicit:** For single-page applications (deprecated)
192
+
193
+ **Implementation:**
194
+ - Store tokens securely
195
+ - Handle token refresh
196
+ - Implement proper error handling
197
+ - Monitor token expiration
198
+
199
+ ---
200
+
201
+ ## 5. Data Synchronization
202
+
203
+ ### 5.1 Synchronization Patterns
204
+
205
+ **Full Sync:**
206
+ - Replace all data periodically
207
+ - Use for initial data load
208
+ - Handle large datasets
209
+
210
+ **Incremental Sync:**
211
+ - Sync only changes
212
+ - Use timestamps or change logs
213
+ - More efficient for frequent updates
214
+
215
+ **Real-time Sync:**
216
+ - Sync changes immediately
217
+ - Use events or webhooks
218
+ - Low latency
219
+
220
+ ### 5.2 Conflict Resolution
221
+
222
+ **Conflict Resolution Strategies:**
223
+ - **Last Write Wins:** Use latest timestamp
224
+ - **Source of Truth:** Designate authoritative source
225
+ - **Merge:** Combine changes intelligently
226
+ - **Manual Resolution:** Require human intervention
227
+
228
+ **Conflict Detection:**
229
+ - Use version numbers
230
+ - Use timestamps
231
+ - Use checksums
232
+ - Detect concurrent modifications
233
+
234
+ ---
235
+
236
+ ## 6. Error Handling in Integrations
237
+
238
+ ### 6.1 Retry Strategy
239
+
240
+ **Retry Configuration:**
241
+ - Max retries: <Number>
242
+ - Retry delay: <Duration>
243
+ - Backoff strategy: <Exponential/Linear>
244
+ - Retryable errors: <List of error codes>
245
+
246
+ **Retry Logic:**
247
+ ```javascript
248
+ // Example retry logic
249
+ async function callWithRetry(apiCall, maxRetries = 3) {
250
+ for (let i = 0; i < maxRetries; i++) {
251
+ try {
252
+ return await apiCall();
253
+ } catch (error) {
254
+ if (!isRetryable(error) || i === maxRetries - 1) {
255
+ throw error;
256
+ }
257
+ await sleep(exponentialBackoff(i));
258
+ }
259
+ }
260
+ }
261
+ ```
262
+
263
+ ### 6.2 Circuit Breaker
264
+
265
+ **Circuit Breaker States:**
266
+ - **Closed:** Normal operation
267
+ - **Open:** Failing, reject requests
268
+ - **Half-Open:** Testing recovery
269
+
270
+ **Configuration:**
271
+ - Failure threshold: <Number of failures>
272
+ - Timeout: <Duration before retry>
273
+ - Success threshold: <Number of successes>
274
+
275
+ ### 6.3 Fallback Mechanisms
276
+
277
+ **Fallback Strategies:**
278
+ - Return cached data
279
+ - Return default values
280
+ - Queue request for later processing
281
+ - Return error to user with retry option
282
+
283
+ ---
284
+
285
+ ## 7. Integration Monitoring
286
+
287
+ ### 7.1 Metrics to Monitor
288
+
289
+ **Integration Metrics:**
290
+ - Request rate
291
+ - Response time
292
+ - Error rate
293
+ - Success rate
294
+ - Timeout rate
295
+ - Circuit breaker state
296
+
297
+ **Third-Party Service Metrics:**
298
+ - Service availability
299
+ - Response time
300
+ - Error rate
301
+ - Rate limit usage
302
+ - Quota usage
303
+
304
+ ### 7.2 Logging
305
+
306
+ **Log Events:**
307
+ - Integration requests
308
+ - Integration responses
309
+ - Errors and exceptions
310
+ - Retry attempts
311
+ - Circuit breaker state changes
312
+ - Webhook events
313
+
314
+ **Log Format:**
315
+ ```json
316
+ {
317
+ "timestamp": "2025-01-15T10:30:00Z",
318
+ "integration": "payment-service",
319
+ "operation": "process_payment",
320
+ "request_id": "req_123456789",
321
+ "status": "success",
322
+ "duration_ms": 150,
323
+ "metadata": {
324
+ "amount": 100.00,
325
+ "currency": "USD"
326
+ }
327
+ }
328
+ ```
329
+
330
+ ### 7.3 Alerting
331
+
332
+ **Alert Conditions:**
333
+ - High error rate
334
+ - Slow response times
335
+ - Service unavailable
336
+ - Circuit breaker opened
337
+ - Quota exceeded
338
+
339
+ ---
340
+
341
+ ## 8. Integration Testing
342
+
343
+ ### 8.1 Testing Strategies
344
+
345
+ **Contract Testing:**
346
+ - Verify API contracts
347
+ - Test request/response formats
348
+ - Validate schemas
349
+
350
+ **Integration Testing:**
351
+ - Test with real services (staging)
352
+ - Test error scenarios
353
+ - Test retry logic
354
+ - Test circuit breaker
355
+
356
+ **Mock Services:**
357
+ - Use mocks for development
358
+ - Use mocks for unit testing
359
+ - Use service virtualization
360
+
361
+ ### 8.2 Test Scenarios
362
+
363
+ **Scenarios:**
364
+ - Successful integration
365
+ - Service unavailable
366
+ - Timeout scenarios
367
+ - Invalid responses
368
+ - Rate limiting
369
+ - Authentication failures
370
+
371
+ ---
372
+
373
+ ## 9. Integration Checklist
374
+
375
+ **Integration Requirements:**
376
+ - [ ] Authentication/authorization configured
377
+ - [ ] Error handling implemented
378
+ - [ ] Retry logic implemented
379
+ - [ ] Circuit breaker implemented (if needed)
380
+ - [ ] Logging and monitoring set up
381
+ - [ ] Rate limiting configured
382
+ - [ ] Timeout configured
383
+ - [ ] Idempotency handled
384
+ - [ ] Versioning strategy defined
385
+ - [ ] Documentation updated
386
+
387
+ ---
388
+
389
+ ## 10. References
390
+
391
+ **Related Documents:**
392
+ - [Architecture Overview](../common/architecture-overview-template.md)
393
+ - [Error Handling Patterns](../common/error-handling-patterns-template.md)
394
+ - [Security Patterns](../common/security-patterns-template.md)
395
+ - [Feature Detail Design Template](../feature-detail-design-template.md)
396
+
397
+ **SRS References:**
398
+ - SRS Section 6.2: Software Interfaces
399
+
400
+ ---
401
+
402
+ ## 11. Notes
403
+
404
+ **Integration Considerations:**
405
+ - <Consideration 1>
406
+ - <Consideration 2>
407
+
408
+ **Future Enhancements:**
409
+ - <Enhancement 1>
410
+ - <Enhancement 2>