-
Notifications
You must be signed in to change notification settings - Fork 1
Development ‐ Backend
Griddle's backend is an OpenAPI-enabled HTTP API written in python using FastAPI.
- Python 3.10
- recommend using
pyenv
for managing python versions
- recommend using
-
pipenv
- (
python -m pip install --user pipenv
)
- (
- Docker
- (if on Unix system) postgres libraries
We use FastAPI for our backend. To get started, cd
into this backend
folder, and create a virtualenv with our dependencies using pipenv install
.
Make sure to spin up our development docker-compose.yml
. To start up both a local postgres database and localstack (s3 simulator) run:
docker-compose up -d
Enter a shell using pipenv shell
.
To start a dev server, run:
uvicorn main:app --reload
After the initial run of the commands above, you might encounter issues with dependency modules missing. Try running the commands below: (Make sure you are in virtualenv!)
pipenv requirements > requirements.txt
pip install -r requirements.txt
If there're still erros with modules such as uvicorn
and bcrypt
, pip install
these packages individually, and then try starting the server.
We use a couple libraries to streamline the creation of our backend API.
-
FastAPI to build routes and handlers. This automatically generates OpenAPI docs which can be found at localhost:8000/docs. Most things you'd want to do are covered in their docs.
-
SQLAlchemy to model and access our database.
-
Alembic to auto-generate and run database migrations. These are kept in the
migrations
folder. -
boto3 to access S3 (or in our deployed case Cloudflare R2).
-
sqladmin to view the DB with a nice web GUI. Can be found at localhost:8000/admin.
Here are some key files to get started:
-
routers/api_v1/assets.py for routes that have to do with assets.
-
util/crud.py for CRUD logic used in the above file.
-
If updating routes, make sure to sync them with the frontend. See the frontend README for how to do this.
-
-
database/models.py for our database models. Make sure to do matching edits to the below file.
- schemas/models.py are Pydantic models that the routes and CRUD logic will use.
When you're ready to make a full migration (change in the DB models) run the following in your virtualenv:
alembic revision --autogenerate
Then, commit the resulting autogenerated file in migrations
.