Feature-Sliced Design Architecture
Overview
Feature-Sliced Design (FSD) is an architectural methodology for scaffolding frontend applications with rules and conventions for organizing code to remain understandable and stable amid changing business requirements.
Official Documentation: https://feature-sliced.design/llms.txt
Core Principles
Layers - 7 standardized horizontal levels (top to bottom):
app/ → routing, entrypoints, global styles, providers
processes/ → (deprecated) complex cross-page scenarios
pages/ → full pages or nested routing sections
widgets/ → self-contained UI blocks delivering complete use cases
features/ → reused product functionality with business value
entities/ → business domain objects (user, product, order)
shared/ → reusable, project-detached functionality
Import Rule - Modules can only import from layers strictly below them. Never import sideways or upward.
Slices - Business-domain partitions within layers (e.g., user, product, cart). Cannot reference other slices at the same layer.
Segments - Purpose-based groupings within slices:
ui/ → components, formatters, styles
api/ → backend interactions, data types
model/ → schemas, stores, business logic
lib/ → slice-specific utilities
config/ → feature flags, configuration
Public API - Each slice exposes functionality via index.ts barrel file.
Quick Reference Structure
src/
├── app/ # Layer: Application initialization
│ ├── providers/ # Context providers, store setup
│ ├── routes/ # Router configuration
│ └── styles/ # Global styles
├── pages/ # Layer: Route-based screens
│ └── {page-name}/
│ ├── ui/
│ ├── api/
│ └── index.ts # Public API
├── widgets/ # Layer: Complex reusable blocks
│ └── {widget-name}/
│ ├── ui/
│ └── index.ts
├── features/ # Layer: User interactions
│ └── {feature-name}/
│ ├── ui/
│ ├── api/
│ ├── model/
│ └── index.ts
├── entities/ # Layer: Business entities
│ └── {entity-name}/
│ ├── ui/
│ ├── api/
│ ├── model/
│ └── index.ts
└── shared/ # Layer: Shared infrastructure
├── ui/ # UI kit, design system
├── api/ # API client, request functions
├── lib/ # Utilities (dates, validation)
├── config/ # Environment, constants
└── i18n/ # Internationalization
When Implementing FSD
- Creating a new feature: Place in
features/ if reused across pages, otherwise keep in pages/
- Creating a new entity: Place in
entities/ with ui/, api/, model/ segments
- Creating shared utilities: Place in
shared/lib/ or shared/ui/
- Integrating with Next.js: Place App Router in
src/app/ (no root app/), which serves as both routing and FSD app layer
Reference Documentation
For detailed implementation guidance, consult these reference files:
- Layer Details - Complete layer specifications and guidelines
- Public API Patterns - Export patterns, barrel files, cross-imports
- Implementation Patterns - Code examples, entity/feature patterns
- Next.js Integration - App Router and Pages Router setup
- Migration Guide - Migrating existing projects to FSD
- Cheatsheet - Quick decision guide and common patterns
Key Anti-Patterns to Avoid
- Importing from higher layers (breaks unidirectional flow)
- Cross-slice imports at the same layer (use lower layers instead)
- Generic segment names like
components/, hooks/, types/
- Wildcard exports (
export * from) in public APIs
- Storing business logic in
shared/ layer
1---2name: feature-slicing-23description: Apply Feature-Sliced Design (FSD) architecture to frontend projects. Use when creating new frontend features, components, pages, or restructuring existing code. Triggers on tasks involving React/Next.js/Vue project organization, layer architecture, feature isolation, module boundaries, or when user mentions FSD, feature slicing, or scalable frontend structure.4---5
6# Feature-Sliced Design Architecture
7
8## Overview
9
10Feature-Sliced Design (FSD) is an architectural methodology for scaffolding frontend applications with rules and conventions for organizing code to remain understandable and stable amid changing business requirements.
11
12**Official Documentation:** https://feature-sliced.design/llms.txt
13
14## Core Principles
15
161. **Layers** - 7 standardized horizontal levels (top to bottom):
17 - `app/` → routing, entrypoints, global styles, providers
18 - `processes/` → (deprecated) complex cross-page scenarios
19 - `pages/` → full pages or nested routing sections
20 - `widgets/` → self-contained UI blocks delivering complete use cases
21 - `features/` → reused product functionality with business value
22 - `entities/` → business domain objects (user, product, order)
23 - `shared/` → reusable, project-detached functionality
24
252. **Import Rule** - Modules can only import from layers strictly below them. Never import sideways or upward.
26
273. **Slices** - Business-domain partitions within layers (e.g., `user`, `product`, `cart`). Cannot reference other slices at the same layer.
28
294. **Segments** - Purpose-based groupings within slices:
30 - `ui/` → components, formatters, styles
31 - `api/` → backend interactions, data types
32 - `model/` → schemas, stores, business logic
33 - `lib/` → slice-specific utilities
34 - `config/` → feature flags, configuration
35
365. **Public API** - Each slice exposes functionality via `index.ts` barrel file.
37
38## Quick Reference Structure
39
40```
41src/
42├── app/ # Layer: Application initialization
43│ ├── providers/ # Context providers, store setup
44│ ├── routes/ # Router configuration
45│ └── styles/ # Global styles
46├── pages/ # Layer: Route-based screens
47│ └── {page-name}/
48│ ├── ui/
49│ ├── api/
50│ └── index.ts # Public API
51├── widgets/ # Layer: Complex reusable blocks
52│ └── {widget-name}/
53│ ├── ui/
54│ └── index.ts
55├── features/ # Layer: User interactions
56│ └── {feature-name}/
57│ ├── ui/
58│ ├── api/
59│ ├── model/
60│ └── index.ts
61├── entities/ # Layer: Business entities
62│ └── {entity-name}/
63│ ├── ui/
64│ ├── api/
65│ ├── model/
66│ └── index.ts
67└── shared/ # Layer: Shared infrastructure
68 ├── ui/ # UI kit, design system
69 ├── api/ # API client, request functions
70 ├── lib/ # Utilities (dates, validation)
71 ├── config/ # Environment, constants
72 └── i18n/ # Internationalization
73```
74
75## When Implementing FSD
76
771. **Creating a new feature**: Place in `features/` if reused across pages, otherwise keep in `pages/`
782. **Creating a new entity**: Place in `entities/` with `ui/`, `api/`, `model/` segments
793. **Creating shared utilities**: Place in `shared/lib/` or `shared/ui/`
804. **Integrating with Next.js**: Place App Router in `src/app/` (no root `app/`), which serves as both routing and FSD app layer
81
82## Reference Documentation
83
84For detailed implementation guidance, consult these reference files:
85
86- **[Layer Details](references/LAYERS.md)** - Complete layer specifications and guidelines
87- **[Public API Patterns](references/PUBLIC-API.md)** - Export patterns, barrel files, cross-imports
88- **[Implementation Patterns](references/IMPLEMENTATION.md)** - Code examples, entity/feature patterns
89- **[Next.js Integration](references/NEXTJS.md)** - App Router and Pages Router setup
90- **[Migration Guide](references/MIGRATION.md)** - Migrating existing projects to FSD
91- **[Cheatsheet](references/CHEATSHEET.md)** - Quick decision guide and common patterns
92
93## Key Anti-Patterns to Avoid
94
95- Importing from higher layers (breaks unidirectional flow)
96- Cross-slice imports at the same layer (use lower layers instead)
97- Generic segment names like `components/`, `hooks/`, `types/`
98- Wildcard exports (`export * from`) in public APIs
99- Storing business logic in `shared/` layer