feature-sliced-design
Feature-Sliced Design (FSD、フロントエンドアーキテクチャ手法) リファレンスとルール。 別名 fsd / feature-sliced。layers (app / pages / widgets / features / entities / shared)、 依存方向、Public API、@x 記法 (cross-import)、slice groups (スライスグループ)、 segments (ui / model / api / lib / config)、steiger、Next.js、TanStack Query 連携。 コードレビュー・リファクタリング時に自動参照。
How do I install this agent skill?
npx skills add https://github.com/fandhe-ai/agent-reference-skills --skill feature-sliced-designIs this agent skill safe to install?
- Gen Agent Trust Hubpass
This skill is a reference guide for the Feature-Sliced Design (FSD) architecture, providing rules, patterns, and tooling documentation for frontend projects. No security issues were detected; the provided commands and dependencies are standard for the described development methodology.
- Socketpass
No alerts
- Snykpass
Risk: LOW · No issues
What does this agent skill do?
Feature-Sliced Design ガイドライン
ディレクトリ構成
skills/feature-sliced-design/
SKILL.md
references/
README.md
import-rules.md
layers.md
public-api.md
slice-groups.md
slices-segments.md
samples/
README.md
project-structure.md
slice-public-api.md
layer-imports.md
cross-entity-import.md
slice-groups.md
composition-in-pages.md
nextjs-app-router.md
react-query-integration.md
scripts/
README.md
install.md
generate.md
lint.md
rules/
README.md
layer-dependency.md
public-api-enforcement.md
slice-isolation.md
segment-naming.md
探索手順
タスクからカテゴリを引き、カテゴリの README.md で目的のページを特定する:
- 下記マッピング表でタスクに対応するカテゴリを探す
- そのカテゴリの
README.mdを参照して目的のページを特定する - 該当ページの
.mdを Read して詳細を確認する
タスク → カテゴリ マッピング
| タスク | カテゴリ | 参照 README |
|---|---|---|
| レイヤー構成・責務を知りたい | references | references/README.md |
| インポートルール・依存方向を確認したい | references | references/README.md |
| Public API パターンを理解したい | references | references/README.md |
| スライス・セグメントの定義を知りたい | references | references/README.md |
| スライスグループ(関連スライスのまとめ方)を知りたい | references | references/README.md |
| 典型的な FSD プロジェクト構成の例を見たい | samples | samples/README.md |
| Next.js / React Query との組み合わせ例を見たい | samples | samples/README.md |
| @x 記法・クロスエンティティ依存の実例を見たい | samples | samples/README.md |
| pages での合成パターン(同一レイヤー間依存の回避)を知りたい | samples | samples/README.md |
| ツールチェーンのインストール・CLI コマンドを知りたい | scripts | scripts/README.md |
| steiger でアーキテクチャ準拠チェックを実行したい | scripts | scripts/README.md |
| @feature-sliced/cli でコード生成したい | scripts | scripts/README.md |
| レイヤー依存方向のルールを自動適用したい | rules | rules/README.md |
| Public API 経由のみ許可するルールを確認したい | rules | rules/README.md |
| スライス分離・セグメント命名規約を確認したい | rules | rules/README.md |
コア概念の詳細は references/<topic>.md、チェックルールは rules/<rule>.md を参照。
必須ルール
- コードは標準レイヤーに分割する:
app,pages,widgets,features,entities,shared(processesは deprecated)。全レイヤーは必須ではなく、最低限shared/pages/app。widgetsは公式が非推奨 - インポートは下位レイヤーへの一方向のみ許可。同一レイヤー内のスライス間インポートは禁止
- 各スライスは
index.tsで Public API を定義する。外部からは Public API 経由でのみインポートする export *は使用しない。公開するものを明示的に列挙する- セグメント名は「目的」で命名する(
ui,model,api)。「本質」で命名しない(components,hooks,types) appとsharedにスライスは持たない。セグメントのみで構成する
レイヤー構成(上位 → 下位)
app — ルーティング、プロバイダー、グローバル設定(スライスなし)
pages — 画面単位のスライス
widgets — 複数ページで再利用される大規模 UI ブロック(公式は非推奨)
features — ビジネス価値をもたらすユーザーインタラクション
entities — ビジネスエンティティ(User, Product 等)
shared — 汎用的な再利用可能コード(スライスなし)
標準セグメント
| セグメント | 内容 |
|---|---|
ui | UI コンポーネント、フォーマッタ、スタイル |
api | バックエンド連携、リクエスト関数、レスポンス型 |
model | データスキーマ、ストア、ビジネスロジック |
lib | スライスローカルのユーティリティ |
config | 設定定数、フィーチャーフラグ |
ディレクトリ構造例
src/
├── app/
│ ├── routes/
│ ├── store/
│ └── styles/
├── pages/
│ └── feed/
│ ├── ui/
│ ├── api/
│ └── index.ts
├── widgets/
│ └── header/
│ ├── ui/
│ └── index.ts
├── features/
│ └── search-articles/
│ ├── ui/
│ ├── model/
│ └── index.ts
├── entities/
│ └── user/
│ ├── ui/
│ ├── model/
│ ├── api/
│ └── index.ts
└── shared/
├── ui/
├── api/
├── lib/
└── config/
よくある間違い
- セグメント名に
components/,hooks/,types/を使う →ui/,model/,lib/を使用する export *でまとめてエクスポートする → 明示的にexport { Name } fromで列挙する- 同一レイヤーのスライスを直接インポートする → 上位レイヤーで合成するか、
@x記法を使用する(@xはentitiesレイヤー限定) - 再利用されないコードを
featuresやwidgetsに早期移動する → まずpagesに置き、複数ページで再利用されるアクションになったらfeaturesへ昇格する sharedにビジネスロジックを置く → ビジネスロジックはentities以上に配置する- 独自レイヤーを追加する → 標準レイヤーのみ使用する
- Public API なしでスライスを作成する → 必ず
index.tsを先に定義する - 型定義を
types/フォルダにまとめる → ドメインごとにmodel/セグメント内に配置する
How can the creator link this skill?
Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.
<a href="https://skillzs.dev/skills/fandhe-ai/agent-reference-skills/feature-sliced-design">View feature-sliced-design on skillZs</a>