Menu

How to Build a SvelteKit SPA with FastAPI Backend
πŸ“°

How to Build a SvelteKit SPA with FastAPI Backend

DEV CommunityΒ·TortoiseΒ·6 months ago
#xRnk4LMz
#install#start#svelte#fastapi#todo
Reading 0:00
15s threshold

Originally published at turtledev.io

In my previous post , I talked about why I moved from SvelteKit SSR to a Svelte SPA + FastAPI architecture. Today, I want to show you my setup with a simple project.

We'll build a simple todo list app to demonstrate how the frontend and backend communicate, and how to write less and type-safe code by using Orval to auto-generate TypeScript API clients from FastAPI's OpenAPI specs.

Building a production app? Check out FastSvelte - a production-ready FastAPI + SvelteKit starter with authentication, payments, and more built-in.

Project Structure

todo-app/ β”œβ”€β”€ backend/ # FastAPI Python backend β”‚ β”œβ”€β”€ main.py # FastAPI app β”‚ β”œβ”€β”€ models.py # Pydantic models β”‚ └── requirements.txt β”‚ └── frontend/ # SvelteKit SPA β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ routes/ # Pages β”‚ └── lib/ # API client & components └── package.json

Enter fullscreen mode

Exit fullscreen mode

Backend: FastAPI Setup

Create a backend directory and set up a virtual environment:

cd backend python3 -m venv .venv source…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.