@haaaiawd/anws 2.2.6 → 2.4.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 (94) hide show
  1. package/README.md +1 -1
  2. package/bin/cli.js +52 -22
  3. package/lib/diff.js +5 -2
  4. package/lib/init.js +217 -96
  5. package/lib/install-state.js +18 -3
  6. package/lib/manifest.js +510 -213
  7. package/lib/prompt.js +68 -0
  8. package/lib/resources/index.js +36 -2
  9. package/lib/update.js +12 -6
  10. package/package.json +48 -47
  11. package/templates/.agents/skills/anws-system/SKILL.md +108 -108
  12. package/templates/.agents/skills/code-reviewer/SKILL.md +170 -103
  13. package/templates/.agents/skills/concept-modeler/SKILL.md +230 -179
  14. package/templates/.agents/skills/craft-authoring/SKILL.md +112 -49
  15. package/templates/.agents/skills/craft-authoring/references/BUNDLE_POLICY.md +61 -0
  16. package/templates/.agents/skills/craft-authoring/references/PROMPT_QUALITY_RUBRIC.md +99 -0
  17. package/templates/.agents/skills/craft-authoring/references/SCORECARD_TEMPLATE.md +64 -0
  18. package/templates/.agents/skills/design-reviewer/SKILL.md +265 -190
  19. package/templates/.agents/skills/e2e-testing-guide/SKILL.md +246 -135
  20. package/templates/.agents/skills/nexus-mapper/SKILL.md +321 -321
  21. package/templates/.agents/skills/output-contract/SKILL.md +37 -0
  22. package/templates/.agents/skills/report-template/SKILL.md +92 -92
  23. package/templates/.agents/skills/sequential-thinking/SKILL.md +222 -225
  24. package/templates/.agents/skills/spec-writer/SKILL.md +75 -30
  25. package/templates/.agents/skills/system-architect/SKILL.md +538 -678
  26. package/templates/.agents/skills/system-designer/SKILL.md +601 -601
  27. package/templates/.agents/skills/task-planner/SKILL.md +1 -2
  28. package/templates/.agents/skills/task-reviewer/SKILL.md +428 -388
  29. package/templates/.agents/skills/tech-evaluator/SKILL.md +252 -144
  30. package/templates/.agents/workflows/blueprint.md +166 -43
  31. package/templates/.agents/workflows/challenge.md +331 -497
  32. package/templates/.agents/workflows/change.md +182 -339
  33. package/templates/.agents/workflows/craft.md +159 -236
  34. package/templates/.agents/workflows/design-system.md +202 -674
  35. package/templates/.agents/workflows/explore.md +187 -399
  36. package/templates/.agents/workflows/forge.md +650 -550
  37. package/templates/.agents/workflows/genesis.md +439 -351
  38. package/templates/.agents/workflows/probe.md +219 -241
  39. package/templates/.agents/workflows/quickstart.md +302 -123
  40. package/templates/.agents/workflows/upgrade.md +145 -182
  41. package/templates_en/.agents/skills/anws-system/SKILL.md +108 -0
  42. package/templates_en/.agents/skills/code-reviewer/SKILL.md +170 -0
  43. package/templates_en/.agents/skills/concept-modeler/SKILL.md +230 -0
  44. package/templates_en/.agents/skills/craft-authoring/SKILL.md +179 -0
  45. package/templates_en/.agents/skills/craft-authoring/references/BUNDLE_POLICY.md +60 -0
  46. package/templates_en/.agents/skills/craft-authoring/references/PROMPT_QUALITY_RUBRIC.md +92 -0
  47. package/templates_en/.agents/skills/craft-authoring/references/SCORECARD_TEMPLATE.md +52 -0
  48. package/templates_en/.agents/skills/design-reviewer/SKILL.md +265 -0
  49. package/templates_en/.agents/skills/e2e-testing-guide/SKILL.md +246 -0
  50. package/templates_en/.agents/skills/nexus-mapper/SKILL.md +306 -0
  51. package/templates_en/.agents/skills/nexus-mapper/references/language-customization.md +167 -0
  52. package/templates_en/.agents/skills/nexus-mapper/references/output-schema.md +311 -0
  53. package/templates_en/.agents/skills/nexus-mapper/references/probe-protocol.md +246 -0
  54. package/templates_en/.agents/skills/nexus-mapper/scripts/extract_ast.py +706 -0
  55. package/templates_en/.agents/skills/nexus-mapper/scripts/git_detective.py +194 -0
  56. package/templates_en/.agents/skills/nexus-mapper/scripts/languages.json +127 -0
  57. package/templates_en/.agents/skills/nexus-mapper/scripts/query_graph.py +556 -0
  58. package/templates_en/.agents/skills/nexus-mapper/scripts/requirements.txt +6 -0
  59. package/templates_en/.agents/skills/nexus-query/SKILL.md +114 -0
  60. package/templates_en/.agents/skills/nexus-query/scripts/extract_ast.py +706 -0
  61. package/templates_en/.agents/skills/nexus-query/scripts/git_detective.py +194 -0
  62. package/templates_en/.agents/skills/nexus-query/scripts/languages.json +127 -0
  63. package/templates_en/.agents/skills/nexus-query/scripts/query_graph.py +556 -0
  64. package/templates_en/.agents/skills/nexus-query/scripts/requirements.txt +6 -0
  65. package/templates_en/.agents/skills/output-contract/SKILL.md +37 -0
  66. package/templates_en/.agents/skills/report-template/SKILL.md +85 -0
  67. package/templates_en/.agents/skills/report-template/references/REPORT_TEMPLATE.md +100 -0
  68. package/templates_en/.agents/skills/runtime-inspector/SKILL.md +101 -0
  69. package/templates_en/.agents/skills/sequential-thinking/SKILL.md +214 -0
  70. package/templates_en/.agents/skills/spec-writer/SKILL.md +153 -0
  71. package/templates_en/.agents/skills/spec-writer/references/prd_template.md +177 -0
  72. package/templates_en/.agents/skills/system-architect/SKILL.md +538 -0
  73. package/templates_en/.agents/skills/system-architect/references/rfc_template.md +59 -0
  74. package/templates_en/.agents/skills/system-designer/SKILL.md +534 -0
  75. package/templates_en/.agents/skills/system-designer/references/system-design-detail-template.md +187 -0
  76. package/templates_en/.agents/skills/system-designer/references/system-design-template.md +605 -0
  77. package/templates_en/.agents/skills/task-planner/SKILL.md +251 -0
  78. package/templates_en/.agents/skills/task-planner/references/TASK_TEMPLATE_05A.md +109 -0
  79. package/templates_en/.agents/skills/task-planner/references/TASK_TEMPLATE_05B.md +176 -0
  80. package/templates_en/.agents/skills/task-reviewer/SKILL.md +428 -0
  81. package/templates_en/.agents/skills/tech-evaluator/SKILL.md +252 -0
  82. package/templates_en/.agents/skills/tech-evaluator/references/ADR_TEMPLATE.md +78 -0
  83. package/templates_en/.agents/workflows/blueprint.md +200 -0
  84. package/templates_en/.agents/workflows/challenge.md +331 -0
  85. package/templates_en/.agents/workflows/change.md +182 -0
  86. package/templates_en/.agents/workflows/craft.md +159 -0
  87. package/templates_en/.agents/workflows/design-system.md +202 -0
  88. package/templates_en/.agents/workflows/explore.md +187 -0
  89. package/templates_en/.agents/workflows/forge.md +651 -0
  90. package/templates_en/.agents/workflows/genesis.md +439 -0
  91. package/templates_en/.agents/workflows/probe.md +219 -0
  92. package/templates_en/.agents/workflows/quickstart.md +303 -0
  93. package/templates_en/.agents/workflows/upgrade.md +145 -0
  94. package/templates_en/AGENTS.md +149 -0
@@ -0,0 +1,605 @@
1
+ # {System Name} System Design Document (L0 — Navigation Layer)
2
+
3
+ | Field | Value |
4
+ | ------------- | ------------------------------------------------------------------------ |
5
+ | **System ID** | `{system-id}` |
6
+ | **Project** | {Project Name} |
7
+ | **Version** | 1.0 |
8
+ | **Status** | `Draft` / `Review` / `Approved` |
9
+ | **Author** | {Author Name or Agent} |
10
+ | **Date** | {YYYY-MM-DD} |
11
+ | **L1 Detail** | [{system-id}.detail.md](./{system-id}.detail.md) — Load only during `/forge` |
12
+
13
+ > [!IMPORTANT]
14
+ > **Document Layering Explanation**
15
+ > - **This file (L0 Navigation Layer)**: Architecture diagrams, operation contracts, design decisions. For quick understanding and task planning. Prohibited from placing config dictionaries, algorithm pseudocode and method bodies.
16
+ > - **[{system-id}.detail.md](./{system-id}.detail.md) (L1 Implementation Layer)**: Complete pseudocode, config constants, edge cases. Load only when explicitly referenced by `/forge` tasks.
17
+ > - **L1 Anchor Principle **: Every section in L1 must have a corresponding hyperlink entry in this file. Strictly prohibited from having "orphaned content" in L1 that is completely unmentioned in L0.
18
+
19
+ ---
20
+
21
+ ## Table of Contents
22
+
23
+ | § | Chapter | Key Content |
24
+ | :---: | --------------------------------------------------------------- | -------------------------------------------------------------- |
25
+ | 1 | [Overview](#1-overview) | System purpose, boundaries, responsibilities |
26
+ | 2 | [Goals & Non-Goals](#2-goals--non-goals) | Goals / Non-Goals |
27
+ | 3 | [Background & Context](#3-background--context) | Why this system is needed, constraints |
28
+ | 4 | [Architecture](#4-architecture) | Mermaid architecture diagram, component responsibilities, data flow |
29
+ | 5 | [Interface Design](#5-interface-design) | Operation contract table, cross-system protocols, HTTP API |
30
+ | 6 | [Data Model](#6-data-model) | Entity field declarations, ER diagram → [L1 §1-2](./{system-id}.detail.md) |
31
+ | 7 | [Technology Stack](#7-technology-stack) | Core technologies, key dependencies |
32
+ | 8 | [Trade-offs](#8-trade-offs--alternatives) | Decision rationale, alternative comparison |
33
+ | 9 | [Security](#9-security-considerations) | Authentication authorization, risks and mitigation |
34
+ | 10 | [Performance](#10-performance-considerations) | Performance goals, optimization strategies |
35
+ | 11 | [Testing](#11-testing-strategy) | Unit tests, integration, performance tests |
36
+ | 12 | [Deployment](#12-deployment--operations) *(optional)* | Process, monitoring, observability |
37
+ | 13 | [Future](#13-future-considerations) *(optional)* | Extensibility, technical debt |
38
+ | 14 | [Appendix](#14-appendix) *(optional)* | Glossary, references, change log |
39
+
40
+ **L1 Implementation Layer** → [{system-id}.detail.md](./{system-id}.detail.md) (Load only during `/forge`)
41
+ > [§1 Config Constants](./{system-id}.detail.md) · [§2 Data Structures](./{system-id}.detail.md) · [§3 Algorithms](./{system-id}.detail.md) · [§4 Decision Trees](./{system-id}.detail.md) · [§5 Edge Cases](./{system-id}.detail.md)
42
+
43
+ ---
44
+
45
+ ## 1. Overview
46
+
47
+ ### 1.1 System Purpose
48
+ [What problem does this system solve? Why is it needed?]
49
+
50
+ ### 1.2 System Boundary
51
+ <!-- CRITICAL: Clearly define boundaries to avoid unclear responsibilities -->
52
+
53
+ - **Input**: [What does the system receive? From where?]
54
+ - **Output**: [What does the system produce? For whom?]
55
+ - **Dependencies**: [Which other systems does it depend on?]
56
+ - **Dependents**: [Which systems depend on this system?]
57
+
58
+ ### 1.3 System Responsibilities
59
+ <!-- Clearly define "what is responsible for" and "what is not responsible for" -->
60
+
61
+ **Responsible for**:
62
+ - [Responsibility 1]
63
+ - [Responsibility 2]
64
+
65
+ **Not responsible for**:
66
+ - [Non-responsibility 1 - handled by XX system]
67
+ - [Non-responsibility 2 - out of scope]
68
+
69
+ ---
70
+
71
+ ## 2. Goals & Non-Goals
72
+
73
+ ### 2.1 Goals
74
+ <!-- Inherit requirements from PRD, convert to technical goals for this system -->
75
+
76
+ - **[G1]**: [Specific goal for this system, e.g., API response time p95 < 200ms]
77
+ - **[G2]**: [Measurable performance/quality goal]
78
+
79
+ ### 2.2 Non-Goals
80
+ - **[NG1]**: [Content not within this system's scope]
81
+
82
+ ---
83
+
84
+ ## 3. Background & Context
85
+
86
+ ### 3.1 Why This System?
87
+ [Problem background, business drivers, related PRD requirements]
88
+
89
+ **Related PRD Requirements**: [REQ-001], [REQ-002], ...
90
+
91
+ ### 3.2 Current State
92
+ [How is it currently done? What are the problems?]
93
+
94
+ ### 3.3 Constraints
95
+ <!-- Inherit from Constraint Analysis in PRD -->
96
+
97
+ - **Technical constraints**: [Must use or avoid certain technologies, e.g., must be compatible with existing Python 3.9 environment]
98
+ - **Performance constraints**: [Performance requirements, e.g., 1000 concurrent req/s]
99
+ - **Resource constraints**: [Team, time, budget]
100
+ - **Security constraints**: [Security requirements, e.g., all data must be encrypted in transit]
101
+
102
+ ---
103
+
104
+ ## 4. Architecture
105
+
106
+ ### 4.1 Architecture Diagram
107
+ <!-- CRITICAL: Use Mermaid or image to display system architecture -->
108
+
109
+ ```mermaid
110
+ graph TD
111
+ A[User] -->|HTTP| B[Frontend Component]
112
+ B -->|API Call| C[API Client]
113
+ C -->|REST/GraphQL| D[Backend API]
114
+ D -->|Query| E[Database]
115
+
116
+ style B fill:#e1f5ff
117
+ style D fill:#fff4e1
118
+ style E fill:#e1ffe1
119
+ ```
120
+
121
+ ### 4.2 Core Components
122
+ <!-- Responsibilities and tech stack for each component -->
123
+
124
+ | Component Name | Responsibility | Tech Stack | Notes |
125
+ | -------------- | -------------- | ---------- | ------ |
126
+ | [Component 1] | [Responsibility description] | [Technology] | [Notes] |
127
+ | [Component 2] | [Responsibility description] | [Technology] | [Notes] |
128
+
129
+ ### 4.3 Data Flow
130
+ <!-- Describe how data flows between components -->
131
+
132
+ ```mermaid
133
+ sequenceDiagram
134
+ participant User
135
+ participant Frontend
136
+ participant Backend
137
+ participant Database
138
+
139
+ User->>Frontend: Input login info
140
+ Frontend->>Backend: POST /auth/login
141
+ Backend->>Database: Verify user
142
+ Database-->>Backend: User info
143
+ Backend-->>Frontend: JWT Token
144
+ Frontend-->>User: Redirect to Dashboard
145
+ ```
146
+
147
+ **Key data flow description**:
148
+ 1. [Flow 1 description]
149
+ 2. [Flow 2 description]
150
+
151
+ ---
152
+
153
+ ## 5. Interface Design
154
+
155
+ <!-- L0 writing principles:
156
+ - Backend API: Only place endpoint paths + request/response structure summary (no need for complete JSON examples)
157
+ - Agent/Game systems: Use "operation contract table" instead of function pseudocode
158
+ - Complete parameter details, error code lists → {system}.detail.md §3
159
+ -->
160
+
161
+ ### 5.1 Operation Contracts
162
+
163
+ <!-- Core format: Use table instead of function pseudocode. Each row covers one atomic operation. -->
164
+ <!-- "detail link" fills in the corresponding § section number of {system}.detail.md -->
165
+
166
+ | Operation | [REQ-XXX] | Preconditions | Cost/Input | Output/Side Effects | Implementation Detail |
167
+ | ------------------------ | :-------: | ----------------- | ---------- | -------------------- | :-------------------------------: |
168
+ | `operation_a(param)` | [REQ-001] | Condition 1; Condition 2 | cost | State change description | [§3.1](./detail.md) |
169
+ | `operation_b(param)` | [REQ-002] | Condition 1 | cost | State change description | [§3.2](./detail.md) |
170
+
171
+ > **Fill instructions**:
172
+ > - **Operation**: Use function signature style `func_name(key_params)`, parameters only write key input types, no type annotations
173
+ > - **Preconditions**: Concise list, separated by `;`, no more than 3
174
+ > - **Output/Side Effects**: Describe state changes, e.g., "Generate Boat, carry unit; original unit disappears"
175
+ > - **Implementation Detail**: Link to corresponding chapter in `.detail.md` (if not yet created, fill "to be added")
176
+
177
+ ### 5.2 Cross-System Interface Protocols
178
+
179
+ <!-- Boundary protocols with other systems: Protocol / ABC interface signatures, without method bodies -->
180
+
181
+ ```python
182
+ # Example: Interface protocol exposed by this system for other systems to call (Protocol/ABC)
183
+ class ISystemName(Protocol):
184
+ def method_a(self, param: Type) -> ReturnType: ...
185
+ def method_b(self, param: Type) -> ReturnType: ...
186
+ ```
187
+
188
+ ### 5.3 HTTP API Endpoint Summary (if applicable)
189
+
190
+ <!-- Only required for backend service systems, Agent/game core systems skip this -->
191
+ <!-- Only list endpoint list, no complete JSON examples (JSON examples → detail.md) -->
192
+
193
+ | Method | Path | Auth | Purpose | [REQ-XXX] |
194
+ | ------ | ------------- | :---: | --------------------- | :-------: |
195
+ | POST | `/auth/login` | No | User login, return JWT | [REQ-001] |
196
+ | GET | `/users/me` | JWT | Get current user info | [REQ-002] |
197
+
198
+ ---
199
+
200
+ ## 6. Data Model
201
+
202
+ <!-- L0 writing principles — strictly follow:
203
+ Allowed: @dataclass attribute field declarations
204
+ Allowed: Protocol style method signatures (def foo(self, x: T) -> R: ...)
205
+ Prohibited: Any method bodies (even if only 2 lines)
206
+ Prohibited: Comment-style method lists (# def foo... this kind)
207
+ Prohibited: Config constant dictionaries (UNIT_CONFIG = {...})
208
+ → Above content all goes into {system}.detail.md §1 and §2. And based on "L1 anchor principle", you must use Markdown hyperlinks here to indicate where they are in L1, for example:
209
+ *(Complete config constant dictionary see [{system}.detail.md §1](./{system}.detail.md))*
210
+ -->
211
+
212
+ ### 6.1 Core Entities
213
+
214
+ ```python
215
+ # ── Only attribute fields + method signatures, method bodies prohibited ──
216
+ @dataclass
217
+ class EntityName:
218
+ id: str
219
+ field_a: TypeA
220
+ field_b: TypeB = default_value
221
+
222
+ def some_method(self, param: Type) -> ReturnType: ...
223
+ def another_method(self) -> bool: ...
224
+ ```
225
+
226
+ > *(Complete method implementation → [L1 §2](./{system-id}.detail.md) · Config constant dictionary → [L1 §1](./{system-id}.detail.md))*
227
+
228
+ ### 6.2 Entity Relationship Diagram
229
+
230
+ ```mermaid
231
+ classDiagram
232
+ class EntityA {
233
+ +id: str
234
+ +field_a: TypeA
235
+ }
236
+ class EntityB {
237
+ +id: str
238
+ +entity_a_id: str
239
+ }
240
+ EntityA "1" --> "0..*" EntityB : has
241
+ ```
242
+
243
+ ### 6.3 Data Flow Direction
244
+ [How does data flow between systems? Where is it stored?]
245
+
246
+ ---
247
+
248
+ ## 7. Technology Stack
249
+
250
+ ### 7.1 Core Technologies
251
+ <!-- Inherit from ADR, or add new system-level tech decisions -->
252
+
253
+ | Domain | Choice | Rationale |
254
+ | --------- | ---------- | -------------------------------------- |
255
+ | Framework | FastAPI | High performance, async, type safe, auto OpenAPI generation |
256
+ | Database | PostgreSQL | ACID, JSON support, mature ecosystem, team familiar |
257
+ | Cache | Redis | High performance, rich data structures, persistence options |
258
+ | ORM | SQLAlchemy | Type safe, flexible, async support |
259
+
260
+ ### 7.2 Key Libraries/Dependencies
261
+ - `pydantic ^2.0`: Data validation, serialization
262
+ - `jose`: JWT token generation and verification
263
+ - `passlib[bcrypt]`: Password hashing
264
+ - `asyncpg`: PostgreSQL async driver
265
+
266
+ ---
267
+
268
+ ## 8. Trade-offs & Alternatives
269
+ <!-- CRITICAL: Google Design Docs style - explain why choose A not B -->
270
+
271
+ > [!IMPORTANT]
272
+ > **ADR Reference Rule (unidirectional reference chain)**
273
+ >
274
+ > **Why**: Decisions recorded once, other places only reference not copy. This way when modifying ADR, all SYSTEM_DESIGN automatically associate through reference, won't miss.
275
+ >
276
+ > **Rules**:
277
+ > - If decision already recorded in ADR, **only reference not copy**
278
+ > - Reference format: `> **Decision source**: [ADR-XXX: Decision title](../03_ADR/ADR_XXX.md)`
279
+ > - Only decisions specific to this system are detailed here
280
+ >
281
+ > **Self-check example**:
282
+ >
283
+ > **Wrong** - Copy ADR content:
284
+ > ```markdown
285
+ > ### 8.1 Database selection
286
+ > We choose PostgreSQL because:
287
+ > - ACID guarantee
288
+ > - JSON support
289
+ > - Team familiar
290
+ > (These reasons already recorded in ADR-001, should not copy)
291
+ > ```
292
+ >
293
+ > **Correct** - Reference ADR:
294
+ > ```markdown
295
+ > ### 8.1 Database selection
296
+ > > **Decision source**: [ADR-001: Tech Stack Selection](../03_ADR/ADR_001_TECH_STACK.md)
297
+ > >
298
+ > > This system uses PostgreSQL defined in ADR-001.
299
+ > >
300
+ > > **System-specific config**: Connection pool size 20, use asyncpg async driver
301
+ > ```
302
+
303
+ ### 8.1 [Cross-system Decision] - Reference ADR
304
+
305
+ <!-- If this decision affects multiple systems, should be recorded in ADR -->
306
+
307
+ > **Decision source**: [ADR-XXX: Decision title](../03_ADR/ADR_XXX.md)
308
+ >
309
+ > This system implements design defined in ADR-XXX, decision rationale not repeated here.
310
+ >
311
+ > **System-specific implementation**: [Supplement how this system implements that decision]
312
+
313
+ ---
314
+
315
+ ### 8.2 [System-specific Decision] - Detailed Explanation
316
+
317
+ <!-- If this decision only affects this system, detail here -->
318
+
319
+ **Option A: [Name] ( Selected)**
320
+ - **Pros**:
321
+ - ...
322
+ - **Cons**:
323
+ - ...
324
+
325
+ **Option B: [Name]**
326
+ - **Pros**:
327
+ - ...
328
+ - **Cons**:
329
+ - ...
330
+
331
+ **Decision**: Choose [Option A], because [core reason].
332
+
333
+ ---
334
+
335
+ <!-- Example: Decision referencing ADR -->
336
+ ### 8.x Example: Database Selection (Reference ADR)
337
+
338
+ > **Decision source**: [ADR-001: Tech Stack Selection](../03_ADR/ADR_001_TECH_STACK.md)
339
+ >
340
+ > This system uses PostgreSQL defined in ADR-001 as primary database.
341
+ >
342
+ > **System-specific config**:
343
+ > - Connection pool size: 20
344
+ > - Use asyncpg async driver
345
+
346
+ ---
347
+
348
+ <!-- Example: System-specific decision -->
349
+ ### 8.y Example: Caching Strategy (System Decision)
350
+
351
+ **Option A: Redis ( Selected)**
352
+ - High performance, team familiar
353
+ - Requires additional ops
354
+
355
+ **Option B: In-memory cache**
356
+ - Simple
357
+ - Does not support distributed
358
+
359
+ **Decision**: Choose Redis, because this system needs to support multi-instance deployment.
360
+
361
+ ## 9. Security Considerations
362
+
363
+ ### 9.1 Authentication & Authorization
364
+ - **Authentication**: JWT + bcrypt password hashing (rounds=10)
365
+ - **Authorization**: RBAC (Role-Based Access Control)
366
+
367
+ ### 9.2 Data Encryption
368
+ - **In Transit**: HTTPS/TLS 1.3, disable TLS 1.0/1.1
369
+ - **At Rest**: Sensitive field encryption (e.g., password hash, payment info)
370
+
371
+ ### 9.3 Security Risks & Mitigations
372
+
373
+ | Risk | Severity | Mitigation |
374
+ | ------------ | :------: | --------------------------------------- |
375
+ | SQL injection | High | Use ORM parameterized queries, prohibit SQL concatenation |
376
+ | XSS | Medium | Input validation, output escaping, CSP header |
377
+ | CSRF | Medium | CSRF Token (if applicable) |
378
+ | Password brute force | High | Rate limiting (5 times/minute/IP) |
379
+ | JWT forgery | High | Use strong key (HS256, 256-bit), regular rotation |
380
+
381
+ ---
382
+
383
+ ## 10. Performance Considerations
384
+
385
+ ### 10.1 Performance Goals
386
+ <!-- Inherit from Constraints in PRD -->
387
+
388
+ - **API response time**: p95 < 200ms, p99 < 500ms
389
+ - **Concurrency support**: 1000 req/s
390
+ - **Database query**: < 50ms (p95)
391
+ - **Cache hit rate**: > 80% (hot data)
392
+
393
+ ### 10.2 Optimization Strategies
394
+
395
+ 1. **Caching**:
396
+ - Redis cache user info, permission config
397
+ - TTL: 5 minutes (user info), 10 minutes (config)
398
+ - Cache invalidation strategy: Write-through
399
+
400
+ 2. **Database Optimization**:
401
+ - Build indexes for high-frequency query fields (`email`, `created_at`)
402
+ - Connection pool size: 20 (adjust based on concurrency)
403
+ - Use `EXPLAIN ANALYZE` to analyze slow queries
404
+
405
+ 3. **Async I/O**:
406
+ - FastAPI async endpoints
407
+ - asyncpg async database driver
408
+ - Redis async client (aioredis)
409
+
410
+ ### 10.3 Performance Monitoring
411
+
412
+ - **Tools**: Prometheus + Grafana
413
+ - **Key metrics**:
414
+ - Latency (p50, p95, p99)
415
+ - Throughput (req/s)
416
+ - Error Rate (%)
417
+ - Cache Hit Rate (%)
418
+
419
+ ---
420
+
421
+ ## 11. Testing Strategy
422
+
423
+ ### 11.1 Unit Testing
424
+ - **Coverage Target**: > 80%
425
+ - **Framework**: pytest + pytest-asyncio
426
+ - **Key Test Areas**:
427
+ - [ ] User authentication logic (password verification, JWT generation)
428
+ - [ ] Data validation (Pydantic models)
429
+ - [ ] Business logic (user CRUD)
430
+
431
+ ### 11.2 Integration Testing
432
+ - **Tool**: pytest + TestClient (FastAPI)
433
+ - **Test Scenarios**:
434
+ - [ ] End-to-end login flow (POST /auth/login → verify → return Token)
435
+ - [ ] Database transaction (create user → Rollback on error)
436
+ - [ ] Redis cache interaction
437
+
438
+ ### 11.3 End-to-End Testing - Optional
439
+ - **Tool**: Playwright / Cypress (if frontend system)
440
+ - **Test Scenarios**:
441
+ - [ ] User login complete flow (frontend → backend → database)
442
+
443
+ ### 11.4 Performance Testing
444
+ - **Tool**: Locust / k6
445
+ - **Scenarios**:
446
+ - [ ] 1000 concurrent user login
447
+ - [ ] Target: p95 < 200ms
448
+
449
+ ### 11.5 Contract Verification Matrix
450
+
451
+ | Contract | Risk Level | Normal State Verification | Failure State Verification | Regression Responsibility |
452
+ |----------|------------|-------------------------|---------------------------|-------------------------|
453
+ | `POST /auth/login` | Critical path | Integration test | Invalid credential returns 401 | Authentication main chain minimal regression |
454
+ | JWT generation rule | Base rule layer | Unit test | Invalid input/expiry boundary | Token related regression |
455
+
456
+ > **Requirements**:
457
+ > - Each key public contract should have one verification responsibility
458
+ > - Failure state / boundary state should not be omitted
459
+ > - Blueprint and Challenge should prioritize reusing this matrix, not completely rely on subsequent inference
460
+
461
+ ---
462
+
463
+ ## 12. Deployment & Operations
464
+
465
+ ### 12.1 Deployment Process
466
+
467
+ 1. **Build**: `docker build -t backend-api:v1.0 .`
468
+ 2. **Push**: `docker push registry.example.com/backend-api:v1.0`
469
+ 3. **Deploy**: Kubernetes deployment
470
+ ```yaml
471
+ apiVersion: apps/v1
472
+ kind: Deployment
473
+ metadata:
474
+ name: backend-api
475
+ spec:
476
+ replicas: 3
477
+ selector:
478
+ matchLabels:
479
+ app: backend-api
480
+ template:
481
+ spec:
482
+ containers:
483
+ - name: api
484
+ image: registry.example.com/backend-api:v1.0
485
+ resources:
486
+ requests:
487
+ cpu: "500m"
488
+ memory: "512Mi"
489
+ limits:
490
+ cpu: "1000m"
491
+ memory: "1Gi"
492
+ ```
493
+
494
+ ### 12.2 Monitoring & Alerting
495
+
496
+ **Logging**:
497
+ - **Format**: Structured JSON logging
498
+ - **Destination**: stdout → Fluentd → Elasticsearch
499
+ - **Log Levels**: INFO (production), DEBUG (development)
500
+ - **Prohibited from recording**: Passwords, Tokens, PII
501
+
502
+ **Metrics**:
503
+ - **Tool**: Prometheus → Grafana
504
+ - **Key Metrics**: Latency, Throughput, Error Rate, Cache Hit Rate
505
+
506
+ **Alerting**:
507
+ - API error rate > 5% → Slack notification
508
+ - p95 response time > 500ms → Email notification
509
+ - Service Down → PagerDuty
510
+
511
+ ### 12.3 Observability
512
+
513
+ - **Tracing**: Jaeger / OpenTelemetry (optional)
514
+ - **Health Check**: `/health` endpoint
515
+ ```json
516
+ {
517
+ "status": "healthy",
518
+ "database": "connected",
519
+ "redis": "connected",
520
+ "version": "1.0.0"
521
+ }
522
+ ```
523
+
524
+ ---
525
+
526
+ ## 13. Future Considerations
527
+
528
+ ### 13.1 Scalability
529
+ - **Horizontal Scaling**: Kubernetes HPA (Horizontal Pod Autoscaler)
530
+ - Target: CPU > 70% → Scale up
531
+ - **Database Scaling**: Read-write separation + sharding (when user count > 1 million)
532
+
533
+ ### 13.2 Tech Debt
534
+ - [ ] Migrate to microservices architecture (when API endpoints > 50)
535
+ - [ ] Introduce GraphQL (when frontend needs flexible queries)
536
+ - [ ] Database sharding strategy design
537
+
538
+ ### 13.3 Future Enhancements
539
+ - [ ] Implement OAuth2.0 for third-party login [REQ-XXX future]
540
+ - [ ] Add multi-factor authentication (MFA) [REQ-XXX future]
541
+ - [ ] User behavior analytics (Analytics)
542
+
543
+ ---
544
+
545
+ ## 14. Appendix
546
+
547
+ ### 14.1 Glossary
548
+ - **JWT (JSON Web Token)**: A stateless authentication method
549
+ - **RBAC (Role-Based Access Control)**: Role-based access control
550
+ - **p95**: 95th percentile, 95% of request response times are less than this value
551
+
552
+ ### 14.2 Optional Skills & Reference Resources
553
+ >
554
+ > This section is used to record skills, component libraries, methodologies, or external materials actually referenced during the design process.
555
+ > These contents are auxiliary inputs, not system fact sources; final solution still based on this project's PRD, ADR, Architecture Overview and this document itself.
556
+ >
557
+ > **Recording suggestions**:
558
+ > - Write resource name
559
+ > - Write which design decision it helped
560
+ > - Write what was finally adopted, what was discarded
561
+ >
562
+ > **Example (frontend system)**:
563
+ > - `vercel-react-best-practices`: Used to verify React component boundaries, rendering strategy, performance optimization suggestions
564
+ > - `frontend-design`: Used to reference layout, color scheme, hierarchy and animation direction
565
+ > - `shadcn/ui`: Used for basic component pattern reference
566
+ > - `Aceternity UI`: Used for display blocks and interactive animation inspiration
567
+ > - `Magic UI`: Used for Tailwind-first visual and animation reference
568
+
569
+ ### 14.3 References
570
+ - [FastAPI Documentation](https://fastapi.tiangolo.com/)
571
+ - [PostgreSQL Best Practices](https://wiki.postgresql.org/wiki/Don%27t_Do_This)
572
+ - [JWT Best Practices](https://tools.ietf.org/html/rfc8725)
573
+ - [Architecture Overview](../02_ARCHITECTURE_OVERVIEW.md)
574
+ - [ADR001: Tech Stack](../03_ADR/ADR001_TECH_STACK.md)
575
+
576
+ ### 14.4 Change Log
577
+
578
+ | Version | Date | Changes | Author |
579
+ | ------- | ---------- | -------- | ------ |
580
+ | 1.0 | 2026-01-08 | Initial version | XXX |
581
+
582
+ ---
583
+
584
+ <!-- AGENT Usage Guide
585
+
586
+ L0 writing nine principles:
587
+ 1. Navigation layer positioning — Do not show implementation details, for quick understanding and task planning
588
+ 2. TOC synchronization — New chapters must synchronously update file header directory table
589
+ 3. Operation contract table — §5.1 one atomic operation per row, "implementation detail" column must link to L1
590
+ 4. Attribute declarations — §6 only place fields + method signatures (def foo(): ...), method bodies prohibited
591
+ 5. L1 anchors — Any content extracted to L1 must leave hyperlink at corresponding position in L0, prohibited from orphan islands
592
+ 6. Traceability chain — [REQ-XXX] reference PRD, do not copy original text
593
+ 7. Constraint inheritance — Inherit from PRD / ADR, cannot relax
594
+ 8. Trade-offs — Each selection explains "reason for choosing A not B"
595
+ 9. Mermaid priority — Architecture diagrams / data flow / decision trees, use diagrams not text lists
596
+
597
+ L1 split rules (trigger any one to create .detail.md):
598
+ R1 Single code block > 30 lines
599
+ R2 Total code block lines > 200 lines
600
+ R3 Config constant dictionary entries > 5
601
+ R4 Version inline comments > 5 places
602
+ R5 Total document lines > 500 lines
603
+
604
+ Mandatory chapters: 1-11 | Optional chapters: 12 (deployment) · 13 (future) · 14 (appendix)
605
+ -->