---
name: architecture-rules
type: review_rule
when: '代码审查, review, 架构检查, 设计审查'
scope:
  - backend
  - frontend
products:
  - '*'
id: ka-review-rule-架构审查规则
asset_kind: review_rule
lifecycle_status: active
owner_mechanism_id: mc-generic-review
authority: supporting
routes:
  - code_change
primary_triggers:
  - 架构审查规则
secondary_triggers: []
negative_triggers: []
priority: P1
specificity: 5
version: 1.1.0
last_reviewed: '2026-06-01'
stages: ["代码审查"]
---

## ARC-01: Controller 包含业务逻辑
pattern: /@(?:RestController|Controller)[\s\S]*?public\s+\w+\s+\w+\s*\([^)]*\)\s*\{[\s\S]*?(?:if\s*\(.*[><=!]|for\s*\(|while\s*\().*(?:calculate|compute|validate)/
severity: warning
scope: backend
description: Controller 层禁止包含业务逻辑（if/else 分支、计算、校验），必须下沉到 Service 层

## ARC-02: Entity 直接暴露给外部
pattern: /(?:ResponseEntity|ResponseBody).*<.*Entity>/
severity: warning
scope: backend
description: Controller 返回类型禁止使用 Entity，必须通过 DTO/VO 转换，防止结构耦合和敏感字段泄漏

## ARC-03: 缺少 @Transactional 注解的写操作
pattern: /public\s+\w+\s+(?:save|create|update|delete|insert|remove)\w*\s*\(/
severity: critical
scope: backend
description: 写操作 Service 方法必须标注 @Transactional(rollbackFor = Exception.class)

## ARC-04: 未使用依赖注入直接 new 服务对象
pattern: /new\s+\w*(?:Service|Repository|Mapper|Dao|Manager)\s*\(/
severity: warning
scope: backend
description: 禁止手动 new Service/Repository 实例，必须通过构造器注入或 @Autowired

## ARC-05: 前端组件文件超过 300 行应拆分
pattern: //
severity: info
scope: frontend
check: lines
description: 单个组件文件超过 300 行时应拆分为子组件，保持单一职责

## ARC-06: API 调用未封装到 service 层
pattern: /(?:fetch|axios)\s*\.\s*(?:get|post|put|delete)\s*\(/
severity: warning
scope: frontend
description: HTTP 调用禁止直接写在组件中，必须封装到独立的 service/API 层

## ARC-07: 循环依赖导致启动失败
pattern: /@Autowired.*@Lazy|@Lazy\s+@Autowired/
severity: warning
scope: backend
description: 使用 @Lazy 解决循环依赖是临时方案，应重构消除循环依赖

## ARC-08: Service 层直接操作 HttpServletRequest/Response
pattern: /(?:HttpServletRequest|HttpServletResponse)\s/
severity: warning
scope: backend
description: Service 层禁止依赖 Servlet API，应通过参数 DTO 传递数据

## ARC-09: 未配置全局异常处理器
pattern: /@(?:RestControllerAdvice|ControllerAdvice)/
severity: info
scope: backend
description: 项目必须有全局异常处理器（@RestControllerAdvice），统一错误响应格式
