This project is an example of how SvelteKit, FastAPI, and MongoDB can be dockerized and ran via docker compose. Note that, as of right now, this is not perfect. This project is meant to serve as an example/reference. However, it can be manually converted into a starting template.
- Clone project:
git clone https://github.com/smartgoo/sveltekit-fastapi-mongodb.git
cd sveltekit-fastapi-mongodb
- Install SvelteKit packages:
npm install frontend/
- Build the containers:
docker-compose build
- Bring up the containers:
docker-compose up
- Open the web app:
http://localhost:5173/
- Open the FastAPI OpenAPI docs:
http://localhost:8000/docs
This project was updated on October 23 2022, and uses the latest versions available at the time.
- Node v16
- SvelteKit 1.0.0-next.522
- Python 3.10.8
- FastAPI 0.85.1
Please note this process is incomplete, but the process of converting a starter template would look roughly like this:
- Remove FastAPI endpoints from
backend/app/api/endpoints
and updatebackend/app/api/api.py
accordingly. - Remove SvelteKit routes from
frontend/src/routes
. - Remove SvelteKit components from
frontend/src/lib
.
I hope to add more features to this project, and convert it to a full starter template at some point. Features on the roadmap are:
- Authentication and code to illustrate how it could work
- Nginx with HTTPS
- Scaffold SvelteKit (
frontend
) codebase a little bit more - Scaffold testing for SvelteKit and FastAPI
- FastAPI background task examples
A few existing existing project templates were referenced while building this. A big thanks to these:
- FastAPI MongoDB Real World Example
- FastAPI Project Template
- Jeff Astor's FastAPI Blog Posts heavily influenced authentication