@torus-engineering/tas-kit 1.7.0 → 1.8.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 (71) hide show
  1. package/.claude/commands/tas-adr.md +33 -29
  2. package/.claude/commands/tas-api-test.md +95 -0
  3. package/.claude/commands/tas-bug.md +113 -109
  4. package/.claude/commands/tas-design.md +37 -33
  5. package/.claude/commands/tas-dev.md +128 -115
  6. package/.claude/commands/tas-e2e-mobile.md +155 -0
  7. package/.claude/commands/tas-e2e-web.md +163 -0
  8. package/.claude/commands/tas-e2e.md +102 -0
  9. package/.claude/commands/tas-epic.md +35 -31
  10. package/.claude/commands/tas-feature.md +47 -43
  11. package/.claude/commands/tas-fix.md +51 -47
  12. package/.claude/commands/tas-functest-mobile.md +144 -0
  13. package/.claude/commands/tas-functest-web.md +192 -0
  14. package/.claude/commands/tas-functest.md +76 -0
  15. package/.claude/commands/tas-plan.md +200 -184
  16. package/.claude/commands/tas-prd.md +37 -33
  17. package/.claude/commands/tas-review.md +111 -104
  18. package/.claude/commands/tas-sad.md +43 -39
  19. package/.claude/commands/tas-security.md +81 -80
  20. package/.claude/commands/tas-story.md +91 -87
  21. package/.claude/commands/tas-verify.md +51 -41
  22. package/.claude/rules/common/post-review-agent.md +49 -39
  23. package/.claude/rules/common/testing.md +24 -0
  24. package/.claude/rules/common/token-logging.md +27 -0
  25. package/.claude/rules/csharp/api-testing.md +171 -0
  26. package/.claude/rules/csharp/patterns.md +10 -0
  27. package/.claude/rules/python/patterns.md +10 -0
  28. package/.claude/rules/typescript/patterns.md +10 -0
  29. package/.claude/rules/web/performance.md +9 -0
  30. package/.claude/skills/api-design/SKILL.md +3 -1
  31. package/.claude/skills/{backend-patterns → js-backend-patterns}/SKILL.md +2 -1
  32. package/.claude/skills/tas-implementation-complete/SKILL.md +99 -97
  33. package/.claude/skills/tas-tdd/SKILL.md +123 -82
  34. package/.claude/skills/token-logger/SKILL.md +19 -0
  35. package/.tas/templates/E2E-Execution-Report.md +198 -0
  36. package/.tas/templates/E2E-Mobile-Spec.md +130 -0
  37. package/.tas/templates/E2E-Report.md +174 -0
  38. package/.tas/templates/E2E-Scenario.md +180 -0
  39. package/.tas/templates/E2E-Web-Spec.md +164 -0
  40. package/.tas/templates/Feature.md +55 -55
  41. package/.tas/templates/Func-Test-Script.md +254 -0
  42. package/.tas/templates/Func-Test-Spec.md +187 -0
  43. package/.tas/templates/SAD.md +274 -274
  44. package/.tas/templates/Story.md +90 -88
  45. package/bin/cli.js +56 -56
  46. package/lib/deleted-files.json +33 -0
  47. package/lib/install.js +213 -176
  48. package/package.json +34 -34
  49. package/.claude/agents/README.md +0 -83
  50. package/.claude/agents/ado-agent.md +0 -39
  51. package/.claude/agents/code-architect.md +0 -62
  52. package/.claude/agents/code-simplifier.md +0 -53
  53. package/.claude/agents/comment-analyzer.md +0 -59
  54. package/.claude/agents/conversation-analyzer.md +0 -57
  55. package/.claude/agents/docs-lookup.md +0 -55
  56. package/.claude/agents/harness-optimizer.md +0 -62
  57. package/.claude/agents/loop-operator.md +0 -56
  58. package/.claude/agents/performance-optimizer.md +0 -78
  59. package/.claude/agents/pr-test-analyzer.md +0 -68
  60. package/.claude/agents/pytorch-build-resolver.md +0 -76
  61. package/.claude/agents/refactor-cleaner.md +0 -70
  62. package/.claude/agents/seo-specialist.md +0 -75
  63. package/.claude/agents/silent-failure-hunter.md +0 -69
  64. package/.claude/agents/type-design-analyzer.md +0 -75
  65. package/.claude/rules/common/agents.md +0 -65
  66. package/.claude/rules/common/coding-style.md +0 -90
  67. package/.claude/rules/common/development-workflow.md +0 -44
  68. package/.claude/rules/common/git-workflow.md +0 -24
  69. package/.claude/rules/common/performance.md +0 -55
  70. package/.claude/skills/agent-harness-construction/SKILL.md +0 -77
  71. package/.claude/skills/agent-introspection-debugging/SKILL.md +0 -157
@@ -1,274 +1,274 @@
1
- # Solution Architecture Document (SAD)
2
-
3
- > **Version:** 1.0
4
- > **Last Updated:** [Date]
5
- > **Author:** [SE name]
6
-
7
- ---
8
-
9
- ## 1. Executive Summary
10
-
11
- <!-- MANDATORY. Viết cho người đọc không có technical background.
12
- Bắt buộc:
13
- - 1.1 Purpose: Tại sao SAD này tồn tại, vấn đề gì cần giải quyết
14
- - 1.2 Scope: Hệ thống nào, ranh giới nào được/không được cover
15
- - 1.3 Key Objectives: 3-5 mục tiêu kiến trúc cụ thể, đo lường được
16
- Format: Prose ngắn, tối đa 1 trang tổng cộng -->
17
-
18
- ### 1.1 Purpose
19
- ### 1.2 Scope
20
- ### 1.3 Key Objectives
21
-
22
- ---
23
-
24
- ## 2. Architecture Vision
25
-
26
- <!-- MANDATORY.
27
- Bắt buộc:
28
- - 2.1 Vision Statement: 1-2 câu mô tả "kiến trúc này hướng tới điều gì"
29
- - 2.2 Architecture Principles: 4-8 nguyên tắc dẫn dắt quyết định thiết kế
30
- (vd: Stateless services, API-first, Defense in depth, Fail fast)
31
- - 2.3 Constraints & Assumptions: Ràng buộc kỹ thuật/tổ chức, giả định đang được chấp nhận
32
- Format: Bullet list cho principles và constraints -->
33
-
34
- ### 2.1 Vision Statement
35
- ### 2.2 Architecture Principles
36
- ### 2.3 Constraints & Assumptions
37
-
38
- ---
39
-
40
- ## 3. Business Requirements
41
-
42
- <!-- MANDATORY.
43
- Bắt buộc:
44
- - 3.1 Business Problem: Mô tả bài toán kinh doanh cần giải quyết
45
- - 3.2 Stakeholders: Bảng stakeholder (role, concerns, influence)
46
- - 3.3 Functional Requirements: Danh sách FR-xxx, mỗi item có ID để trace
47
- - 3.4 Non-Functional Requirements: Danh sách NFR với metric cụ thể
48
- (vd: Latency P99 < 300ms, Availability 99.9%, RPS 5000)
49
- Nên có: Priority (Must/Should/Could) cho mỗi requirement
50
- Format: Table hoặc numbered list với ID (FR-001, NFR-001) -->
51
-
52
- ### 3.1 Business Problem
53
- ### 3.2 Stakeholders
54
- ### 3.3 Functional Requirements
55
- ### 3.4 Non-Functional Requirements
56
-
57
- ---
58
-
59
- ## 4. Technology Baseline
60
-
61
- <!-- MANDATORY.
62
- Bắt buộc:
63
- - 4.1 Current State: Hệ thống hiện tại (nếu là greenfield thì ghi rõ)
64
- - 4.2 Technology Stack: Bảng layer → technology → version → rationale
65
- (Frontend / Backend / Database / Infrastructure / Messaging / Monitoring)
66
- - 4.3 Dependencies: External services, third-party APIs, shared platforms
67
- Nên có: Diagram current-state nếu là migration/modernization
68
- Format: Table cho Technology Stack -->
69
-
70
- ### 4.1 Current State
71
- ### 4.2 Technology Stack
72
- ### 4.3 Dependencies
73
-
74
- ---
75
-
76
- ## 5. System Context (C4 Level 1)
77
-
78
- <!-- MANDATORY. Trả lời: "Hệ thống này nằm ở đâu trong hệ sinh thái?"
79
- Bắt buộc:
80
- - Mermaid flowchart: hệ thống ở giữa, xung quanh là users và external systems
81
- - Chú thích mỗi external system: tên, vai trò, protocol giao tiếp
82
- Không cần: chi tiết nội bộ của hệ thống (để C4 Level 2)
83
- Format: Mermaid flowchart (dùng :::mermaid wrapper, không dùng () trong node label)
84
-
85
- Ví dụ:
86
- :::mermaid
87
- flowchart TD
88
- U[fa:fa-user End User] -- |HTTPS| SYS[Your System]
89
- SYS -- |REST| EXT1[Payment Gateway]
90
- SYS -- |SMTP| EXT2[Email Service]
91
- ADMIN[fa:fa-user Admin] -- |HTTPS| SYS
92
- ::: -->
93
-
94
- ---
95
-
96
- ## 6. Logical View (C4 Level 2 — Container)
97
-
98
- <!-- MANDATORY. Trả lời: "Hệ thống gồm những container nào?"
99
- Bắt buộc:
100
- - Mermaid flowchart: tất cả containers (web app, API, DB, cache, queue, ...)
101
- - Mỗi container: tên, technology, vai trò chính
102
- - Luồng tương tác giữa containers với protocol/label
103
- Nên có: Phân nhóm theo bounded context nếu hệ thống lớn
104
- Format: Mermaid flowchart với subgraph để nhóm theo domain
105
-
106
- Ví dụ node: WebApp["Web App\n(Next.js / Vercel)"] -->
107
-
108
- ---
109
-
110
- ## 7. Component View (C4 Level 3)
111
-
112
- <!-- CONDITIONAL — Bắt buộc nếu hệ thống có độ phức tạp cao hoặc team mới.
113
- Trả lời: "Bên trong mỗi container có components nào?"
114
- Hướng dẫn:
115
- - Mỗi container phức tạp → một subsection riêng (7.1, 7.2, ...)
116
- - Container đơn giản (chỉ proxy, static file, thin wrapper) → bỏ qua
117
- - Không cần drill vào mọi container — chỉ những container có internal logic đáng kể
118
- Mỗi subsection bắt buộc:
119
- - Mermaid flowchart liệt kê components bên trong container đó
120
- - Mỗi component: tên, trách nhiệm chính, interface exposed
121
- - Dependency direction giữa components (tránh circular)
122
- Format: Mermaid flowchart với subgraph bao ngoài (tên container), nodes là components
123
-
124
- Ví dụ:
125
- :::mermaid
126
- flowchart TD
127
- subgraph API["API Service (NestJS)"]
128
- Router[Route Handler] -- AuthMW[Auth Middleware]
129
- AuthMW -- Controller[Order Controller]
130
- Controller -- Service[Order Service]
131
- Service -- Repo[Order Repository]
132
- Service -- Queue[Queue Publisher]
133
- end
134
- ::: -->
135
-
136
- ### 7.1 [Container Name]
137
-
138
- <!-- Bắt buộc: Mermaid component diagram như hướng dẫn trên.
139
- Nên có: Mô tả ngắn vai trò của container này trước diagram. -->
140
-
141
- ### 7.2 [Container Name]
142
-
143
- <!-- Thêm subsection cho mỗi container phức tạp. Xóa subsection này nếu không cần. -->
144
-
145
- ---
146
-
147
- ## 8. Data Architecture & ERD
148
-
149
- <!-- MANDATORY nếu hệ thống có persistence layer.
150
- Bắt buộc:
151
- - ERD: entities, attributes (chỉ key fields), relationships với cardinality
152
- - Data flow overview: data đi từ đâu đến đâu, transform ở đâu
153
- Nên có:
154
- - Data classification: PII / Sensitive / Internal / Public cho mỗi entity
155
- - Retention policy nếu có compliance requirement
156
- - Sharding/partitioning strategy nếu data scale lớn
157
- Format: Mermaid erDiagram cho ERD -->
158
-
159
- ---
160
-
161
- ## 9. Integration & Data Flow
162
-
163
- <!-- MANDATORY nếu hệ thống tích hợp với external services hoặc có async flows.
164
- Bắt buộc:
165
- - Sequence diagram cho mỗi critical flow (auth, payment, order, ...)
166
- - Async flows: queue/event-driven patterns phải được diagram rõ
167
- Nên có: Error/retry flows cho critical paths
168
- Format: Mermaid sequenceDiagram, một diagram per flow -->
169
-
170
- ### 9.1 API Design Principles
171
-
172
- <!-- MANDATORY nếu hệ thống expose API (internal hoặc external).
173
- Bắt buộc:
174
- - API Style: REST / GraphQL / gRPC / Event-driven — và lý do chọn
175
- - Versioning strategy: URL path (/v1/) vs header vs query param
176
- - Authentication scheme: Bearer JWT / API Key / OAuth2 / mTLS
177
- - Standard error format: HTTP status codes, error body structure
178
- Nên có:
179
- - Rate limiting approach (per-user, per-IP, tiered)
180
- - Pagination convention (cursor vs offset)
181
- - Idempotency handling cho mutating operations
182
- Không đưa vào đây: endpoint list, request/response schema chi tiết
183
- → Những thứ đó thuộc API Contract document riêng (viết khi implement)
184
- Format: Bullet list hoặc table ngắn gọn -->
185
-
186
- ---
187
-
188
- ## 10. Security Architecture
189
-
190
- <!-- MANDATORY. Đây là architectural concern, không phải implementation detail.
191
- Bắt buộc:
192
- - Threat Model: attack surfaces, trust boundaries, top threats (dùng STRIDE nếu cần)
193
- - Identity & Auth Flow: AuthN/AuthZ mechanism, token lifecycle, privilege escalation path
194
- - Data Classification: PII / Sensitive / Internal / Public — handling rules per class
195
- - Network Security Zones: public / DMZ / private / data tier và rules giữa các zones
196
- - Encryption: at-rest (algorithm, key management) và in-transit (TLS version, cert strategy)
197
- Nên có:
198
- - Secrets management approach (Vault, AWS SSM, env vars strategy)
199
- - Audit logging scope: what events must be logged, retention
200
- - Compliance requirements: GDPR, PCI-DSS, SOC2, ... nếu applicable
201
- Format:
202
- - Threat model: table (Threat | Vector | Mitigation)
203
- - Auth flow: Mermaid sequenceDiagram
204
- - Network zones: Mermaid flowchart với subgraph per zone -->
205
-
206
- ---
207
-
208
- ## 11. NFR Strategies
209
-
210
- <!-- MANDATORY. Mỗi NFR-xxx trong Section 3.4 phải có strategy tương ứng ở đây (reference bằng ID).
211
- Bắt buộc — cover các categories sau nếu có NFR liên quan:
212
- - Performance: caching strategy (L1/L2/CDN), DB indexing, query optimization approach
213
- - Scalability: horizontal vs vertical, stateless design, queue-based decoupling
214
- - Availability: redundancy model (Active-Active/Active-Passive), failover mechanism, SLA target
215
- - Resilience: circuit breaker, retry with backoff, bulkhead, timeout policy
216
- - Observability: structured logging, distributed tracing, metrics & alerting thresholds
217
- Nên có:
218
- - Capacity planning baseline: expected load, growth projection, scale trigger points
219
- - DR strategy: RPO/RTO targets, backup frequency, restore procedure overview
220
- Format: Table với cột NFR ID để trace ngược về Section 3.4
221
- | NFR ID | Category | Target | Strategy | Notes |
222
- |--------|----------|--------|----------|-------|
223
- | NFR-001 | Latency | P99 < 300ms | Redis cache L2, read replicas | Cache TTL 5m |
224
- | NFR-002 | Availability | 99.9% | Active-Active, 2 AZs | Health check interval 10s | -->
225
-
226
- ---
227
-
228
- ## 12. Deployment Topology
229
-
230
- <!-- MANDATORY. Trả lời: "Các components chạy ở đâu trong infrastructure?"
231
- Bắt buộc:
232
- - Infrastructure diagram: regions, AZs, VPC/subnets, load balancers, entry points
233
- - Component-to-infrastructure mapping: service X → ECS Fargate, DB → RDS Multi-AZ, ...
234
- - Traffic entry points: CDN → ALB → API Gateway → Service flow
235
- - Environment matrix: dev / staging / prod — sự khác nhau về scale, config, isolation
236
- Nên có:
237
- - Network topology: public subnet / private subnet / data subnet và routing rules
238
- - CI/CD pipeline overview: build → test → deploy flow và approval gates
239
- - Container orchestration config nếu dùng K8s/ECS (namespace, resource limits)
240
- Format:
241
- - Mermaid flowchart với subgraph per environment tier hoặc per network zone
242
- - Environment matrix: table (Component | Dev | Staging | Prod) -->
243
-
244
- ---
245
-
246
- ## 13. Architectural Decisions
247
-
248
- <!-- MANDATORY. Ghi lại mọi quyết định kiến trúc quan trọng và lý do.
249
- Bắt buộc: Mỗi ADR entry gồm Decision, Status, Date, Rationale
250
- Nên có: Alternatives considered và tại sao không chọn
251
- Format: Table — thêm row mỗi khi có quyết định mới
252
- Status values: Proposed | Accepted | Deprecated | Superseded -->
253
-
254
- | ID | Decision | Status | Date | Rationale |
255
- |----|----------|--------|------|-----------|
256
-
257
- ---
258
-
259
- ## 14. Risks & Mitigation
260
-
261
- <!-- MANDATORY.
262
- Bắt buộc: Risk, Impact (H/M/L), Probability (H/M/L), Mitigation action
263
- Nên có: Owner và review date cho mỗi risk
264
- Format: Table, sắp xếp theo Impact × Probability giảm dần -->
265
-
266
- | Risk | Impact | Probability | Mitigation | Owner |
267
- |------|--------|-------------|------------|-------|
268
-
269
- ---
270
-
271
- ## Changelog
272
-
273
- | Date | Version | Changes | Author |
274
- |------|---------|---------|--------|
1
+ # Solution Architecture Document (SAD)
2
+
3
+ > **Version:** 1.0
4
+ > **Last Updated:** [Date]
5
+ > **Author:** [SE name]
6
+
7
+ ---
8
+
9
+ ## 1. Executive Summary
10
+
11
+ <!-- MANDATORY. Viết cho người đọc không có technical background.
12
+ Bắt buộc:
13
+ - 1.1 Purpose: Tại sao SAD này tồn tại, vấn đề gì cần giải quyết
14
+ - 1.2 Scope: Hệ thống nào, ranh giới nào được/không được cover
15
+ - 1.3 Key Objectives: 3-5 mục tiêu kiến trúc cụ thể, đo lường được
16
+ Format: Prose ngắn, tối đa 1 trang tổng cộng -->
17
+
18
+ ### 1.1 Purpose
19
+ ### 1.2 Scope
20
+ ### 1.3 Key Objectives
21
+
22
+ ---
23
+
24
+ ## 2. Architecture Vision
25
+
26
+ <!-- MANDATORY.
27
+ Bắt buộc:
28
+ - 2.1 Vision Statement: 1-2 câu mô tả "kiến trúc này hướng tới điều gì"
29
+ - 2.2 Architecture Principles: 4-8 nguyên tắc dẫn dắt quyết định thiết kế
30
+ (vd: Stateless services, API-first, Defense in depth, Fail fast)
31
+ - 2.3 Constraints & Assumptions: Ràng buộc kỹ thuật/tổ chức, giả định đang được chấp nhận
32
+ Format: Bullet list cho principles và constraints -->
33
+
34
+ ### 2.1 Vision Statement
35
+ ### 2.2 Architecture Principles
36
+ ### 2.3 Constraints & Assumptions
37
+
38
+ ---
39
+
40
+ ## 3. Business Requirements
41
+
42
+ <!-- MANDATORY.
43
+ Bắt buộc:
44
+ - 3.1 Business Problem: Mô tả bài toán kinh doanh cần giải quyết
45
+ - 3.2 Stakeholders: Bảng stakeholder (role, concerns, influence)
46
+ - 3.3 Functional Requirements: Danh sách FR-xxx, mỗi item có ID để trace
47
+ - 3.4 Non-Functional Requirements: Danh sách NFR với metric cụ thể
48
+ (vd: Latency P99 < 300ms, Availability 99.9%, RPS 5000)
49
+ Nên có: Priority (Must/Should/Could) cho mỗi requirement
50
+ Format: Table hoặc numbered list với ID (FR-001, NFR-001) -->
51
+
52
+ ### 3.1 Business Problem
53
+ ### 3.2 Stakeholders
54
+ ### 3.3 Functional Requirements
55
+ ### 3.4 Non-Functional Requirements
56
+
57
+ ---
58
+
59
+ ## 4. Technology Baseline
60
+
61
+ <!-- MANDATORY.
62
+ Bắt buộc:
63
+ - 4.1 Current State: Hệ thống hiện tại (nếu là greenfield thì ghi rõ)
64
+ - 4.2 Technology Stack: Bảng layer → technology → version → rationale
65
+ (Frontend / Backend / Database / Infrastructure / Messaging / Monitoring)
66
+ - 4.3 Dependencies: External services, third-party APIs, shared platforms
67
+ Nên có: Diagram current-state nếu là migration/modernization
68
+ Format: Table cho Technology Stack -->
69
+
70
+ ### 4.1 Current State
71
+ ### 4.2 Technology Stack
72
+ ### 4.3 Dependencies
73
+
74
+ ---
75
+
76
+ ## 5. System Context (C4 Level 1)
77
+
78
+ <!-- MANDATORY. Trả lời: "Hệ thống này nằm ở đâu trong hệ sinh thái?"
79
+ Bắt buộc:
80
+ - Mermaid flowchart: hệ thống ở giữa, xung quanh là users và external systems
81
+ - Chú thích mỗi external system: tên, vai trò, protocol giao tiếp
82
+ Không cần: chi tiết nội bộ của hệ thống (để C4 Level 2)
83
+ Format: Mermaid flowchart (dùng :::mermaid wrapper, không dùng () trong node label)
84
+
85
+ Ví dụ:
86
+ :::mermaid
87
+ flowchart TD
88
+ U[fa:fa-user End User] -- |HTTPS| SYS[Your System]
89
+ SYS -- |REST| EXT1[Payment Gateway]
90
+ SYS -- |SMTP| EXT2[Email Service]
91
+ ADMIN[fa:fa-user Admin] -- |HTTPS| SYS
92
+ ::: -->
93
+
94
+ ---
95
+
96
+ ## 6. Logical View (C4 Level 2 — Container)
97
+
98
+ <!-- MANDATORY. Trả lời: "Hệ thống gồm những container nào?"
99
+ Bắt buộc:
100
+ - Mermaid flowchart: tất cả containers (web app, API, DB, cache, queue, ...)
101
+ - Mỗi container: tên, technology, vai trò chính
102
+ - Luồng tương tác giữa containers với protocol/label
103
+ Nên có: Phân nhóm theo bounded context nếu hệ thống lớn
104
+ Format: Mermaid flowchart với subgraph để nhóm theo domain
105
+
106
+ Ví dụ node: WebApp["Web App\n(Next.js / Vercel)"] -->
107
+
108
+ ---
109
+
110
+ ## 7. Component View (C4 Level 3)
111
+
112
+ <!-- CONDITIONAL — Bắt buộc nếu hệ thống có độ phức tạp cao hoặc team mới.
113
+ Trả lời: "Bên trong mỗi container có components nào?"
114
+ Hướng dẫn:
115
+ - Mỗi container phức tạp → một subsection riêng (7.1, 7.2, ...)
116
+ - Container đơn giản (chỉ proxy, static file, thin wrapper) → bỏ qua
117
+ - Không cần drill vào mọi container — chỉ những container có internal logic đáng kể
118
+ Mỗi subsection bắt buộc:
119
+ - Mermaid flowchart liệt kê components bên trong container đó
120
+ - Mỗi component: tên, trách nhiệm chính, interface exposed
121
+ - Dependency direction giữa components (tránh circular)
122
+ Format: Mermaid flowchart với subgraph bao ngoài (tên container), nodes là components
123
+
124
+ Ví dụ:
125
+ :::mermaid
126
+ flowchart TD
127
+ subgraph API["API Service (NestJS)"]
128
+ Router[Route Handler] -- AuthMW[Auth Middleware]
129
+ AuthMW -- Controller[Order Controller]
130
+ Controller -- Service[Order Service]
131
+ Service -- Repo[Order Repository]
132
+ Service -- Queue[Queue Publisher]
133
+ end
134
+ ::: -->
135
+
136
+ ### 7.1 [Container Name]
137
+
138
+ <!-- Bắt buộc: Mermaid component diagram như hướng dẫn trên.
139
+ Nên có: Mô tả ngắn vai trò của container này trước diagram. -->
140
+
141
+ ### 7.2 [Container Name]
142
+
143
+ <!-- Thêm subsection cho mỗi container phức tạp. Xóa subsection này nếu không cần. -->
144
+
145
+ ---
146
+
147
+ ## 8. Data Architecture & ERD
148
+
149
+ <!-- MANDATORY nếu hệ thống có persistence layer.
150
+ Bắt buộc:
151
+ - ERD: entities, attributes (chỉ key fields), relationships với cardinality
152
+ - Data flow overview: data đi từ đâu đến đâu, transform ở đâu
153
+ Nên có:
154
+ - Data classification: PII / Sensitive / Internal / Public cho mỗi entity
155
+ - Retention policy nếu có compliance requirement
156
+ - Sharding/partitioning strategy nếu data scale lớn
157
+ Format: Mermaid erDiagram cho ERD -->
158
+
159
+ ---
160
+
161
+ ## 9. Integration & Data Flow
162
+
163
+ <!-- MANDATORY nếu hệ thống tích hợp với external services hoặc có async flows.
164
+ Bắt buộc:
165
+ - Sequence diagram cho mỗi critical flow (auth, payment, order, ...)
166
+ - Async flows: queue/event-driven patterns phải được diagram rõ
167
+ Nên có: Error/retry flows cho critical paths
168
+ Format: Mermaid sequenceDiagram, một diagram per flow -->
169
+
170
+ ### 9.1 API Design Principles
171
+
172
+ <!-- MANDATORY nếu hệ thống expose API (internal hoặc external).
173
+ Bắt buộc:
174
+ - API Style: REST / GraphQL / gRPC / Event-driven — và lý do chọn
175
+ - Versioning strategy: URL path (/v1/) vs header vs query param
176
+ - Authentication scheme: Bearer JWT / API Key / OAuth2 / mTLS
177
+ - Standard error format: HTTP status codes, error body structure
178
+ Nên có:
179
+ - Rate limiting approach (per-user, per-IP, tiered)
180
+ - Pagination convention (cursor vs offset)
181
+ - Idempotency handling cho mutating operations
182
+ Không đưa vào đây: endpoint list, request/response schema chi tiết
183
+ → Những thứ đó thuộc API Contract document riêng (viết khi implement)
184
+ Format: Bullet list hoặc table ngắn gọn -->
185
+
186
+ ---
187
+
188
+ ## 10. Security Architecture
189
+
190
+ <!-- MANDATORY. Đây là architectural concern, không phải implementation detail.
191
+ Bắt buộc:
192
+ - Threat Model: attack surfaces, trust boundaries, top threats (dùng STRIDE nếu cần)
193
+ - Identity & Auth Flow: AuthN/AuthZ mechanism, token lifecycle, privilege escalation path
194
+ - Data Classification: PII / Sensitive / Internal / Public — handling rules per class
195
+ - Network Security Zones: public / DMZ / private / data tier và rules giữa các zones
196
+ - Encryption: at-rest (algorithm, key management) và in-transit (TLS version, cert strategy)
197
+ Nên có:
198
+ - Secrets management approach (Vault, AWS SSM, env vars strategy)
199
+ - Audit logging scope: what events must be logged, retention
200
+ - Compliance requirements: GDPR, PCI-DSS, SOC2, ... nếu applicable
201
+ Format:
202
+ - Threat model: table (Threat | Vector | Mitigation)
203
+ - Auth flow: Mermaid sequenceDiagram
204
+ - Network zones: Mermaid flowchart với subgraph per zone -->
205
+
206
+ ---
207
+
208
+ ## 11. NFR Strategies
209
+
210
+ <!-- MANDATORY. Mỗi NFR-xxx trong Section 3.4 phải có strategy tương ứng ở đây (reference bằng ID).
211
+ Bắt buộc — cover các categories sau nếu có NFR liên quan:
212
+ - Performance: caching strategy (L1/L2/CDN), DB indexing, query optimization approach
213
+ - Scalability: horizontal vs vertical, stateless design, queue-based decoupling
214
+ - Availability: redundancy model (Active-Active/Active-Passive), failover mechanism, SLA target
215
+ - Resilience: circuit breaker, retry with backoff, bulkhead, timeout policy
216
+ - Observability: structured logging, distributed tracing, metrics & alerting thresholds
217
+ Nên có:
218
+ - Capacity planning baseline: expected load, growth projection, scale trigger points
219
+ - DR strategy: RPO/RTO targets, backup frequency, restore procedure overview
220
+ Format: Table với cột NFR ID để trace ngược về Section 3.4
221
+ | NFR ID | Category | Target | Strategy | Notes |
222
+ |--------|----------|--------|----------|-------|
223
+ | NFR-001 | Latency | P99 < 300ms | Redis cache L2, read replicas | Cache TTL 5m |
224
+ | NFR-002 | Availability | 99.9% | Active-Active, 2 AZs | Health check interval 10s | -->
225
+
226
+ ---
227
+
228
+ ## 12. Deployment Topology
229
+
230
+ <!-- MANDATORY. Trả lời: "Các components chạy ở đâu trong infrastructure?"
231
+ Bắt buộc:
232
+ - Infrastructure diagram: regions, AZs, VPC/subnets, load balancers, entry points
233
+ - Component-to-infrastructure mapping: service X → ECS Fargate, DB → RDS Multi-AZ, ...
234
+ - Traffic entry points: CDN → ALB → API Gateway → Service flow
235
+ - Environment matrix: dev / staging / prod — sự khác nhau về scale, config, isolation
236
+ Nên có:
237
+ - Network topology: public subnet / private subnet / data subnet và routing rules
238
+ - CI/CD pipeline overview: build → test → deploy flow và approval gates
239
+ - Container orchestration config nếu dùng K8s/ECS (namespace, resource limits)
240
+ Format:
241
+ - Mermaid flowchart với subgraph per environment tier hoặc per network zone
242
+ - Environment matrix: table (Component | Dev | Staging | Prod) -->
243
+
244
+ ---
245
+
246
+ ## 13. Architectural Decisions
247
+
248
+ <!-- MANDATORY. Ghi lại mọi quyết định kiến trúc quan trọng và lý do.
249
+ Bắt buộc: Mỗi ADR entry gồm Decision, Status, Date, Rationale
250
+ Nên có: Alternatives considered và tại sao không chọn
251
+ Format: Table — thêm row mỗi khi có quyết định mới
252
+ Status values: Proposed | Accepted | Deprecated | Superseded -->
253
+
254
+ | ID | Decision | Status | Date | Rationale |
255
+ |----|----------|--------|------|-----------|
256
+
257
+ ---
258
+
259
+ ## 14. Risks & Mitigation
260
+
261
+ <!-- MANDATORY.
262
+ Bắt buộc: Risk, Impact (H/M/L), Probability (H/M/L), Mitigation action
263
+ Nên có: Owner và review date cho mỗi risk
264
+ Format: Table, sắp xếp theo Impact × Probability giảm dần -->
265
+
266
+ | Risk | Impact | Probability | Mitigation | Owner |
267
+ |------|--------|-------------|------------|-------|
268
+
269
+ ---
270
+
271
+ ## Changelog
272
+
273
+ | Date | Version | Changes | Author |
274
+ |------|---------|---------|--------|