Analyze the package/module structure of existing code, and create and execute improvement proposals and a migration plan.
Workflow
1. 現状分析 → 2. 問題特定 → 3. 改善提案 → 4. 移行計画
1. Current State Analysis
Understand the structure of the target directory.
Tools used:
mcp__serena__list_dir: Understanding the directory structure (recursive: true)mcp__serena__get_symbols_overview: Understanding symbols within filesmcp__serena__find_referencing_symbols: Detecting dependencies
Checkpoints:
- Directory depth (4 levels or fewer is ideal)
- Number of files/directory (10 or fewer is ideal)
- Consistency of naming conventions
2. Problem Identification
references/analysis-patterns.mdRefer to and detect problems.
Priority(high→low):
- Circular dependencies (cause of build failure)
- God modules (large impact of changes)
- Scattered functionality (reduced development efficiency)
- Excessive nesting (reduced readability)
3. Improvement Proposals
For solutions to each problem, refer toreferences/analysis-patterns.md.
4. Migration Plan
Create a phased migration plan:
### Phase 1: 準備
- [ ] テストカバレッジ確認
- [ ] 依存関係マップ作成
### Phase 2: 構造変更
- [ ] 新ディレクトリ作成
- [ ] ファイル移動
- [ ] インポートパス更新
### Phase 3: 検証
- [ ] テスト実行
- [ ] ビルド確認
Concrete Example
Input
ユーザー: 「auth/モジュールが肥大化している」
Analysis
auth/
├── mod.rs (800行) ← 神モジュール検出
├── jwt.rs
├── oauth.rs
└── session.rs
問題: mod.rsに認証ロジック、ミドルウェア、エラー型が混在
Output
# パッケージ構造分析レポート
## 検出された問題
1. **神モジュール**: auth/mod.rs (800行、3責務)
## 改善提案
### 提案1: 責務分離
- Before: auth/mod.rs に全ロジック
- After:
- auth/core.rs (認証ロジック)
- auth/middleware.rs (ミドルウェア)
- auth/error.rs (エラー型)
- 理由: 単一責任の原則適用、変更影響範囲の限定
## 移行計画
### Phase 1: 準備
- [ ] 既存テストの確認
### Phase 2: 分割
- [ ] auth/core.rs 作成、ロジック移動
- [ ] auth/middleware.rs 作成
- [ ] auth/error.rs 作成
- [ ] mod.rs を再エクスポートのみに
### Phase 3: 検証
- [ ] cargo test
- [ ] cargo clippy
Related Skills (Recommended for Concurrent Reading)
When using this skill, also refer to the following skills:
package-design: Package design principles that serve as refactoring goalsddd-module-pattern: Target refactoring structure in a DDD contextintent-based-dedup: Judgment on consolidating duplicate code during refactoring