Structure a Flask React Monorepo

June 8, 2019

This is my project structure for a Flask server and React client residing in the same git repository. It's fairly similar to the many NodeJS, React monorepos out there where the server code will be in the server subdirectory and the client code will reside in the client subdirectory.

First, let's start by creating the project directory and intialize the git repository:

mkdir flask-react-monorepo
cd flask-react-monorepo
git init

Let's create a virtual environment for the repo with venv and place it in the venv directory inside the project. We will want to add this to our .gitignore file also. Once we have our virtual environment set up, we'll need to let our system know to use it.

python -m venv venv
echo venv/ > .gitignore
source venv/bin/activate

Let's install our dependencies, first for Python, then keep a list of the dependencies in a file called requirements.txt.

pip install Flask
pip freeze > requirements.txt

requirements.txt (your versions may vary)


The canonical way to structure flask apps have a Python package named whatever the actual app is supposed to be within a subdirectory. Check out the Flask tutorial here for more details.

For now, let's call the Flask server server. It can easily be api or something else you prefer.

mkdir server

For our Flask setup to work, we will need to create a file named in the root of our project directory:

from setuptools import setup


Now, let's just set up a simple Flask app in the server Python package by having an file in our server directory.


from flask import Flask

app = Flask(__name__)

def index():
    return 'Hello, World!'

Now comes for the fun part of integrating our JavaScript client. I'll simply use create-react-app for this, but you can pretty much replace this with any front end framework or CLI tools you like.

From the project root:

create-react-app client

Now, we can go and type FLASK_APP=server flask run from the project root to run our development server and, from another terminal, run yarn start from the client directory to run the development client, but that's just 1 too many steps for me.

To streamline the development process, I'll also use yarn in the project root and install the concurrently package.

From the root directory:

yarn init
yarn add -D concurrently
echo node_modules/ >> .gitignore

Now, let's add some scripts to the package.json file yarn init generated. I want yarn client to run the client development server and yarn server to run the backend development server. I also want to call yarn start from the root to run both concurrently.

  "name": "flask-react-monorepo",
  "version": "1.0.0",
  "main": "index.js",
  "author": "Warren Wong <>",
  "license": "MIT",
  "devDependencies": {
    "concurrently": "^4.1.0"
  "scripts": {
    "start": "concurrently \"yarn client\" \"yarn server\"",
    "client": "cd client && yarn start",
    "server": "FLASK_APP=server flask run"

If everything works out, your back end will be on port 5000 and your client will be on port 3000 by default.


I'd like to send you a weekly recap of all the articles I write as well as my take on the latest news on web development with Vue, React, Elixir/Phoenix, and others. Just fill out your email and name below!

Prev: Setting Up TypeScript for Node
Next: Object Oriented Playing Cards in Python