Skip to main content

Feature slice architecture

Where to place routes, actions, schemas, repositories, UI, and messages when adding a feature.

SectionFor developers / Project development
PurposeDeveloper how-to
UpdatedJul 6, 2026
AuthorTemplate Maintainers
Versionv1.2.0
Reading time2 min

Feature slice architecture

Use a feature slice for each product capability. The goal is to keep business behavior close to the feature that owns it while keeping route files thin.

Default file layout

Feature code lives under src/features/{feature-name}:

File or folderPurpose
actions/Server actions for mutations.
components/Feature-specific UI components.
{feature}-repository.tsData access and cached reads.
{feature}-types.tsTypes, DTOs, and cache tag helpers.
{feature}-schemas.tsZod validation schemas.
{feature}-routes.tsRoute definitions owned by the feature.
{feature}-logger.tsStructured logger child for the feature.

src/app should contain only pages, layouts, and route handlers that delegate to feature modules.

Dependency direction

Feature slices may depend on shared libraries and shared UI. They should not depend on other features directly. When two features need shared behavior, move the behavior to src/lib, src/server, or a shared component boundary.

Messages and metadata

User-facing text belongs in src/messages and should be added for both supported locales. Route metadata should use the existing page metadata helpers instead of hard-coded strings in page files.

Public documentation

When a feature changes user-visible behavior, update or add the matching public documentation page. Use OpenSpec, E2E, and docs as the cross-surface checklist.