create-dp-koa 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/README.md +50 -0
  2. package/index.mjs +97 -0
  3. package/package.json +33 -0
  4. package/template/.env.development +9 -0
  5. package/template/.env.production +12 -0
  6. package/template/.github/workflows/ci-cd.yml +182 -0
  7. package/template/.trae/documents/controller_development_plan.md +386 -0
  8. package/template/.trae/skills/00-backend-core.skill.md +50 -0
  9. package/template/.trae/skills/01-backend-skill-router.skill.md +55 -0
  10. package/template/.trae/skills/10-backend-api.skill.md +54 -0
  11. package/template/.trae/skills/11-backend-controller-recipes.skill.md +107 -0
  12. package/template/.trae/skills/20-backend-repository.skill.md +25 -0
  13. package/template/.trae/skills/21-backend-service.skill.md +135 -0
  14. package/template/.trae/skills/25-backend-comments-and-doc.skill.md +97 -0
  15. package/template/.trae/skills/30-backend-validation.skill.md +320 -0
  16. package/template/.trae/skills/40-backend-error-logging.skill.md +21 -0
  17. package/template/.trae/skills/50-backend-bootstrap-lifecycle.skill.md +90 -0
  18. package/template/.trae/skills/60-backend-router-registration.skill.md +71 -0
  19. package/template/.trae/skills/70-backend-middleware.skill.md +98 -0
  20. package/template/.trae/skills/80-backend-utils-and-libs.skill.md +90 -0
  21. package/template/.trae/skills/85-backend-plugins.rule.md +64 -0
  22. package/template/.trae/skills/90-backend-testing.skill.md +29 -0
  23. package/template/.trae/skills/README.md +49 -0
  24. package/template/.vscode/launch.json +38 -0
  25. package/template/.vscode/settings.json +1 -0
  26. package/template/Dockerfile +36 -0
  27. package/template/README.md +229 -0
  28. package/template/docker-compose.yml +135 -0
  29. package/template/docs/API_DOCUMENTATION.md +837 -0
  30. package/template/docs/ARCHITECTURE_REFACTOR.md +109 -0
  31. package/template/docs/CACHE_MIGRATION_GUIDE.md +142 -0
  32. package/template/docs/DEPLOYMENT_GUIDE.md +1062 -0
  33. package/template/docs/DEVELOPMENT_GUIDE.md +1097 -0
  34. package/template/docs/DOCUMENTATION_CLEANUP_REPORT.md +166 -0
  35. package/template/docs/DOCUMENTATION_COMPLETION_REPORT.md +223 -0
  36. package/template/docs/DOCUMENTATION_INDEX.md +294 -0
  37. package/template/docs/DOCUMENTATION_STRUCTURE.md +221 -0
  38. package/template/docs/ENTERPRISE_ANNOTATION_SYSTEM_GUIDE.md +2069 -0
  39. package/template/docs/ENTERPRISE_DATABASE_ARCHITECTURE.md +318 -0
  40. package/template/docs/ENTERPRISE_DEPLOYMENT_GUIDE.md +547 -0
  41. package/template/docs/ENTERPRISE_ERROR_HANDLING_GUIDE.md +357 -0
  42. package/template/docs/ENTERPRISE_LOGGING_SYSTEM_GUIDE.md +494 -0
  43. package/template/docs/ENVIRONMENT_CONFIG_EXAMPLE.md +69 -0
  44. package/template/docs/FINAL_IMPLEMENTATION_SUMMARY.md +206 -0
  45. package/template/docs/HEALTH_CHECK_ROUTE_FIX.md +134 -0
  46. package/template/docs/IMPLEMENTATION_CHECKLIST.md +204 -0
  47. package/template/docs/INSTALLATION_GUIDE.md +611 -0
  48. package/template/docs/INTERCEPTOR_TESTING_REPORT.md +226 -0
  49. package/template/docs/INTERCEPTOR_TESTING_SCRIPTS.md +143 -0
  50. package/template/docs/LOGGING_OPTIMIZATION_GUIDE.md +126 -0
  51. package/template/docs/MEMORY_DATABASE_GUIDE.md +212 -0
  52. package/template/docs/NEW_ROUTER_INTEGRATION_GUIDE.md +345 -0
  53. package/template/docs/NEW_ROUTER_INTEGRATION_SUMMARY.md +259 -0
  54. package/template/docs/NEW_ROUTER_USAGE_GUIDE.md +364 -0
  55. package/template/docs/QUICK_START.md +268 -0
  56. package/template/docs/ROUTE_SLASH_COMPATIBILITY_FIX.md +191 -0
  57. package/template/docs/SERVICE_INTERCEPTOR_GUIDE.md +243 -0
  58. package/template/docs/SERVICE_LAYER_INDEX.md +205 -0
  59. package/template/docs/SERVICE_PATTERN_GUIDE.md +270 -0
  60. package/template/docs/SERVICE_RETURN_VALUE_SPECIFICATION.md +466 -0
  61. package/template/docs/SWAGGER_DEBUG_MODE_GUIDE.md +80 -0
  62. package/template/docs/SWAGGER_INTEGRATION_GUIDE.md +416 -0
  63. package/template/docs/TRANSACTION_MANAGER_USAGE.md +360 -0
  64. package/template/docs/TROUBLESHOOTING.md +869 -0
  65. package/template/env.production.example +62 -0
  66. package/template/jest.config.js +34 -0
  67. package/template/package-lock.json +13240 -0
  68. package/template/package.json +119 -0
  69. package/template/patches/typeorm+0.3.25.patch +22 -0
  70. package/template/scripts/sync-template.mjs +84 -0
  71. package/template/scripts/test-annotation-system.sh +48 -0
  72. package/template/scripts/test-core-functionality.sh +28 -0
  73. package/template/src/annotations/decorators/ConfigManagement.ts +9 -0
  74. package/template/src/annotations/decorators/DistributedTracing.ts +9 -0
  75. package/template/src/annotations/decorators/EnterprisePerformance.ts +9 -0
  76. package/template/src/annotations/decorators/PerformanceMonitor.ts +32 -0
  77. package/template/src/annotations/decorators/SecurityAudit.ts +9 -0
  78. package/template/src/annotations/index.ts +50 -0
  79. package/template/src/annotations/processors/ConfigManagementProcessor.ts +369 -0
  80. package/template/src/annotations/processors/DistributedTracingProcessor.ts +288 -0
  81. package/template/src/annotations/processors/EnterprisePerformanceProcessor.ts +189 -0
  82. package/template/src/annotations/processors/PerformanceMonitorProcessor.ts +101 -0
  83. package/template/src/annotations/processors/SecurityAuditProcessor.ts +345 -0
  84. package/template/src/annotations/processors/SwaggerProcessor.ts +612 -0
  85. package/template/src/annotations/processors/index.ts +10 -0
  86. package/template/src/app.ts +123 -0
  87. package/template/src/controllers/base.controller.ts +41 -0
  88. package/template/src/controllers/cacheManagement.controller.ts +131 -0
  89. package/template/src/controllers/captcha.controller.ts +57 -0
  90. package/template/src/controllers/demo/AnnotationDemoController.ts +118 -0
  91. package/template/src/controllers/example/EnterpriseExampleController.ts +297 -0
  92. package/template/src/controllers/example/ExampleController.ts +110 -0
  93. package/template/src/controllers/example/NewAnnotationExampleController.ts +159 -0
  94. package/template/src/controllers/example/SwaggerExampleController.ts +205 -0
  95. package/template/src/controllers/example/TransactionExample.controller.ts +336 -0
  96. package/template/src/controllers/health.controller.ts +235 -0
  97. package/template/src/controllers/home/register.controller.ts +58 -0
  98. package/template/src/controllers/home/ytGoods.controller.ts +92 -0
  99. package/template/src/controllers/home/ytShop.controller.ts +135 -0
  100. package/template/src/controllers/home/ytUser.controller.ts +89 -0
  101. package/template/src/controllers/logManagement.controller.ts +396 -0
  102. package/template/src/controllers/public/emailSend.controller.ts +65 -0
  103. package/template/src/controllers/public/ytUserAuth.controller.ts +174 -0
  104. package/template/src/controllers/testData.controller.ts +253 -0
  105. package/template/src/dto/controller/example/NewAnnotationExampleController.dto.ts +73 -0
  106. package/template/src/dto/controller/home/emailSend.controller.dto.ts +40 -0
  107. package/template/src/dto/controller/home/register.controller.dto.ts +45 -0
  108. package/template/src/dto/controller/home/ytGoods.controller.dto.ts +55 -0
  109. package/template/src/dto/controller/home/ytShop.controller.dto.ts +69 -0
  110. package/template/src/dto/controller/home/ytUser.controller.dto.ts +44 -0
  111. package/template/src/dto/controller/public/ytUserAuth.controller.dto.ts +63 -0
  112. package/template/src/dto/goods.dto.ts +212 -0
  113. package/template/src/dto/service/ytService.dto.ts +13 -0
  114. package/template/src/dto/user.dto.ts +177 -0
  115. package/template/src/entity/base.entity.ts +13 -0
  116. package/template/src/entity/columnTypes.ts +13 -0
  117. package/template/src/entity/goodsImagesUnlockKey.entity.ts +33 -0
  118. package/template/src/entity/goodsUnlocker.entity.ts +34 -0
  119. package/template/src/entity/index.ts +15 -0
  120. package/template/src/entity/shop.entity.ts +52 -0
  121. package/template/src/entity/shopUser.entity.ts +41 -0
  122. package/template/src/entity/ytGoods.entity.ts +94 -0
  123. package/template/src/entity/ytUser.entity.ts +96 -0
  124. package/template/src/examples/InterceptorExampleRunner.ts +284 -0
  125. package/template/src/examples/ServiceInterceptorExample.ts +214 -0
  126. package/template/src/examples/SwaggerProcessorExample.ts +169 -0
  127. package/template/src/examples/TransactionManagerDemo.ts +377 -0
  128. package/template/src/examples/cacheExamples.ts +155 -0
  129. package/template/src/framework/decorator/controller.ts +311 -0
  130. package/template/src/framework/decorator/processor/AnnotationDecorators.ts +100 -0
  131. package/template/src/framework/decorator/processor/AnnotationProcessor.ts +156 -0
  132. package/template/src/framework/decorator/processor/AnnotationProcessorConfig.ts +45 -0
  133. package/template/src/framework/decorator/processor/AnnotationRegistry.ts +117 -0
  134. package/template/src/framework/decorator/processor/AnnotationSystemInitializer.ts +95 -0
  135. package/template/src/framework/decorator/processor/ProcessorManager.ts +76 -0
  136. package/template/src/framework/decorator/processor/processors/CustomProcessors.ts +126 -0
  137. package/template/src/framework/decorator/processor/processors/DefaultProcessors.ts +207 -0
  138. package/template/src/framework/decorator/refactored/DecoratorFactory.ts +99 -0
  139. package/template/src/framework/decorator/refactored/DecoratorMetadataManager.ts +125 -0
  140. package/template/src/framework/decorator/refactored/DecoratorValidator.ts +128 -0
  141. package/template/src/framework/decorator/refactored/TypeSafeDecorators.ts +139 -0
  142. package/template/src/framework/decorator/refactored/index.ts +98 -0
  143. package/template/src/framework/decorator/swagger.ts +150 -0
  144. package/template/src/framework/interceptors/AdvancedServiceCallInterceptor.ts +375 -0
  145. package/template/src/framework/interceptors/ServiceCallInterceptor.ts +348 -0
  146. package/template/src/framework/interceptors/index.ts +19 -0
  147. package/template/src/framework/plugins/registry.ts +63 -0
  148. package/template/src/framework/plugins/types.ts +15 -0
  149. package/template/src/framework/types/ServiceResult.ts +151 -0
  150. package/template/src/framework/types/index.ts +16 -0
  151. package/template/src/framework/utils/CacheManager.ts +430 -0
  152. package/template/src/framework/utils/CacheService.ts +248 -0
  153. package/template/src/framework/utils/DtoValidator.ts +164 -0
  154. package/template/src/framework/utils/MigrationHelper.ts +179 -0
  155. package/template/src/framework/utils/MigrationManager.ts +256 -0
  156. package/template/src/framework/utils/NewRouter.ts +207 -0
  157. package/template/src/framework/utils/TransactionManager.ts +172 -0
  158. package/template/src/framework/utils/bootstrap.ts +445 -0
  159. package/template/src/framework/utils/cache.ts +269 -0
  160. package/template/src/framework/utils/databaseConfig.ts +148 -0
  161. package/template/src/framework/utils/db.ts +39 -0
  162. package/template/src/framework/utils/dbMonitor.ts +106 -0
  163. package/template/src/framework/utils/dynamicSwagger.ts +410 -0
  164. package/template/src/framework/utils/function.ts +61 -0
  165. package/template/src/framework/utils/gracefulShutdown.ts +131 -0
  166. package/template/src/framework/utils/logger.ts +388 -0
  167. package/template/src/framework/utils/metrics.ts +182 -0
  168. package/template/src/framework/utils/router.ts +417 -0
  169. package/template/src/framework/utils/swagger.ts +184 -0
  170. package/template/src/framework/utils/testDb.ts +19 -0
  171. package/template/src/framework/utils/token.ts +23 -0
  172. package/template/src/framework/utils/transform.ts +17 -0
  173. package/template/src/libs/aokEmailSender.ts +42 -0
  174. package/template/src/libs/captcha.ts +37 -0
  175. package/template/src/libs/cos.ts +45 -0
  176. package/template/src/libs/mCache.ts +7 -0
  177. package/template/src/libs/serviceValidate.ts +3 -0
  178. package/template/src/libs/tecentSms.ts +51 -0
  179. package/template/src/middlewares/a.middleware.ts +6 -0
  180. package/template/src/middlewares/error.middleware.ts +14 -0
  181. package/template/src/middlewares/logging.middleware.ts +187 -0
  182. package/template/src/middlewares/static.middleware.ts +79 -0
  183. package/template/src/middlewares/swagger.middleware.ts +70 -0
  184. package/template/src/middlewares/token.middleware.ts +32 -0
  185. package/template/src/migrations/1700000000000-InitialDatabaseStructure.ts +172 -0
  186. package/template/src/migrations/index.ts +6 -0
  187. package/template/src/plugins/weboffice/core/context.ts +47 -0
  188. package/template/src/plugins/weboffice/core/errors.ts +51 -0
  189. package/template/src/plugins/weboffice/core/types.ts +63 -0
  190. package/template/src/plugins/weboffice/core/utils.ts +7 -0
  191. package/template/src/plugins/weboffice/entities/index.ts +3 -0
  192. package/template/src/plugins/weboffice/entities/webofficeFile.entity.ts +28 -0
  193. package/template/src/plugins/weboffice/entities/webofficeFileVersion.entity.ts +29 -0
  194. package/template/src/plugins/weboffice/http/routes.ts +179 -0
  195. package/template/src/plugins/weboffice/index.ts +23 -0
  196. package/template/src/plugins/weboffice/services/webofficeCallback.service.ts +274 -0
  197. package/template/src/repository/UserRepository.ts +122 -0
  198. package/template/src/repository/base/BaseRepository.ts +124 -0
  199. package/template/src/repository/interfaces/IBaseRepository.ts +67 -0
  200. package/template/src/routers/index.ts +49 -0
  201. package/template/src/service/base.service.ts +116 -0
  202. package/template/src/service/paramValidateTest.service.ts +139 -0
  203. package/template/src/service/ytGoods.service.ts +42 -0
  204. package/template/src/service/ytShop.service.ts +90 -0
  205. package/template/src/service/ytUser.service.ts +451 -0
  206. package/template/src/test/swaggerParameterTest.ts +90 -0
  207. package/template/src/utils/testDataInitializer.ts +296 -0
  208. package/template/static/output.json +15203 -0
  209. package/template/test/controllers/controllers.test.ts +173 -0
  210. package/template/test/controllers/example/ExampleController.test.ts +222 -0
  211. package/template/test/controllers/example/NewAnnotationExampleController.test.ts +200 -0
  212. package/template/test/framework/TransactionManagerDemo.test.ts +363 -0
  213. package/template/test/framework/annotation/AnnotationDecorators.test.ts +222 -0
  214. package/template/test/framework/annotation/AnnotationExecutor.test.ts +246 -0
  215. package/template/test/framework/annotation/AnnotationProcessor.test.ts +179 -0
  216. package/template/test/framework/annotation/CustomProcessors.test.ts +313 -0
  217. package/template/test/framework/annotation/DefaultProcessors.test.ts +371 -0
  218. package/template/test/framework/annotation/NewRouter.test.ts +272 -0
  219. package/template/test/framework/annotation/ProcessorManager.test.ts +248 -0
  220. package/template/test/framework/annotation/setup.ts +26 -0
  221. package/template/test/framework/cache.test.ts +101 -0
  222. package/template/test/framework/databaseConfig.test.ts +142 -0
  223. package/template/test/integration/integration.test.ts +153 -0
  224. package/template/test/plugins/weboffice/http.routes.int.test.ts +61 -0
  225. package/template/test/service/business.test.ts +87 -0
  226. package/template/test/service/paramValidateTest.service.test.ts +184 -0
  227. package/template/test/service/ytUser.service.test.ts +566 -0
  228. package/template/test/setup.ts +20 -0
  229. package/template/test/setupAfterEnv.ts +14 -0
  230. package/template/test/utils/testHelpers.ts +220 -0
  231. package/template/test_output.txt +0 -0
  232. package/template/tsconfig.build.json +17 -0
  233. package/template/tsconfig.json +31 -0
  234. package/template/webpack.config.js +71 -0
  235. package/template/yarn.lock +7354 -0
@@ -0,0 +1,611 @@
1
+ # 安装配置指南
2
+
3
+ 本指南提供 DP-Koa Framework 的详细安装和配置步骤,适用于不同的部署环境。
4
+
5
+ ## 📋 目录
6
+
7
+ - [系统要求](#系统要求)
8
+ - [环境准备](#环境准备)
9
+ - [项目安装](#项目安装)
10
+ - [环境配置](#环境配置)
11
+ - [数据库配置](#数据库配置)
12
+ - [缓存配置](#缓存配置)
13
+ - [安全配置](#安全配置)
14
+ - [监控配置](#监控配置)
15
+ - [验证安装](#验证安装)
16
+ - [常见问题](#常见问题)
17
+
18
+ ## 🖥️ 系统要求
19
+
20
+ ### 最低要求
21
+
22
+ | 组件 | 最低版本 | 推荐版本 |
23
+ |------|----------|----------|
24
+ | Node.js | 18.0.0 | 20.0.0+ |
25
+ | npm | 8.0.0 | 10.0.0+ |
26
+ | MySQL | 8.0 | 8.0.30+ |
27
+ | Redis | 6.0 | 7.0+ |
28
+ | Docker | 20.0 | 24.0+ |
29
+
30
+ ### 操作系统支持
31
+
32
+ - **Linux**: Ubuntu 20.04+, CentOS 8+, RHEL 8+
33
+ - **macOS**: macOS 10.15+
34
+ - **Windows**: Windows 10/11, Windows Server 2019+
35
+
36
+ ## 🔧 环境准备
37
+
38
+ ### 1. 安装 Node.js
39
+
40
+ #### 使用 Node Version Manager (推荐)
41
+
42
+ ```bash
43
+ # 安装 nvm
44
+ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
45
+
46
+ # 重新加载终端
47
+ source ~/.bashrc
48
+
49
+ # 安装 Node.js 20
50
+ nvm install 20
51
+ nvm use 20
52
+ nvm alias default 20
53
+ ```
54
+
55
+ #### 直接安装
56
+
57
+ **Ubuntu/Debian:**
58
+ ```bash
59
+ curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
60
+ sudo apt-get install -y nodejs
61
+ ```
62
+
63
+ **CentOS/RHEL:**
64
+ ```bash
65
+ curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -
66
+ sudo yum install -y nodejs
67
+ ```
68
+
69
+ **macOS (使用 Homebrew):**
70
+ ```bash
71
+ brew install node@20
72
+ ```
73
+
74
+ **Windows:**
75
+ 下载并安装 [Node.js 官方安装包](https://nodejs.org/)
76
+
77
+ ### 2. 安装数据库
78
+
79
+ #### MySQL 安装
80
+
81
+ **Ubuntu/Debian:**
82
+ ```bash
83
+ sudo apt update
84
+ sudo apt install mysql-server-8.0
85
+ sudo mysql_secure_installation
86
+ ```
87
+
88
+ **CentOS/RHEL:**
89
+ ```bash
90
+ sudo yum install mysql-server
91
+ sudo systemctl start mysqld
92
+ sudo systemctl enable mysqld
93
+ sudo mysql_secure_installation
94
+ ```
95
+
96
+ **Docker (推荐):**
97
+ ```bash
98
+ docker run --name mysql -e MYSQL_ROOT_PASSWORD=root_password \
99
+ -e MYSQL_DATABASE=app_db -e MYSQL_USER=app_user \
100
+ -e MYSQL_PASSWORD=app_password -p 3306:3306 -d mysql:8.0
101
+ ```
102
+
103
+ #### SQLite (开发环境)
104
+
105
+ SQLite 通常随系统安装,如需手动安装:
106
+
107
+ **Ubuntu/Debian:**
108
+ ```bash
109
+ sudo apt install sqlite3 libsqlite3-dev
110
+ ```
111
+
112
+ **CentOS/RHEL:**
113
+ ```bash
114
+ sudo yum install sqlite sqlite-devel
115
+ ```
116
+
117
+ ### 3. 安装 Redis (可选)
118
+
119
+ **Ubuntu/Debian:**
120
+ ```bash
121
+ sudo apt install redis-server
122
+ sudo systemctl start redis-server
123
+ sudo systemctl enable redis-server
124
+ ```
125
+
126
+ **CentOS/RHEL:**
127
+ ```bash
128
+ sudo yum install redis
129
+ sudo systemctl start redis
130
+ sudo systemctl enable redis
131
+ ```
132
+
133
+ **Docker:**
134
+ ```bash
135
+ docker run --name redis -p 6379:6379 -d redis:7-alpine
136
+ ```
137
+
138
+ ### 4. 安装 Docker (可选)
139
+
140
+ **Ubuntu/Debian:**
141
+ ```bash
142
+ curl -fsSL https://get.docker.com -o get-docker.sh
143
+ sudo sh get-docker.sh
144
+ sudo usermod -aG docker $USER
145
+ ```
146
+
147
+ **CentOS/RHEL:**
148
+ ```bash
149
+ sudo yum install -y yum-utils
150
+ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
151
+ sudo yum install docker-ce docker-ce-cli containerd.io
152
+ sudo systemctl start docker
153
+ sudo systemctl enable docker
154
+ ```
155
+
156
+ ## 📦 项目安装
157
+
158
+ ### 1. 克隆项目
159
+
160
+ ```bash
161
+ git clone <your-repository-url>
162
+ cd dp-koa-framework
163
+ ```
164
+
165
+ ### 2. 安装依赖
166
+
167
+ ```bash
168
+ # 安装生产依赖
169
+ npm install --production
170
+
171
+ # 或安装所有依赖(包括开发依赖)
172
+ npm install
173
+ ```
174
+
175
+ ### 3. 验证安装
176
+
177
+ ```bash
178
+ # 检查 Node.js 版本
179
+ node --version
180
+
181
+ # 检查 npm 版本
182
+ npm --version
183
+
184
+ # 检查项目依赖
185
+ npm list --depth=0
186
+ ```
187
+
188
+ ## ⚙️ 环境配置
189
+
190
+ ### 1. 创建环境配置文件
191
+
192
+ ```bash
193
+ # 复制环境变量模板
194
+ cp env.production.example .env
195
+ ```
196
+
197
+ ### 2. 基础配置
198
+
199
+ 编辑 `.env` 文件:
200
+
201
+ ```bash
202
+ # 应用配置
203
+ NODE_ENV=development
204
+ PORT=3000
205
+ APP_NAME=DP-Koa-Framework
206
+ APP_VERSION=1.0.0
207
+
208
+ # 日志配置
209
+ LOG_LEVEL=info
210
+ LOG_DIR=./logs
211
+
212
+ # 安全配置
213
+ JWT_SECRET=your-super-secret-jwt-key-here
214
+ JWT_EXPIRES_IN=24h
215
+ BCRYPT_ROUNDS=12
216
+
217
+ # 缓存配置
218
+ CACHE_TTL=3600
219
+ CACHE_MAX_SIZE=1000
220
+ ```
221
+
222
+ ### 3. 数据库配置
223
+
224
+ #### MySQL 配置
225
+
226
+ ```bash
227
+ # 数据库类型
228
+ DB_TYPE=mysql
229
+
230
+ # MySQL 连接配置
231
+ DB_HOST=localhost
232
+ DB_PORT=3306
233
+ DB_USERNAME=app_user
234
+ DB_PASSWORD=app_password
235
+ DB_DATABASE=app_db
236
+
237
+ # 连接池配置
238
+ DB_POOL_MIN=5
239
+ DB_POOL_MAX=20
240
+ DB_POOL_IDLE=10000
241
+ ```
242
+
243
+ #### SQLite 配置
244
+
245
+ ```bash
246
+ # 数据库类型
247
+ DB_TYPE=sqlite
248
+
249
+ # SQLite 配置
250
+ DB_DATABASE=./database/app.db
251
+ DB_SYNCHRONIZE=true
252
+ ```
253
+
254
+ #### 内存数据库配置(开发/测试)
255
+
256
+ ```bash
257
+ # 数据库类型
258
+ DB_TYPE=memory
259
+
260
+ # 内存数据库配置
261
+ DB_SYNCHRONIZE=true
262
+ DB_LOGGING=true
263
+ ```
264
+
265
+ ### 4. Redis 配置
266
+
267
+ ```bash
268
+ # Redis 配置
269
+ REDIS_HOST=localhost
270
+ REDIS_PORT=6379
271
+ REDIS_PASSWORD=
272
+ REDIS_DB=0
273
+ REDIS_TTL=3600
274
+ ```
275
+
276
+ ## 🗄️ 数据库配置
277
+
278
+ ### 1. MySQL 数据库设置
279
+
280
+ #### 创建数据库和用户
281
+
282
+ ```sql
283
+ -- 连接到 MySQL
284
+ mysql -u root -p
285
+
286
+ -- 创建数据库
287
+ CREATE DATABASE app_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
288
+
289
+ -- 创建用户
290
+ CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'app_password';
291
+ CREATE USER 'app_user'@'%' IDENTIFIED BY 'app_password';
292
+
293
+ -- 授权
294
+ GRANT ALL PRIVILEGES ON app_db.* TO 'app_user'@'localhost';
295
+ GRANT ALL PRIVILEGES ON app_db.* TO 'app_user'@'%';
296
+
297
+ -- 刷新权限
298
+ FLUSH PRIVILEGES;
299
+ ```
300
+
301
+ #### 验证连接
302
+
303
+ ```bash
304
+ # 测试数据库连接
305
+ mysql -h localhost -u app_user -p app_db
306
+ ```
307
+
308
+ ### 2. SQLite 数据库设置
309
+
310
+ ```bash
311
+ # 创建数据库目录
312
+ mkdir -p database
313
+
314
+ # 创建数据库文件(应用启动时自动创建)
315
+ touch database/app.db
316
+ ```
317
+
318
+ ### 3. 运行数据库迁移
319
+
320
+ ```bash
321
+ # 生产环境自动运行迁移
322
+ NODE_ENV=production npm start
323
+
324
+ # 或手动运行迁移
325
+ npm run migration:run
326
+ ```
327
+
328
+ ## 🚀 缓存配置
329
+
330
+ ### 1. Redis 缓存配置
331
+
332
+ #### 安装和启动 Redis
333
+
334
+ ```bash
335
+ # Ubuntu/Debian
336
+ sudo apt install redis-server
337
+ sudo systemctl start redis-server
338
+ sudo systemctl enable redis-server
339
+
340
+ # CentOS/RHEL
341
+ sudo yum install redis
342
+ sudo systemctl start redis
343
+ sudo systemctl enable redis
344
+ ```
345
+
346
+ #### 配置 Redis
347
+
348
+ 编辑 `/etc/redis/redis.conf`:
349
+
350
+ ```bash
351
+ # 绑定地址
352
+ bind 127.0.0.1
353
+
354
+ # 端口
355
+ port 6379
356
+
357
+ # 密码(可选)
358
+ requirepass your_redis_password
359
+
360
+ # 持久化
361
+ save 900 1
362
+ save 300 10
363
+ save 60 10000
364
+ ```
365
+
366
+ #### 验证 Redis
367
+
368
+ ```bash
369
+ # 测试 Redis 连接
370
+ redis-cli ping
371
+ # 应该返回 PONG
372
+ ```
373
+
374
+ ### 2. 内存缓存配置
375
+
376
+ 如果使用内存缓存,无需额外配置:
377
+
378
+ ```bash
379
+ # 在 .env 中设置
380
+ CACHE_TYPE=memory
381
+ CACHE_TTL=3600
382
+ CACHE_MAX_SIZE=1000
383
+ ```
384
+
385
+ ## 🔒 安全配置
386
+
387
+ ### 1. JWT 配置
388
+
389
+ ```bash
390
+ # 生成强密钥
391
+ openssl rand -base64 64
392
+
393
+ # 在 .env 中设置
394
+ JWT_SECRET=your-generated-secret-key
395
+ JWT_EXPIRES_IN=24h
396
+ JWT_REFRESH_EXPIRES_IN=7d
397
+ ```
398
+
399
+ ### 2. 密码加密配置
400
+
401
+ ```bash
402
+ # bcrypt 轮数(推荐 12-15)
403
+ BCRYPT_ROUNDS=12
404
+ ```
405
+
406
+ ### 3. CORS 配置
407
+
408
+ ```bash
409
+ # CORS 配置
410
+ CORS_ORIGIN=http://localhost:3000
411
+ CORS_CREDENTIALS=true
412
+ CORS_MAX_AGE=86400
413
+ ```
414
+
415
+ ### 4. 速率限制
416
+
417
+ ```bash
418
+ # API 速率限制
419
+ RATE_LIMIT_WINDOW_MS=900000
420
+ RATE_LIMIT_MAX_REQUESTS=100
421
+ ```
422
+
423
+ ## 📊 监控配置
424
+
425
+ ### 1. 日志配置
426
+
427
+ ```bash
428
+ # 日志级别
429
+ LOG_LEVEL=info
430
+
431
+ # 日志目录
432
+ LOG_DIR=./logs
433
+
434
+ # 日志轮转
435
+ LOG_MAX_SIZE=10m
436
+ LOG_MAX_FILES=5
437
+ ```
438
+
439
+ ### 2. 健康检查配置
440
+
441
+ ```bash
442
+ # 健康检查端点
443
+ HEALTH_CHECK_ENABLED=true
444
+ HEALTH_CHECK_PATH=/health
445
+
446
+ # 监控端点
447
+ METRICS_ENABLED=true
448
+ METRICS_PATH=/metrics
449
+ ```
450
+
451
+ ### 3. Prometheus 配置
452
+
453
+ 创建 `docker/prometheus/prometheus.yml`:
454
+
455
+ ```yaml
456
+ global:
457
+ scrape_interval: 15s
458
+
459
+ scrape_configs:
460
+ - job_name: 'dp-koa-framework'
461
+ static_configs:
462
+ - targets: ['app:3000']
463
+ metrics_path: '/metrics'
464
+ scrape_interval: 5s
465
+ ```
466
+
467
+ ## ✅ 验证安装
468
+
469
+ ### 1. 启动应用
470
+
471
+ ```bash
472
+ # 开发模式
473
+ npm run dev
474
+
475
+ # 生产模式
476
+ npm run build
477
+ npm start
478
+ ```
479
+
480
+ ### 2. 健康检查
481
+
482
+ ```bash
483
+ # 检查应用状态
484
+ curl http://localhost:3000/health
485
+
486
+ # 检查数据库连接
487
+ curl http://localhost:3000/health/db
488
+
489
+ # 检查缓存状态
490
+ curl http://localhost:3000/health/cache
491
+ ```
492
+
493
+ ### 3. API 测试
494
+
495
+ ```bash
496
+ # 测试用户 API
497
+ curl http://localhost:3000/api/users
498
+
499
+ # 测试商品 API
500
+ curl http://localhost:3000/api/goods
501
+
502
+ # 查看 Swagger 文档
503
+ open http://localhost:3000/swagger-ui
504
+ ```
505
+
506
+ ### 4. 运行测试
507
+
508
+ ```bash
509
+ # 运行所有测试
510
+ npm test
511
+
512
+ # 运行特定测试
513
+ npm run test:framework
514
+ npm run test:service
515
+ npm run test:integration
516
+ ```
517
+
518
+ ## ❓ 常见问题
519
+
520
+ ### 1. 数据库连接失败
521
+
522
+ **问题**: 无法连接到数据库
523
+
524
+ **解决方案**:
525
+ ```bash
526
+ # 检查数据库服务状态
527
+ sudo systemctl status mysql
528
+
529
+ # 检查连接配置
530
+ mysql -h localhost -u app_user -p app_db
531
+
532
+ # 检查防火墙
533
+ sudo ufw status
534
+ ```
535
+
536
+ ### 2. 端口被占用
537
+
538
+ **问题**: 端口 3000 被占用
539
+
540
+ **解决方案**:
541
+ ```bash
542
+ # 查找占用进程
543
+ lsof -i :3000
544
+
545
+ # 杀死进程
546
+ kill -9 <PID>
547
+
548
+ # 或使用其他端口
549
+ PORT=3001 npm start
550
+ ```
551
+
552
+ ### 3. 依赖安装失败
553
+
554
+ **问题**: npm install 失败
555
+
556
+ **解决方案**:
557
+ ```bash
558
+ # 清理缓存
559
+ npm cache clean --force
560
+
561
+ # 删除 node_modules
562
+ rm -rf node_modules package-lock.json
563
+
564
+ # 重新安装
565
+ npm install
566
+ ```
567
+
568
+ ### 4. 权限问题
569
+
570
+ **问题**: 文件权限错误
571
+
572
+ **解决方案**:
573
+ ```bash
574
+ # 修复文件权限
575
+ sudo chown -R $USER:$USER .
576
+ chmod -R 755 .
577
+ ```
578
+
579
+ ### 5. 内存不足
580
+
581
+ **问题**: 构建时内存不足
582
+
583
+ **解决方案**:
584
+ ```bash
585
+ # 增加 Node.js 内存限制
586
+ export NODE_OPTIONS="--max-old-space-size=4096"
587
+
588
+ # 或使用 swap
589
+ sudo fallocate -l 2G /swapfile
590
+ sudo chmod 600 /swapfile
591
+ sudo mkswap /swapfile
592
+ sudo swapon /swapfile
593
+ ```
594
+
595
+ ## 📚 下一步
596
+
597
+ 安装完成后,建议您:
598
+
599
+ 1. **阅读开发指南**: [开发指南](DEVELOPMENT_GUIDE.md)
600
+ 2. **了解注解系统**: [注解系统指南](ENTERPRISE_ANNOTATION_SYSTEM_GUIDE.md)
601
+ 3. **学习服务层设计**: [服务层指南](SERVICE_PATTERN_GUIDE.md)
602
+ 4. **查看部署指南**: [部署指南](ENTERPRISE_DEPLOYMENT_GUIDE.md)
603
+
604
+ ---
605
+
606
+ **相关链接**:
607
+ - [快速开始指南](QUICK_START.md) - 5分钟快速上手
608
+ - [开发指南](DEVELOPMENT_GUIDE.md) - 开发规范和最佳实践
609
+ - [故障排除指南](TROUBLESHOOTING.md) - 常见问题解决
610
+
611
+