Loading...
Loading...
Compare original and translation side by side
.cursor/rules.cursor/rules.cursor/rules.cursor/rulesWrite clean code with good practices.
Use proper TypeScript types.Use functional components with TypeScript.
Define prop types with interfaces, not inline types.
Extract custom hooks when logic exceeds 10 lines.使用良好实践编写整洁的代码。
使用正确的TypeScript类型。结合TypeScript使用函数式组件。
使用接口定义属性类型,而非内联类型。
当逻辑超过10行时提取自定义hooks。Use semicolons in JavaScript.
Indent with 2 spaces.
Add trailing commas.Choose Zustand for global state, React Context for component trees.
Use Zod for runtime validation at API boundaries only.
Prefer server components except for: forms, client-only APIs, animations.在JavaScript中使用分号。
使用2个空格缩进。
添加 trailing commas。全局状态选择Zustand,组件树状态选择React Context。
仅在API边界使用Zod进行运行时验证。
默认优先使用服务端组件,除了:表单、仅客户端API、动画场景。undefinedundefinedundefinedundefined------
description: Brief description of when and how to use this rule
globs: ["**/*.ts", "**/*.tsx"]
alwaysApply: false
---------
description: 简要说明此规则的使用场景和方式
globs: ["**/*.ts", "**/*.tsx"]
alwaysApply: false
---| Property | Type | Required | Description |
|---|---|---|---|
| string | Yes | Brief description of the rule's purpose. Used by AI to decide relevance. Never use placeholders like |
| array | No | File patterns that trigger auto-attachment (e.g., |
| boolean | No | If |
| 属性 | 类型 | 必填 | 描述 |
|---|---|---|---|
| 字符串 | 是 | 规则用途的简要说明,AI会据此判断相关性。禁止使用 |
| 数组 | 否 | 触发自动附加的文件模式(例如 |
| 布尔值 | 否 | 如果为 |
| Rule Type | Description | When to Use |
|---|---|---|
| Always | Always included in model context | Core project conventions, tech stack, universal patterns that apply everywhere |
| Auto Attached | Included when files matching | File-type specific rules (e.g., React components, API routes, test files) |
| Agent Requested | Available to AI, which decides whether to include it based on | Contextual patterns, specialized workflows, optional conventions |
| Manual | Only included when explicitly mentioned using | Rarely-used patterns, experimental conventions, legacy documentation |
| 规则类型 | 描述 | 使用场景 |
|---|---|---|
| Always(始终应用) | 始终包含在模型上下文环境中 | 核心项目约定、技术栈、全局通用模式 |
| Auto Attached(自动附加) | 当引用匹配 | 特定文件类型的规则(例如React组件、API路由、测试文件) |
| Agent Requested(AI主动调用) | 可供AI使用,AI会根据 | 上下文相关的模式、特定工作流、可选约定 |
| Manual(手动应用) | 仅当使用 | 极少使用的模式、实验性约定、遗留文档 |
---
description: TypeScript and code style conventions for the entire project
alwaysApply: true
------
description: React component patterns and conventions
globs: ["**/components/**/*.tsx", "**/app/**/*.tsx"]
alwaysApply: false
------
description: RPC service boilerplate and patterns for creating new RPC endpoints
globs: []
alwaysApply: false
------
description: Legacy API migration patterns (deprecated, use for reference only)
globs: []
alwaysApply: false
------
description: 整个项目的TypeScript和代码风格约定
alwaysApply: true
------
description: React组件模式与约定
globs: ["**/components/**/*.tsx", "**/app/**/*.tsx"]
alwaysApply: false
------
description: 创建新RPC端点的RPC服务模板与模式
globs: []
alwaysApply: false
------
description: 遗留API迁移模式(已废弃,仅作参考)
globs: []
alwaysApply: false
---Backend codeFastify API route patterns, error handling, and validation using Zod["**/*.tsx", "**/*.jsx"]["**/api/**/*.ts", "**/routes/**/*.ts"]["**/*.test.ts", "**/*.spec.ts"]alwaysApply: true后端代码使用Zod的Fastify API路由模式、错误处理和验证["**/*.tsx", "**/*.jsx"]["**/api/**/*.ts", "**/routes/**/*.ts"]["**/*.test.ts", "**/*.spec.ts"]alwaysApply: trueundefinedundefined
**Why:** Prevents AI from suggesting wrong tools/patterns.
**原因:** 避免AI推荐错误的工具/模式。undefinedundefinedundefinedundefinedundefinedundefinedtry {
const result = await operation();
toast.success('Operation completed');
return result;
} catch (error) {
const message = error instanceof Error ? error.message : 'Unknown error';
toast.error(message);
throw error; // Re-throw for caller to handle
}try {
const result = await operation();
toast.success('操作完成');
return result;
} catch (error) {
const message = error instanceof Error ? error.message : '未知错误';
toast.error(message);
throw error; // 重新抛出供调用者处理
}// app/api/users/route.ts
export async function GET(request: Request) {
try {
// 1. Parse/validate input
// 2. Check auth/permissions
// 3. Perform operation
// 4. Return Response
} catch (error) {
return new Response(JSON.stringify({ error: 'Message' }), {
status: 500
});
}
}undefined// app/api/users/route.ts
export async function GET(request: Request) {
try {
// 1. 解析/验证输入
// 2. 检查权限
// 3. 执行操作
// 4. 返回响应
} catch (error) {
return new Response(JSON.stringify({ error: 'Message' }), {
status: 500
});
}
}undefined- Write readable code
- Use meaningful variable names
- Add comments when necessary
- Follow best practices- Never use any third-party libraries
- Always write everything from scratch
- Every function must be under 5 lines- Use design patterns
- Think before you code
- Test your code
- Keep it simple- 编写可读代码
- 使用有意义的变量名
- 必要时添加注释
- 遵循最佳实践- 禁止使用任何第三方库
- 所有功能必须从零开始编写
- 每个函数必须少于5行- 使用设计模式
- 编码前先思考
- 测试代码
- 保持简洁undefinedundefinedundefinedundefinedundefinedundefined@tanstack/react-querydate-fnsclsxtailwind-mergeundefined@tanstack/react-querydate-fnsclsxtailwind-mergeundefinedundefinedundefined// ❌ BAD
export default function Button() { }
// ✅ GOOD
export function Button() { }// ❌ 错误示例
export default function Button() { }
// ✅ 正确示例
export function Button() { }// ❌ BAD
function UserCard({ user }: { user: { name: string; email: string } }) { }
// ✅ GOOD
interface User {
name: string;
email: string;
}
function UserCard({ user }: { user: User }) { }undefined// ❌ 错误示例
function UserCard({ user }: { user: { name: string; email: string } }) { }
// ✅ 正确示例
interface User {
name: string;
email: string;
}
function UserCard({ user }: { user: User }) { }undefinedundefinedundefinedapp/api/[route]/route.tsResponseimport { z } from 'zod';
const schema = z.object({
name: z.string().min(1)
});
export async function POST(request: Request) {
try {
const body = await request.json();
const data = schema.parse(body);
// Process...
return Response.json({ success: true });
} catch (error) {
if (error instanceof z.ZodError) {
return Response.json(
{ error: error.errors },
{ status: 400 }
);
}
return Response.json(
{ error: 'Internal error' },
{ status: 500 }
);
}
}undefinedapp/api/[route]/route.tsResponseimport { z } from 'zod';
const schema = z.object({
name: z.string().min(1)
});
export async function POST(request: Request) {
try {
const body = await request.json();
const data = schema.parse(body);
// 处理逻辑...
return Response.json({ success: true });
} catch (error) {
if (error instanceof z.ZodError) {
return Response.json(
{ error: error.errors },
{ status: 400 }
);
}
return Response.json(
{ error: '内部错误' },
{ status: 500 }
);
}
}undefinedbackend-api.mdcbackend-api.mdc.cursor/rules/
├── tech-stack.mdc # Core technologies
├── typescript-patterns.mdc # Language-specific patterns
├── api-conventions.mdc # API route standards
├── component-patterns.mdc # React/UI patterns
└── testing-standards.mdc # Testing approaches.cursor/rules/
├── tech-stack.mdc # 核心技术
├── typescript-patterns.mdc # 语言特定模式
├── api-conventions.mdc # API路由标准
├── component-patterns.mdc # React/UI模式
└── testing-standards.mdc # 测试方法See components/auth/LoginForm.tsx for exampleUse proper error handling in API routes.API routes must use try/catch with typed errors. Example:
```typescript
// app/api/users/route.ts (lines 10-25)
export async function POST(request: Request) {
try {
const data = await request.json();
return Response.json({ success: true });
} catch (error) {
return handleApiError(error); // See lib/errors.ts
}
}app/api/products/route.tsundefined在API路由中使用正确的错误处理。API路由必须使用try/catch处理类型化错误。示例:
```typescript
// app/api/users/route.ts(第10-25行)
export async function POST(request: Request) {
try {
const data = await request.json();
return Response.json({ success: true });
} catch (error) {
return handleApiError(error); // 参见lib/errors.ts
}
}app/api/products/route.tsundefined.cursor/rules/.cursor/rules/.cursor/rules.cursor/rules