backend-dev-guidelines
使用最佳實踐構建 Node.js 後端服務
也可从以下获取: diet103,Dimon94,DojoCodingLabs,sickn33
不一致的後端代碼會導致錯誤和開發速度變慢。本技能提供分層架構模式、BaseController 模板、Prisma 倉庫模式、Zod 驗證指南以及 Sentry 集成,用於可靠的 Express 微服務。
下载技能 ZIP
在 Claude 中上传
前往 设置 → 功能 → 技能 → 上传技能
开启并开始使用
测试它
正在使用“backend-dev-guidelines”。 Create a route for creating a new user
预期结果:
- Route definition (routes/userRoutes.ts):
- - Define POST /users route
- - Apply SSOMiddlewareClient.verifyLoginStatus
- - Delegate to UserController.createUser
- Controller method (controllers/UserController.ts):
- - Extend BaseController
- - Validate input with createUserSchema.parse(req.body)
- - Call userService.create(validated)
- - Use handleSuccess with 201 status on success
- - Use handleError with Sentry capture on failure
正在使用“backend-dev-guidelines”。 Add validation to an existing API endpoint
预期结果:
- Create a Zod schema in validators/userSchemas.ts:
- - Define input shape with type inference
- - Add string constraints (email format, min length)
- - Export inferred type for TypeScript usage
- Update controller:
- - Import and use schema.parse(req.body)
- - Handle ZodError with formatted messages
- - Return 400 on validation failure
安全审计
安全Pure documentation skill containing only markdown files with TypeScript code examples. No executable code, no network calls, no file system access beyond reading its own files, and no environment variable access. Content matches stated purpose of providing backend development guidelines. All 556 static findings are false positives from misidentified template literals and anti-pattern documentation.
风险因素
⚙️ 外部命令 (319)
🔑 环境变量 (53)
📁 文件系统访问 (44)
质量评分
你能构建什么
新的 Express 端點
創建一個遵循分層架構模式的乾淨路由,將邏輯委託給控制器
添加輸入驗證
使用 Zod 模式和自動 TypeScript 類型推斷實現類型安全的驗證
代碼審查標準
透過 BaseController 和倉庫模式在微服務中強制執行一致的代碼模式
试试这些提示
Create a route for /users that returns a list of active users. Use the layered architecture pattern with a controller that extends BaseController.
Create a Zod schema for a user registration form with email, name, and password fields. Include TypeScript type inference.
Create a UserRepository class that uses PrismaService to find users by email and create new users. Include error handling.
Show how to properly capture errors in a service method with Sentry, including user context and operation tags.
最佳实践
- 透過將所有邏輯委託給控制器來保持路由乾淨
- 擴展 BaseController 以實現一致的錯誤處理和 Sentry 集成
- 使用 Zod 實現類型安全的輸入驗證,帶有自動 TypeScript 推斷
- 關注點分離:路由處理路由、控制器處理 HTTP、服務處理業務邏輯、倉庫處理數據訪問
避免
- 業務邏輯在路由處理程序中 - 違反關注點分離原則
- 直接使用 process.env 而不是 unifiedConfig
- 缺少錯誤處理或在沒有 Sentry 捕獲的情況下吞掉錯誤
- 在控制器或服務中直接調用 Prisma - 應使用倉庫