furniture-3d-system-Wu/.cursor/rules/core-standards.mdc

66 lines
2.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
description: 核心规则摘要 - 必须在写代码前阅读并遵循
alwaysApply: true
---
# 核心规则摘要
> **这是所有规则的浓缩版,必须 100% 遵循!**
---
## 一、后端必遵循(5 条)
| # | 规则 | 正确示例 | 错误示例 |
|---|------|----------|----------|
| 1 | **分层架构**:API → Service → Repository | `await xxxService.getXxx()` | `await prisma.xxx.findMany()` |
| 2 | **统一请求处理**:使用 `handleRequest` | `handleRequest(request, async (ctx) => {...})` | 自己写 try-catch |
| 3 | **统一响应**:使用 `jsonSuccess/jsonError` | `return jsonSuccess(data)` | `return NextResponse.json({...})` |
| 4 | **错误抛出**:使用 `AppError + ErrorCode` | `throw new AppError(ErrorCode.XXX)` | `throw new Error('xxx')` |
| 5 | **多表操作**:必须使用 `$transaction` | `prisma.$transaction(async (tx) => {...})` | 多个独立的 prisma 调用 |
---
## 二、前端必遵循(5 条)
| # | 规则 | 正确示例 | 错误示例 |
|---|------|----------|----------|
| 1 | **使用元组件** | `<Button>` `<Input>` `<Modal>` | `<button>` `<input>` `<div className="modal">` |
| 2 | **文本颜色** | `text-apple-label-primary/secondary` | `text-gray-900` `text-gray-500` |
| 3 | **背景颜色** | `bg-apple-bg-primary/secondary` | `bg-gray-100` `bg-white` |
| 4 | **品牌色** | `#008D74` 或 `text-apple-brand` | `blue-500` `green-600` |
| 5 | **圆角** | `rounded-apple-md/lg` | `rounded-lg` `rounded-xl` |
---
## 三、禁止事项(绝对不能做)
```
❌ API 中直接写 prisma.xxx.findMany() / create() / update()
❌ 使用 text-gray-* / bg-gray-* / shadow-* 类名
❌ 直接写原生 HTML 元素:<button> <input> <select>
❌ 组件内直接 fetch() 请求数据
❌ 不使用 AppError 直接 throw new Error()
```
---
## 四、文件路径速查
| 用途 | 路径 |
|------|------|
| 元组件 | `@/components/ui/` |
| 后端服务 | `src/server/services/` |
| 数据仓库 | `src/server/repositories/` |
| 错误码 | `src/server/core/errors.ts` |
| 响应工具 | `src/server/core/response.ts` |
---
## 五、详细规范位置
如需更多细节,查看以下文件:
- 完整架构规范:`.cursor/rules/backend.mdc`
- 视觉标准:`docs/设计规范/苹果风格视觉标准.md`
- 开发检查清单:`.cursor/rules/checklist.mdc`