A template for quickly bootstrapping SvelteKit projects with Shadcn UI components and Feature-Sliced Design (FSD) architecture.
This template provides a pre-configured SvelteKit project that combines:
The project follows a modified Feature-Sliced Design architecture with layers organized under src/lib
:
src/
├── lib/
│ ├── entities/ # Business entities (users, products, etc.)
│ ├── features/ # User interactions and business logic
│ ├── pages/ # Page components
│ ├── shared/ # Shared utilities, UI components, and APIs
│ │ ├── lib/ # Utility functions and hooks
│ │ │ └── shadcn.ts # Shadcn utilities
│ │ └── ui/ # Shadcn UI components and custom reusable components with no business logic
│ └── widgets/ # Complex UI blocks composed of entities and features
├── routes/ # SvelteKit routes (maps to FSD "app" layer)
└── app.css # Global styles
┌────────────┐
│ routes │ (SvelteKit routes - FSD "app" layer)
└─────┬──────┘
│
▼
┌────────────┐
│ pages │ Page components
└─────┬──────┘
│
▼
┌────────────┐
│ widgets │ Complex UI blocks
└─────┬──────┘
│
▼
┌────────────┐
│ features │ User interactions and business logic
└─────┬──────┘
│
▼
┌────────────┐
│ entities │ Business entities
└─────┬──────┘
│
▼
┌────────────┐
│ shared │ Reusable utilities and components
└────────────┘
Each layer can import from any layer below it, but only through the public API (index.ts).
Clone this repository
git clone https://github.com/yourusername/sveltekit-shadcn-fsd-template.git my-project
cd my-project
Install dependencies with pnpm install
Run the development server with pnpm dev
Build for production with pnpm build
Here's a quick example of how to add a new slice following the FSD structure:
Create the feature slice structure:
src/lib/features/auth/
├── ui/
│ ├── login-form.svelte
│ └── register-form.svelte
├── model/
│ └── types.ts
├── api/
│ └── api.ts
└── index.ts
Create public API in index.ts:
// src/lib/features/auth/index.ts
export { default as LoginForm } from './ui/login-form.svelte';
export { default as RegisterForm } from './ui/register-form.svelte';
export type { LoginData, RegisterData } from './model/types';
Use in a page slice:
<!-- src/lib/pages/login/ui/page.svelte -->
<script>
import { LoginForm } from '$lib/features/auth';
</script>
<div class="container">
<h1>Login</h1>
<LoginForm />
</div>
The template uses Shadcn UI for Svelte, a collection of beautifully designed, accessible UI components built with Tailwind CSS. These components are not a component library, but rather a collection of reusable components you can copy and paste into your projects.
Shadcn configuration:
$lib/shared/ui/
$lib/shared/lib/shadcn.ts
Note: This template uses
shadcn-svelte@next
with Tailwind CSS v3. It will be updated when the stable version of shadcn-svelte is released.
Feature-Sliced Design is a methodology for organizing code in frontend applications. This template implements FSD with a slight adaptation to work well with SvelteKit.
The project follows strict layer boundaries:
pages -> widgets -> features -> entities -> shared
Example of correct imports:
// ✅ Correct: Using public API
import { UserCard } from '$lib/entities/user';
// ❌ Wrong: Using internal structure
import { UserCard } from '$lib/entities/user/ui/user-card';
// ❌ Wrong: Cross-segment import within same layer
import { AdminCard } from '$lib/entities/admin'; // from user/index.ts inside $lib/entities/user
For more detailed information about FSD principles and guidelines, refer to the official documentation.
routes
folder - application initialization, routing, and global providersThis template integrates FSD with SvelteKit in the following ways:
routes
directory$lib/pages
are imported and used in SvelteKit routes+layout.svelte
) handle global layouts and data loadingroutes
directoryExample:
<!-- src/routes/dashboard/+page.svelte -->
<script>
import { DashboardPage } from '$lib/pages/dashboard';
</script>
<DashboardPage />
The template includes:
This is primarily a personal template that reflects my development workflow. However, contributions and suggestions are welcome if you'd like to help improve it!
MIT