|
| 1 | +# FastAPI React MongoDB - Base Project Generator |
| 2 | + |
| 3 | +[](https://github.com/ajthr/fastapi-react-mongodb/actions/workflows/test.yml) |
| 4 | + |
| 5 | +<div> |
| 6 | +<img src="assets/fastapi-logo.png" alt="fastapi-logo" height="60" /> <img |
| 7 | +src="assets/react-logo.png" alt="react-logo" height="60" /> <img |
| 8 | +src="assets/typescript-logo.png" alt="typescript-logo" height="60" /> |
| 9 | +<img src="assets/mongodb-logo.png" alt="mongodb-logo" height="60" /> |
| 10 | +</div> |
| 11 | + |
| 12 | +## Features |
| 13 | + |
| 14 | +- **[FastAPI](https://fastapi.tiangolo.com/)** (Python 3.8) |
| 15 | + - JWT authentication using [OAuth2 "password |
| 16 | + flow"](https://fastapi.tiangolo.com/tutorial/security/simple-oauth2/) and |
| 17 | + PyJWT |
| 18 | +- **[React](https://reactjs.org/)** (with Typescript) |
| 19 | + - [react-router v5](https://reacttraining.com/react-router/) to handle routing |
| 20 | +- **[MongoDB](https://www.mongodb.com/)** for the database |
| 21 | +- **[PyMongo](https://pymongo.readthedocs.io/)** for ODM |
| 22 | +- **[Pytest](https://docs.pytest.org/en/latest/)** for backend tests. |
| 23 | +- **[Docker Compose](https://docs.docker.com/compose/)** for development |
| 24 | +- **[Nginx](https://www.nginx.com/)** as a reverse proxy to allow |
| 25 | + backend/frontend on the same port |
| 26 | + |
| 27 | +## Quick Start |
| 28 | + |
| 29 | +First, install cookiecutter if you don't already have it: |
| 30 | + |
| 31 | +```bash |
| 32 | +pip3 install cookiecutter |
| 33 | +``` |
| 34 | + |
| 35 | +Second, install docker-compose if you don't already have it: |
| 36 | + |
| 37 | +[docker-compose installation official |
| 38 | +docs](https://docs.docker.com/compose/install/). |
| 39 | + |
| 40 | +Then, in the directory you want your project to live: |
| 41 | + |
| 42 | +```bash |
| 43 | +cookiecutter gh:ajthr/fastapi-react-mongodb |
| 44 | +``` |
| 45 | + |
| 46 | +<details><summary>Input Variables</summary> |
| 47 | + |
| 48 | +- project_name [default fastapi-react-mongodb] |
| 49 | +- project_slug [default fastapi-react-mongodb] - this is your project directory |
| 50 | +- external_database [default n] - whether to use any external database like mongodb atlas |
| 51 | +- external_db_uri [optional default None] - database uri to connect to external database if using one. |
| 52 | +- mongodb_user [default root] |
| 53 | +- mongodb_password [default password] |
| 54 | +- secret_key [default super_secret] |
| 55 | + |
| 56 | +</details> |
| 57 | + |
| 58 | +## Develop |
| 59 | + |
| 60 | +Change into your project directory and run: |
| 61 | + |
| 62 | +```bash |
| 63 | +docker-compose build |
| 64 | +``` |
| 65 | + |
| 66 | +This will build and run the docker containers. |
| 67 | + |
| 68 | +It may take a while to build the first time it's run since it needs to fetch all |
| 69 | +the docker images. |
| 70 | + |
| 71 | +Once you've built the images once, you can simply use regular `docker-compose` |
| 72 | +commands to manage your development environment, for example to start your |
| 73 | +containers: |
| 74 | + |
| 75 | +```bash |
| 76 | +docker-compose up -d |
| 77 | +``` |
| 78 | + |
| 79 | +Once this finishes you can navigate to the localhost port, you should see the slightly modified create-react-app page. |
| 80 | + |
| 81 | +## Testing |
| 82 | + |
| 83 | +To run test for the template, run: |
| 84 | + |
| 85 | +```bash |
| 86 | +chmod +x ./test.sh |
| 87 | +./test.sh |
| 88 | +``` |
| 89 | + |
| 90 | +To run test for api, run |
| 91 | +```bash |
| 92 | +docker-compose run --rm api sh -c "pytest" |
| 93 | +``` |
| 94 | + |
| 95 | +to run test for web, run |
| 96 | +```bash |
| 97 | +docker-compose run --rm web sh -c "npm run test" |
| 98 | +``` |
0 commit comments