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
- •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
- •Check dependency direction: Verify imports flow downward (handler → service → repository → models)
- •Measure coupling: Count cross-package imports and identify highly-coupled packages
- •Measure complexity: Run complexity analysis and flag functions > 15 cyclomatic complexity
- •Score: Assign A-F grade based on violation count and severity
- •Report: Produce fitness report with specific violations and remediation guidance
Fitness Functions
| Function | Threshold | Measurement |
|---|---|---|
| Layer violations | 0 | Count of cross-layer imports |
| Dependency direction | 0 | Count of upward imports |
| Package coupling | < 10 imports per package | Max import count |
| Cyclomatic complexity | < 15 per function | Max complexity score |
| File size | < 500 lines | Max lines per file |
| Function count | < 20 per file | Max exported functions |
References
- •
.cursor/rules/125-go-layer-boundaries.mdc - •
.cursor/rules/020-code-complexity.mdc - •
.cursor/rules/015-code-organization.mdc