npx claudepluginhub xiaobei930/cc-best --plugin cc-bestThis skill is limited to using the following tools:
本技能提供后端服务开发的最佳实践和模式,支持多语言按需加载。
Enforces workflow for full-stack apps: requirements, architecture decisions, scaffolding checklists, patterns for API integration, auth, error handling, real-time (SSE/WebSocket) across Node/React/Next.js, Python, Go.
Guides backend tasks like REST/GraphQL API design, database query optimization, authentication, microservices building, code review, migrations, and load testing across detected stacks.
Implements Node.js backend patterns with Express/Fastify for middleware, error handling, auth, DB integration, REST/GraphQL APIs, microservices, and WebSockets.
Share bugs, ideas, or general feedback.
本技能提供后端服务开发的最佳实践和模式,支持多语言按需加载。
根据项目技术栈,加载对应的语言专属文件:
| 技术栈 | 加载文件 | 框架 |
|---|---|---|
| Python | python.md | FastAPI, Django, Flask |
| TypeScript/Node.js | typescript.md | Express, NestJS, Fastify |
| Java | java.md | Spring Boot, Quarkus |
| Go | go.md | Gin, Echo, Fiber |
| C# | csharp.md | ASP.NET Core |
| Rust | rust.md | Axum, Actix-web, Rocket |
加载方式: 检测项目中的 pyproject.toml/package.json/pom.xml/go.mod/Cargo.toml 等文件确定技术栈。
┌─────────────────────────────────────┐
│ Controller 层 │ 处理 HTTP 请求/响应
├─────────────────────────────────────┤
│ Service 层 │ 业务逻辑
├─────────────────────────────────────┤
│ Repository 层 │ 数据访问
├─────────────────────────────────────┤
│ Model 层 │ 数据模型
└─────────────────────────────────────┘
src/
├── controllers/ # 控制器(或 routes/handlers)
├── services/ # 业务逻辑
├── repositories/ # 数据访问(或 dal/)
├── models/ # 数据模型(或 entities/)
├── middlewares/ # 中间件
├── utils/ # 工具函数
├── config/ # 配置
└── types/ # 类型定义(如适用)
┌─────────────────────────────────────────────────────┐
│ 错误处理金字塔 │
├─────────────────────────────────────────────────────┤
│ 业务错误 (400-499) │
│ ├─ ValidationError (400) 输入验证失败 │
│ ├─ UnauthorizedError (401) 未认证 │
│ ├─ ForbiddenError (403) 无权限 │
│ └─ NotFoundError (404) 资源不存在 │
├─────────────────────────────────────────────────────┤
│ 系统错误 (500-599) │
│ ├─ InternalError (500) 服务器内部错误 │
│ ├─ ServiceUnavailable (503) 服务不可用 │
│ └─ GatewayTimeout (504) 网关超时 │
└─────────────────────────────────────────────────────┘
原则:
日志级别:
| 级别 | 用途 | 示例 |
|---|---|---|
| ERROR | 需要立即关注的错误 | 数据库连接失败 |
| WARN | 潜在问题 | 重试成功、降级处理 |
| INFO | 重要业务事件 | 用户登录、订单创建 |
| DEBUG | 开发调试信息 | 变量值、执行路径 |
结构化日志字段:
{
"timestamp": "2025-01-22T10:00:00Z",
"level": "info",
"message": "用户登录成功",
"requestId": "uuid",
"userId": "123",
"duration": 45
}
| 策略 | 适用场景 | TTL 建议 |
|---|---|---|
| Cache-Aside | 读多写少 | 5-60 分钟 |
| Write-Through | 强一致性要求 | 短 TTL |
| Write-Behind | 写多读少 | 根据业务 |
缓存键命名:
{service}:{entity}:{id}
{service}:{entity}:list:{hash}
/api/v1/...成功响应:
{
"success": true,
"data": { ... },
"meta": { "total": 100, "page": 1 }
}
错误响应:
{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "邮箱格式不正确"
}
}
GET /health
{
"status": "ok",
"timestamp": "2025-01-22T10:00:00Z",
"services": {
"database": { "status": "ok" },
"redis": { "status": "ok" }
}
}
1. 收到 SIGTERM 信号
2. 停止接受新请求
3. 等待进行中的请求完成(超时时间内)
4. 关闭数据库连接
5. 关闭其他资源
6. 退出进程
详细的语言专属实现请参考:
记住: 后端代码的质量标准是可维护性——类型安全、错误处理、日志追踪缺一不可。