speccrew 0.1.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.
- package/.speccrew/agents/speccrew-feature-designer.md +142 -0
- package/.speccrew/agents/speccrew-product-manager.md +61 -0
- package/.speccrew/agents/speccrew-system-designer.md +200 -0
- package/.speccrew/agents/speccrew-system-developer.md +238 -0
- package/.speccrew/agents/speccrew-task-worker.md +80 -0
- package/.speccrew/agents/speccrew-team-leader.md +92 -0
- package/.speccrew/agents/speccrew-test-manager.md +313 -0
- package/.speccrew/skills/speccrew-create-agents/SKILL.md +98 -0
- package/.speccrew/skills/speccrew-create-agents/templates/agents/designer-agent.md +54 -0
- package/.speccrew/skills/speccrew-create-agents/templates/agents/dev-agent.md +79 -0
- package/.speccrew/skills/speccrew-create-agents/templates/agents/test-agent.md +80 -0
- package/.speccrew/skills/speccrew-dev-backend/SKILL.md +205 -0
- package/.speccrew/skills/speccrew-dev-backend/templates/TASK-RECORD-TEMPLATE.md +118 -0
- package/.speccrew/skills/speccrew-dev-desktop/SKILL.md +258 -0
- package/.speccrew/skills/speccrew-dev-desktop/templates/TASK-RECORD-TEMPLATE.md +161 -0
- package/.speccrew/skills/speccrew-dev-frontend/SKILL.md +202 -0
- package/.speccrew/skills/speccrew-dev-frontend/templates/TASK-RECORD-TEMPLATE.md +115 -0
- package/.speccrew/skills/speccrew-dev-mobile/SKILL.md +200 -0
- package/.speccrew/skills/speccrew-dev-mobile/templates/TASK-RECORD-TEMPLATE.md +125 -0
- package/.speccrew/skills/speccrew-fd-api-contract/SKILL.md +73 -0
- package/.speccrew/skills/speccrew-fd-api-contract/templates/API-CONTRACT-TEMPLATE.md +96 -0
- package/.speccrew/skills/speccrew-fd-feature-design/SKILL.md +395 -0
- package/.speccrew/skills/speccrew-fd-feature-design/templates/FEATURE-SPEC-TEMPLATE.md +387 -0
- package/.speccrew/skills/speccrew-get-timestamp/SKILL.md +80 -0
- package/.speccrew/skills/speccrew-get-timestamp/scripts/get-timestamp.js +35 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-api-analyze/SKILL.md +1116 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-api-analyze/templates/FEATURE-DETAIL-TEMPLATE-FASTAPI.md +462 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-api-analyze/templates/FEATURE-DETAIL-TEMPLATE-JAVA.md +480 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-api-analyze/templates/FEATURE-DETAIL-TEMPLATE-NET.md +464 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-api-analyze/templates/FEATURE-DETAIL-TEMPLATE.md +480 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-api-analyze/templates/MODULE-OVERVIEW-TEMPLATE.md +367 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-dispatch/SKILL.md +667 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-dispatch/STATUS-FORMATS.md +74 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-dispatch/scripts/batch-orchestrator.js +176 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-dispatch/scripts/get-next-batch.js +150 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-dispatch/scripts/get-pending-features.js +106 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-dispatch/scripts/mark-stale.js +249 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-dispatch/scripts/process-batch-results.js +848 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-dispatch/scripts/update-feature-status.js +226 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-init-features/SKILL.md +264 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-init-features/examples/features.json +34 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-init-features/scripts/generate-inventory.js +867 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-init-features/scripts/test-inventory.js +26 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-module-classify/SKILL.md +165 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-module-classify/scripts/apply-module-mapping.js +208 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-module-classify/scripts/extract-module-summary.js +180 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-module-classify/scripts/reindex-modules.js +358 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-ui-analyze/SKILL.md +1055 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-ui-analyze/templates/FEATURE-DETAIL-TEMPLATE-UI-DESKTOP.md +303 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-ui-analyze/templates/FEATURE-DETAIL-TEMPLATE-UI-ELECTRON.md +327 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-ui-analyze/templates/FEATURE-DETAIL-TEMPLATE-UI-MINIAPP.md +292 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-ui-analyze/templates/FEATURE-DETAIL-TEMPLATE-UI-MOBILE.md +281 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-ui-analyze/templates/FEATURE-DETAIL-TEMPLATE-UI.md +324 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-ui-style-extract/SKILL.md +270 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-ui-style-extract/templates/COMPONENT-PATTERN-TEMPLATE.md +33 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-ui-style-extract/templates/LAYOUT-PATTERN-TEMPLATE.md +33 -0
- package/.speccrew/skills/speccrew-knowledge-bizs-ui-style-extract/templates/PAGE-TYPE-TEMPLATE.md +33 -0
- package/.speccrew/skills/speccrew-knowledge-graph-query/SKILL.md +229 -0
- package/.speccrew/skills/speccrew-knowledge-graph-query/scripts/graph-query.js +549 -0
- package/.speccrew/skills/speccrew-knowledge-graph-write/SKILL.md +181 -0
- package/.speccrew/skills/speccrew-knowledge-graph-write/scripts/graph-write.js +651 -0
- package/.speccrew/skills/speccrew-knowledge-module-summarize/SKILL.md +305 -0
- package/.speccrew/skills/speccrew-knowledge-module-summarize/templates/MODULE-OVERVIEW-TEMPLATE.md +400 -0
- package/.speccrew/skills/speccrew-knowledge-system-summarize/SKILL.md +351 -0
- package/.speccrew/skills/speccrew-knowledge-system-summarize/templates/SYSTEM-OVERVIEW-TEMPLATE.md +294 -0
- package/.speccrew/skills/speccrew-knowledge-techs-dispatch/SKILL.md +683 -0
- package/.speccrew/skills/speccrew-knowledge-techs-dispatch/STATUS-FORMATS.md +550 -0
- package/.speccrew/skills/speccrew-knowledge-techs-dispatch/templates/techs-manifest-EXAMPLE.json +35 -0
- package/.speccrew/skills/speccrew-knowledge-techs-generate/SKILL.md +1087 -0
- package/.speccrew/skills/speccrew-knowledge-techs-generate/templates/ARCHITECTURE-TEMPLATE.md +240 -0
- package/.speccrew/skills/speccrew-knowledge-techs-generate/templates/COLOR-SYSTEM-TEMPLATE.md +68 -0
- package/.speccrew/skills/speccrew-knowledge-techs-generate/templates/COMPONENT-LIBRARY-TEMPLATE.md +86 -0
- package/.speccrew/skills/speccrew-knowledge-techs-generate/templates/CONVENTIONS-BUILD-TEMPLATE.md +466 -0
- package/.speccrew/skills/speccrew-knowledge-techs-generate/templates/CONVENTIONS-DATA-TEMPLATE.md +432 -0
- package/.speccrew/skills/speccrew-knowledge-techs-generate/templates/CONVENTIONS-DESIGN-TEMPLATE.md +1209 -0
- package/.speccrew/skills/speccrew-knowledge-techs-generate/templates/CONVENTIONS-DEV-TEMPLATE.md +1433 -0
- package/.speccrew/skills/speccrew-knowledge-techs-generate/templates/CONVENTIONS-SYSTEM-TEST-TEMPLATE.md +1052 -0
- package/.speccrew/skills/speccrew-knowledge-techs-generate/templates/CONVENTIONS-UNIT-TEST-TEMPLATE.md +946 -0
- package/.speccrew/skills/speccrew-knowledge-techs-generate/templates/INDEX-TEMPLATE.md +29 -0
- package/.speccrew/skills/speccrew-knowledge-techs-generate/templates/PAGE-LAYOUTS-TEMPLATE.md +69 -0
- package/.speccrew/skills/speccrew-knowledge-techs-generate/templates/PAGE-TYPE-SUMMARY-TEMPLATE.md +74 -0
- package/.speccrew/skills/speccrew-knowledge-techs-generate/templates/TECH-STACK-TEMPLATE.md +232 -0
- package/.speccrew/skills/speccrew-knowledge-techs-generate-conventions/SKILL.md +628 -0
- package/.speccrew/skills/speccrew-knowledge-techs-generate-ui-style/SKILL.md +392 -0
- package/.speccrew/skills/speccrew-knowledge-techs-index/SKILL.md +489 -0
- package/.speccrew/skills/speccrew-knowledge-techs-index/templates/INDEX-TEMPLATE.md +243 -0
- package/.speccrew/skills/speccrew-knowledge-techs-init/SKILL.md +269 -0
- package/.speccrew/skills/speccrew-knowledge-techs-ui-analyze/SKILL.md +562 -0
- package/.speccrew/skills/speccrew-knowledge-techs-ui-analyze/templates/BUSINESS-COMPONENTS-TEMPLATE.md +171 -0
- package/.speccrew/skills/speccrew-knowledge-techs-ui-analyze/templates/COMMON-COMPONENTS-TEMPLATE.md +177 -0
- package/.speccrew/skills/speccrew-knowledge-techs-ui-analyze/templates/COMPONENT-INDIVIDUAL-TEMPLATE.md +80 -0
- package/.speccrew/skills/speccrew-knowledge-techs-ui-analyze/templates/COMPONENT-LIBRARY-TEMPLATE.md +118 -0
- package/.speccrew/skills/speccrew-knowledge-techs-ui-analyze/templates/LAYOUT-INDIVIDUAL-TEMPLATE.md +97 -0
- package/.speccrew/skills/speccrew-knowledge-techs-ui-analyze/templates/LAYOUT-PATTERNS-TEMPLATE.md +208 -0
- package/.speccrew/skills/speccrew-knowledge-techs-ui-analyze/templates/NAVIGATION-PATTERNS-TEMPLATE.md +157 -0
- package/.speccrew/skills/speccrew-knowledge-techs-ui-analyze/templates/PAGE-TYPE-INDIVIDUAL-TEMPLATE.md +123 -0
- package/.speccrew/skills/speccrew-knowledge-techs-ui-analyze/templates/PAGE-TYPE-SUMMARY-TEMPLATE.md +58 -0
- package/.speccrew/skills/speccrew-knowledge-techs-ui-analyze/templates/SPACING-TEMPLATE.md +119 -0
- package/.speccrew/skills/speccrew-knowledge-techs-ui-analyze/templates/STYLE-SYSTEM-TEMPLATE.md +117 -0
- package/.speccrew/skills/speccrew-knowledge-techs-ui-analyze/templates/TYPOGRAPHY-TEMPLATE.md +107 -0
- package/.speccrew/skills/speccrew-knowledge-techs-ui-analyze/templates/UI-STYLE-GUIDE-TEMPLATE.md +171 -0
- package/.speccrew/skills/speccrew-pm-requirement-analysis/SKILL.md +434 -0
- package/.speccrew/skills/speccrew-pm-requirement-analysis/templates/BIZS-MODELING-TEMPLATE.md +332 -0
- package/.speccrew/skills/speccrew-pm-requirement-analysis/templates/PRD-TEMPLATE.md +200 -0
- package/.speccrew/skills/speccrew-pm-requirement-assess/SKILL.md +195 -0
- package/.speccrew/skills/speccrew-project-diagnosis/SKILL.md +208 -0
- package/.speccrew/skills/speccrew-project-diagnosis/templates/DIAGNOSIS-REPORT-TEMPLATE.md +202 -0
- package/.speccrew/skills/speccrew-sd-backend/SKILL.md +188 -0
- package/.speccrew/skills/speccrew-sd-backend/templates/INDEX-TEMPLATE.md +85 -0
- package/.speccrew/skills/speccrew-sd-backend/templates/SD-BACKEND-TEMPLATE.md +269 -0
- package/.speccrew/skills/speccrew-sd-desktop/SKILL.md +192 -0
- package/.speccrew/skills/speccrew-sd-desktop/templates/INDEX-TEMPLATE.md +271 -0
- package/.speccrew/skills/speccrew-sd-desktop/templates/SD-DESKTOP-TEMPLATE.md +673 -0
- package/.speccrew/skills/speccrew-sd-frontend/SKILL.md +176 -0
- package/.speccrew/skills/speccrew-sd-frontend/templates/INDEX-TEMPLATE.md +184 -0
- package/.speccrew/skills/speccrew-sd-frontend/templates/SD-FRONTEND-TEMPLATE.md +382 -0
- package/.speccrew/skills/speccrew-sd-mobile/SKILL.md +189 -0
- package/.speccrew/skills/speccrew-sd-mobile/templates/INDEX-TEMPLATE.md +219 -0
- package/.speccrew/skills/speccrew-sd-mobile/templates/SD-MOBILE-TEMPLATE.md +534 -0
- package/.speccrew/skills/speccrew-test-case-design/SKILL.md +284 -0
- package/.speccrew/skills/speccrew-test-case-design/templates/TEST-CASE-DESIGN-TEMPLATE.md +263 -0
- package/.speccrew/skills/speccrew-test-code-gen/SKILL.md +313 -0
- package/.speccrew/skills/speccrew-test-code-gen/templates/TEST-CODE-PLAN-TEMPLATE.md +180 -0
- package/.speccrew/skills/speccrew-test-execute/SKILL.md +283 -0
- package/.speccrew/skills/speccrew-test-execute/templates/BUG-REPORT-TEMPLATE.md +50 -0
- package/.speccrew/skills/speccrew-test-execute/templates/TEST-REPORT-TEMPLATE.md +57 -0
- package/.speccrew/skills/speccrew-workflow-diagnose/SKILL.md +155 -0
- package/LICENSE +21 -0
- package/README.ar.md +318 -0
- package/README.en.md +318 -0
- package/README.es.md +318 -0
- package/README.md +340 -0
- package/bin/cli.js +62 -0
- package/lib/commands/doctor.js +138 -0
- package/lib/commands/init.js +231 -0
- package/lib/commands/list.js +114 -0
- package/lib/commands/uninstall.js +117 -0
- package/lib/commands/update.js +351 -0
- package/lib/ide-adapters.js +73 -0
- package/lib/utils.js +104 -0
- package/package.json +28 -0
- package/workspace-template/docs/configs/document-templates.json +667 -0
- package/workspace-template/docs/configs/platform-mapping.json +194 -0
- package/workspace-template/docs/configs/tech-stack-mappings.json +313 -0
- package/workspace-template/docs/configs/validation-rules.json +87 -0
- package/workspace-template/docs/rules/mermaid-rule.md +114 -0
- package/workspace-template/docs/solutions/Agent/346/212/200/350/203/275/345/256/232/344/271/211+/351/234/200/346/261/202/346/226/207/346/241/243+UML/344/275/277/347/224/250/346/250/241/346/235/277/357/274/210ISA-95/345/205/255/346/256/265/345/274/217/350/236/215/345/220/210/347/211/210/357/274/211.md +586 -0
- package/workspace-template/docs/solutions/agent-knowledge-map.md +238 -0
- package/workspace-template/docs/solutions/bizs-knowledge-pipeline.md +678 -0
- package/workspace-template/docs/solutions/harness.md +410 -0
- package/workspace-template/docs/solutions/knowledge-incremental-sync-spec.md +943 -0
- package/workspace-template/docs/solutions/techs-knowledge-pipeline.md +803 -0
- package/workspace-template/docs/solutions/workspace-structure.md +318 -0
package/.speccrew/skills/speccrew-knowledge-techs-generate/templates/CONVENTIONS-DESIGN-TEMPLATE.md
ADDED
|
@@ -0,0 +1,1209 @@
|
|
|
1
|
+
# {{platform_name}} Design Conventions
|
|
2
|
+
|
|
3
|
+
<cite>
|
|
4
|
+
**Files Referenced in This Document**
|
|
5
|
+
{{#each source_files}}
|
|
6
|
+
- [{{name}}]({{path}})
|
|
7
|
+
{{/each}}
|
|
8
|
+
</cite>
|
|
9
|
+
|
|
10
|
+
> **Target Audience**: devcrew-designer-{{platform_id}}, devcrew-dev-{{platform_id}}, devcrew-test-{{platform_id}}
|
|
11
|
+
|
|
12
|
+
## Table of Contents
|
|
13
|
+
|
|
14
|
+
1. [Design Principles](#1-design-principles)
|
|
15
|
+
2. [Architecture Overview](#2-architecture-overview)
|
|
16
|
+
3. [API & Interface Design (Backend Only)](#3-api--interface-design-backend-only)
|
|
17
|
+
4. [Data Flow Design (Platform-Specific)](#4-data-flow-design-platform-specific)
|
|
18
|
+
5. [State & Session Design (Platform-Specific)](#5-state--session-design-platform-specific)
|
|
19
|
+
6. [Transaction Design (Backend Only)](#6-transaction-design-backend-only)
|
|
20
|
+
7. [Authorization & Permission Design (Platform-Specific)](#7-authorization--permission-design-platform-specific)
|
|
21
|
+
8. [Menu & Navigation Design (Frontend Only)](#8-menu--navigation-design-frontend-only)
|
|
22
|
+
9. [Multi-tenancy Design](#9-multi-tenancy-design)
|
|
23
|
+
10. [Exception Handling & Error Codes](#10-exception-handling--error-codes)
|
|
24
|
+
11. [Security Design](#11-security-design)
|
|
25
|
+
12. [Caching Design (Platform-Specific)](#12-caching-design-platform-specific)
|
|
26
|
+
13. [Logging Design (Architecture Level)](#13-logging-design-architecture-level)
|
|
27
|
+
14. [Distributed Design (Backend Only, if distributed)](#14-distributed-design-backend-only-if-distributed)
|
|
28
|
+
15. [Observability & Deployment Design (Platform-Specific)](#15-observability--deployment-design-platform-specific)
|
|
29
|
+
16. [Compliance & Governance](#16-compliance--governance)
|
|
30
|
+
17. [Performance Design](#17-performance-design)
|
|
31
|
+
18. [Anti-Patterns & Pitfalls](#18-anti-patterns--pitfalls)
|
|
32
|
+
19. [Appendix](#appendix)
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 1. Design Principles
|
|
37
|
+
|
|
38
|
+
<!-- AI-TAG: DESIGN_PRINCIPLES -->
|
|
39
|
+
<!-- Fill with SOLID principles, layered design principles, and design decision records found in source code -->
|
|
40
|
+
|
|
41
|
+
### 1.1 SOLID Principles
|
|
42
|
+
|
|
43
|
+
| Principle | Description | Application in {{platform_name}} |
|
|
44
|
+
|-----------|-------------|----------------------------------|
|
|
45
|
+
| SRP | Single Responsibility Principle | srp_application |
|
|
46
|
+
| OCP | Open/Closed Principle | ocp_application |
|
|
47
|
+
| LSP | Liskov Substitution Principle | lsp_application |
|
|
48
|
+
| ISP | Interface Segregation Principle | isp_application |
|
|
49
|
+
| DIP | Dependency Inversion Principle | dip_application |
|
|
50
|
+
|
|
51
|
+
**Good Example:**
|
|
52
|
+
```
|
|
53
|
+
good_solid_example
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Bad Example:**
|
|
57
|
+
```
|
|
58
|
+
bad_solid_example
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 1.2 Layered Design Principles
|
|
62
|
+
|
|
63
|
+
<!-- Fill with Controller/Service/Repository responsibility boundaries -->
|
|
64
|
+
|
|
65
|
+
| Layer | Responsibility | What to Do | What NOT to Do |
|
|
66
|
+
|-------|---------------|------------|----------------|
|
|
67
|
+
| Controller | controller_responsibility | controller_do | controller_not_do |
|
|
68
|
+
| Service | service_responsibility | service_do | service_not_do |
|
|
69
|
+
| Repository | repository_responsibility | repository_do | repository_not_do |
|
|
70
|
+
|
|
71
|
+
### 1.3 Design Decision Records
|
|
72
|
+
|
|
73
|
+
{{#each design_decisions}}
|
|
74
|
+
#### {{title}}
|
|
75
|
+
|
|
76
|
+
**Context:** {{context}}
|
|
77
|
+
|
|
78
|
+
**Decision:** {{decision}}
|
|
79
|
+
|
|
80
|
+
**Consequences:** {{consequences}}
|
|
81
|
+
|
|
82
|
+
{{/each}}
|
|
83
|
+
|
|
84
|
+
**Section Source**
|
|
85
|
+
{{#each design_principles_sources}}
|
|
86
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
87
|
+
{{/each}}
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 2. Architecture Overview
|
|
92
|
+
|
|
93
|
+
<!-- AI-TAG: ARCHITECTURE_OVERVIEW -->
|
|
94
|
+
<!-- Fill with overall architecture diagram, layered architecture details, and directory structure -->
|
|
95
|
+
|
|
96
|
+
### 2.1 Overall Architecture
|
|
97
|
+
|
|
98
|
+
```mermaid
|
|
99
|
+
graph TB
|
|
100
|
+
{{#each architecture_layers}}
|
|
101
|
+
{{id}}["{{name}}"]
|
|
102
|
+
{{/each}}
|
|
103
|
+
{{#each architecture_relations}}
|
|
104
|
+
{{from}} --> {{to}}
|
|
105
|
+
{{/each}}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Diagram Source**
|
|
109
|
+
{{#each architecture_diagram_sources}}
|
|
110
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
111
|
+
{{/each}}
|
|
112
|
+
|
|
113
|
+
### 2.2 Layered Architecture Details
|
|
114
|
+
|
|
115
|
+
| Layer | Components | Key Responsibilities |
|
|
116
|
+
|-------|------------|---------------------|
|
|
117
|
+
{{#each layers}}
|
|
118
|
+
| {{name}} | {{components}} | {{responsibilities}} |
|
|
119
|
+
{{/each}}
|
|
120
|
+
|
|
121
|
+
### 2.3 Directory Structure Convention
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
{{directory_structure}}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Section Source**
|
|
128
|
+
{{#each architecture_overview_sources}}
|
|
129
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
130
|
+
{{/each}}
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 3. API & Interface Design (Backend Only)
|
|
135
|
+
|
|
136
|
+
<!-- AI-TAG: API_DESIGN -->
|
|
137
|
+
<!-- Fill with RESTful API conventions, pagination standards, Swagger/OpenAPI specs, version management. If this platform is frontend or mobile, write 'Not applicable - API design is defined in the backend platform.' Frontend platforms should document their API consumption patterns in the DEV conventions instead. -->
|
|
138
|
+
|
|
139
|
+
### 3.1 RESTful Interface Specification
|
|
140
|
+
|
|
141
|
+
| Aspect | Convention | Example |
|
|
142
|
+
|--------|-----------|---------|
|
|
143
|
+
| HTTP Method Semantics | method_semantics | example |
|
|
144
|
+
| URL Naming | url_naming | example |
|
|
145
|
+
| Resource Naming | resource_naming | example |
|
|
146
|
+
|
|
147
|
+
### 3.2 Pagination Parameter Standardization
|
|
148
|
+
|
|
149
|
+
| Parameter | Type | Default | Description |
|
|
150
|
+
|-----------|------|---------|-------------|
|
|
151
|
+
| pageNum | int | 1 | Current page number |
|
|
152
|
+
| pageSize | int | 10 | Items per page |
|
|
153
|
+
| orderBy | string | null | Sort field |
|
|
154
|
+
| order | string | ASC | Sort direction (ASC/DESC) |
|
|
155
|
+
|
|
156
|
+
### 3.3 Interface Documentation Specification
|
|
157
|
+
|
|
158
|
+
{{#if has_swagger}}
|
|
159
|
+
**Swagger/OpenAPI Configuration:**
|
|
160
|
+
```
|
|
161
|
+
swagger_config
|
|
162
|
+
```
|
|
163
|
+
{{/if}}
|
|
164
|
+
|
|
165
|
+
### 3.4 Interface Compatibility & Version Management
|
|
166
|
+
|
|
167
|
+
| Version Strategy | Implementation | When to Use |
|
|
168
|
+
|-----------------|----------------|-------------|
|
|
169
|
+
| URL Versioning | /v1/, /v2/ | Major breaking changes |
|
|
170
|
+
| Header Versioning | X-API-Version | Minor changes |
|
|
171
|
+
| Query Parameter | ?version=1 | Legacy support |
|
|
172
|
+
|
|
173
|
+
### 3.5 Frontend Interface Integration (if frontend platform)
|
|
174
|
+
|
|
175
|
+
| Aspect | Convention |
|
|
176
|
+
|--------|-----------|
|
|
177
|
+
| API Client Pattern | api_client_pattern |
|
|
178
|
+
| Request Interceptor | request_interceptor |
|
|
179
|
+
| Response Handler | response_handler |
|
|
180
|
+
|
|
181
|
+
**Section Source**
|
|
182
|
+
{{#each api_design_sources}}
|
|
183
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
184
|
+
{{/each}}
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## 4. Data Flow Design (Platform-Specific)
|
|
189
|
+
|
|
190
|
+
<!-- AI-TAG: DATA_FLOW -->
|
|
191
|
+
<!-- Fill with data flow patterns. For backend: DTO/VO/DO transformation rules. For frontend: Props/State/Model/API Response data flow. -->
|
|
192
|
+
|
|
193
|
+
### Backend Data Flow (if backend platform)
|
|
194
|
+
|
|
195
|
+
<!-- AI-TAG: BACKEND_DATA_FLOW -->
|
|
196
|
+
<!-- Fill with backend data flow patterns: DTO/VO/DO transformation rules. If frontend platform, skip this subsection. -->
|
|
197
|
+
|
|
198
|
+
#### 4.1 Data Flow Diagram
|
|
199
|
+
|
|
200
|
+
```mermaid
|
|
201
|
+
flowchart TD
|
|
202
|
+
{{#each data_flow_steps}}
|
|
203
|
+
{{id}}["{{action}}"]
|
|
204
|
+
{{/each}}
|
|
205
|
+
{{#each data_flow_relations}}
|
|
206
|
+
{{from}} --> {{to}}
|
|
207
|
+
{{/each}}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**Diagram Source**
|
|
211
|
+
{{#each data_flow_diagram_sources}}
|
|
212
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
213
|
+
{{/each}}
|
|
214
|
+
|
|
215
|
+
#### 4.2 DTO/VO/DO Transformation Specification
|
|
216
|
+
|
|
217
|
+
| Type | Purpose | Conversion Rules |
|
|
218
|
+
|------|---------|-----------------|
|
|
219
|
+
| DO (Data Object) | Database entity | do_rules |
|
|
220
|
+
| DTO (Data Transfer Object) | Inter-service transfer | dto_rules |
|
|
221
|
+
| VO (View Object) | Frontend response | vo_rules |
|
|
222
|
+
| BO (Business Object) | Business logic | bo_rules |
|
|
223
|
+
|
|
224
|
+
**Good Example:**
|
|
225
|
+
```
|
|
226
|
+
good_dto_conversion_example
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**Bad Example:**
|
|
230
|
+
```
|
|
231
|
+
bad_dto_conversion_example
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
#### 4.3 Data Transfer Anti-Patterns
|
|
235
|
+
|
|
236
|
+
| Anti-Pattern | Problem | Solution |
|
|
237
|
+
|-------------|---------|----------|
|
|
238
|
+
| pattern_name | problem | solution |
|
|
239
|
+
|
|
240
|
+
**Section Source**
|
|
241
|
+
{{#each data_flow_sources}}
|
|
242
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
243
|
+
{{/each}}
|
|
244
|
+
|
|
245
|
+
### Frontend Data Flow (if frontend platform)
|
|
246
|
+
|
|
247
|
+
<!-- AI-TAG: FRONTEND_DATA_FLOW -->
|
|
248
|
+
<!-- Fill with frontend data flow patterns: Props, State, Computed, API Response mapping. If backend platform, skip this subsection. -->
|
|
249
|
+
|
|
250
|
+
| Layer | Data Type | Description | Example |
|
|
251
|
+
|-------|-----------|-------------|---------|
|
|
252
|
+
| API Response | response_type | description | example |
|
|
253
|
+
| State/Store | state_type | description | example |
|
|
254
|
+
| Component Props | props_type | description | example |
|
|
255
|
+
| Computed/Derived | derived_type | description | example |
|
|
256
|
+
|
|
257
|
+
#### Data Transformation Flow
|
|
258
|
+
|
|
259
|
+
```mermaid
|
|
260
|
+
graph LR
|
|
261
|
+
API["API Response"] --> Transform["Transform/Adapter"] --> Store["State Store"] --> Props["Component Props"]
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
**Good Example**
|
|
265
|
+
```lang
|
|
266
|
+
// Good: Clear data transformation from API to component
|
|
267
|
+
good_example
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
**Bad Example**
|
|
271
|
+
```lang
|
|
272
|
+
// Bad: Direct API response usage in component without transformation
|
|
273
|
+
bad_example
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## 5. State & Session Design (Platform-Specific)
|
|
279
|
+
|
|
280
|
+
<!-- AI-TAG: STATE_DESIGN -->
|
|
281
|
+
<!-- Fill with state management patterns. For backend: Session/Token management, server-side state. For frontend: State management libraries like Vuex/Pinia/Redux/Zustand. -->
|
|
282
|
+
|
|
283
|
+
### Backend Session Design (if backend platform)
|
|
284
|
+
|
|
285
|
+
<!-- AI-TAG: BACKEND_SESSION_DESIGN -->
|
|
286
|
+
<!-- Fill with backend session management patterns: Session/Token management, server-side state. If frontend platform, skip this subsection. -->
|
|
287
|
+
|
|
288
|
+
#### 5.1 State Management Patterns
|
|
289
|
+
|
|
290
|
+
| Pattern | Use Case | Implementation |
|
|
291
|
+
|---------|----------|----------------|
|
|
292
|
+
| pattern_name | use_case | implementation |
|
|
293
|
+
|
|
294
|
+
#### 5.2 State Diagram
|
|
295
|
+
|
|
296
|
+
{{#if has_state_diagram}}
|
|
297
|
+
```mermaid
|
|
298
|
+
stateDiagram-v2
|
|
299
|
+
{{state_diagram_content}}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
**Diagram Source**
|
|
303
|
+
{{#each state_diagram_sources}}
|
|
304
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
305
|
+
{{/each}}
|
|
306
|
+
{{/if}}
|
|
307
|
+
|
|
308
|
+
**Section Source**
|
|
309
|
+
{{#each state_design_sources}}
|
|
310
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
311
|
+
{{/each}}
|
|
312
|
+
|
|
313
|
+
### Frontend State Management Design (if frontend platform)
|
|
314
|
+
|
|
315
|
+
<!-- AI-TAG: FRONTEND_STATE_MANAGEMENT -->
|
|
316
|
+
<!-- Fill with frontend state management patterns. If backend platform, skip this subsection. -->
|
|
317
|
+
|
|
318
|
+
| Item | Detail |
|
|
319
|
+
|------|--------|
|
|
320
|
+
| State Library | state_library (e.g., Pinia, Vuex, Redux, Zustand, MobX) |
|
|
321
|
+
| Store Organization | store_organization (e.g., per-module, per-feature) |
|
|
322
|
+
| State Persistence | state_persistence (e.g., localStorage, sessionStorage) |
|
|
323
|
+
|
|
324
|
+
#### State Categories
|
|
325
|
+
|
|
326
|
+
| Category | Where to Store | Example |
|
|
327
|
+
|----------|---------------|---------|
|
|
328
|
+
| Server State | state_location | example |
|
|
329
|
+
| UI State | state_location | example |
|
|
330
|
+
| Form State | state_location | example |
|
|
331
|
+
| Auth State | state_location | example |
|
|
332
|
+
|
|
333
|
+
**Good Example**
|
|
334
|
+
```lang
|
|
335
|
+
good_state_example
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
**Bad Example**
|
|
339
|
+
```lang
|
|
340
|
+
bad_state_example
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
## 6. Transaction Design (Backend Only)
|
|
346
|
+
|
|
347
|
+
<!-- AI-TAG: TRANSACTION_DESIGN -->
|
|
348
|
+
<!-- Fill with transaction boundary rules, propagation mechanisms, isolation levels. If this platform is frontend or mobile, write 'Not applicable - transaction management is a backend concern.' -->
|
|
349
|
+
|
|
350
|
+
### 6.1 Transaction Boundary Rules
|
|
351
|
+
|
|
352
|
+
| Scenario | Transaction Scope | Justification |
|
|
353
|
+
|----------|------------------|---------------|
|
|
354
|
+
| scenario | scope | justification |
|
|
355
|
+
|
|
356
|
+
### 6.2 Propagation Mechanism Selection Guide
|
|
357
|
+
|
|
358
|
+
| Propagation | Use Case | Example Scenario |
|
|
359
|
+
|-------------|----------|-----------------|
|
|
360
|
+
| REQUIRED (Default) | Join existing or create new | Normal business operations |
|
|
361
|
+
| REQUIRES_NEW | Independent transaction | Audit logging, notification |
|
|
362
|
+
| NESTED | Sub-transaction with savepoint | Partial rollback scenarios |
|
|
363
|
+
| SUPPORTS | Optional participation | Read-only queries |
|
|
364
|
+
| NOT_SUPPORTED | Suspend current transaction | Non-transactional operations |
|
|
365
|
+
| MANDATORY | Must have existing transaction | Sub-service calls |
|
|
366
|
+
| NEVER | Must not have transaction | Pure query methods |
|
|
367
|
+
|
|
368
|
+
### 6.3 Isolation Level Selection
|
|
369
|
+
|
|
370
|
+
| Isolation Level | Use Case | Concurrency Issue Prevention |
|
|
371
|
+
|-----------------|----------|------------------------------|
|
|
372
|
+
| READ_UNCOMMITTED | Rarely used | None |
|
|
373
|
+
| READ_COMMITTED | Default for most cases | Dirty read |
|
|
374
|
+
| REPEATABLE_READ | Financial calculations | Dirty read, non-repeatable read |
|
|
375
|
+
| SERIALIZABLE | Critical operations | All concurrency issues |
|
|
376
|
+
|
|
377
|
+
### 6.4 Distributed Transaction Solution (if applicable)
|
|
378
|
+
|
|
379
|
+
| Solution | Use Case | Implementation |
|
|
380
|
+
|----------|----------|----------------|
|
|
381
|
+
| 2PC/3PC | Strong consistency required | implementation |
|
|
382
|
+
| TCC | Try-Confirm-Cancel pattern | implementation |
|
|
383
|
+
| Saga | Long-running transactions | implementation |
|
|
384
|
+
| Local Message Table | Eventually consistent | implementation |
|
|
385
|
+
|
|
386
|
+
### 6.5 Transaction Anti-Patterns
|
|
387
|
+
|
|
388
|
+
| Anti-Pattern | Problem | Solution |
|
|
389
|
+
|-------------|---------|----------|
|
|
390
|
+
| Transaction Abuse | Performance degradation | Minimize transaction scope |
|
|
391
|
+
| Long Transaction | Lock contention | Break into smaller transactions |
|
|
392
|
+
| Nested Service Calls | Unexpected rollback | Careful propagation selection |
|
|
393
|
+
|
|
394
|
+
**Good Example:**
|
|
395
|
+
```
|
|
396
|
+
good_transaction_example
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
**Bad Example:**
|
|
400
|
+
```
|
|
401
|
+
bad_transaction_example
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
**Section Source**
|
|
405
|
+
{{#each transaction_design_sources}}
|
|
406
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
407
|
+
{{/each}}
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
411
|
+
## 7. Authorization & Permission Design (Platform-Specific)
|
|
412
|
+
|
|
413
|
+
<!-- AI-TAG: PERMISSION_DESIGN -->
|
|
414
|
+
<!-- Fill with permission architecture. For backend: Permission framework, annotations, data scope. For frontend: Route guards, permission directives, menu filtering. -->
|
|
415
|
+
|
|
416
|
+
### Backend Permission Architecture (if backend platform)
|
|
417
|
+
|
|
418
|
+
<!-- AI-TAG: BACKEND_PERMISSION_ARCHITECTURE -->
|
|
419
|
+
<!-- Fill with backend permission framework content. If frontend platform, skip this subsection. -->
|
|
420
|
+
|
|
421
|
+
#### 7.1 Permission Architecture
|
|
422
|
+
|
|
423
|
+
```mermaid
|
|
424
|
+
graph TB
|
|
425
|
+
{{#each permission_components}}
|
|
426
|
+
{{id}}["{{name}}"]
|
|
427
|
+
{{/each}}
|
|
428
|
+
{{#each permission_relations}}
|
|
429
|
+
{{from}} --> {{to}}
|
|
430
|
+
{{/each}}
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
#### 7.2 Permission Check Flow
|
|
434
|
+
|
|
435
|
+
| Stage | Action | Implementation | Code Example |
|
|
436
|
+
|-------|--------|---------------|--------------|
|
|
437
|
+
| stage | action | implementation | `@PreAuthorize("hasRole('ADMIN')")` |
|
|
438
|
+
|
|
439
|
+
#### 7.3 Data Permission Strategy
|
|
440
|
+
|
|
441
|
+
| Strategy | Description | Example | Annotation |
|
|
442
|
+
|----------|-------------|---------|------------|
|
|
443
|
+
| strategy | description | example | `@DataPermission` |
|
|
444
|
+
|
|
445
|
+
#### 7.4 Permission Annotation Usage Examples
|
|
446
|
+
|
|
447
|
+
```java
|
|
448
|
+
// Role-based permission
|
|
449
|
+
@PreAuthorize("hasRole('ADMIN')")
|
|
450
|
+
|
|
451
|
+
// Permission-based
|
|
452
|
+
@PreAuthorize("hasPermission('system:user:create')")
|
|
453
|
+
|
|
454
|
+
// Data scope
|
|
455
|
+
@DataPermission(deptAlias = "d", userAlias = "u")
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
**Section Source**
|
|
459
|
+
{{#each permission_design_sources}}
|
|
460
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
461
|
+
{{/each}}
|
|
462
|
+
|
|
463
|
+
### Frontend Permission Design (if frontend platform)
|
|
464
|
+
|
|
465
|
+
<!-- AI-TAG: FRONTEND_PERMISSION_DESIGN -->
|
|
466
|
+
<!-- Fill with frontend permission UI design. If backend platform, skip this subsection. -->
|
|
467
|
+
|
|
468
|
+
| Item | Detail |
|
|
469
|
+
|------|--------|
|
|
470
|
+
| Permission Data Source | permission_source (e.g., login API response, user info API) |
|
|
471
|
+
| Permission Storage | permission_storage (e.g., Pinia store, Vuex, Redux) |
|
|
472
|
+
| Route Guard Strategy | route_guard_strategy |
|
|
473
|
+
| Button/Element Control | element_permission_strategy |
|
|
474
|
+
|
|
475
|
+
#### Permission Flow
|
|
476
|
+
|
|
477
|
+
```mermaid
|
|
478
|
+
graph TB
|
|
479
|
+
Login["User Login"] --> FetchPerm["Fetch Permissions"] --> StorePerm["Store in State"]
|
|
480
|
+
StorePerm --> RouteGuard["Route Guard Filter"]
|
|
481
|
+
StorePerm --> DirectiveCheck["v-permission Directive"]
|
|
482
|
+
StorePerm --> MenuFilter["Dynamic Menu Filter"]
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
**Good Example**
|
|
486
|
+
```lang
|
|
487
|
+
good_permission_example
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
**Bad Example**
|
|
491
|
+
```lang
|
|
492
|
+
bad_permission_example
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
---
|
|
496
|
+
|
|
497
|
+
## 8. Menu & Navigation Design (Frontend Only)
|
|
498
|
+
|
|
499
|
+
<!-- AI-TAG: MENU_DESIGN -->
|
|
500
|
+
<!-- Fill with menu/navigation design patterns. If this platform is backend, write 'Not applicable - menu and navigation design is a frontend concern. Backend exposes menu data via API endpoint.' -->
|
|
501
|
+
|
|
502
|
+
### 8.1 Menu Architecture
|
|
503
|
+
|
|
504
|
+
| Item | Detail |
|
|
505
|
+
|------|--------|
|
|
506
|
+
| Menu Levels | menu_levels |
|
|
507
|
+
| Navigation Pattern | nav_pattern |
|
|
508
|
+
| Dynamic Loading | dynamic_loading |
|
|
509
|
+
| Icon System | icon_system |
|
|
510
|
+
|
|
511
|
+
### 8.2 Menu Permission Integration
|
|
512
|
+
|
|
513
|
+
| Mechanism | Description | Implementation |
|
|
514
|
+
|-----------|-------------|----------------|
|
|
515
|
+
| mechanism | description | implementation |
|
|
516
|
+
|
|
517
|
+
### 8.3 Route Configuration (if frontend platform)
|
|
518
|
+
|
|
519
|
+
| Property | Description | Example |
|
|
520
|
+
|----------|-------------|---------|
|
|
521
|
+
| path | Route path | /system/user |
|
|
522
|
+
| component | Component reference | views/system/user/index |
|
|
523
|
+
| meta.permissions | Required permissions | ['system:user:list'] |
|
|
524
|
+
|
|
525
|
+
**Section Source**
|
|
526
|
+
{{#each menu_design_sources}}
|
|
527
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
528
|
+
{{/each}}
|
|
529
|
+
|
|
530
|
+
---
|
|
531
|
+
|
|
532
|
+
## 9. Multi-tenancy Design
|
|
533
|
+
|
|
534
|
+
<!-- AI-TAG: MULTITENANCY_DESIGN -->
|
|
535
|
+
<!-- Fill if the platform implements multi-tenancy. If not applicable, write "Not applicable - this platform does not implement multi-tenancy." -->
|
|
536
|
+
|
|
537
|
+
### 9.1 Tenant Isolation Strategy
|
|
538
|
+
|
|
539
|
+
| Item | Detail |
|
|
540
|
+
|------|--------|
|
|
541
|
+
| Isolation Level | isolation_level (row-level, schema-level, database-level) |
|
|
542
|
+
| Tenant Identifier | tenant_id_field |
|
|
543
|
+
| Tenant Context | tenant_context (ThreadLocal, HTTP header, JWT claim) |
|
|
544
|
+
| Default Tenant | default_tenant_id |
|
|
545
|
+
|
|
546
|
+
### 9.2 Tenant-Aware Query Pattern
|
|
547
|
+
|
|
548
|
+
```java
|
|
549
|
+
// Example of tenant-aware data access
|
|
550
|
+
tenant_query_example
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
### 9.3 Cross-Tenant Access Control
|
|
554
|
+
|
|
555
|
+
| Scenario | Rule | Implementation |
|
|
556
|
+
|----------|------|---------------|
|
|
557
|
+
| scenario | rule | implementation |
|
|
558
|
+
|
|
559
|
+
### 9.4 Tenant Data Migration
|
|
560
|
+
|
|
561
|
+
| Operation | Strategy |
|
|
562
|
+
|-----------|----------|
|
|
563
|
+
| Tenant onboarding | strategy |
|
|
564
|
+
| Tenant offboarding | strategy |
|
|
565
|
+
|
|
566
|
+
**Section Source**
|
|
567
|
+
{{#each multitenancy_design_sources}}
|
|
568
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
569
|
+
{{/each}}
|
|
570
|
+
|
|
571
|
+
---
|
|
572
|
+
|
|
573
|
+
## 10. Exception Handling & Error Codes
|
|
574
|
+
|
|
575
|
+
<!-- AI-TAG: EXCEPTION_HANDLING -->
|
|
576
|
+
<!-- Fill with exception handling patterns, error code system, response formats -->
|
|
577
|
+
|
|
578
|
+
### 10.1 Global Exception Handler
|
|
579
|
+
|
|
580
|
+
| Item | Detail |
|
|
581
|
+
|------|--------|
|
|
582
|
+
| Handler Class/Middleware | exception_handler |
|
|
583
|
+
| Location | handler_location |
|
|
584
|
+
| Handler Pattern | handler_pattern |
|
|
585
|
+
|
|
586
|
+
### 10.2 Error Code System
|
|
587
|
+
|
|
588
|
+
| Code Range | Category | Example |
|
|
589
|
+
|-----------|----------|---------|
|
|
590
|
+
| 000-099 | System errors | 001: Service unavailable |
|
|
591
|
+
| 100-199 | Authentication errors | 101: Token expired |
|
|
592
|
+
| 200-299 | Authorization errors | 201: Access denied |
|
|
593
|
+
| 300-399 | Validation errors | 301: Invalid parameter |
|
|
594
|
+
| 400-499 | Business errors | 401: User not found |
|
|
595
|
+
| 500-599 | Integration errors | 501: Third-party service error |
|
|
596
|
+
|
|
597
|
+
### 10.3 Exception Hierarchy
|
|
598
|
+
|
|
599
|
+
| Exception Type | HTTP Status | When to Use | Example |
|
|
600
|
+
|---------------|------------|-------------|---------|
|
|
601
|
+
| BusinessException | 200 | Business logic error | User not found |
|
|
602
|
+
| ValidationException | 400 | Input validation | Invalid email format |
|
|
603
|
+
| AuthenticationException | 401 | Auth failure | Invalid credentials |
|
|
604
|
+
| AuthorizationException | 403 | Permission denied | No admin role |
|
|
605
|
+
| SystemException | 500 | System error | Database connection failed |
|
|
606
|
+
|
|
607
|
+
### 10.4 Error Response Format
|
|
608
|
+
|
|
609
|
+
```json
|
|
610
|
+
{
|
|
611
|
+
"code": "error_code",
|
|
612
|
+
"message": "error_message",
|
|
613
|
+
"data": null,
|
|
614
|
+
"traceId": "trace_id",
|
|
615
|
+
"timestamp": 1234567890
|
|
616
|
+
}
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
### 10.5 Frontend Error Handling (if frontend platform)
|
|
620
|
+
|
|
621
|
+
| Error Type | Handling Strategy | User Feedback |
|
|
622
|
+
|-----------|------------------|---------------|
|
|
623
|
+
| Network Error | strategy | feedback |
|
|
624
|
+
| Business Error (200 with error code) | strategy | feedback |
|
|
625
|
+
| Auth Error (401) | Redirect to login | "Session expired, please login again" |
|
|
626
|
+
| Permission Error (403) | Show forbidden page | "You don't have permission" |
|
|
627
|
+
| Validation Error (400) | Highlight fields | field-specific message |
|
|
628
|
+
|
|
629
|
+
### 10.6 Error Code Assignment Process
|
|
630
|
+
|
|
631
|
+
1. Identify error category
|
|
632
|
+
2. Check existing codes in the range
|
|
633
|
+
3. Assign next available code
|
|
634
|
+
4. Document in error code registry
|
|
635
|
+
5. Add i18n message if needed
|
|
636
|
+
|
|
637
|
+
### 10.7 Cross-Service Exception Propagation (if distributed)
|
|
638
|
+
|
|
639
|
+
| Scenario | Strategy | Implementation |
|
|
640
|
+
|----------|----------|----------------|
|
|
641
|
+
| Service A calls Service B | strategy | implementation |
|
|
642
|
+
| Circuit breaker triggered | strategy | implementation |
|
|
643
|
+
|
|
644
|
+
**Section Source**
|
|
645
|
+
{{#each exception_handling_sources}}
|
|
646
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
647
|
+
{{/each}}
|
|
648
|
+
|
|
649
|
+
---
|
|
650
|
+
|
|
651
|
+
## 11. Security Design
|
|
652
|
+
|
|
653
|
+
<!-- AI-TAG: SECURITY_DESIGN -->
|
|
654
|
+
<!-- Fill with security protection matrix, XSS/CSRF/SQL injection prevention, encryption, sensitive data masking -->
|
|
655
|
+
|
|
656
|
+
### 11.1 Security Protection Matrix
|
|
657
|
+
|
|
658
|
+
| Threat | Protection Mechanism | Implementation |
|
|
659
|
+
|--------|---------------------|----------------|
|
|
660
|
+
| XSS | xss_protection | implementation |
|
|
661
|
+
| CSRF | csrf_protection | implementation |
|
|
662
|
+
| SQL Injection | sql_injection_protection | implementation |
|
|
663
|
+
| Session Hijacking | session_protection | implementation |
|
|
664
|
+
| Brute Force | rate_limiting | implementation |
|
|
665
|
+
|
|
666
|
+
### 11.2 XSS/CSRF/SQL Injection Prevention
|
|
667
|
+
|
|
668
|
+
**XSS Prevention:**
|
|
669
|
+
```
|
|
670
|
+
xss_prevention_config
|
|
671
|
+
```
|
|
672
|
+
|
|
673
|
+
**CSRF Prevention:**
|
|
674
|
+
```
|
|
675
|
+
csrf_prevention_config
|
|
676
|
+
```
|
|
677
|
+
|
|
678
|
+
**SQL Injection Prevention:**
|
|
679
|
+
```
|
|
680
|
+
sql_injection_prevention_config
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
### 11.3 API Encryption & Key Management
|
|
684
|
+
|
|
685
|
+
| Aspect | Implementation |
|
|
686
|
+
|--------|---------------|
|
|
687
|
+
| Transport Encryption | TLS 1.2+ |
|
|
688
|
+
| Payload Encryption | encryption_method |
|
|
689
|
+
| Key Storage | key_storage_method |
|
|
690
|
+
| Key Rotation | rotation_policy |
|
|
691
|
+
|
|
692
|
+
### 11.4 Unauthorized Access Prevention
|
|
693
|
+
|
|
694
|
+
| Mechanism | Implementation |
|
|
695
|
+
|-----------|---------------|
|
|
696
|
+
| URL-based access control | implementation |
|
|
697
|
+
| Method-level security | implementation |
|
|
698
|
+
| Data scope filtering | implementation |
|
|
699
|
+
|
|
700
|
+
### 11.5 Sensitive Data Masking Rules
|
|
701
|
+
|
|
702
|
+
| Data Type | Masking Rule | Example |
|
|
703
|
+
|-----------|-------------|---------|
|
|
704
|
+
| Phone Number | `***####` | 138****8888 |
|
|
705
|
+
| ID Card | `************####` | 110101********1234 |
|
|
706
|
+
| Bank Card | `****####****####` | ****8888****8888 |
|
|
707
|
+
| Email | `**@domain.com` | ab**@gmail.com |
|
|
708
|
+
|
|
709
|
+
**Good Example:**
|
|
710
|
+
```
|
|
711
|
+
good_security_example
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
**Bad Example:**
|
|
715
|
+
```
|
|
716
|
+
bad_security_example
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
**Section Source**
|
|
720
|
+
{{#each security_design_sources}}
|
|
721
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
722
|
+
{{/each}}
|
|
723
|
+
|
|
724
|
+
---
|
|
725
|
+
|
|
726
|
+
## 12. Caching Design (Platform-Specific)
|
|
727
|
+
|
|
728
|
+
<!-- AI-TAG: CACHING_DESIGN -->
|
|
729
|
+
<!-- Fill with caching strategies. For backend: Redis/Caffeine/cache implementations. For frontend: localStorage/sessionStorage/IndexedDB/Service Worker. -->
|
|
730
|
+
|
|
731
|
+
### Backend Caching Design (if backend platform)
|
|
732
|
+
|
|
733
|
+
<!-- AI-TAG: BACKEND_CACHING -->
|
|
734
|
+
<!-- Fill with backend caching strategies: Redis/Caffeine/cache implementations. If frontend platform, skip this subsection. -->
|
|
735
|
+
|
|
736
|
+
#### 12.1 Caching Strategy Selection
|
|
737
|
+
|
|
738
|
+
| Strategy | Use Case | Consistency | Complexity |
|
|
739
|
+
|----------|----------|-------------|------------|
|
|
740
|
+
| Cache-Aside | Read-heavy, eventual consistency | Low | Low |
|
|
741
|
+
| Write-Through | Write-heavy, strong consistency | High | Medium |
|
|
742
|
+
| Write-Behind | High write throughput | Low | High |
|
|
743
|
+
| Read-Through | Simplified cache logic | Medium | Low |
|
|
744
|
+
|
|
745
|
+
#### 12.2 Cache Consistency Solutions
|
|
746
|
+
|
|
747
|
+
| Scenario | Solution | Trade-off |
|
|
748
|
+
|----------|----------|-----------|
|
|
749
|
+
| Cache update | solution | trade_off |
|
|
750
|
+
| Cache invalidation | solution | trade_off |
|
|
751
|
+
| Concurrent update | solution | trade_off |
|
|
752
|
+
|
|
753
|
+
#### 12.3 Cache Penetration/Breakdown/Avalanche Prevention
|
|
754
|
+
|
|
755
|
+
| Problem | Cause | Solution |
|
|
756
|
+
|---------|-------|----------|
|
|
757
|
+
| Cache Penetration | Query non-existent data | Bloom filter, empty value caching |
|
|
758
|
+
| Cache Breakdown | Hot key expires | Mutex lock, logical expiration |
|
|
759
|
+
| Cache Avalanche | Mass key expiration | Random TTL, circuit breaker |
|
|
760
|
+
|
|
761
|
+
#### 12.4 Scenario-Based Caching Decisions
|
|
762
|
+
|
|
763
|
+
| Scenario | Strategy | TTL | Notes |
|
|
764
|
+
|----------|----------|-----|-------|
|
|
765
|
+
| High read, low write | strategy | ttl | notes |
|
|
766
|
+
| Low read, high write | strategy | ttl | notes |
|
|
767
|
+
| Real-time data | strategy | ttl | notes |
|
|
768
|
+
|
|
769
|
+
**Good Example:**
|
|
770
|
+
```
|
|
771
|
+
good_caching_example
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
**Bad Example:**
|
|
775
|
+
```
|
|
776
|
+
bad_caching_example
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
**Section Source**
|
|
780
|
+
{{#each caching_design_sources}}
|
|
781
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
782
|
+
{{/each}}
|
|
783
|
+
|
|
784
|
+
### Frontend Caching Design (if frontend platform)
|
|
785
|
+
|
|
786
|
+
<!-- AI-TAG: FRONTEND_CACHING -->
|
|
787
|
+
<!-- Fill with frontend caching strategies. If backend platform, skip this subsection. -->
|
|
788
|
+
|
|
789
|
+
| Storage Type | Use Case | Capacity | Persistence |
|
|
790
|
+
|-------------|----------|----------|-------------|
|
|
791
|
+
| localStorage | use_case | ~5MB | Permanent |
|
|
792
|
+
| sessionStorage | use_case | ~5MB | Tab session |
|
|
793
|
+
| IndexedDB | use_case | Large | Permanent |
|
|
794
|
+
| Memory (State Store) | use_case | Runtime | Page session |
|
|
795
|
+
|
|
796
|
+
#### Cache Invalidation Strategy
|
|
797
|
+
|
|
798
|
+
| Data Type | Cache Location | TTL/Invalidation | Example |
|
|
799
|
+
|-----------|---------------|------------------|---------|
|
|
800
|
+
| data_type | location | strategy | example |
|
|
801
|
+
|
|
802
|
+
**Good Example**
|
|
803
|
+
```lang
|
|
804
|
+
good_cache_example
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
**Bad Example**
|
|
808
|
+
```lang
|
|
809
|
+
bad_cache_example
|
|
810
|
+
```
|
|
811
|
+
|
|
812
|
+
---
|
|
813
|
+
|
|
814
|
+
## 13. Logging Design (Architecture Level)
|
|
815
|
+
|
|
816
|
+
<!-- AI-TAG: LOGGING_DESIGN -->
|
|
817
|
+
<!-- Fill with logging patterns at design level. If not applicable, write "Not applicable." -->
|
|
818
|
+
|
|
819
|
+
### 13.1 Log Content Template
|
|
820
|
+
|
|
821
|
+
| Field | Description | Example |
|
|
822
|
+
|-------|-------------|---------|
|
|
823
|
+
| traceId | Distributed tracing ID | trace_id_format |
|
|
824
|
+
| userId | Current user ID | user_id_format |
|
|
825
|
+
| requestId | Request identifier | request_id_format |
|
|
826
|
+
| timestamp | Log timestamp | ISO 8601 |
|
|
827
|
+
| level | Log level | INFO, WARN, ERROR |
|
|
828
|
+
| class | Source class | ClassName.method |
|
|
829
|
+
| message | Log message | message_format |
|
|
830
|
+
| context | Additional context | JSON format |
|
|
831
|
+
|
|
832
|
+
### 13.2 Log Level Usage Specification
|
|
833
|
+
|
|
834
|
+
| Level | Use Case | Example |
|
|
835
|
+
|-------|----------|---------|
|
|
836
|
+
| ERROR | System errors, exceptions | Database connection failed |
|
|
837
|
+
| WARN | Business anomalies, recoverable | Login failed, validation error |
|
|
838
|
+
| INFO | Key business events | User login, order created |
|
|
839
|
+
| DEBUG | Development debugging | Method entry/exit, variable values |
|
|
840
|
+
| TRACE | Detailed tracing | SQL statements, request details |
|
|
841
|
+
|
|
842
|
+
### 13.3 Sensitive Information Masking Rules
|
|
843
|
+
|
|
844
|
+
| Data Type | Masking Strategy |
|
|
845
|
+
|-----------|-----------------|
|
|
846
|
+
| Password | Never log, replace with [MASKED] |
|
|
847
|
+
| Token | Log first 6 chars only |
|
|
848
|
+
| Credit Card | Mask all but last 4 digits |
|
|
849
|
+
| Personal ID | Full mask in logs |
|
|
850
|
+
|
|
851
|
+
### 13.4 Audit Log Design
|
|
852
|
+
|
|
853
|
+
| Aspect | Specification |
|
|
854
|
+
|--------|--------------|
|
|
855
|
+
| What to log | User actions, data changes, security events |
|
|
856
|
+
| Log format | Structured JSON |
|
|
857
|
+
| Retention | retention_policy |
|
|
858
|
+
| Storage | storage_solution |
|
|
859
|
+
| Compliance | compliance_requirements |
|
|
860
|
+
|
|
861
|
+
**Section Source**
|
|
862
|
+
{{#each logging_design_sources}}
|
|
863
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
864
|
+
{{/each}}
|
|
865
|
+
|
|
866
|
+
---
|
|
867
|
+
|
|
868
|
+
## 14. Distributed Design (Backend Only, if distributed)
|
|
869
|
+
|
|
870
|
+
<!-- AI-TAG: DISTRIBUTED_DESIGN -->
|
|
871
|
+
<!-- Fill with distributed patterns. If this platform is frontend/mobile, or if the backend is a monolithic architecture, write 'Not applicable.' -->
|
|
872
|
+
|
|
873
|
+
### 14.1 Distributed Lock Specification
|
|
874
|
+
|
|
875
|
+
| Implementation | Use Case | Pros | Cons |
|
|
876
|
+
|---------------|----------|------|------|
|
|
877
|
+
| Redis RedLock | High availability | Fast, scalable | Clock skew issues |
|
|
878
|
+
| ZooKeeper | Strong consistency | Reliable | Higher latency |
|
|
879
|
+
| Database | Simple scenarios | Easy to implement | Performance bottleneck |
|
|
880
|
+
|
|
881
|
+
**Usage Pattern:**
|
|
882
|
+
```
|
|
883
|
+
distributed_lock_example
|
|
884
|
+
```
|
|
885
|
+
|
|
886
|
+
### 14.2 Cross-Service Call Design
|
|
887
|
+
|
|
888
|
+
| Aspect | Configuration | Recommendation |
|
|
889
|
+
|--------|--------------|----------------|
|
|
890
|
+
| Timeout | timeout_value | Set based on P99 latency |
|
|
891
|
+
| Retry | retry_policy | Exponential backoff |
|
|
892
|
+
| Fallback | fallback_strategy | Degrade gracefully |
|
|
893
|
+
| Circuit Breaker | cb_config | Fail fast on errors |
|
|
894
|
+
|
|
895
|
+
### 14.3 Database Sharding Design Principles
|
|
896
|
+
|
|
897
|
+
| Aspect | Principle |
|
|
898
|
+
|--------|-----------|
|
|
899
|
+
| Shard Key Selection | shard_key_principle |
|
|
900
|
+
| Sharding Strategy | strategy |
|
|
901
|
+
| Rebalancing | rebalancing_approach |
|
|
902
|
+
| Cross-shard Query | cross_shard_solution |
|
|
903
|
+
|
|
904
|
+
### 14.4 Message Queue Usage Specification
|
|
905
|
+
|
|
906
|
+
| Aspect | @Async | MQ |
|
|
907
|
+
|--------|--------|-----|
|
|
908
|
+
| Use Case | async_use_case | mq_use_case |
|
|
909
|
+
| Reliability | reliability_level | high |
|
|
910
|
+
| Ordering | ordering | guaranteed |
|
|
911
|
+
| Scalability | limited | high |
|
|
912
|
+
|
|
913
|
+
**Decision Guide:**
|
|
914
|
+
- Use @Async for: Simple async tasks, same JVM, acceptable loss
|
|
915
|
+
- Use MQ for: Cross-service, guaranteed delivery, high throughput
|
|
916
|
+
|
|
917
|
+
**Section Source**
|
|
918
|
+
{{#each distributed_design_sources}}
|
|
919
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
920
|
+
{{/each}}
|
|
921
|
+
|
|
922
|
+
---
|
|
923
|
+
|
|
924
|
+
## 15. Observability & Deployment Design (Platform-Specific)
|
|
925
|
+
|
|
926
|
+
<!-- AI-TAG: OBSERVABILITY_DESIGN -->
|
|
927
|
+
<!-- Fill with monitoring and observability patterns. For backend: JVM/APM/metrics. For frontend: Error reporting, performance monitoring, user analytics. -->
|
|
928
|
+
|
|
929
|
+
### Backend Observability (if backend platform)
|
|
930
|
+
|
|
931
|
+
<!-- AI-TAG: BACKEND_OBSERVABILITY -->
|
|
932
|
+
<!-- Fill with backend observability: JVM/APM/metrics, health checks. If frontend platform, skip this subsection. -->
|
|
933
|
+
|
|
934
|
+
#### 15.1 Monitoring Metrics Design
|
|
935
|
+
|
|
936
|
+
| Category | Metrics | Collection Method |
|
|
937
|
+
|----------|---------|------------------|
|
|
938
|
+
| JVM | Heap, GC, Threads | Micrometer + Prometheus |
|
|
939
|
+
| API | QPS, Latency, Error Rate | AOP interceptors |
|
|
940
|
+
| Database | Connection pool, Slow queries | DataSource metrics |
|
|
941
|
+
| Cache | Hit rate, Eviction rate | Cache statistics |
|
|
942
|
+
|
|
943
|
+
#### 15.2 Distributed Tracing Integration
|
|
944
|
+
|
|
945
|
+
| Solution | Integration | Trace Propagation |
|
|
946
|
+
|----------|-------------|------------------|
|
|
947
|
+
| SkyWalking | Agent-based | Automatic |
|
|
948
|
+
| Zipkin | Client library | Manual headers |
|
|
949
|
+
| Jaeger | Agent-based | Automatic |
|
|
950
|
+
|
|
951
|
+
#### 15.3 Health Check Interface Design
|
|
952
|
+
|
|
953
|
+
| Endpoint | Purpose | Response |
|
|
954
|
+
|----------|---------|----------|
|
|
955
|
+
| /health | Liveness probe | {"status": "UP"} |
|
|
956
|
+
| /ready | Readiness probe | {"ready": true} |
|
|
957
|
+
| /metrics | Metrics export | Prometheus format |
|
|
958
|
+
|
|
959
|
+
#### 15.4 Configuration Externalization
|
|
960
|
+
|
|
961
|
+
| Configuration | Externalization Method | Reload Support |
|
|
962
|
+
|--------------|----------------------|----------------|
|
|
963
|
+
| Database | Config center | hot_reload |
|
|
964
|
+
| Cache | Config center | hot_reload |
|
|
965
|
+
| Feature flags | Config center | hot_reload |
|
|
966
|
+
|
|
967
|
+
#### 15.5 Containerization Adaptation (if applicable)
|
|
968
|
+
|
|
969
|
+
| Aspect | Specification |
|
|
970
|
+
|--------|--------------|
|
|
971
|
+
| Base Image | base_image |
|
|
972
|
+
| Resource Limits | cpu_limit, memory_limit |
|
|
973
|
+
| Health Probes | probe_configuration |
|
|
974
|
+
| Logging | stdout/stderr |
|
|
975
|
+
|
|
976
|
+
**Section Source**
|
|
977
|
+
{{#each observability_design_sources}}
|
|
978
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
979
|
+
{{/each}}
|
|
980
|
+
|
|
981
|
+
### Frontend Monitoring (if frontend platform)
|
|
982
|
+
|
|
983
|
+
<!-- AI-TAG: FRONTEND_MONITORING -->
|
|
984
|
+
<!-- Fill with frontend monitoring and error reporting setup. If backend platform, skip this subsection. -->
|
|
985
|
+
|
|
986
|
+
| Item | Detail |
|
|
987
|
+
|------|--------|
|
|
988
|
+
| Error Reporting | error_reporting_tool (e.g., Sentry, Bugsnag, custom) |
|
|
989
|
+
| Performance Monitoring | perf_monitoring (e.g., Web Vitals, Lighthouse CI) |
|
|
990
|
+
| User Analytics | analytics_tool (e.g., Google Analytics, Mixpanel) |
|
|
991
|
+
| Log Collection | log_collection (e.g., custom API, third-party service) |
|
|
992
|
+
|
|
993
|
+
#### Key Metrics
|
|
994
|
+
|
|
995
|
+
| Metric | Target | Measurement |
|
|
996
|
+
|--------|--------|-------------|
|
|
997
|
+
| LCP (Largest Contentful Paint) | target | measurement_method |
|
|
998
|
+
| FID (First Input Delay) | target | measurement_method |
|
|
999
|
+
| CLS (Cumulative Layout Shift) | target | measurement_method |
|
|
1000
|
+
| Error Rate | target | measurement_method |
|
|
1001
|
+
|
|
1002
|
+
---
|
|
1003
|
+
|
|
1004
|
+
## 16. Compliance & Governance
|
|
1005
|
+
|
|
1006
|
+
<!-- AI-TAG: COMPLIANCE_DESIGN -->
|
|
1007
|
+
<!-- Fill with compliance requirements. If not applicable, write "Not applicable." -->
|
|
1008
|
+
|
|
1009
|
+
### 16.1 Data Privacy Protection
|
|
1010
|
+
|
|
1011
|
+
| Regulation | Requirement | Implementation |
|
|
1012
|
+
|------------|-------------|----------------|
|
|
1013
|
+
| GDPR | Right to erasure | data_deletion_procedure |
|
|
1014
|
+
| GDPR | Data portability | data_export_api |
|
|
1015
|
+
| 等保2.0 | Access control | access_control_measures |
|
|
1016
|
+
| 等保2.0 | Audit logging | audit_log_implementation |
|
|
1017
|
+
|
|
1018
|
+
### 16.2 Dependency Management Specification
|
|
1019
|
+
|
|
1020
|
+
| Aspect | Rule |
|
|
1021
|
+
|--------|------|
|
|
1022
|
+
| Version Selection | Prefer stable releases, LTS versions |
|
|
1023
|
+
| Upgrade Strategy | upgrade_strategy |
|
|
1024
|
+
| Vulnerability Scanning | scan_frequency, tools |
|
|
1025
|
+
| License Compliance | allowed_licenses |
|
|
1026
|
+
|
|
1027
|
+
### 16.3 Code Quality Governance
|
|
1028
|
+
|
|
1029
|
+
| Tool | Purpose | Configuration |
|
|
1030
|
+
|------|---------|---------------|
|
|
1031
|
+
| CheckStyle | Style enforcement | checkstyle_config_location |
|
|
1032
|
+
| PMD | Static analysis | pmd_config_location |
|
|
1033
|
+
| SpotBugs | Bug detection | spotbugs_config_location |
|
|
1034
|
+
| SonarQube | Quality gates | sonar_config |
|
|
1035
|
+
|
|
1036
|
+
**Section Source**
|
|
1037
|
+
{{#each compliance_design_sources}}
|
|
1038
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
1039
|
+
{{/each}}
|
|
1040
|
+
|
|
1041
|
+
---
|
|
1042
|
+
|
|
1043
|
+
## 17. Performance Design
|
|
1044
|
+
|
|
1045
|
+
<!-- AI-TAG: PERFORMANCE_DESIGN -->
|
|
1046
|
+
<!-- Fill with performance design guidelines and scenario-based optimization -->
|
|
1047
|
+
|
|
1048
|
+
### 17.1 Performance Design Guidelines
|
|
1049
|
+
|
|
1050
|
+
{{#each performance_guidelines}}
|
|
1051
|
+
#### {{category}}
|
|
1052
|
+
|
|
1053
|
+
{{description}}
|
|
1054
|
+
|
|
1055
|
+
**Guidelines:**
|
|
1056
|
+
{{#each items}}
|
|
1057
|
+
- {{this}}
|
|
1058
|
+
{{/each}}
|
|
1059
|
+
|
|
1060
|
+
{{/each}}
|
|
1061
|
+
|
|
1062
|
+
### 17.2 Scenario-Based Performance Optimization
|
|
1063
|
+
|
|
1064
|
+
| Scenario | Optimization Strategy | Implementation |
|
|
1065
|
+
|----------|----------------------|----------------|
|
|
1066
|
+
| High Concurrency Read | strategy | implementation |
|
|
1067
|
+
| High Concurrency Write | strategy | implementation |
|
|
1068
|
+
| Mixed Workload | strategy | implementation |
|
|
1069
|
+
| Batch Processing | strategy | implementation |
|
|
1070
|
+
|
|
1071
|
+
**Section Source**
|
|
1072
|
+
{{#each performance_design_sources}}
|
|
1073
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
1074
|
+
{{/each}}
|
|
1075
|
+
|
|
1076
|
+
---
|
|
1077
|
+
|
|
1078
|
+
## 18. Anti-Patterns & Pitfalls
|
|
1079
|
+
|
|
1080
|
+
<!-- AI-TAG: ANTI_PATTERNS -->
|
|
1081
|
+
<!-- Fill with common design anti-patterns and solutions -->
|
|
1082
|
+
|
|
1083
|
+
### 18.1 Common Design Anti-Patterns
|
|
1084
|
+
|
|
1085
|
+
| Anti-Pattern | Problem | Solution | Example |
|
|
1086
|
+
|-------------|---------|----------|---------|
|
|
1087
|
+
| God Class | Too many responsibilities | Split into cohesive classes | example |
|
|
1088
|
+
| Anemic Domain Model | Logic in services | Rich domain model | example |
|
|
1089
|
+
| Leaky Abstraction | Implementation details exposed | Proper encapsulation | example |
|
|
1090
|
+
| Premature Optimization | Unnecessary complexity | Measure first, optimize later | example |
|
|
1091
|
+
| Magic Numbers | Unclear constants | Named constants | example |
|
|
1092
|
+
|
|
1093
|
+
### 18.2 High-Frequency Failure Scenarios
|
|
1094
|
+
|
|
1095
|
+
| Scenario | Root Cause | Prevention | Recovery |
|
|
1096
|
+
|----------|-----------|------------|----------|
|
|
1097
|
+
| scenario | cause | prevention | recovery |
|
|
1098
|
+
|
|
1099
|
+
### 18.3 Cache-Database Consistency Issues
|
|
1100
|
+
|
|
1101
|
+
| Issue | Cause | Solution |
|
|
1102
|
+
|-------|-------|----------|
|
|
1103
|
+
| Stale cache | Update without invalidation | Cache-Aside with proper invalidation |
|
|
1104
|
+
| Inconsistent read | Race condition | Distributed lock or versioning |
|
|
1105
|
+
|
|
1106
|
+
### 18.4 Thread Pool Misconfiguration
|
|
1107
|
+
|
|
1108
|
+
| Misconfiguration | Impact | Correct Configuration |
|
|
1109
|
+
|-----------------|--------|----------------------|
|
|
1110
|
+
| Pool too small | Request queuing, timeouts | Based on CPU cores + expected load |
|
|
1111
|
+
| Pool too large | Resource exhaustion | Monitor and tune |
|
|
1112
|
+
| Unbounded queue | Memory issues | Use bounded queue with rejection policy |
|
|
1113
|
+
|
|
1114
|
+
**Good Example:**
|
|
1115
|
+
```
|
|
1116
|
+
good_threadpool_example
|
|
1117
|
+
```
|
|
1118
|
+
|
|
1119
|
+
**Bad Example:**
|
|
1120
|
+
```
|
|
1121
|
+
bad_threadpool_example
|
|
1122
|
+
```
|
|
1123
|
+
|
|
1124
|
+
### 18.5 DTO/VO/DO Confusion
|
|
1125
|
+
|
|
1126
|
+
| Confusion | Problem | Solution |
|
|
1127
|
+
|-----------|---------|----------|
|
|
1128
|
+
| Using DO in API | Exposes internal structure | Use DTO/VO |
|
|
1129
|
+
| No separation | Tight coupling | Clear layer separation |
|
|
1130
|
+
| Wrong conversion | Data loss or exposure | Proper mapping |
|
|
1131
|
+
|
|
1132
|
+
**Section Source**
|
|
1133
|
+
{{#each anti_patterns_sources}}
|
|
1134
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
1135
|
+
{{/each}}
|
|
1136
|
+
|
|
1137
|
+
---
|
|
1138
|
+
|
|
1139
|
+
## Appendix
|
|
1140
|
+
|
|
1141
|
+
<!-- AI-TAG: APPENDIX -->
|
|
1142
|
+
|
|
1143
|
+
### Design Checklist
|
|
1144
|
+
|
|
1145
|
+
Before finalizing design, verify:
|
|
1146
|
+
|
|
1147
|
+
**Architecture:**
|
|
1148
|
+
- [ ] Layer boundaries are respected
|
|
1149
|
+
- [ ] Dependencies flow inward only
|
|
1150
|
+
- [ ] External dependencies are abstracted
|
|
1151
|
+
|
|
1152
|
+
**API Design:**
|
|
1153
|
+
- [ ] RESTful conventions followed
|
|
1154
|
+
- [ ] Versioning strategy defined
|
|
1155
|
+
- [ ] Error responses are consistent
|
|
1156
|
+
|
|
1157
|
+
**Data:**
|
|
1158
|
+
- [ ] DTO/VO/DO separation is clear
|
|
1159
|
+
- [ ] Data flow is documented
|
|
1160
|
+
- [ ] Sensitive data is protected
|
|
1161
|
+
|
|
1162
|
+
**Security:**
|
|
1163
|
+
- [ ] Authentication is enforced
|
|
1164
|
+
- [ ] Authorization checks are in place
|
|
1165
|
+
- [ ] Input validation is comprehensive
|
|
1166
|
+
|
|
1167
|
+
**Performance:**
|
|
1168
|
+
- [ ] Caching strategy is defined
|
|
1169
|
+
- [ ] Transaction boundaries are optimal
|
|
1170
|
+
- [ ] N+1 query issues are addressed
|
|
1171
|
+
|
|
1172
|
+
**Operations:**
|
|
1173
|
+
- [ ] Logging is structured
|
|
1174
|
+
- [ ] Metrics are defined
|
|
1175
|
+
- [ ] Health checks are implemented
|
|
1176
|
+
|
|
1177
|
+
{{#each design_checklist}}
|
|
1178
|
+
- [ ] {{item}}
|
|
1179
|
+
{{/each}}
|
|
1180
|
+
|
|
1181
|
+
### Common Design Scenarios Decision Guide
|
|
1182
|
+
|
|
1183
|
+
| Scenario | Decision Factors | Recommended Approach |
|
|
1184
|
+
|----------|-----------------|---------------------|
|
|
1185
|
+
| Sync vs Async | factors | approach |
|
|
1186
|
+
| Cache vs No Cache | factors | approach |
|
|
1187
|
+
| Single DB vs Sharding | factors | approach |
|
|
1188
|
+
| Monolith vs Microservice | factors | approach |
|
|
1189
|
+
|
|
1190
|
+
{{#each common_scenarios}}
|
|
1191
|
+
#### {{name}}
|
|
1192
|
+
|
|
1193
|
+
{{description}}
|
|
1194
|
+
|
|
1195
|
+
**Recommended Approach:**
|
|
1196
|
+
{{approach}}
|
|
1197
|
+
|
|
1198
|
+
{{/each}}
|
|
1199
|
+
|
|
1200
|
+
### Version History
|
|
1201
|
+
|
|
1202
|
+
| Version | Date | Author | Changes |
|
|
1203
|
+
|---------|------|--------|---------|
|
|
1204
|
+
| 1.0 | date | author | Initial version |
|
|
1205
|
+
|
|
1206
|
+
**Section Source**
|
|
1207
|
+
{{#each appendix_sources}}
|
|
1208
|
+
- [{{name}}]({{path}}#L{{start}}-L{{end}})
|
|
1209
|
+
{{/each}}
|