Communitygithub.com

pproenca/クリーンアーキテクチャ

Robert C. Martin氏の書籍に基づくクリーンアーキテクチャの原則とベストプラクティス。ソフトウェアシステムの設計、コード構造のレビュー、関心の分離を改善するためのリファクタリングに活用します。レイヤー、境界、依存関係の方向性、エンティティ、ユースケース、システムアーキテクチャに関わるタスクで発動します。

クリーンアーキテクチャ とは?

このスキルは、Robert C. Martin(通称「Uncle Bob」)が提唱するクリーンアーキテクチャの原則を実践するためのガイドです。ソフトウェアシステムの設計やコード構造のレビュー、関心の分離を改善するリファクタリングにおいて、依存関係の方向性やレイヤー境界の正確な理解を支援します。具体的には、エンティティ、ユースケース、インターフェースアダプター、フレームワークという4つのレイヤーにシステムを分割し、内側のレイヤーが外側のレイヤーに依存しないように設計します。このスキルを使用することで、テスト容易性、保守性、柔軟性が向上し、フレームワークやデータベースなどの技術的な詳細からビジネスロジックを保護できます。Claude CodeやCursor、CodexなどのAIエージェントプラットフォーム上で動作し、コード生成やアーキテクチャレビュー、リファクタリングの際に自動的に適用されます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/pproenca/dot-skills/tree/main/skills/clean-architecture

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

クリーンアーキテクチャ は何をしますか?

Robert C. Martin氏の著書『Clean Architecture』に基づく、クリーンアーキテクチャの原則とベストプラクティス。このスキルは、ソフトウェアシステムの設計、コード構造のレビュー、アプリケーションのリファクタリングにおいて、より良い関心の分離を実現するために活用されるべきです。レイヤー、境界、依存関係の方向性、エンティティ、ユースケース、システムアーキテクチャに関わるタスクで発動します。

主要原則

依存関係のルール

  • ソースコードの依存関係は、内側のレイヤー(抽象度の高いもの)のみを指すこと
  • 外側のレイヤーが内側のレイヤーに依存してはならない
  • 内側のレイヤーは、外側のレイヤーについて一切知らないこと

レイヤー構造(外側から内側へ)

  1. フレームワーク&ドライバー

    • データベース、Webフレームワーク、UIなど
    • 最も外側のレイヤー
    • 詳細はここに置く
  2. インターフェースアダプター

    • コントローラー、プレゼンター、ゲートウェイ
    • 外側のフォーマットと内側のフォーマットを変換する
  3. アプリケーションビジネスルール(ユースケース)

    • アプリケーション固有のビジネスルール
    • システムのすべてのユースケースを調整
  4. エンタープライズビジネスルール(エンティティ)

    • 最も内側のレイヤー
    • エンタープライズ全体のビジネスルール
    • 最も安定した要素

実装パターン

依存関係逆転の原則 (DIP)

  • インターフェースを通じて依存関係を逆転させる
  • 具象クラスは外側のレイヤーで定義する

境界を越える方法

  • 境界を越えるデータは、単純なデータ構造であること
  • 内側のレイヤーのインターフェースを、外側のレイヤーが実装する

使用例

// エンティティ(内側)
interface UserEntity {
  id: string;
  name: string;
  email: string;
}

// ユースケース(中間)
interface UserRepository {
  findById(id: string): Promise<UserEntity>;
}

class GetUserUseCase {
  constructor(private userRepository: UserRepository) {}

  async execute(id: string): Promise<UserEntity> {
    return this.userRepository.findById(id);
  }
}

// アダプター(外側)
class PostgresUserRepository implements UserRepository {
  async findById(id: string): Promise<UserEntity> {
    // データベース接続ロジック
  }
}

テスト戦略

  • 内側のレイヤーは、外側のレイヤーをモックしてテストする
  • エンティティは依存関係がないため、単体テストが容易
  • ユースケースは、リポジトリインターフェースをモックしてテストする

よくある間違い

  1. エンティティにビジネスルール以外のロジックを含める
  2. ユースケースがフレームワークに依存する
  3. 境界を無視した依存関係の注入
  4. 過剰な抽象化

参考資料

Individual skills in this repo

This repo contains 7 individual skills — each has its own dedicated page.

pproenca/code-simplifier

Code simplification skill for improving clarity, consistency, and maintainability while preserving exact behavior. Use when simplifying code, reducing complexity, cleaning up recent changes, applying refactoring patterns, or improving readability. Triggers on tasks involving code cleanup, simplification, refactoring, or readability improvements.

pproenca/emilkowal-animations

Emil Kowalski's animation best practices for web interfaces. Use when writing, reviewing, or implementing animations in React, CSS, or Framer Motion. Triggers on tasks involving transitions, easing, gestures, toasts, drawers, or motion.

pproenca/nuqs

nuqs (type-safe URL query state) best practices for Next.js and other React frameworks. This skill should be used when writing, reviewing, or refactoring code that uses nuqs for URL state management. Triggers on tasks involving useQueryState, useQueryStates, search params, URL state, query parameters, nuqs parsers, limitUrlUpdates, Standard Schema, NuqsAdapter, or Next.js routing with state.

pproenca/react-hook-form

React Hook Form performance optimization for client-side form validation using useForm, useWatch, useController, useFieldArray, and the v7.55+ subscribe() API. This skill should be used when building client-side controlled forms with React Hook Form library. This skill does NOT cover React 19 Server Actions, useActionState, or server-side form handling (use react-19 skill for those).

pproenca/typescript

TypeScript performance, tsconfig, type errors, async patterns — triggered when the user asks to "optimize TypeScript performance", "speed up tsc compilation", "configure tsconfig.json", "fix type errors", "improve async patterns", or encounters TS errors (TS2322, TS2339, "is not assignable to"). Also triggers on .ts, .tsx, .d.ts file work involving type definitions, module organization, or memory management. Does NOT cover TypeScript basics, framework-specific patterns, or testing.

pproenca/vitest

Vitest testing framework patterns for test setup, async testing, mocking with vi.*, snapshots, and test performance (formerly test-vitest). This skill should be used when writing or debugging Vitest tests. This skill does NOT cover TDD methodology (use test-tdd skill), API mocking with MSW (use test-msw skill), or Jest-specific APIs.

pproenca/zod

Zod schema validation best practices for type safety, parsing, and error handling. This skill should be used when defining z.object schemas, using z.string validations, safeParse, or z.infer. This skill does NOT cover React Hook Form integration patterns (use react-hook-form skill) or OpenAPI client generation (use orval skill).

関連スキル