Loading...
Loading...
Apply Feature-Sliced Design (FSD) architecture to frontend projects. Triggers on: FSD, feature slicing, frontend architecture, layer structure, module boundaries, scalable frontend, slice organization. Use when: creating new features/components/pages, restructuring React/Next.js/Vue/Remix projects, organizing frontend code, setting up project structure, fixing import violations, or migrating legacy codebases.
npx skill4agent add ccheney/robust-skills feature-slicingOfficial Docs: feature-sliced.design | GitHub: feature-sliced
app → pages → widgets → features → entities → shared
↓ ↓ ↓ ↓ ↓ ✓
✓ ✓ ✓ ✓ ✓ (external only)| Violation | Example | Fix |
|---|---|---|
| Cross-slice (same layer) | | Extract to |
| Upward import | | Move shared code down |
| Shared importing up | | Shared has NO internal deps |
app/shared/| Layer | Purpose | Has Slices | Required |
|---|---|---|---|
| Initialization, routing, providers, global styles | No | Yes |
| Route-based screens (one slice per route) | Yes | Yes |
| Complex reusable UI blocks (header, sidebar) | Yes | No |
| User interactions with business value (login, checkout) | Yes | No |
| Business domain models (user, product, order) | Yes | No |
| Project-agnostic infrastructure (UI kit, API client, utils) | No | Yes |
app/pages/shared/Code Placement:
├─ App-wide config, providers, routing → app/
├─ Full page / route component → pages/
├─ Complex reusable UI block → widgets/
├─ User action with business value → features/
├─ Business domain object (data model) → entities/
└─ Reusable, domain-agnostic code → shared/| Entity (noun) | Feature (verb) |
|---|---|
| |
| |
| |
| |
Segments (within a slice):
├─ ui/ → React components, styles
├─ api/ → Backend calls, data fetching, DTOs
├─ model/ → Types, schemas, stores, business logic
├─ lib/ → Slice-specific utilities
└─ config/ → Feature flags, constantsapi/model/hooks/types/src/
├── app/ # App layer (no slices)
│ ├── providers/ # React context, QueryClient, theme
│ ├── routes/ # Router configuration
│ └── styles/ # Global CSS, theme tokens
├── pages/ # Page slices
│ └── {page-name}/
│ ├── ui/ # Page components
│ ├── api/ # Loaders, server actions
│ ├── model/ # Page-specific state
│ └── index.ts # Public API
├── widgets/ # Widget slices
│ └── {widget-name}/
│ ├── ui/ # Composed UI
│ └── index.ts
├── features/ # Feature slices
│ └── {feature-name}/
│ ├── ui/ # Feature UI
│ ├── api/ # Feature API calls
│ ├── model/ # State, schemas
│ └── index.ts
├── entities/ # Entity slices
│ └── {entity-name}/
│ ├── ui/ # Entity UI (Card, Avatar)
│ ├── api/ # CRUD operations
│ ├── model/ # Types, mappers, validation
│ └── index.ts
└── shared/ # Shared layer (no slices)
├── ui/ # Design system components
├── api/ # API client, interceptors
├── lib/ # Utilities (dates, validation)
├── config/ # Environment, constants
├── routes/ # Route path constants
└── i18n/ # Translationsindex.ts// entities/user/index.ts
export { UserCard } from './ui/UserCard';
export { UserAvatar } from './ui/UserAvatar';
export { getUser, updateUser } from './api/userApi';
export type { User, UserRole } from './model/types';
export { userSchema } from './model/schema';// ✅ Correct
import { UserCard, type User } from '@/entities/user';
// ❌ Wrong
import { UserCard } from '@/entities/user/ui/UserCard';// ❌
export * from './ui';
// ✅
export { UserCard } from './ui/UserCard';@xentities/
├── product/
│ ├── @x/
│ │ └── order.ts # API specifically for order entity
│ └── index.ts
└── order/
└── model/types.ts # Imports from product/@x/order// entities/product/@x/order.ts
export type { ProductId } from '../model/types';
// entities/order/model/types.ts
import type { ProductId } from '@/entities/product/@x/order';| Anti-Pattern | Problem | Fix |
|---|---|---|
| Cross-slice import | | Extract shared logic down |
| Generic segments | | Use |
| Wildcard exports | | Explicit named exports |
| Business logic in shared | Domain logic in | Move to |
| Single-use widgets | Widget used by one page | Keep in page slice |
| Skipping public API | Import from internal paths | Always use |
| Making everything a feature | All interactions as features | Only reused actions |
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}| File | Purpose |
|---|---|
| references/LAYERS.md | Complete layer specifications, flowcharts |
| references/PUBLIC-API.md | Export patterns, @x notation, tree-shaking |
| references/IMPLEMENTATION.md | Code patterns: entities, features, React Query |
| references/NEXTJS.md | App Router integration, page re-exports |
| references/MIGRATION.md | Incremental migration strategy |
| references/CHEATSHEET.md | Quick reference, import matrix |