https://github.com/rmwiesenberg/template-fastapi-react-k8s
Template repo for FastAPI + React with auto-generation of Typescript models from React. Includes actions to lint, test, build, and deploy to k8s and github pages simultaneously.
https://github.com/rmwiesenberg/template-fastapi-react-k8s
fastapi k8s pages pydantic react template typescript
Last synced: 5 months ago
JSON representation
Template repo for FastAPI + React with auto-generation of Typescript models from React. Includes actions to lint, test, build, and deploy to k8s and github pages simultaneously.
- Host: GitHub
- URL: https://github.com/rmwiesenberg/template-fastapi-react-k8s
- Owner: rmwiesenberg
- License: mit
- Created: 2024-08-24T19:48:16.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-06T17:00:17.000Z (almost 2 years ago)
- Last Synced: 2025-04-05T19:20:49.196Z (about 1 year ago)
- Topics: fastapi, k8s, pages, pydantic, react, template, typescript
- Language: TypeScript
- Homepage:
- Size: 218 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# template-fastapi-react-k8s
Template repo for FastAPI + React with auto-generation of Typescript models from React. Includes actions to lint, test,
build, and deploy to a locally-managed k8s instance and GitHub Pages simultaneously.
This template is python-first, meaning most api/control decisions are populated from the backend first, and then
recreated on the front-end. Namely by creating the model definition first in [api/model](template/model.py) and then running
the model generation scripts to provide the same structure to the front-end.
## Structure and Layout
The managed python environment starts in the root directory, with the `pyproject.toml` and is backed up by several
sub-directories and files:
```
[Development]
- api/ > fastapi code
- scripts/ > python scripts external to the api
- template/ > core logic and model for the api
- tests/ > tests for the api or scripts
- web/ > react-based single-page web app
[Deployment]
- k8s/ > kubernetes deployment scripts (managed by .github/worflows)
- Dockerfile > api image deployed to docker.io and pulled by k8s
- VERSION > release version echo file (updated by deploy workflow)
```
### One-time setup
After this repo is used as a template, there are several one-time changes that should be made to ensure all scripts are
ready for initial use and deployment.
#### Connect to api
Replace urls (`XXXX.template.com`) in api and web with your url for web and k8s respectively.
#### K8s deployment setup
1. rename all instances of `template` in [k8s](k8s) to your app name
2. update the email in `encrypt.yml`
3. update ENV variables in `.github/workflows/deploy.yml`
4. run `login.sh` wherever your k8s is hosted to login to docker.io
5. run `create-service-account.sh` to create a service account and get your secret information to use as a GitHub action
secret `K8S_SECRET`
## Development
### Installation
- `poetry install`
- (in `web/`) `yarn install`
### Sharing model data
1. Export model from python: `poetry run gen-model`
2. Translate schema to TypeScript (in `web/`): `yarn run gen-model`
### Local development
- run api (in `api/`): `poetry run fastapi dev`
- run web (in `web/`): `yarn run start`
- `REACT_APP_API_URL=http://localhost:8000`