{"id":16999523,"url":"https://github.com/jonasrenault/fastapi-react-mongodb-docker","last_synced_at":"2025-04-05T20:03:25.946Z","repository":{"id":103531940,"uuid":"606435224","full_name":"jonasrenault/fastapi-react-mongodb-docker","owner":"jonasrenault","description":"A FARM stack boilerplate with docker integration. This is a starting template for projects using a Python FastAPI server, MongoDB  storage and React frontend, with docker setup for development and production.","archived":false,"fork":false,"pushed_at":"2024-10-10T14:27:14.000Z","size":533,"stargazers_count":109,"open_issues_count":0,"forks_count":36,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T19:02:06.948Z","etag":null,"topics":["docker","farm-stack","fastapi","fastapi-boilerplate","fastapi-docker","fastapi-mongodb","fastapi-template","mongodb","python3","react","reactjs","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonasrenault.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-25T13:41:24.000Z","updated_at":"2025-03-21T13:01:17.000Z","dependencies_parsed_at":"2023-11-10T15:31:02.549Z","dependency_job_id":"c3fad413-694b-4b56-9bc7-e1a1afceb679","html_url":"https://github.com/jonasrenault/fastapi-react-mongodb-docker","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonasrenault%2Ffastapi-react-mongodb-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonasrenault%2Ffastapi-react-mongodb-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonasrenault%2Ffastapi-react-mongodb-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonasrenault%2Ffastapi-react-mongodb-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonasrenault","download_url":"https://codeload.github.com/jonasrenault/fastapi-react-mongodb-docker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393552,"owners_count":20931811,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","farm-stack","fastapi","fastapi-boilerplate","fastapi-docker","fastapi-mongodb","fastapi-template","mongodb","python3","react","reactjs","typescript"],"created_at":"2024-10-14T04:09:06.495Z","updated_at":"2025-04-05T20:03:25.926Z","avatar_url":"https://github.com/jonasrenault.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fastapi-React-Mongodb-Docker\n\n![Tests](https://github.com/jonasrenault/fastapi-react-mongodb-docker/actions/workflows/test.yml/badge.svg)\n![Build](https://github.com/jonasrenault/fastapi-react-mongodb-docker/actions/workflows/build.yml/badge.svg)\n[![License](https://img.shields.io/badge/License-MIT-yellow)](LICENSE)\n![python_version](https://img.shields.io/badge/Python-%3E=3.10-blue)\n\nThis is a template application for a FARM stack. FARM stands for FastAPI, React, MongoDB.\n\n## Features\n\n### Clean design with minimal dependencies\n\n[![API docs](frontend/public/farmd-1.png)](https://github.com/jonasrenault/fastapi-react-mongodb-docker)\n\n### Basic user management with OAuth2 SSO\n\n[![API docs](frontend/public/farmd-2.png)](https://github.com/jonasrenault/fastapi-react-mongodb-docker)\n\n## Project structure\n\nThe project is composed of :\n\n* a backend API server built with FastAPI located in the [backend](backend) dir.\n* a frontend web app build with React and located in the [frontend](frontend) dir.\n\n## Running the application locally for development\n\nTo run the application manually in a terminal, see both the [backend](backend/README.md) and [frontend](frontend/README.md)'s READMEs for instructions.\n\n## Running the application with Docker\n\nThe project contains Docker configuration files to run the application with Docker compose. Two docker-compose files are provided with configuration for `dev` and for `production` environments. The Docker configuration is largely adapted from Tiangolo's [Full stack FastAPI template](https://github.com/fastapi/full-stack-fastapi-template) project.\n\n### Local development with Docker\n\nThe local development file for docker is [docker-compose.yml](./docker-compose.yml).\n\nStart the stack with Docker Compose:\n\n```bash\ndocker compose watch\n```\n\nYou can then open your browser and interact with these URLs:\n\n* Frontend, served with vite with hot reload of code: http://localhost\n\n* Backend, JSON based web API based on OpenAPI, with hot code reloading: http://localhost/api/v1\n\n* Automatic interactive documentation with Swagger UI (from the OpenAPI backend): http://localhost/docs\n\n* Alternative automatic documentation with ReDoc (from the OpenAPI backend): http://localhost/redoc\n\n* Traefik UI, to see how the routes are being handled by the proxy: http://localhost:8090\n\nOnce the stack is up, to check the logs, run:\n\n```bash\ndocker compose logs\n```\n\nTo check the logs of a specific service, add the name of the service, e.g.:\n\n```bash\ndocker compose logs backend\n```\n\nTo get access to a bash session inside a container (e.g. the `backend`):\n\n```console\n$ docker compose exec backend bash\n```\n\n\n### Docker Compose settings for production\n\nThe [docker-compose-prod.yml](./docker-compose.prod.yml) file contains the configuration to run the application with docker in a production environment, on a host server. To run the application with this file, run\n\n```console\ndocker compose -f docker-compose.prod.yml up -d\n```\n\n**Note:** This will not work out of the box, mainly because the `docker-compose-prod.yml` configures a traefik proxy with ssl enabled that will try to fetch ssl certificates from Let's Encrypt, which will not work unless you specify a valid hostname accessible on the internet. However, to deploy the application in production on a server, you only need to set the required env variables in the [.env](./.env) file.\n\nWhen using the production configuration, the frontend app is built into static files and the app is served by an nginx server. The [nginx configuration file](frontend/nginx.conf) is in the frontend dir.\n\n### Docker Compose files and env vars\n\nBoth the [docker-compose.yml](./docker-compose.yml) and [docker-compose-prod.yml](./docker-compose.prod.yml) files use the [.env](./.env) file containing configurations to be injected as environment variables in the containers.\n\nThe docker-compose files are designed to support several environments (i.e. development, testing, production) simply by setting the appropriate variable values in the `.env` file.\n\nThe [.env](./.env) file contains all the configuration variables. The values set in the `.env` file will override those that are set in the frontend `.env` files for local development.\n\nThe `.env` file that is commited to the github repository contains example values which are ok to use for testing and development, but which should be changed when running the application in production (admin passwords, secret keys, client ids, etc.). During deployment in production, the .env file is replaced with one containing the appropriate values.\n\n## Setting up Single Sign-On (SSO) with google\n\nTo setup SSO and enable the `Sign-In with Google` button, you must first obtain a client-id and secret token from Google. Follow [these steps](https://developers.google.com/identity/protocols/oauth2) to obtain client credentials from your [Google Cloud Console](https://console.cloud.google.com/).\n\nCreate a new project, and from the `APIs \u0026 Services` menu, first create an `OAuth consent screen` for you application, then add an `OAuth 2.0 Client Id` in the `Credentials` menu. Select `Web application` as the application type. In the `Authorized redirect URIs`, add your hostname with the `api/v1/login/google/callback` endpoint. For instance, if testing locally while running the backend app with `uvicorn`, add `http://localhost:8000/api/v1/login/google/callback` (use `http://localhost/api/v1/login/google/callback` if running the application in dev with docker). If your application is hosted on a domain name, add it to the list of URIs (remember to update `http` to `https` when using SSL).\n\nOnce you've create a client-id and token in your Google cloud console, copy those into your `.env` file's `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` variables.\n\n## Setting up automatic build of the docker images in github\n\nThe project has a [build workflow](./.github/workflows/build.yml) configuration to build the docker images for production and publish those into your Github package registry. To do this, you must first create a [Github Environment](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment) for your project (call this environment `prod` or update the environment name in the workflow configuration.\n\nYou also need to add an environment secret variable `SERVER_ENV_PROD` which should contain the root `.env` file with the variables set for your production environment (simply copy-paste the contents of the env file as the github secret). This secret environment variable will be used by the github workflow to build the docker images with the [docker-compose.prod.yml](./docker-compose.prod.yml) file.\n\nFinally, enable write permission for the `GITHUB_TOKEN` to enable pushing images to your package registry: Go to `Settings` \u003e `Actions` \u003e `General` and check `Read and write permissions` under `Workflow permissions`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonasrenault%2Ffastapi-react-mongodb-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonasrenault%2Ffastapi-react-mongodb-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonasrenault%2Ffastapi-react-mongodb-docker/lists"}