- Lab
- Core Tech

Guided: Develop a Full-stack App with SvelteKit
Ready to build modern, fast, and scalable web applications without the boilerplate? This lab is an introduction to SvelteKit, the full-stack framework from the creators of Svelte. You'll go from an empty folder to a deployed, feature-complete "Smart Notes" application. Along the way, you'll learn key SvelteKit concepts like file-based routing, server-side form actions, and data loading. By the end, you'll have hands-on experience building a real-world app and a powerful new tool in your developer toolkit.

Path Info
Table of Contents
-
Challenge
Introduction
Welcome to the SvelteKit Smart Notes lab! In this lab, you'll build a complete full-stack application from scratch. SvelteKit is a powerful framework that simplifies building robust web apps by seamlessly integrating front-end and back-end development.
Your Goal
You will build a "Smart Notes" application where users can create, view, and delete their personal notes. This hands-on experience will teach you the core concepts of SvelteKit.
Key Features You'll Implement:
- UI Components: You'll use Svelte 5's new reactive primitives, called runes, to build your user interface.
- Database Integration: You'll connect to a SQLite database using the Drizzle ORM to define your data schema and manage notes.
- Server-Side Logic: You'll use SvelteKit's form actions to handle creating and deleting notes securely on the server.
- Data Loading: You'll use
load
functions to fetch data server-side and render it efficiently. - User Sessions: You'll implement a simple cookie-based session to ensure users only see their own notes.
The project files are already set up for you to begin!
-
Challenge
Database Schema with Drizzle ORM
Every data-driven application needs a database schema. You'll use Drizzle, a modern TypeScript ORM (Object-Relational Mapping) library, to define the structure of the data. It provides a type-safe way to interact with the database.
The application will have two main entities:
users
andnotes
. You'll define these insrc/lib/server/db/schema.ts
. A note will belong to a user, creating a relationship between the two tables. With the schema defined, you need to tell Drizzle where to find it and where to place the migration files. These migration files contain the SQL commands to create or update the database tables. Now that your schema and configuration are ready, you can create and apply the database migration. Run the following command in the Terminal to generate the SQL files:npm run db:generate
Then, run this command to apply the migration to your database:
npm run db:push
With the database set up, you can now build the user interface.
Running the Application
In the Terminal tab, start the development server by running the following command:
npm run dev
This will start the application, and you can view your progress in the Web Browser.
-
Challenge
Building the UI with Svelte 5
A great application needs a clean and functional user interface. You'll build the UI using Svelte components. Svelte makes it easy to create reusable, encapsulated pieces of UI.
You'll create two main components:
NoteCard
– displays a single noteNoteForm
– the input form
The
NoteCard.svelte
andNoteForm.svelte
files have already been created for you. You’ll update these files in the following tasks. Great! The basic UI components are ready. Next, you'll fetch data from the database and display it using these components. -
Challenge
Loading and Displaying Notes
To get data into our Svelte components, you use SvelteKit's
load
functions. Aload
function in a+page.server.ts
file runs on the server before the page is rendered. It can fetch data from a database or an API and pass it to the corresponding+page.svelte
component as adata
prop.This is a core concept in SvelteKit that enables server-side rendering (SSR) and provides a powerful data-loading pattern. Now that the
load
function is providing the data, render it in your page component. -
Challenge
Handling Form Submissions with Actions
Handling form submissions is a fundamental part of any web app. SvelteKit makes this incredibly easy and secure with form actions. Actions are server-side functions that run when a form is submitted. They live alongside your
load
function in+page.server.ts
.This approach works even if JavaScript is disabled and prevents you from having to create separate API endpoints for form handling. With the action defined, any
POST
request from a form on this page will be handled by the server-side logic. Now, add user context to the app. -
Challenge
Implementing User Sessions and Deleting Notes
The app needs to distinguish between different users. In this step, you'll implement a simple session mechanism using cookies.
A server hook (
src/hooks.server.ts
) is a file that exports ahandle
function that runs for every request made to your server. You'll use this to check for auserId
cookie and create one if it doesn't exist. With the user's ID available on every request, you can now scope the data operations to the current user. Finally, you'll add the ability to delete notes. You'll create a new named action for this. While a page can only have one default action, it can have multiple named actions, which are triggered by adding a query parameter to the form'saction
attribute (e.g.,action="?/delete"
). -
Challenge
Conclusion
Congratulations on completing the lab! You have successfully built a full-stack Smart Notes application from the ground up using SvelteKit.
What You've Learned
- Full-stack Structure: You've seen how SvelteKit organizes an application with file-based routing.
- Data Loading: You implemented server-side data fetching with
load
functions. - Form Handling: You used secure form
actions
to handle creating and deleting data. - Database Integration: You defined a schema and interacted with a database using the Drizzle ORM. -Server Hooks: You implemented a simple session management system using server hooks and cookies.
SvelteKit is a powerful tool for modern web development, and you now have the foundational skills to build your own fast, scalable, and enjoyable-to-develop applications. Keep exploring and building!
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.