Skip to content
fsd-architecture logo

Feature-Sliced Design (FSD) Architecture

fsd-architecture

Feature-Sliced Design architecture for frontend. Use when creating new features, slices, or understanding the FSD layer structure.

SKILL.md

Full skill instructions

Feature-Sliced Design (FSD) Architecture

The frontend uses Feature-Sliced Design. This skill documentation helps you understand the architecture and correctly create new features.

Layer Hierarchy (STRICT)

app/        → widgets, features, entities, shared
widgets/    → features, entities, shared
features/   → entities, shared
entities/   → shared
shared/     → (only external libs)

Import direction: ONLY downward!

Project Structure

frontend/​src/
├── app/                        # Next.js App Router (outside FSD)
│
├── widgets/                    # Composite UI Blocks
│   └── header/
│       ├── ui/
│       │   ├── header.tsx
│       │   └── mode-toggle.tsx
│       └── index.ts            # Public API
│
├── features/                   # User Interactions / Use Cases
│   ├── auth/
│   │   ├── ui/
│   │   │   ├── login-form.tsx
│   │   │   └── register-form.tsx
│   │   ├── model/
│   │   │   └── use-auth-sync.ts
│   │   └── index.ts
│   └── stats/
│       ├── ui/
│       │   └── stats-grid.tsx
│       ├── model/
│       │   └── use-sse.ts
│       └── index.ts
│
├── entities/                   # Business Objects
│   └── user/
│       ├── ui/
│       │   └── user-info.tsx
│       ├── model/
│       │   └── types.ts
│       └── index.ts
│
└── shared/                     # Reusable Code
    ├── ui/                     # shadcn/​ui components
    ├── api/                    # Orval-generated
    │   ├── endpoints/
    │   ├── models/
    │   └── custom-fetch.ts
    ├── lib/
    │   ├── auth-client/        # Client-safe Auth
    │   ├── auth-server/        # Server-only Auth
    │   ├── query-client.ts
    │   └── utils.ts
    └── config/
        ├── providers.tsx
        └── theme-provider.tsx

TypeScript Path Aliases

// Always use layer aliases:
import { Button } from "@shared/​ui/​button"
import { useAuthSync } from "@features/​auth"
import { SessionUser } from "@entities/​user"
import { Header } from "@widgets/​header"

Slice Segments

Each slice can have these segments:

SegmentPurposeExample
ui/React Componentslogin-form.tsx
model/Hooks, State, Typesuse-auth-sync.ts
api/API Calls (rare, mostly in shared)user-api.ts
lib/Utilities for the slicevalidation.ts

Public API Pattern (IMPORTANT!)

Every slice MUST have an index.ts:

// features/​auth/​index.ts
export { LoginForm } from "./​ui/​login-form"
export { RegisterForm } from "./​ui/​register-form"
export { useAuthSync, broadcastSignOut } from "./​model/​use-auth-sync"

Always import via index.ts:

// ✅ Correct
import { LoginForm } from "@features/​auth"

// ❌ Wrong (Public API Sidestep)
import { LoginForm } from "@features/​auth/​ui/​login-form"

Creating a New Feature

1. Create folder structure

mkdir -p src/​features/<name>/​ui
mkdir -p src/​features/<name>/​model  # if hooks/​state needed

2. Create UI Component

// src/​features/<name>/​ui/<name>-form.tsx
"use client"

import { Button } from "@shared/​ui/​button"
import { Card } from "@shared/​ui/​card"

export function NameForm() {
  return (
    <Card>
      <Button>Action</​Button>
    </​Card>
  )
}

3. Create Model/​Hook (optional)

// src/​features/<name>/​model/​use-<name>.ts
"use client"

import { useQueryClient } from "@tanstack/​react-query"
import { useCallback } from "react"

export function useName() {
  const queryClient = useQueryClient()
  // ...
  return { /​* ... */ }
}

4. Create Public API

// src/​features/<name>/​index.ts
export { NameForm } from "./​ui/​name-form"
export { useName } from "./​model/​use-name"

5. Use in App

// app/(protected)/​page.tsx
import { NameForm } from "@features/<name>"

export default function Page() {
  return <NameForm />
}

Creating a New Entity

// src/​entities/<name>/​model/​types.ts
export interface Product {
  id: string
  name: string
  price: number
}

// src/​entities/<name>/​ui/​product-card.tsx
"use client"

import type { Product } from "../​model/​types"
import { Card } from "@shared/​ui/​card"

export function ProductCard({ product }: { product: Product }) {
  return <Card>{product.name}</​Card>
}

// src/​entities/<name>/​index.ts
export type { Product } from "./​model/​types"
export { ProductCard } from "./​ui/​product-card"

Import Rules

// ✅ ALLOWED
// In app/:
import { Header } from "@widgets/​header"
import { LoginForm } from "@features/​auth"
import { SessionUser } from "@entities/​user"
import { Button } from "@shared/​ui/​button"

// In widgets/:
import { useAuthSync } from "@features/​auth"
import { SessionUser } from "@entities/​user"
import { Button } from "@shared/​ui/​button"

// In features/:
import { SessionUser } from "@entities/​user"
import { Button } from "@shared/​ui/​button"

// In entities/:
import { Button } from "@shared/​ui/​button"

// ❌ FORBIDDEN
// In shared/ NEVER import features/!
// In entities/ NEVER import features/!
// In features/ NEVER import other features/!

Steiger Linting

FSD rules are automatically checked:

# Integrated in lint
bun run lint

# Only Steiger
bunx steiger src

Common Steiger Errors

ErrorCauseSolution
no-public-api-sidestepDirect import instead of via index.tsImport via index.ts
insignificant-sliceSlice has only 1 referenceUse more or move to widget/​higher layer
forbidden-importsImport from higher layerFix import direction

Server vs Client Components

// Server Component (no "use client")
// → Can only import shared/, no hooks

// Client Component
"use client"
// → Can use hooks, but NEVER server-only code

Auth Separation

// In Client Components:
import { signIn, signOut } from "@shared/​lib/​auth-client"

// In Server Components:
import { getSession } from "@shared/​lib/​auth-server"

Summary

  1. Respect layers: Only import downward
  2. Public API: Always export/​import via index.ts
  3. Segments: ui/, model/, api/, lib/ as needed
  4. Aliases: @shared/, @entities/, @features/, @widgets/
  5. Linting: bun run lint checks FSD rules

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View