← 返回列表
全部 Skill›工具 Tools›backend-code-guideline

backend-code-guideline

作者 @findsun-vn · 语言 en
Enforce consistent, production-ready Spring Boot backend generation for module-based architecture.
工具 Tools命令行工具通用访问网络待翻译
最近源活动
—
检测 SKILL.md 语言
en
星标 ★
0
分支 Fork
0
安装选项
提示
指令
使用 AI 助手安装
将下面的提示复制到你正在使用的 AI 助手中。
下载完整 Skill 目录(含全部配套文件)。 下载压缩包 ↓
SKILL.md 原文预览

Skill: backend-code-guideline

Purpose

Ensure all generated backend code is:

  • module-based
  • API-contract-safe
  • layered correctly
  • production-ready
  • consistent with AGENTS.md and OpenAPI

Backend Architecture Standard

Every backend business module must live under:

backend/src/main/java/com/yourapp/modules/<module_name>/

Standard module structure:

  • controller/
  • service/
  • service/impl/
  • mapper/
  • entity/
  • dto/
  • vo/
  • convertor/

Core Layering Rule

Backend flow must always be:

controller -> service -> service/impl -> mapper -> entity

Forbidden:

  • business logic in controllers
  • skipping service layer
  • exposing entities directly to clients
  • introducing repository/ unless explicitly required for JPA

Naming Rules

Classes

  • Controller: XController
  • Service: XService
  • Service implementation: XServiceImpl
  • Mapper: XMapper
  • Entity: X
  • Convertor: XConvertor

Requests

  • CreateXRequest
  • UpdateXRequest

Responses

  • XResponse

Controller Rules

Controllers must:

  • use @RestController
  • contain endpoint wiring only
  • delegate business logic to service layer
  • use request DTOs
  • return response VOs wrapped in the standard API response envelope

Controllers must not:

  • perform heavy business logic
  • perform manual persistence logic
  • return entity objects directly

Service Rules

Services must:

  • define clear business operations
  • enforce business rules
  • coordinate persistence and conversion
  • remain reusable and testable

Service implementations must:

  • not leak persistence concerns to controllers
  • not duplicate mapping logic unnecessarily

Mapper Rules

Use MyBatis Plus mappers as the default data access layer.

Mapper interfaces should:

  • extend BaseMapper<Entity> where appropriate
  • remain focused on DB access
  • avoid business orchestration logic

Use XML mappers only if really needed, and place them under:

backend/src/main/resources/mapper/


Entity Rules

Entities must:

  • map DB schema exactly
  • use proper table mapping annotations
  • follow schema-defined fields
  • map snake_case DB names cleanly

Include base fields where required:

  • id
  • createdAt
  • updatedAt
  • deletedAt

DTO Rules

Use DTOs for all request payloads.

Apply validation annotations where appropriate:

  • @NotNull
  • @NotBlank
  • @Size
  • @Min
  • @Max

DTOs must reflect OpenAPI request contracts.


VO Rules

Use VOs for all response payloads.

VOs must:

  • expose only API-required fields
  • avoid persistence-only/internal fields
  • match OpenAPI response schemas

Convertor Rules

Put mapping logic into convertor/.

Typical mappings:

  • DTO -> Entity
  • Entity -> VO
  • List<Entity> -> List<VO>

Avoid:

  • duplicated mapping logic across services
  • controller-level object mapping
  • entity-to-response leakage

Standard API Response Contract

All successful backend responses must use:

{

"code": 0,

"message": "success",

"data": {}

}

Controllers must NOT return:

  • raw entity
  • raw VO
  • raw list
  • raw pagination object

Pagination Rule

Backend may use MyBatis Plus Page<Entity> internally.

But API responses for paginated endpoints must be:

{

"code": 0,

"message": "success",

"data": {

"content": [],

"page": 1,

"size": 10,

"total": 100

}

}

The pagination object must always be inside data.


Soft Delete Rule

Use deleted_at semantics.

Backend must:

  • exclude soft-deleted rows from normal list/detail queries
  • avoid hard delete unless explicitly required
  • keep DB and API behavior aligned on soft delete

Error Handling Rule

Use global exception handling.

Goals:

  • clean error responses
  • no internal leak
  • consistent HTTP semantics
  • centralized handling

Security Rule

Where auth is involved:

  • respect role boundaries
  • do not expose sensitive fields
  • keep admin behavior explicit
  • align with OpenAPI security expectations

Forbidden Patterns

  • business logic in controller
  • exposing entity directly
  • missing DTO layer
  • missing VO layer
  • duplicating mapping logic everywhere
  • hardcoding API contract outside OpenAPI
  • skipping wrapper response format

Final Goal

Generated backend code must be:

  • clean
  • layered
  • contract-safe
  • scalable
  • production-ready
评论
Ffindsun-vn
findsun-vn
findsun-vn/E-Commerce
查看 GitHub 仓库 查看作者的其他 Skill
来源信息
作者@findsun-vn
所属大类工具 Tools / 命令行工具
国内可用性通用
最近源活动—
风险提示访问网络
提示:风险标签为程序静态扫描结果,仅作提示,不代表安全认证。安装前请阅读 SKILL.md 及其引用的脚本、权限,自行判断是否可信。