api
RESTful API design patterns and best practices. Use when creating endpoints, designing APIs, or implementing routes.
Backend development patterns for services, error handling, logging, caching. Use when building backend services, APIs, or microservices.
$ npx -y skills add xiaobei930/cc-best --skill backend --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/backendContext preview
The summary Claude sees to decide when to auto-load this skill.
Backend development patterns for services, error handling, logging, caching. Use when building backend services, APIs, or microservices.
name: backend description: "Backend development patterns for services, error handling, logging, caching. Use when building backend services, APIs, or microservices." allowed-tools: Read, Write, Edit, Bash, Grep, Glob
本技能提供后端服务开发的最佳实践和模式,支持多语言按需加载。
根据项目技术栈,加载对应的语言专属文件:
| 技术栈 | 加载文件 | 框架 | | ------------------ | --------------- | ------------------------ | | 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}---
成功响应:
{
"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. 退出进程
---
详细的语言专属实现请参考:
---
> **记住**: 后端代码的质量标准是可维护性——类型安全、错误处理、日志追踪缺一不可。
Role-Driven Development Workflow for Claude Code Transform Claude into a complete development team. From product requirements to code review — one plugin, full workflow. Quick Start • Features • Workflow • Commands • FAQ
Repo: xiaobei930/cc-best
RESTful API design patterns and best practices. Use when creating endpoints, designing APIs, or implementing routes.
Architecture design skill: ADR records, system design checklists, scalability assessment, architecture patterns. Use for complex system design and architecture…
Strategic compaction skill: suggests context compression at logical breakpoints. Use to suggest compaction at logical intervals during development sessions.
Database design, query optimization, migrations, and indexing. Use when designing schemas, writing queries, or managing migrations.
Systematic debugging methods, log analysis, and performance diagnostics. Use when debugging issues, analyzing errors, or troubleshooting incidents.
DevOps patterns: containerization, CI/CD, deployment strategies, monitoring. Use when containerizing apps, setting up pipelines, or deploying services.