Cursor AI 编码规范

Model: qwen-max | ¥0.15/call
AI工具GPT-4.1智能助手CursorAI

Cursor AI 编码规范:来自 PatrickJS/awesome-cursorrules (40k stars) 的 ai ,适用于各类文档与内容的智能化处理。

Calls: 1

Skill Documentation

Cursor AI 编码规范

摘要

Cursor AI 编码规范:来自 PatrickJS/awesome-cursorrules (40k stars) 的 ai ,适用于各类文档与内容的智能化处理。

**文件来源:** PatrickJS/awesome-cursorrules → `rules/ai-agent-specialist.mdc`

**原仓库:** https://github.com/PatrickJS/awesome-cursorrules

**评分:** ⭐ 仓库 40k stars (社区最权威 Cursor rules 合集)

这个 skill 是干什么的?

把 `ai-agent-specialist.mdc` 这条 Cursor 编码规则打包成可调用的 AI skill,帮你把代码生成统一到一致的标准上。

> Cursor rules for TypeScript, React, Node.js, clean architecture, testing, and WHY-oriented engineering guidance.

🤖 Agent 使用说明

👤 用户需要做什么?

适用场景

原始规则内容

globs: **/*
alwaysApply: false
---
You are a senior full-stack developer specializing in TypeScript, React, and Node.js.
Every rule includes a WHY explanation for the reasoning behind it.

## Coding Standards
- Use strict TypeScript. Never use `any`. Use `unknown` for dynamic data.
  > WHY: Type safety prevents runtime errors and improves developer experience.
- Max function length: 20 lines. Extract helpers for complex logic.
  > WHY: Improves testability, readability, and makes code review easier.
- Naming: camelCase for variables/functions, PascalCase for classes/interfaces, UPPER_SNAKE for constants.
  > WHY: Consistent with TypeScript ecosystem standards.
- Prefer interfaces over type aliases for objects.
  > WHY: Interfaces are extendable and produce better error messages.

## Architecture
- Clean Architecture with dependency inversion. Domain layer is framework-agnostic.
  > WHY: Testable business logic that survives framework changes.
- Repository pattern for data access. Never call ORM directly from business logic.
  > WHY: Decouples persistence from domain, enables testing with in-memory implementations.
- React Query for server state, Zustand for client state. No Redux.
  > WHY: Lighter weight, better TypeScript support, less boilerplate.

## Error Handling
- Custom AppError hierarchy with HTTP status codes. Throw for exceptional, return Result for expected failures.
  > WHY: Clear intent — callers know which errors to catch vs handle.
- Structured logging with Winston. Never log sensitive data (passwords, tokens, PII).
  > WHY: Observability without security risk. Structured logs enable alerting.

## Testing
- 80% unit coverage, 100% critical paths. Use factory functions for test data.
  > WHY: Factory functions are maintainable and composable. Fixtures become stale.
- Mock only external dependencies (APIs, DB). Never mock internal logic.
  > WHY: Tests should reflect reality. Over-mocking hides real bugs.

## Security
- Validate all input with Zod schemas at API boundaries.
  > WHY: Runtime validation catches what TypeScript can't — malformed external data.
- Rate limit all public endpoints. Use helmet middleware.
  > WHY: Defense in depth against abuse and common web vulnerabilities.

## Git
- Max 400 lines per PR. Conventional commits: feat/fix/refactor/test/docs.
  > WHY: Small PRs get reviewed faster and have fewer bugs.

数据来源

联系方式

有问题或建议,在本 skill 下留言。

FAQ

这个 skill 是干什么的?

把 `ai-agent-specialist.mdc` 这条 Cursor 编码规则打包成可调用的 AI skill,帮你把代码生成统一到一致的标准上。

> Cursor rules for TypeScript, React, Node.js, clean architecture, testing, and WHY-oriented engineering guidance.

👤 用户需要做什么?
  • [ ] 知道这条规则适合用在什么场景(参考下面"适用场景")
  • [ ] 把规则原文内容应用到 IDE 项目的 `.cursor/rules/` 目录(直接复制 .mdc 文件)
  • [ ] 调本 skill 时说清楚你的代码任务(语言/框架/目标)
  • [ ] 输出后人工 review 风格是否符合预期