A simple todo app demonstrating how to build a full-stack application with:
- Backend: FastAPI (Python) with Pydantic models
- Frontend: SvelteKit SPA with TypeScript
- Type Safety: Auto-generated TypeScript API client using Orval
This code accompanies the blog post: Svelte SPA and FastAPI Integration Tutorial
svelte-spa-fastapi-tutorial/
├── backend/ # FastAPI Python backend
│ ├── main.py # FastAPI app with CRUD endpoints
│ ├── models.py # Pydantic models for Todo
│ └── requirements.txt
│
└── frontend/ # SvelteKit SPA
├── src/
│ ├── routes/ # Pages
│ └── lib/ # API client & components
├── orval.config.cjs # Orval configuration for API client generation
└── package.json
- Python 3.11+
cd backend
pip install -r requirements.txt
uvicorn main:app --reload
- API runs at
http://localhost:8000
- API docs at
http://localhost:8000/docs
- Node.js 18+
cd frontend
npm install
With the backend running, generate the TypeScript API client:
npm run generate
This creates typed API functions from the backend's OpenAPI spec.
npm run dev
Frontend runs at http://localhost:5173
- Make changes to backend models or endpoints
- Restart backend server
- Run
npm run generate
in frontend to update API client - TypeScript will show errors if frontend needs updates
- Update frontend code to match new API
- Type Safety: Backend Pydantic models → OpenAPI spec → TypeScript types
- Auto-generated Client: Changes in backend automatically flow to frontend
- Simple Architecture: Clear separation between frontend and backend
- Local Development: CORS configured, both services run locally
- This is a tutorial/demo project - not production-ready
- Uses in-memory storage (data is lost on restart)
- No authentication or authorization
- CORS is wide open for local development
- For production use, check out FastSvelte
Read the full tutorial: Svelte SPA and FastAPI Integration Tutorial