trinity-method-sdk 2.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.
Files changed (191) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/LICENSE +21 -0
  3. package/README.md +555 -0
  4. package/dist/cli/commands/deploy/agents.d.ts +14 -0
  5. package/dist/cli/commands/deploy/agents.js +59 -0
  6. package/dist/cli/commands/deploy/ci-cd.d.ts +13 -0
  7. package/dist/cli/commands/deploy/ci-cd.js +50 -0
  8. package/dist/cli/commands/deploy/claude-setup.d.ts +17 -0
  9. package/dist/cli/commands/deploy/claude-setup.js +91 -0
  10. package/dist/cli/commands/deploy/configuration.d.ts +13 -0
  11. package/dist/cli/commands/deploy/configuration.js +215 -0
  12. package/dist/cli/commands/deploy/directories.d.ts +12 -0
  13. package/dist/cli/commands/deploy/directories.js +38 -0
  14. package/dist/cli/commands/deploy/gitignore.d.ts +12 -0
  15. package/dist/cli/commands/deploy/gitignore.js +53 -0
  16. package/dist/cli/commands/deploy/index.d.ts +38 -0
  17. package/dist/cli/commands/deploy/index.js +156 -0
  18. package/dist/cli/commands/deploy/knowledge-base.d.ts +16 -0
  19. package/dist/cli/commands/deploy/knowledge-base.js +75 -0
  20. package/dist/cli/commands/deploy/linting.d.ts +18 -0
  21. package/dist/cli/commands/deploy/linting.js +51 -0
  22. package/dist/cli/commands/deploy/metrics.d.ts +13 -0
  23. package/dist/cli/commands/deploy/metrics.js +34 -0
  24. package/dist/cli/commands/deploy/pre-flight.d.ts +13 -0
  25. package/dist/cli/commands/deploy/pre-flight.js +29 -0
  26. package/dist/cli/commands/deploy/root-files.d.ts +16 -0
  27. package/dist/cli/commands/deploy/root-files.js +178 -0
  28. package/dist/cli/commands/deploy/sdk-install.d.ts +12 -0
  29. package/dist/cli/commands/deploy/sdk-install.js +57 -0
  30. package/dist/cli/commands/deploy/summary.d.ts +14 -0
  31. package/dist/cli/commands/deploy/summary.js +130 -0
  32. package/dist/cli/commands/deploy/templates.d.ts +14 -0
  33. package/dist/cli/commands/deploy/templates.js +84 -0
  34. package/dist/cli/commands/deploy/types.d.ts +39 -0
  35. package/dist/cli/commands/deploy/types.js +5 -0
  36. package/dist/cli/commands/update/agents.d.ts +14 -0
  37. package/dist/cli/commands/update/agents.js +31 -0
  38. package/dist/cli/commands/update/backup.d.ts +31 -0
  39. package/dist/cli/commands/update/backup.js +97 -0
  40. package/dist/cli/commands/update/commands.d.ts +14 -0
  41. package/dist/cli/commands/update/commands.js +75 -0
  42. package/dist/cli/commands/update/index.d.ts +15 -0
  43. package/dist/cli/commands/update/index.js +118 -0
  44. package/dist/cli/commands/update/knowledge-base.d.ts +14 -0
  45. package/dist/cli/commands/update/knowledge-base.js +38 -0
  46. package/dist/cli/commands/update/pre-flight.d.ts +13 -0
  47. package/dist/cli/commands/update/pre-flight.js +37 -0
  48. package/dist/cli/commands/update/summary.d.ts +20 -0
  49. package/dist/cli/commands/update/summary.js +47 -0
  50. package/dist/cli/commands/update/templates.d.ts +14 -0
  51. package/dist/cli/commands/update/templates.js +25 -0
  52. package/dist/cli/commands/update/types.d.ts +13 -0
  53. package/dist/cli/commands/update/types.js +7 -0
  54. package/dist/cli/commands/update/utils.d.ts +11 -0
  55. package/dist/cli/commands/update/utils.js +19 -0
  56. package/dist/cli/commands/update/verification.d.ts +20 -0
  57. package/dist/cli/commands/update/verification.js +54 -0
  58. package/dist/cli/commands/update/version.d.ts +18 -0
  59. package/dist/cli/commands/update/version.js +36 -0
  60. package/dist/cli/commands/update.d.ts +7 -0
  61. package/dist/cli/commands/update.js +7 -0
  62. package/dist/cli/index.d.ts +3 -0
  63. package/dist/cli/index.js +36 -0
  64. package/dist/cli/types.d.ts +77 -0
  65. package/dist/cli/types.js +5 -0
  66. package/dist/cli/utils/deploy-ci.d.ts +22 -0
  67. package/dist/cli/utils/deploy-ci.js +138 -0
  68. package/dist/cli/utils/deploy-linting.d.ts +3 -0
  69. package/dist/cli/utils/deploy-linting.js +136 -0
  70. package/dist/cli/utils/detect-stack.d.ts +3 -0
  71. package/dist/cli/utils/detect-stack.js +270 -0
  72. package/dist/cli/utils/error-classes.d.ts +63 -0
  73. package/dist/cli/utils/error-classes.js +84 -0
  74. package/dist/cli/utils/error-handler.d.ts +59 -0
  75. package/dist/cli/utils/error-handler.js +127 -0
  76. package/dist/cli/utils/errors.d.ts +52 -0
  77. package/dist/cli/utils/errors.js +102 -0
  78. package/dist/cli/utils/get-sdk-path.d.ts +18 -0
  79. package/dist/cli/utils/get-sdk-path.js +31 -0
  80. package/dist/cli/utils/inject-dependencies.d.ts +2 -0
  81. package/dist/cli/utils/inject-dependencies.js +55 -0
  82. package/dist/cli/utils/linting-tools.d.ts +8 -0
  83. package/dist/cli/utils/linting-tools.js +206 -0
  84. package/dist/cli/utils/metrics/code-quality.d.ts +32 -0
  85. package/dist/cli/utils/metrics/code-quality.js +122 -0
  86. package/dist/cli/utils/metrics/dependency-parser.d.ts +21 -0
  87. package/dist/cli/utils/metrics/dependency-parser.js +153 -0
  88. package/dist/cli/utils/metrics/file-complexity.d.ts +26 -0
  89. package/dist/cli/utils/metrics/file-complexity.js +77 -0
  90. package/dist/cli/utils/metrics/framework-detector.d.ts +17 -0
  91. package/dist/cli/utils/metrics/framework-detector.js +120 -0
  92. package/dist/cli/utils/metrics/git-metrics.d.ts +30 -0
  93. package/dist/cli/utils/metrics/git-metrics.js +83 -0
  94. package/dist/cli/utils/metrics/index.d.ts +28 -0
  95. package/dist/cli/utils/metrics/index.js +100 -0
  96. package/dist/cli/utils/template-processor.d.ts +10 -0
  97. package/dist/cli/utils/template-processor.js +188 -0
  98. package/dist/cli/utils/validate-path.d.ts +80 -0
  99. package/dist/cli/utils/validate-path.js +180 -0
  100. package/dist/index.d.ts +6 -0
  101. package/dist/index.js +8 -0
  102. package/dist/templates/agents/aj-team/apo-documentation-specialist.md.template +572 -0
  103. package/dist/templates/agents/aj-team/bas-quality-gate.md.template +906 -0
  104. package/dist/templates/agents/aj-team/bon-dependency-manager.md.template +636 -0
  105. package/dist/templates/agents/aj-team/cap-configuration-specialist.md.template +670 -0
  106. package/dist/templates/agents/aj-team/dra-code-reviewer.md.template +768 -0
  107. package/dist/templates/agents/aj-team/kil-task-executor.md.template +764 -0
  108. package/dist/templates/agents/aj-team/uro-refactoring-specialist.md.template +759 -0
  109. package/dist/templates/agents/audit/juno-auditor.md.template +447 -0
  110. package/dist/templates/agents/deployment/ein-cicd.md.template +694 -0
  111. package/dist/templates/agents/deployment/ino-context.md.template +733 -0
  112. package/dist/templates/agents/deployment/tan-structure.md.template +661 -0
  113. package/dist/templates/agents/deployment/zen-knowledge.md.template +451 -0
  114. package/dist/templates/agents/leadership/aj-cc.md.template +462 -0
  115. package/dist/templates/agents/leadership/aj-maestro.md.template +943 -0
  116. package/dist/templates/agents/leadership/aly-cto.md.template +407 -0
  117. package/dist/templates/agents/planning/eus-decomposer.md.template +496 -0
  118. package/dist/templates/agents/planning/mon-requirements.md.template +323 -0
  119. package/dist/templates/agents/planning/ror-design.md.template +465 -0
  120. package/dist/templates/agents/planning/tra-planner.md.template +432 -0
  121. package/dist/templates/ci/cd.yml.template +175 -0
  122. package/dist/templates/ci/ci.yml.template +196 -0
  123. package/dist/templates/ci/generic-ci.yml +115 -0
  124. package/dist/templates/ci/github-actions.yml +86 -0
  125. package/dist/templates/ci/gitlab-ci.yml +103 -0
  126. package/dist/templates/claude/EMPLOYEE-DIRECTORY.md.template +545 -0
  127. package/dist/templates/documentation/ROOT-README.md.template +307 -0
  128. package/dist/templates/documentation/SUBDIRECTORY-README.md.template +261 -0
  129. package/dist/templates/investigations/bug.md.template +484 -0
  130. package/dist/templates/investigations/feature.md.template +564 -0
  131. package/dist/templates/investigations/performance.md.template +625 -0
  132. package/dist/templates/investigations/security.md.template +714 -0
  133. package/dist/templates/investigations/technical.md.template +433 -0
  134. package/dist/templates/knowledge-base/AI-DEVELOPMENT-GUIDE.md.template +957 -0
  135. package/dist/templates/knowledge-base/ARCHITECTURE.md.template +452 -0
  136. package/dist/templates/knowledge-base/CODING-PRINCIPLES.md.template +750 -0
  137. package/dist/templates/knowledge-base/DOCUMENTATION-CRITERIA.md.template +1118 -0
  138. package/dist/templates/knowledge-base/ISSUES.md.template +539 -0
  139. package/dist/templates/knowledge-base/TESTING-PRINCIPLES.md.template +894 -0
  140. package/dist/templates/knowledge-base/Technical-Debt.md.template +640 -0
  141. package/dist/templates/knowledge-base/To-do.md.template +407 -0
  142. package/dist/templates/knowledge-base/Trinity.md.template +464 -0
  143. package/dist/templates/linting/flutter/.pre-commit-config.yaml.template +27 -0
  144. package/dist/templates/linting/flutter/analysis_options.yaml.template +26 -0
  145. package/dist/templates/linting/nodejs/.eslintrc-commonjs.json.template +19 -0
  146. package/dist/templates/linting/nodejs/.eslintrc-esm.json.template +19 -0
  147. package/dist/templates/linting/nodejs/.eslintrc-typescript.json.template +22 -0
  148. package/dist/templates/linting/nodejs/.pre-commit-config.yaml.template +51 -0
  149. package/dist/templates/linting/nodejs/.prettierrc.json.template +10 -0
  150. package/dist/templates/linting/python/.flake8.template +16 -0
  151. package/dist/templates/linting/python/.pre-commit-config.yaml.template +30 -0
  152. package/dist/templates/linting/python/pyproject.toml.template +38 -0
  153. package/dist/templates/linting/rust/.pre-commit-config.yaml.template +28 -0
  154. package/dist/templates/linting/rust/clippy.toml.template +14 -0
  155. package/dist/templates/linting/rust/rustfmt.toml.template +12 -0
  156. package/dist/templates/root/CLAUDE.md.template +65 -0
  157. package/dist/templates/root/TRINITY.md.template +52 -0
  158. package/dist/templates/shared/claude-commands/trinity-agents.md.template +168 -0
  159. package/dist/templates/shared/claude-commands/trinity-audit.md.template +646 -0
  160. package/dist/templates/shared/claude-commands/trinity-changelog.md.template +624 -0
  161. package/dist/templates/shared/claude-commands/trinity-continue.md.template +549 -0
  162. package/dist/templates/shared/claude-commands/trinity-create-investigation.md.template +232 -0
  163. package/dist/templates/shared/claude-commands/trinity-decompose.md.template +181 -0
  164. package/dist/templates/shared/claude-commands/trinity-design.md.template +347 -0
  165. package/dist/templates/shared/claude-commands/trinity-docs.md.template +2093 -0
  166. package/dist/templates/shared/claude-commands/trinity-end.md.template +397 -0
  167. package/dist/templates/shared/claude-commands/trinity-init.md.template +606 -0
  168. package/dist/templates/shared/claude-commands/trinity-investigate-templates.md.template +725 -0
  169. package/dist/templates/shared/claude-commands/trinity-orchestrate.md.template +1061 -0
  170. package/dist/templates/shared/claude-commands/trinity-plan-investigation.md.template +135 -0
  171. package/dist/templates/shared/claude-commands/trinity-plan.md.template +201 -0
  172. package/dist/templates/shared/claude-commands/trinity-readme.md.template +1971 -0
  173. package/dist/templates/shared/claude-commands/trinity-requirements.md.template +148 -0
  174. package/dist/templates/shared/claude-commands/trinity-start.md.template +268 -0
  175. package/dist/templates/shared/claude-commands/trinity-verify.md.template +453 -0
  176. package/dist/templates/shared/claude-commands/trinity-workorder.md.template +249 -0
  177. package/dist/templates/source/base-CLAUDE.md.template +310 -0
  178. package/dist/templates/source/flutter-CLAUDE.md.template +593 -0
  179. package/dist/templates/source/nodejs-CLAUDE.md.template +531 -0
  180. package/dist/templates/source/python-CLAUDE.md.template +510 -0
  181. package/dist/templates/source/react-CLAUDE.md.template +513 -0
  182. package/dist/templates/source/rust-CLAUDE.md.template +653 -0
  183. package/dist/templates/source/tests-CLAUDE.md.template +432 -0
  184. package/dist/templates/trinity/CLAUDE.md.template +372 -0
  185. package/dist/templates/work-orders/ANALYSIS-TEMPLATE.md.template +276 -0
  186. package/dist/templates/work-orders/AUDIT-TEMPLATE.md.template +262 -0
  187. package/dist/templates/work-orders/IMPLEMENTATION-TEMPLATE.md.template +260 -0
  188. package/dist/templates/work-orders/INVESTIGATION-TEMPLATE.md.template +206 -0
  189. package/dist/templates/work-orders/PATTERN-TEMPLATE.md.template +320 -0
  190. package/dist/templates/work-orders/VERIFICATION-TEMPLATE.md.template +273 -0
  191. package/package.json +94 -0
@@ -0,0 +1,347 @@
1
+ ---
2
+ description: Create technical design using ROR (Design Architect)
3
+ ---
4
+
5
+ # Trinity Technical Design - ROR
6
+
7
+ **Agent:** ROR (Design Architect)
8
+ **Role:** Technical design, ADRs, and Design Doc creation
9
+
10
+ ## What ROR Does
11
+
12
+ 1. **Design Doc Creation:**
13
+ - Input/Output contracts
14
+ - Function signatures with ≤2 parameters
15
+ - Error handling strategy
16
+ - Architecture decisions
17
+
18
+ 2. **Design Principles:**
19
+ - **Functions:** ≤2 parameters (use objects for more)
20
+ - **Length:** <200 lines per function
21
+ - **Nesting:** ≤4 levels deep
22
+ - **Async:** Always wrap in try-catch
23
+ - **DRY:** No code duplication
24
+
25
+ 3. **Architecture Decision Records (ADRs):**
26
+ - Why this approach?
27
+ - Alternatives considered
28
+ - Trade-offs and implications
29
+
30
+ 4. **Design Doc Compliance:**
31
+ - DRA will validate implementation matches design
32
+ - ≥70% acceptance criteria met required
33
+
34
+ ## Output Format
35
+
36
+ ROR produces structured JSON handoff:
37
+ ```json
38
+ {
39
+ "designDoc": {
40
+ "functions": [
41
+ {
42
+ "name": "functionName",
43
+ "parameters": ["param1", "param2"],
44
+ "returns": "ReturnType",
45
+ "throws": ["Error1", "Error2"]
46
+ }
47
+ ],
48
+ "architecture": "description",
49
+ "errorHandling": "strategy"
50
+ },
51
+ "adr": {
52
+ "decision": "chosen approach",
53
+ "alternatives": ["alt1", "alt2"],
54
+ "rationale": "why this approach"
55
+ },
56
+ "compliance": ["criterion1", "criterion2"]
57
+ }
58
+ ```
59
+
60
+ ## ROR Agent Capabilities
61
+
62
+ ROR specializes in technical design following Trinity principles:
63
+ - **Design-First Development:** Comprehensive design before implementation prevents rework
64
+ - **ADR Documentation:** Architecture Decision Records capture rationale and trade-offs
65
+ - **Design Doc Compliance:** DRA validates implementation matches design (≥70% required)
66
+ - **Function Constraints:** ≤2 parameters, <200 lines, ≤4 nesting levels
67
+
68
+ ## Integration with Trinity Workflow
69
+
70
+ ROR's technical design follows MON's requirements analysis:
71
+
72
+ 1. **After MON:** Requirements analysis complete with acceptance criteria
73
+ 2. **ROR Design (Claude adopts ROR persona):** Creates technical design with ADRs
74
+ 3. **Design Doc:** Comprehensive function signatures, error handling, architecture
75
+ 4. **Design Approval:** User reviews design (STOP POINT in Medium/Large workflows)
76
+ 5. **Handoff to TRA:** Design feeds into implementation planning
77
+
78
+ **Example in Medium-scale workflow:**
79
+ ```
80
+ Phase 2: Technical Design (STOP POINT)
81
+ ├── Create technical design with function signatures
82
+ └── Document architecture decisions (ADR)
83
+
84
+ Output: JSON handoff with design doc, ADR, compliance criteria
85
+ User approval required before Phase 3 (Planning)
86
+ ```
87
+
88
+ **See Also:** `/trinity-orchestrate` for complete workflow planning
89
+
90
+ ## Technical Investigation Template
91
+
92
+ For architecture decisions and design choices, use Technical Investigation Template:
93
+ - Architecture options analysis
94
+ - Decision matrix with weighted criteria
95
+ - ADR format documentation
96
+ - Trade-offs and consequences
97
+ - Implementation strategy
98
+
99
+ **See:** `/trinity-investigate-templates` for Technical template structure
100
+
101
+ ## Usage
102
+
103
+ **Provide requirements and Claude (as ROR) will create technical design:**
104
+
105
+ What are the requirements? (Or provide MON's output)
106
+
107
+ **For complete workflow planning:**
108
+
109
+ Use `/trinity-orchestrate` to plan your implementation with ROR design as a key phase
110
+
111
+ ---
112
+
113
+ ## Architecture Decision Record (ADR) Example
114
+
115
+ ### ADR-003: Redis for Session Storage
116
+
117
+ **Status**: Accepted
118
+ **Date**: 2025-12-15
119
+ **Deciders**: Development Team, ALY (CTO)
120
+ **Technical Story**: WO-042 - JWT Refresh Token Implementation
121
+
122
+ ---
123
+
124
+ #### Context
125
+
126
+ We need to store refresh tokens securely with the following requirements:
127
+ - Fast lookup by token hash (<10ms)
128
+ - Automatic expiration after 7 days
129
+ - Support for token family tracking (breach detection)
130
+ - Scalable to 100k+ active sessions
131
+ - High availability (99.9% uptime)
132
+
133
+ Current system stores sessions in PostgreSQL, but refresh token lookups are becoming a bottleneck as user base grows.
134
+
135
+ ---
136
+
137
+ #### Decision
138
+
139
+ We will use **Redis** as the primary storage for refresh tokens, with PostgreSQL as backup for audit logging.
140
+
141
+ **Implementation**:
142
+ - Redis stores active refresh tokens (TTL: 7 days)
143
+ - PostgreSQL stores refresh token audit log (permanent record)
144
+ - Token families tracked in Redis Sets
145
+ - Breach detection via Redis WATCH/MULTI transactions
146
+
147
+ ---
148
+
149
+ #### Alternatives Considered
150
+
151
+ ##### Alternative 1: PostgreSQL Only (Current System)
152
+ **Pros**:
153
+ - Already in use
154
+ - ACID guarantees
155
+ - Familiar to team
156
+ - Backup/recovery established
157
+
158
+ **Cons**:
159
+ - Slower lookups (~50ms vs <10ms)
160
+ - Manual TTL management required
161
+ - Increased database load
162
+ - Doesn't scale well for session data
163
+
164
+ **Why Rejected**: Performance doesn't meet <10ms requirement, especially under load
165
+
166
+ ---
167
+
168
+ ##### Alternative 2: Memcached
169
+ **Pros**:
170
+ - Very fast (<5ms lookups)
171
+ - Simple key-value store
172
+ - Easy to set up
173
+
174
+ **Cons**:
175
+ - No persistence (data loss on restart)
176
+ - No data structures (Sets for token families)
177
+ - No TTL update capability
178
+ - No transactions for breach detection
179
+
180
+ **Why Rejected**: Lack of persistence and data structures makes token family tracking difficult
181
+
182
+ ---
183
+
184
+ ##### Alternative 3: DynamoDB
185
+ **Pros**:
186
+ - Managed service (no ops burden)
187
+ - Auto-scaling
188
+ - TTL built-in
189
+ - High availability
190
+
191
+ **Cons**:
192
+ - AWS lock-in
193
+ - Higher cost ($50-200/month estimated)
194
+ - Latency variability (10-50ms)
195
+ - Requires AWS infrastructure changes
196
+
197
+ **Why Rejected**: Cost and AWS lock-in outweigh benefits for our use case
198
+
199
+ ---
200
+
201
+ ##### Alternative 4: Redis (Selected)
202
+ **Pros**:
203
+ - Extremely fast (<10ms, often <2ms)
204
+ - TTL built-in (EXPIRE command)
205
+ - Data structures (Sets for token families)
206
+ - Transactions (WATCH/MULTI for breach detection)
207
+ - Persistence options (RDB + AOF)
208
+ - Widely adopted (team familiar)
209
+
210
+ **Cons**:
211
+ - Additional infrastructure to manage
212
+ - Memory-bound (more expensive than disk)
213
+ - Requires Redis Cluster for HA
214
+ - Learning curve for advanced features
215
+
216
+ **Why Selected**: Best balance of performance, features, and operational complexity
217
+
218
+ ---
219
+
220
+ #### Rationale
221
+
222
+ Redis meets all requirements while providing significant performance improvements:
223
+
224
+ 1. **Performance**: <10ms lookups (vs 50ms PostgreSQL)
225
+ - Measured: 2-5ms average in load testing
226
+ - 10x faster than current system
227
+
228
+ 2. **Automatic Expiration**: Native TTL support
229
+ - `EXPIRE token_hash 604800` (7 days)
230
+ - No cleanup jobs needed
231
+
232
+ 3. **Token Families**: Redis Sets
233
+ - `SADD family:{id} token_hash`
234
+ - O(1) lookups, O(N) family invalidation
235
+
236
+ 4. **Breach Detection**: Transactions
237
+ ```redis
238
+ WATCH token:hash
239
+ GET token:hash
240
+ MULTI
241
+ DEL token:hash
242
+ SADD breached_families family_id
243
+ EXEC
244
+ ```
245
+
246
+ 5. **Scalability**: Tested to 500k sessions
247
+ - Memory usage: ~50MB per 100k tokens
248
+ - Can scale to 1M+ tokens on modest hardware
249
+
250
+ 6. **High Availability**: Redis Sentinel or Cluster
251
+ - Automatic failover
252
+ - 99.9%+ uptime achievable
253
+
254
+ ---
255
+
256
+ #### Consequences
257
+
258
+ ##### Positive
259
+ - ✅ **10x performance improvement** (50ms → 2-5ms)
260
+ - ✅ **Reduced PostgreSQL load** (offload session reads)
261
+ - ✅ **Simpler TTL management** (automatic expiration)
262
+ - ✅ **Better scalability** (memory-based, easily sharded)
263
+ - ✅ **Improved user experience** (faster auth refresh)
264
+
265
+ ##### Negative
266
+ - ⚠️ **Additional infrastructure** (Redis server/cluster)
267
+ - ⚠️ **Operational complexity** (one more system to monitor)
268
+ - ⚠️ **Memory cost** (~$20/month for 500k tokens)
269
+ - ⚠️ **Data durability risk** (Redis persistence config critical)
270
+ - ⚠️ **Migration required** (move existing tokens from PostgreSQL)
271
+
272
+ ##### Mitigations
273
+ 1. **Infrastructure**: Use managed Redis (e.g., Redis Cloud, AWS ElastiCache)
274
+ 2. **Monitoring**: Add Redis metrics to existing monitoring stack
275
+ 3. **Cost**: Start with single instance, scale only if needed
276
+ 4. **Durability**: Configure AOF (Append-Only File) + daily RDB snapshots
277
+ 5. **Migration**: Gradual migration with dual-write period (1 week)
278
+
279
+ ---
280
+
281
+ #### Implementation Plan
282
+
283
+ **Phase 1: Setup** (1 week)
284
+ - Provision Redis instance
285
+ - Configure persistence (AOF + RDB)
286
+ - Set up monitoring
287
+
288
+ **Phase 2: Dual-Write** (1 week)
289
+ - Write tokens to both Redis and PostgreSQL
290
+ - Read from Redis (fallback to PostgreSQL)
291
+ - Monitor error rates
292
+
293
+ **Phase 3: Migration** (1 week)
294
+ - Backfill existing tokens from PostgreSQL to Redis
295
+ - Verify data consistency
296
+ - Monitor performance improvements
297
+
298
+ **Phase 4: Cleanup** (1 week)
299
+ - Remove PostgreSQL token reads
300
+ - Keep audit logging in PostgreSQL
301
+ - Archive old PostgreSQL tokens
302
+
303
+ **Total Time**: 4 weeks
304
+ **Rollback Plan**: Revert to PostgreSQL-only reads if Redis fails
305
+
306
+ ---
307
+
308
+ #### Metrics for Success
309
+
310
+ **Performance**:
311
+ - ✅ Token lookup latency <10ms (p95)
312
+ - ✅ Token refresh latency <100ms (p95)
313
+
314
+ **Reliability**:
315
+ - ✅ Redis availability >99.9%
316
+ - ✅ Zero data loss during failover
317
+
318
+ **Scalability**:
319
+ - ✅ Support 500k active sessions
320
+ - ✅ Handle 1000 req/sec refresh rate
321
+
322
+ **Cost**:
323
+ - ✅ Infrastructure cost <$50/month
324
+
325
+ ---
326
+
327
+ #### Related Decisions
328
+
329
+ - ADR-001: JWT for Authentication (provides context for why refresh tokens needed)
330
+ - ADR-002: PostgreSQL as Primary Database (explains why PostgreSQL retained for audit)
331
+ - ADR-004: Rate Limiting Strategy (depends on Redis for rate limit counters)
332
+
333
+ ---
334
+
335
+ #### References
336
+
337
+ - [Redis Documentation](https://redis.io/docs/)
338
+ - [Redis Persistence](https://redis.io/topics/persistence)
339
+ - [OAuth 2.0 Refresh Tokens](https://tools.ietf.org/html/rfc6749#section-6)
340
+ - Internal: Load Testing Results (docs/performance/redis-vs-postgresql.md)
341
+
342
+ ---
343
+
344
+ **Decision Date**: 2025-12-15
345
+ **Implemented**: 2025-12-22
346
+ **Status**: ✅ In Production (monitoring metrics)
347
+