This boilerplate is a starting point for building a FastAPI backend using PostgreSQL with a Vue3 frontend.
It includes OAuth2 authentication with JWT tokens, and a simple user CRUD.
Note : For
Vue: Option API
+VueX
version, please check out archived-2023-11-22 branch
localhost
for frontend
localhost:5001/docs
for backend swagger docs
Click image to watch demo video on YouTube ☝️
- FastAPI backend with PostgreSQL database
- SQLAlchemy CRUD with async support
- Simple User CRUD
- OAuth2 authentication with JWT tokens
- Store refresh token in
httpOnly
cookie, access token in memory ( Pinia store ) - Vue3 frontend with Pinia store
- Docker Compose for development and production
app.py
FastAPI application files/api
API endpoints/auth
- OAuth2 authentication
get_current_user
dependency
/crud
- user related CRUD utilities
- database session dependency
/database
Database configuration files/models
SQLAlchemy models usingdeclarative_base
/schemas
Pydantic schemas
PostgreSQL 15.1
image from Docker Hub- exposed on port
5432
- volume
postgres_data
for persistent data
Vite
Frontend build tool/views
Frontend page views- use
RefreshView.vue
as middleware to refresh JWT tokens
- use
/store
Pinia store ( usingData Provider Patten
)/router
Vue router/api
API endpointsreq.js
axios
request wrapper , handle401
unauthorized error to refresh JWT tokens- use
import.meta.env.VITE_APP_API_URL
to load API url from.env
file
-
.env
for postgres databasePOSTGRES_USER
POSTGRES_PASSWORD
POSTGRES_DB
-
backend/.env
for backendPORT
RELOAD
DATABASE_URL
Should be same as above setting dot fileJWT_ALGORITHM
ACCESS_TOKEN_SECRET
REFRESH_TOKEN_SECRET
ACCESS_TOKEN_EXPIRE_MINUTES
REFRESH_TOKEN_EXPIRE_MINUTES
-
nginx/nginx.conf
for nginx server- Note : backend hostname should be same as
docker-compose.yml
service name
- Note : backend hostname should be same as
-
frontend/.env
for development API url -
frontend/.env.production
for production API url
docker-compose.yml
Docker Compose configuration fileDockerfile
Dockerfile for frontend nginx server with production buildbackend/Dockerfile
Dockerfile for backend with hot reload
docker-compose up -d --build
- Database
docker run --name fastapi_vue_oauth2_postgresql -e POSTGRES_USER=fastapi_vue_user -e POSTGRES_PASSWORD=fastapi_vue_password -e POSTGRES_DB=fastapi_vue_dev -p 5432:5432 -d -v postgres_data_dev:/var/lib/postgresql/data postgres:15.1
- Backend
Note : shuold change in changeDATABASE_URL
toDEV_DATABASE_URL
inbackend/.env
- Poetry
cd backend poetry install poetry shell python3 run.py
- Create virtual environment
cd backend python3 -m venv venv source venv/bin/activate pip3 install -r requirements.txt python3 run.py
- Frontend
cd frontend yarn dev
Still working on it on features/k8s branch !
Feel free to open an issue !
Pull requests are welcome.
Any contributions you make are greatly appreciated.