angular-architecture について
Angular プロジェクト向けのアーキテクチャスキルです。機能単位の配置ルールや命名規則、コーディング指針を示します。
主な機能
- 01利用範囲に応じた機能構成
- 02機能別・共有フォルダーの区分
- 03ソースファイルの命名規則
- 04Angular のコーディング指針
- 05Angular CLI の生成例
活用シーン
- 01新しい Angular アプリの構成
- 02再利用コンポーネントの配置判断
- 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.ts | user-profile.ts | 冗長なため - フォルダーでコンテキストが分かります |
user.service.ts | user.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
リソース
コメント
Markdown 対応