- FastAPI
- React Admin
- SQLAlchemy and Alembic
- Pre-commit hooks (black, autoflake, isort, flake8, prettier)
- Github Action
- Dependabot config
- Docker images
The frontend of this project uses React Admin. Follow the quick tutorial to understand how React Admin works.
Start a local development instance with docker-compose
docker-compose up -d
# Run database migration
docker-compose exec backend alembic upgrade head
Now you can navigate to the following URLs:
- Backend OpenAPI docs: http://localhost:8000/docs/
- Frontend: http://localhost:3000
Keep your code clean by using the configured pre-commit hooks. Follow the instructions here to install pre-commit. Once pre-commit is installed, run this command to install the hooks into your git repository:
pre-commit install
The backend setup of docker-compose is set to automatically reload the app whenever code is updated. However, for frontend it's easier to develop locally.
docker-compose stop frontend
cd frontend
yarn
yarn start
If you want to develop against something other than the default host, localhost:8000, you can set the REACT_APP_API_BASE
environment variable:
export REACT_APP_API_BASE=http://mydomain.name:8000
yarn start
Don't forget to edit the .env
file and update the BACKEND_CORS_ORIGINS
value (add http://mydomain:3000
to the allowed origins).
If you add a dependency, you'll need to rebuild your containers like this:
docker-compose up -d --build
Instead of writing frontend API client manually, OpenAPI Generator is used. Typescript bindings for the backend API can be recreated with this command:
yarn genapi
These two are the most used commands when working with alembic. For more info, follow through Alembic's tutorial.
# Auto generate a revision
docker-compose exec backend alembic revision --autogenerate -m 'message'
# Apply latest changes
docker-compose exec backend alembic upgrade head
The Backend
service uses a hardcoded database named apptest
. First, ensure that it's created
docker-compose exec postgres createdb apptest -U postgres
Then you can run tests with this command:
docker-compose run backend pytest --cov --cov-report term-missing
There's a monolith/single docker image that uses FastAPI to serve static assets. You can use this image to deploy directly to Heroku, Fly.io or anywhere where you can run a Dockerfile without having to build a complicated setup out of separate frontend and backend images.
Configure the build-push-action in .github/workflows/test.yaml
.
Created with FastAPI Starter