mcpField
A
angular-architecture

angular-architecture

github.com/gentleman-programming開発661320 回インストール31 週間前に更新
リポジトリ

angular-architecture について

Angular プロジェクト向けのアーキテクチャスキルです。機能単位の配置ルールや命名規則、コーディング指針を示します。

主な機能

  1. 01利用範囲に応じた機能構成
  2. 02機能別・共有フォルダーの区分
  3. 03ソースファイルの命名規則
  4. 04Angular のコーディング指針
  5. 05Angular CLI の生成例

活用シーン

  1. 01新しい Angular アプリの構成
  2. 02再利用コンポーネントの配置判断
  3. 03ソースファイル名の統一

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/gentleman-programming/gentleman-skills --skill angular-architecture

インストール後、Claude Code で/angular-architectureを入力して読み込まれたか確認します。

詳細

スコープのルール(必須)

「スコープが構造を決める」 - コンポーネントをどこに配置するかは、使用方法によって決まります。

使用方法配置先
1 つの機能で使用features/[feature]/components/
2 つ以上の機能で使用features/shared/components/
例
features/
  shopping-cart/
    shopping-cart.ts          # Main component = feature name
    components/
      cart-item.ts            # Used ONLY by shopping-cart
      cart-summary.ts         # Used ONLY by shopping-cart
  checkout/
    checkout.ts
    components/
      payment-form.ts         # Used ONLY by checkout
  shared/
    components/
      button.ts               # Used by shopping-cart AND checkout
      modal.ts                # Used by multiple features

プロジェクト構造

src/app/
  features/
    [feature-name]/
      [feature-name].ts       # Main component (same name as folder)
      components/             # Feature-specific components
      services/               # Feature-specific services
      models/                 # Feature-specific types
    shared/                   # ONLY for 2+ feature usage
      components/
      services/
      pipes/
  core/                       # App-wide singletons
    services/
    interceptors/
    guards/
  app.ts
  app.config.ts
  routes.ts
  main.ts

ファイル命名(必須)

.component、.service、.model のサフィックスは付けません。何のファイルかはフォルダーで分かります。

✅ user-profile.ts
❌ user-profile.component.ts

✅ cart.ts
❌ cart.service.ts

✅ user.ts
❌ user.model.ts

スタイルガイド

準拠する内容(公式ドキュメントより)
  • コンストラクターインジェクションより inject() を使用
  • ngClass/ngStyle より class と style のバインディングを使用
  • テンプレート専用のメンバーには protected を使用
  • 入力、出力、クエリには readonly を使用
  • イベントではなくアクションに基づいてハンドラーに名前を付ける(saveUser ではなく handleClick)
  • ライフサイクルフックはシンプルに保ち、分かりやすい名前のメソッドに処理を委譲
  • 1 ファイルにつき 1 つの概念
@Component({...})
export class UserProfileComponent {
  // 1. Injected dependencies
  private readonly userService = inject(UserService);
  
  // 2. Inputs/Outputs
  readonly userId = input.required<string>();
  readonly userSaved = output<User>();
  
  // 3. Internal state
  private readonly _loading = signal(false);
  readonly loading = this._loading.asReadonly();
  
  // 4. Computed
  protected readonly displayName = computed(() => ...);
  
  // 5. Methods
  save(): void { ... }
}
独自に変更する内容
公式の記述採用する記述理由
user-profile.component.tsuser-profile.ts冗長なため - フォルダーでコンテキストが分かります
user.service.tsuser.ts同様

コマンド

# New project
ng new my-app --style=scss --ssr=false

# Component in feature
ng g c features/products/components/product-card --flat

# Service in feature  
ng g s features/products/services/product --flat

# Guard in core
ng g g core/guards/auth --functional

リソース

コメント