一键导入
refactoring
Safe code refactoring with step-by-step approach
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Safe code refactoring with step-by-step approach
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Design RESTful APIs following best practices
Systematic bug investigation and root cause analysis
Review code quality, patterns, and best practices
Generate commit messages following conventional commits with scope detection
Generate and update technical documentation
Break down features into implementable tasks
| type | skill |
| name | Refactoring |
| description | Safe code refactoring with step-by-step approach |
| skillSlug | refactoring |
| phases | ["E"] |
| generated | "2026-02-08T00:00:00.000Z" |
| status | filled |
| scaffoldVersion | 2.0.0 |
Use this skill when restructuring existing code in the Smart Farming application. Refactoring must preserve behavior while improving code structure, readability, or maintainability.
Before ANY refactoring:
pytest — Establish the baseline (all tests must pass)When: Two or more use cases contain duplicate logic.
Where: src/app/core/commons/
# Before: duplicated in multiple use cases
class CreateSensorRecord:
def execute(self, data):
# validation logic here...
class EditSensorRecord:
def execute(self, data):
# same validation logic here...
# After: extracted to commons
# core/commons/validate_sensor_data.py
def validate_sensor_data(data):
# shared validation logic
# Use in both use cases
from core.commons.validate_sensor_data import validate_sensor_data
When: A use case has too many responsibilities (> 100 lines or multiple distinct operations).
Steps:
When: Multiple repository methods have similar SQL with minor variations.
# Before: separate methods with similar queries
def find_by_plant_id(self, plant_id): ...
def find_by_date_range(self, start, end): ...
def find_by_plant_and_date(self, plant_id, start, end): ...
# After: flexible query method
def find(self, filters: dict): ...
When: Names don't clearly communicate intent.
Checklist:
When: Code is in the wrong architectural layer.
| Code Type | Correct Location |
|---|---|
| Business rules | core/use_cases/ |
| Data validation | core/commons/ or infra/forms/ |
| SQL queries | infra/repositories/ |
| HTTP handling | infra/views/ |
| Configuration | infra/constants/ |
:recycle: refactor(scope): descriptioninit_database() — Can destroy development data