Proj Refactor logo

Proj Refactor

Community
zhangloveyan
proj-refactor

代码重构指南和常见重构模式。用于改善代码质量、消除代码坏味道、优化代码结构。

Overview

Publisherzhangloveyan
Repositorybackend-skill
Skill nameproj-refactor
Stars
102
Forks
31
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by zhangloveyan on GitHub. Read the source before you install it.

Installation

Install the Proj Refactor AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/zhangloveyan/backend-skill/tree/main/.claude/skills/proj-refactor
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/zhangloveyan/backend-skill.git /tmp/backend-skill
mkdir -p .claude/skills
cp -r /tmp/backend-skill/.claude/skills/proj-refactor .claude/skills/proj-refactor
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Proj Refactor in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Proj Refactor on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Proj Refactor is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

代码重构

适用场景

  • 代码质量改善
  • 消除代码坏味道
  • 优化代码结构
  • 提高可维护性

重构流程

Step 0: 校验任务文档 → Step 1: 识别问题 → Step 2: 确定范围 → Step 3: 编写测试 → Step 4: 小步重构 → Step 5: 验证

Step 0: 校验任务文档

  • 确认全流程任务文档存在
  • 若缺失,先创建任务文档骨架并补齐流程状态与上下文快照
  • 在上下文快照记录“重构中”与一句话范围说明

重构原则

  1. 小步前进 - 每次只做一个小改动
  2. 保持功能 - 重构不改变外部行为
  3. 测试保障 - 有测试覆盖再重构
  4. 及时提交 - 每个小步骤后提交

同步任务文档:

  • 产物清单记录相关测试/报告路径(如有)
  • 更新下一步指令为“验证/继续开发”

常见代码坏味道

1. 过长方法

问题: 方法超过 50 行

重构方法: 提取方法

java
// ✗ 重构前
public void processOrder(Order order) {
    // 50+ 行代码...
}

// ✓ 重构后
public void processOrder(Order order) {
    validateOrder(order);
    calculatePrice(order);
    saveOrder(order);
    sendNotification(order);
}

2. 过大类

问题: 类超过 500 行,职责过多

重构方法: 提取类

java
// ✗ 重构前
public class UserService {
    // 用户管理 + 订单管理 + 支付管理...
}

// ✓ 重构后
public class UserService { /* 用户管理 */ }
public class OrderService { /* 订单管理 */ }
public class PaymentService { /* 支付管理 */ }

3. 重复代码

问题: 相同代码出现多处

重构方法: 提取公共方法

java
// ✗ 重构前
public void methodA() {
    // 重复代码块
}
public void methodB() {
    // 重复代码块
}

// ✓ 重构后
private void commonMethod() {
    // 公共代码块
}
public void methodA() {
    commonMethod();
}
public void methodB() {
    commonMethod();
}

4. 过长参数列表

问题: 方法参数超过 4 个

重构方法: 引入参数对象

java
// ✗ 重构前
public void createUser(String name, String phone, String email,
                       String address, Integer age, Integer status) {}

// ✓ 重构后
public void createUser(UserCreateRequest request) {}

5. 魔法值

问题: 硬编码的数字或字符串

重构方法: 提取常量或枚举

java
// ✗ 重构前
if (status == 1) { }
if (type.equals("VIP")) { }

// ✓ 重构后
if (status == StatusEnum.ENABLE.getCode()) { }
if (type.equals(UserType.VIP)) { }

6. 过深嵌套

问题: if/for 嵌套超过 3 层

重构方法: 提前返回、提取方法

java
// ✗ 重构前
public void process(User user) {
    if (user != null) {
        if (user.isEnabled()) {
            if (user.hasPermission()) {
                // 业务逻辑
            }
        }
    }
}

// ✓ 重构后
public void process(User user) {
    if (user == null) return;
    if (!user.isEnabled()) return;
    if (!user.hasPermission()) return;
    // 业务逻辑
}

7. 注释过多

问题: 用注释解释复杂代码

重构方法: 让代码自解释

java
// ✗ 重构前
// 检查用户是否有效
if (u != null && u.getS() == 1 && u.getD() == 0) { }

// ✓ 重构后
if (user.isValid()) { }

// User 类中
public boolean isValid() {
    return this.status == StatusEnum.ENABLE && this.delFlag == 0;
}

重构检查清单

  • 是否有测试覆盖
  • 重构后功能是否正常
  • 代码是否更清晰
  • 是否引入新问题
  • 是否需要更新文档

注意事项

  1. 不要同时重构和加功能 - 分开进行
  2. 有测试再重构 - 没有测试先补测试
  3. 小步提交 - 便于回滚
  4. 保持克制 - 只重构必要的部分
  5. 任务文档同步 - 维护流程状态、产物清单、上下文快照、下一步指令

Frequently asked questions

What does the Proj Refactor AI skill do?

代码重构指南和常见重构模式。用于改善代码质量、消除代码坏味道、优化代码结构。

Why use Proj Refactor on TypingMind?

Because you install it once and use it with any model. Proj Refactor is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Proj Refactor in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/zhangloveyan/backend-skill/tree/main/.claude/skills/proj-refactor. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Proj Refactor?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Proj Refactor?

As many as you like. As long as a model supports skills, you can use Proj Refactor with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Proj Refactor AI skill free?

Yes. It is published on GitHub by zhangloveyan under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇