First Principles Code Refactoring
Paste the following prompt into your AI chat to install this skill:
Please install @user_3299e856/first-principles-refactor into your AI assistant by following https://skillhub.cn/install/skillhub.md.
About this skill
What problem it addresses
When working in an unfamiliar codebase, asking “where should we refactor?” can lead to surface-level changes: too broad scope, mistaken debt, or treating generated code and thin adapters as core problems. This skill turns code optimization into a reviewable engineering workflow: align goals first, then focus on modules that actually justify investment.
How it works
It follows a Pre-Phase + four-phase process:
- Scope alignment: confirm analysis depth, focus areas, and boundaries to avoid indiscriminate full-repo scans.
- Reconnaissance: use
explore.shto summarize directory structure, tech stack, code size, Git health, engineering conventions, and debt signals, then confirm key findings with the user. - Deconstruction: ask first-principles questions such as why a module exists, whether it would be designed the same way from scratch, and what would break if removed, to spot over-engineering, defensive redundancy, ghost dependencies, and misplaced abstraction.
- Audit: select dimensions such as readability, maintainability, and security based on project size, and mark red, yellow, or green risk signals.
- Roadmap: rank work from
P0toP3, prioritizing security, correctness, and stability before performance, dependency upgrades, and architectural changes, with a gradual replacement preference.
Boundaries
It is better suited to codebase upgrades that require technical judgment and team alignment than to simple formatting fixes or single-function cleanup. If test coverage is missing, add tests or explicitly state the risk first. For vague or shifting business goals, complete scope alignment before starting analysis.
Use Cases
- After taking over an unfamiliar codebase, align scope first, then produce a tech stack, size, and risk snapshot.
- Before refactoring a core module, decide which abstractions, dependencies, or configs are inertia versus essential logic.
- Rank security, performance, and maintainability issues from P0 to P3 into a reviewable gradual roadmap.
- Translate audit findings into engineering risks, business impact, and scheduling advice for leaders and PMs.
Best For
- Backend engineers responsible for legacy refactoring who need to turn scattered debt into an executable roadmap.
- Technical leaders who need to assess codebase risk, set priorities, and align the team on upgrade plans.
- Architects who need to judge whether over-engineering, ghost dependencies, or misplaced abstraction should change.
- PMs or stakeholders who need to understand business risk, value, and investment boundaries for engineering upgrades.
Related Skills
Analyzes code to extract control and data flow, then outputs Markdown with Mermaid source and high-resolution PNG diagrams.
For development and programming scenarios around VSCode and TypeScript IDE.
A TypeScript-oriented Windmill Wrap development reference.
A Python-based Selenium wrapper for engineering browser automation workflows.