SuperAPI AI Directory

file-restructurer

Coding & development

View repository

Updated 10-16 08:55

About this skill

File Restructuring Skill

Description

Restructure project file structure, organize folders, and perform modular refactoring.

Trigger Conditions

  • "Restructure file structure"
  • "Organize folders"
  • "Modularize"
  • Refactoring steps in the Workflow

Refactoring Types

1. Folder structure reorganization

Before:
├── app.py
├── utils.py
├── database.py
├── models.py
└── tests.py

After:
├── src/
│   ├── __init__.py
│   ├── app.py
│   ├── core/
│   │   ├── __init__.py
│   │   └── models.py
│   ├── infrastructure/
│   │   ├── __init__.py
│   │   └── database.py
│   └── utils/
│       ├── __init__.py
│       └── helpers.py
└── tests/
    ├── __init__.py
    └── test_models.py

2. Module splitting

Before:
utils.py (500 行)

After:
utils/
├── __init__.py
├── string_utils.py
├── date_utils.py
├── file_utils.py
└── validation.py

3. Import path updates

Automatically update import statements in all affected files

Execution Flow

1. 分析當前結構
2. 生成重構計畫
3. 預覽變更(dry-run)
4. 使用者確認
5. 執行重構
6. 更新 imports
7. 驗證功能正常
8. 生成報告

Safety Mechanisms

Backup Mechanism

# 自動建立備份
.backup/
└── [timestamp]/
    └── [原始結構複製]

Rollback Mechanism

如需回滾,執行:
git checkout HEAD -- .
或
從 .backup/[timestamp]/ 還原

Output Format

🔧 檔案重構報告

═══════════════════════════════════════

📊 重構摘要:
  - 移動檔案:12 個
  - 新建資料夾:5 個
  - 更新 imports:23 處

═══════════════════════════════════════

📁 結構變更:

移動的檔案:
  📄 utils.py → src/utils/helpers.py
  📄 models.py → src/core/models.py
  📄 database.py → src/infrastructure/database.py

新建的資料夾:
  📁 src/
  📁 src/core/
  📁 src/infrastructure/
  📁 src/utils/
  📁 tests/

更新的 imports:
  📄 app.py: 5 處
  📄 test_models.py: 3 處

═══════════════════════════════════════

✅ 重構完成!

⚠️ 建議執行:
1. 運行測試確認功能正常
2. 檢查 IDE 是否正確識別新結構
3. 提交變更到 Git

Usage Examples

「重構為 DDD 結構」
「整理 utils 資料夾」
「模組化 services.py」
「--dry-run 預覽重構」