Преглед изворни кода

📝 docs(architecture): add error handling and monitoring sections

- 添加"17. Error Handling Strategy"章节,包含错误流程和响应格式
- 添加"18. Monitoring and Observability"章节,定义监控栈和关键指标
- 使用mermaid图表可视化错误处理流程
- 定义前后端统一错误响应格式的TypeScript接口
- 明确前后端关键监控指标和监控工具选择
yourname пре 2 месеци
родитељ
комит
6d813580de
1 измењених фајлова са 72 додато и 1 уклоњено
  1. 72 1
      docs/architecture.md

+ 72 - 1
docs/architecture.md

@@ -1225,4 +1225,75 @@ tests/e2e/
 | 组件 | PascalCase | - | `UserProfile.tsx` |
 | Hooks | camelCase带'use' | - | `useAuth.ts` |
 | API路由 | - | kebab-case | `/api/user-profile` |
-| 数据库表 | - | snake_case | `user_profiles` |
+| 数据库表 | - | snake_case | `user_profiles` |
+
+## 17. Error Handling Strategy
+
+定义前端和后端的统一错误处理:
+
+### 17.1 错误流程
+
+```mermaid
+sequenceDiagram
+    participant Client as 客户端
+    participant API as API网关
+    participant Service as 业务服务
+    participant DB as 数据库
+
+    Client->>API: API请求
+    API->>Service: 调用业务逻辑
+    Service->>DB: 数据库操作
+
+    alt 操作成功
+        DB-->>Service: 成功结果
+        Service-->>API: 业务数据
+        API-->>Client: 成功响应
+    else 发生错误
+        DB-->>Service: 数据库错误
+        Service->>Service: 捕获并包装错误
+        Service-->>API: 标准错误格式
+        API->>API: 添加请求ID和时间戳
+        API-->>Client: 错误响应
+        Client->>Client: 统一错误处理
+        Client-->>User: 显示友好错误信息
+    end
+```
+
+### 17.2 错误响应格式
+
+```typescript
+interface ApiError {
+  error: {
+    code: string;
+    message: string;
+    details?: Record<string, any>;
+    timestamp: string;
+    requestId: string;
+  };
+}
+```
+
+## 18. Monitoring and Observability
+
+定义全栈应用程序的监控策略:
+
+### 18.1 监控栈
+
+**前端监控:** 浏览器性能API + 自定义指标
+**后端监控:** OpenTelemetry + Prometheus
+**错误跟踪:** Sentry或类似服务
+**性能监控:** 应用性能管理(APM)工具
+
+### 18.2 关键指标
+
+**前端指标:**
+- 核心Web指标(LCP, FID, CLS)
+- JavaScript错误率
+- API响应时间
+- 用户交互跟踪
+
+**后端指标:**
+- 请求速率
+- 错误率
+- 响应时间(P50, P95, P99)
+- 数据库查询性能