AgentSkillsCN

Architecture Fitness Functions

利用健康度函数评估架构健康状况——包括层边界违规、依赖方向、包耦合度以及圈复杂度等指标。

SKILL.md
--- frontmatter
name: Architecture Fitness Functions
description: Evaluate architectural health using fitness functions — layer boundary violations, dependency direction, package coupling, and cyclomatic complexity
category: architecture
version: 1.0.0
triggers:
  - new-package
  - import-change
  - architecture-review
globs: "**/*.go"

Architecture Fitness Functions Skill

Run automated fitness functions that verify architectural constraints are maintained as the codebase evolves.

Trigger Conditions

  • New package or directory is created
  • Import statements change
  • Architecture review is requested
  • User invokes with "architecture fitness" or "architecture-fitness"

Input Contract

  • Required: Path to Go source root
  • Optional: Architecture rules file or reference to rule 125

Output Contract

  • Layer boundary violation report (imports crossing boundaries)
  • Dependency direction violations
  • Package coupling metrics
  • Cyclomatic complexity hotspots
  • Overall architecture health score (A-F)

Tool Permissions

  • Read: All Go source files
  • Write: None (read-only analysis)
  • Search: Grep for import statements, package declarations
  • Shell: Run go vet, complexity analyzers

Execution Steps

  1. Check layer boundaries: Per rule 125, verify:
    • Handlers don't import repositories
    • Services don't import gin
    • Models don't import internal packages
    • Repositories don't import services
  2. Check dependency direction: Verify imports flow downward (handler → service → repository → models)
  3. Measure coupling: Count cross-package imports and identify highly-coupled packages
  4. Measure complexity: Run complexity analysis and flag functions > 15 cyclomatic complexity
  5. Score: Assign A-F grade based on violation count and severity
  6. Report: Produce fitness report with specific violations and remediation guidance

Fitness Functions

FunctionThresholdMeasurement
Layer violations0Count of cross-layer imports
Dependency direction0Count of upward imports
Package coupling< 10 imports per packageMax import count
Cyclomatic complexity< 15 per functionMax complexity score
File size< 500 linesMax lines per file
Function count< 20 per fileMax exported functions

References

  • .cursor/rules/125-go-layer-boundaries.mdc
  • .cursor/rules/020-code-complexity.mdc
  • .cursor/rules/015-code-organization.mdc