skills/crearize/refactor-code/SKILL.md
コードリファクタリングスキル(DRY原則適用、複雑度削減、パフォーマンス最適化、デグレーション防止)
npx skillsauth add aiskillstore/marketplace refactor-codeInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
MovieMarketerプロジェクトのリファクタリング専門家として、コード改善提案、DRY原則適用、パフォーマンス最適化を行う。デグレーションを防止するため、Regression Guardianと必ず連携する。
ブランチ管理
# 現在のブランチを確認
git branch --show-current
# mainブランチの場合は必ず新しいブランチを作成
# ブランチ名形式: refactor/[content]-[issue-number]
# 例: refactor/reduce-duplication-789
# mainブランチでないことを確認してから作業開始
Issue番号の確認
作業前確認完了の報告 以下を確認したことをOrchestratorに報告:
Orchestratorからのリファクタリング指示を確認
リファクタリング対象のコードを理解:
Regression Guardianにベースライン記録を依頼(Orchestrator経由)
改善提案を作成:
## リファクタリング提案
### 対象ファイル
- [ファイルパス]
### 問題点
- [具体的な問題点]
### 改善案
- [具体的な改善方法]
### 期待される効果
- [パフォーマンス向上、可読性向上等]
### リスク分析
- [デグレーションリスク、影響範囲]
### 対策
- [テスト追加、段階的リファクタリング等]
Orchestratorに提案を報告し、承認を得る
小さな単位で段階的に実施
各ステップで以下を確認:
リファクタリングパターンの活用:
1. 重複コード削除
// Before: 重複コード
public void methodA() {
User user = getCurrentUser();
if (user == null) throw new UnauthorizedException();
// ...
}
public void methodB() {
User user = getCurrentUser();
if (user == null) throw new UnauthorizedException();
// ...
}
// After: ユーティリティメソッド抽出
private User getAuthenticatedUser() {
User user = getCurrentUser();
if (user == null) throw new UnauthorizedException();
return user;
}
public void methodA() {
User user = getAuthenticatedUser();
// ...
}
public void methodB() {
User user = getAuthenticatedUser();
// ...
}
2. 複雑度削減
// Before: 複雑な条件分岐
if (user != null && user.getRole() != null &&
(user.getRole().equals("ADMIN") || user.getRole().equals("MANAGER"))) {
// ...
}
// After: メソッド抽出
private boolean isAdminOrManager(User user) {
return user != null && user.getRole() != null &&
(user.getRole().equals("ADMIN") || user.getRole().equals("MANAGER"));
}
if (isAdminOrManager(user)) {
// ...
}
3. N+1問題解決
// Before: N+1問題
public List<UserDto> getUsers() {
List<User> users = userMapper.selectAll();
return users.stream()
.map(user -> {
List<Post> posts = postMapper.selectByUserId(user.getId()); // N回実行
return UserDto.from(user, posts);
})
.collect(Collectors.toList());
}
// After: JOINまたはIN句で一括取得
public List<UserDto> getUsers() {
List<User> users = userMapper.selectAll();
List<UUID> userIds = users.stream().map(User::getId).collect(Collectors.toList());
Map<UUID, List<Post>> postsByUserId = postMapper.selectByUserIds(userIds) // 1回実行
.stream()
.collect(Collectors.groupingBy(Post::getUserId));
return users.stream()
.map(user -> UserDto.from(user, postsByUserId.get(user.getId())))
.collect(Collectors.toList());
}
1. カスタムフック抽出
// Before: コンポーネントに直接実装
const UserProfile = () => {
const [user, setUser] = useState<User | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<Error | null>(null);
useEffect(() => {
// データフェッチロジック
}, []);
// ...
};
// After: カスタムフック抽出
const useUserData = (userId: string) => {
const [user, setUser] = useState<User | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<Error | null>(null);
useEffect(() => {
// データフェッチロジック
}, [userId]);
return { user, loading, error };
};
const UserProfile = () => {
const { user, loading, error } = useUserData(userId);
// ...
};
2. Presentational/Container分離
// Before: 1つのコンポーネントにすべて
const UserList = () => {
const [users, setUsers] = useState<User[]>([]);
// データフェッチ、状態管理、表示が混在
return (
<div>
{/* 表示ロジック */}
</div>
);
};
// After: 分離
// Container
const UserListContainer = () => {
const { users, loading, error } = useUsers();
if (loading) return <Loading />;
if (error) return <Error message={error.message} />;
return <UserListPresentation users={users} />;
};
// Presentational
export const UserListPresentation = ({ users }: { users: User[] }) => {
return (
<div>
{users.map(user => <UserCard key={user.id} user={user} />)}
</div>
);
};
既存テストを実行:
# Backend
cd backend
./gradlew test
# Frontend
cd frontend
pnpm run test:ci
テスト失敗時:
新規テストの追加(必要に応じて):
リファクタリングによって発生した未使用コードを確認・削除。
重要: PMDではstatic final定数や一部のLombok影響下のフィールドは検出されないため、IDE警告を必ず確認すること。
確認手順:
private static final 定数private フィールド・メソッド確認必須項目:
確認手順:
確認必須項目:
Backend リファクタリングの場合:
cd backend
./gradlew bootRun
確認事項:
Frontend リファクタリングの場合:
cd frontend
pnpm dev
確認事項:
## Refactoring Specialist 完了報告
### リファクタリング内容
- **対象ファイル**: [ファイルパス一覧]
- **改善内容**: [具体的な改善内容]
### 改善効果
- **パフォーマンス**: [改善前/改善後の測定値]
- **可読性**: [具体的な改善点]
- **保守性**: [具体的な改善点]
### テスト結果
- 既存テスト: 全件合格
- 新規テスト: [追加したテスト数] 件
- カバレッジ: [数値]%(維持または向上)
### Regression Guardian検証結果
- デグレーション: なし
- テスト成功率: 100%維持
- ビルド: 成功
- パフォーマンス: 劣化なし(または向上)
### サーバー起動確認
- [ ] サーバー起動成功(Backend: `./gradlew bootRun` または Frontend: `pnpm dev`)
- [ ] リファクタリング対象機能の動作確認済み
- [ ] エラーログなし
### 確認事項
- [ ] 作業前にブランチ確認済み(mainブランチでない)
- [ ] Issue番号確認済み
- [ ] Regression Guardian連携済み
- [ ] テストカバレッジ維持(80%以上)
- [ ] デグレーションなし
- [ ] サーバー起動・動作確認済み
### 次のステップ
リファクタリング完了。Orchestratorへ報告してください。
## Refactoring Specialist 報告
### デグレーション検出
Regression Guardianからデグレーション検出の報告を受けました。
### デグレーション内容
- [具体的なデグレーション内容]
### 原因分析
- [推測される原因]
### 対処方針
**即座にロールバック実施**
### ロールバック実施
- git revert [コミットハッシュ]
- テスト実行: 成功
- ビルド実行: 成功
### 次のステップ
ロールバック完了。リファクタリング計画を再検討します。
リファクタリングのベストプラクティス・デザインパターン確認:
リファクタリング技法
resolve-library-id: "refactoring"
topic: "extract method pattern"
デザインパターン
resolve-library-id: "design patterns"
topic: "strategy pattern java"
活用場面:
documents/development/coding-rules/: コーディング規約documents/development/development-policy.md: 開発ガイドラインdevelopment
Apple Human Interface Guidelines for content display components. Use this skill when the user asks about charts component, collection view, image view, web view, color well, image well, activity view, lockup, data visualization, content display, displaying images, rendering web content, color pickers, or presenting collections of items in Apple apps. Also use when the user says how should I display charts, what's the best way to show images, should I use a web view, how do I build a grid of items, what component shows media, or how do I present a share sheet. Cross-references: hig-foundations for color/typography/accessibility, hig-patterns for data visualization patterns, hig-components-layout for structural containers, hig-platforms for platform-specific component behavior.
tools
Automate HelpDesk tasks via Rube MCP (Composio): list tickets, manage views, use canned responses, and configure custom fields. Always search tools first for current schemas.
testing
Expert Haskell engineer specializing in advanced type systems, pure functional design, and high-reliability software. Use PROACTIVELY for type-level programming, concurrency, and architecture guidance.
tools
GraphQL gives clients exactly the data they need - no more, no less. One endpoint, typed schema, introspection. But the flexibility that makes it powerful also makes it dangerous. Without proper controls, clients can craft queries that bring down your server. This skill covers schema design, resolvers, DataLoader for N+1 prevention, federation for microservices, and client integration with Apollo/urql. Key insight: GraphQL is a contract. The schema is the API documentation. Design it carefully.