Clean Code Refactorer
Overview
This skill provides a systematic approach to improving code quality without changing external behavior. It enforces SOLID principles and project-specific FastAPI standards.
Refactoring Workflow
Follow this cycle for every refactoring task:
- Observe: Identify code smells (long functions, duplication, tight coupling).
- Orient: Read the Clean Code Rules to determine the best pattern to apply.
- Validate (Pre): Run existing tests to ensure the current state is stable.
- Act: Apply surgical changes (extract method, rename variable, etc.).
- Validate (Post): Execute the
scripts/check_quality.shto verify linters and tests.
Standards & Principles
Refer to the following for detailed guidance:
- Clean Code & SOLID Reference: Mandatory rules for naming, function size, and architectural layers.
Examples
- User: "This service function is too long, can you refactor it?"
- Agent: Reads the function, identifies logic that can be extracted to a helper, verifies tests pass, refactors, and runs quality checks.
Resources
scripts/check_quality.sh: Automates Ruff, Black, and Pytest validation.references/clean-code-rules.md: Comprehensive guide for SOLID and Clean Code.
Source: fike/fastapi-blog — distributed by TomeVault.