- FastAPI (Python 3.8)
- JWT authentication using OAuth2 "password flow" and PyJWT
- React (with Typescript)
- react-router v5 to handle routing
- MongoDB for the database
- PyMongo for ODM
- Pytest for backend tests.
- Docker Compose for development
- Nginx as a reverse proxy to allow backend/frontend on the same port
First, install cookiecutter if you don't already have it:
pip3 install cookiecutter
Second, install docker-compose if you don't already have it:
docker-compose installation official docs.
Then, in the directory you want your project to live:
cookiecutter gh:ajthr/fastapi-react-mongodb
Input Variables
- project_name [default fastapi-react-mongodb]
- project_slug [default fastapi-react-mongodb] - this is your project directory
- external_database [default n] - whether to use any external database like mongodb atlas
- external_db_uri [optional default None] - database uri to connect to external database if using one.
- mongodb_user [default root]
- mongodb_password [default password]
- secret_key [default super_secret]
Change into your project directory and run:
docker-compose build
This will build and run the docker containers.
It may take a while to build the first time it's run since it needs to fetch all the docker images.
Once you've built the images once, you can simply use regular docker-compose
commands to manage your development environment, for example to start your
containers:
docker-compose up -d
Once this finishes you can navigate to the localhost port, you should see the slightly modified create-react-app page.
To run test for the template, run:
chmod +x ./test.sh
./test.sh
To run test for api, run
docker-compose run --rm api sh -c "pytest"
to run test for web, run
docker-compose run --rm web sh -c "npm run test"