Feature-Sliced Design (FSD) Skill - v2.1.0
An architectural methodology skill for scaffolding and organizing frontend applications using Feature-Sliced Design principles.
Overview
Feature-Sliced Design v2.1 is a compilation of rules and conventions for organizing frontend code to make projects more understandable, maintainable, and stable in the face of changing business requirements.
Version 2.1 introduces the "Pages First" approach - keeping more code in pages and widgets rather than prematurely extracting it to features and entities.
Core Principles
The "Pages First" Approach (FSD v2.1)
The fundamental principle of FSD v2.1: Keep code where it's used until you need to reuse it.
Instead of immediately extracting everything into entities and features, start by keeping code in pages and widgets. Only move code to lower layers when you actually need to reuse it.
What stays in Pages and Widgets:
โ
Large UI blocks that are only used on one page
โ
Forms and their validation logic specific to a page
โ
Data fetching and state management for page-specific data
โ
Business logic that serves only this page/widget
โ
API interactions needed only here
When to extract to lower layers:
- To Shared: When you need the same infrastructure in multiple places (modal manager, date formatter, UI components)
- To Entities: When you have a clear business domain model that's used across multiple features
- To Features: When you have a complete user interaction that's reused in multiple places
Why "Pages First"?
- Better code cohesion - related code stays together
- Easier to delete - unused code is right there with its usage
- Less abstraction overhead - no need to identify entities/features prematurely
- Natural decomposition - pages are intuitive to understand
- Faster development - no time wasted on premature optimization
1. Layered Architecture (Vertical Organization)
FSD uses 6 active standardized layers organized by responsibility and dependencies. Layers are ordered from most specific (top) to most generic (bottom):
app/ โ Application initialization, providers, global styles
pages/ โ Full page compositions with their own logic, routing
widgets/ โ Large composite UI blocks with their own logic
features/ โ Reusable user interactions and business features
entities/ โ Reusable business entities (user, product, order)
shared/ โ Reusable infrastructure code (UI kit, utils, API)
Note: Historically, FSD included processes/ as a 7th layer, but it is deprecated in v2.1. If you're using it, move the code to features/ with help from app/ if needed.
Import Rule: A module can only import from layers strictly below it.
- โ
features/ โ entities/, shared/
- โ
pages/ โ widgets/, features/, entities/, shared/
- โ
entities/ โ features/ (upward import)
- โ
features/comments/ โ features/posts/ (same-layer cross-import)
2. Slices (Horizontal Organization)
Slices group code by business domain meaning. Each slice represents a specific business concept:
features/
โโโ auth/ โ Authentication feature
โโโ comments/ โ Comments functionality
โโโ post-editor/ โ Post editing feature
entities/
โโโ user/ โ User business entity
โโโ product/ โ Product business entity
โโโ order/ โ Order business entity
Key Rules:
- Slices must be independent from other slices on the same layer (zero coupling)
- Slices should contain most code related to their primary goal (high cohesion)
- Slice names are not standardized - they reflect your business domain
3. Segments (Technical Organization)
Segments group code within slices by technical purpose:
features/
โโโ auth/
โโโ ui/ โ React components, styles, formatters
โโโ api/ โ API requests, data types, mappers
โโโ model/ โ State management, business logic, stores
โโโ lib/ โ Internal utilities for this slice
โโโ config/ โ Configuration, feature flags
โโโ index.ts โ Public API (exports only what other slices need)
Standard Segments:
ui - UI components, styles, date formatters
api - Backend interactions, request functions, data types
model - Data models, state stores, business logic
lib - Utility functions needed by this slice
config - Configuration files, feature flags
4. Public API
Every slice must define a public API through an index file:
export { LoginForm } from './ui/LoginForm';
export { useAuth } from './model/useAuth';
export { loginUser } from './api/loginUser';
Rule: Modules outside a slice can only import from the public API, not from internal files.
Public API for Cross-Imports (@x notation)
New in v2.1: You can now create explicit connections between slices on the same layer (typically entities) using the @x notation.
This allows entities to reference each other when there's a legitimate business relationship:
export { UserCard } from './ui/UserCard';
export { userModel } from './model';
export { UserOrderHistory } from './ui/UserOrderHistory';
export { getUserOrders } from './api/getUserOrders';
import { UserOrderHistory } from '@/entities/user/@x/order';
When to use cross-imports:
- There's a clear business relationship between entities (e.g., User and Order)
- The dependency is bidirectional or circular in the business domain
- You want to keep the code together while acknowledging the relationship
Important: Regular cross-imports between slices (without @x) are still not allowed. Use @x notation to make cross-dependencies explicit and controlled.
Layer Definitions & Examples
App Layer
Application-wide settings, providers, routing setup.
app/
โโโ providers/ โ Redux Provider, React Query, Theme Provider
โโโ styles/ โ Global CSS, resets, theme variables
โโโ index.tsx โ Application entry point
โโโ router.tsx โ Route configuration
Pages Layer
Route-level compositions with their own logic and data management.
pages/
โโโ home/
โ โโโ ui/
โ โ โโโ HomePage.tsx
โ โ โโโ HeroSection.tsx โ Large UI blocks
โ โ โโโ FeaturesGrid.tsx
โ โโโ model/
โ โ โโโ useHomeData.ts โ Page-specific state
โ โโโ api/
โ โ โโโ fetchHomeData.ts โ Page-specific API
โ โโโ index.ts
โโโ profile/
โ โโโ ui/
โ โ โโโ ProfilePage.tsx
โ โ โโโ ProfileForm.tsx โ Forms specific to this page
โ โ โโโ ProfileStats.tsx
โ โโโ model/
โ โ โโโ profileStore.ts โ State for profile page
โ โ โโโ validation.ts โ Form validation
โ โโโ api/
โ โ โโโ updateProfile.ts
โ โ โโโ fetchProfile.ts
โ โโโ index.ts
โโโ settings/
v2.1 Approach: Pages can now contain:
- โ
Large UI blocks used only on this page
- โ
Forms and their validation logic
- โ
Data fetching and state management
- โ
Business logic that serves only this page
- โ
API interactions specific to this page
Only extract to lower layers when you need to reuse the code elsewhere.
Widgets Layer
Complex, composite UI blocks with their own logic, used across multiple pages.
widgets/
โโโ header/
โ โโโ ui/
โ โ โโโ Header.tsx
โ โ โโโ Navigation.tsx
โ โ โโโ UserMenu.tsx
โ โโโ model/
โ โ โโโ headerStore.ts โ Widget state
โ โโโ api/
โ โ โโโ fetchNotifications.ts โ Widget-specific API
โ โโโ index.ts
โโโ sidebar/
โ โโโ ui/
โ โโโ model/
โ โ โโโ sidebarState.ts
โ โโโ index.ts
โโโ footer/
v2.1 Approach: Widgets are no longer just compositional blocks. They can contain:
- โ
UI components of the widget
- โ
Widget-specific state management
- โ
Business logic that serves the widget
- โ
API interactions the widget needs
- โ
Internal utilities
Only extract code to entities/features when other widgets or pages need it.
Features Layer
Reusable user interactions and complete business features used in multiple places.
features/
โโโ auth/
โ โโโ ui/
โ โ โโโ LoginForm.tsx
โ โ โโโ RegisterForm.tsx
โ โโโ model/
โ โ โโโ useAuth.ts
โ โโโ api/
โ โ โโโ login.ts
โ โ โโโ register.ts
โ โโโ index.ts
โโโ add-to-cart/
โโโ like-post/
โโโ comment-create/
v2.1 Approach: Only create a feature when:
- โ
The user interaction is used on multiple pages/widgets
- โ
It's a complete, self-contained user action
- โ
It has clear business value
Don't create features prematurely. If a user interaction is only used in one place, keep it in the page or widget until you actually need to reuse it.
Entities Layer
Reusable business entities - the core domain models used across the application.
entities/
โโโ user/
โ โโโ ui/
โ โ โโโ UserCard.tsx
โ โ โโโ UserAvatar.tsx
โ โโโ model/
โ โ โโโ types.ts
โ โ โโโ userStore.ts
โ โโโ api/
โ โ โโโ userApi.ts
โ โโโ @x/
โ โ โโโ order.ts โ Cross-import API for order
โ โโโ index.ts
โโโ product/
โโโ order/
v2.1 Approach: Only create an entity when:
- โ
It represents a clear business domain concept
- โ
It's used in multiple features, pages, or widgets
- โ
It has well-defined boundaries and responsibilities
Don't prematurely extract entities. If a data structure is only used in one place, keep it there until you need to share it.
Shared Layer
Reusable infrastructure code with no business logic.
shared/
โโโ ui/ โ UI kit components
โ โโโ Button/
โ โโโ Input/
โ โโโ Modal/
โโโ lib/ โ Utilities
โ โโโ formatDate/
โ โโโ debounce/
โ โโโ classnames/
โโโ api/ โ API client setup, base config
โ โโโ client.ts
โ โโโ apiRoutes.ts โ Route constants (v2.1: allowed!)
โโโ config/ โ Environment variables, constants
โ โโโ env.ts
โ โโโ appConfig.ts
โโโ assets/ โ Images, fonts, icons
โ โโโ logo.svg โ Company logo (v2.1: allowed!)
โ โโโ icons/
โโโ types/ โ Common TypeScript types
v2.1 Update: Shared can now contain application-aware code:
- โ
Route constants and path builders
- โ
API endpoint definitions
- โ
Company branding assets (logos, colors)
- โ
Application configuration
- โ
Common type definitions
Still not allowed:
- โ Business logic (calculations, workflows, domain rules)
- โ Feature-specific code
- โ Entity-specific code
No slices in Shared - organized by segments only. Segments can import from each other within Shared.
Common Patterns
1. Working with API (Pages First Approach)
Start simple - keep API logic in the page until you need to reuse it:
export const fetchProfile = (id: string) =>
apiClient.get(`/users/${id}`);
export const useProfile = (id: string) => {
const [user, setUser] = useState(null);
useEffect(() => {
fetchProfile(id).then(setUser);
}, [id]);
return user;
};
import { useProfile } from '../model/useProfile';
const