This repository contains a full stack web application template that runs on the FARM solution stack, which stands for:
- Flask, a backend Python web framework.
- Amazon Web Services, a cloud service that can host software.
- React, a frontend JavaScript web framework.
- MySQL, a relational database management system.
The FARM stack is more or less an extension of the LAMP stack with these notable changes:
- The middleware framework is explicit (Flask)
- Like the MEAN stack, it includes an application presentation layer (React)
- The environment which the software runs on is instead replaced by PaaS/IaaS cloud computing services (AWS)
- There is no opinion for which operating system to use
Flask is used to write the web APIs / middleware that can communicate between the web UI and the web backend / database. This is the core of the entire application that glues the pieces of the full stack application together.
Note that this particular template does not use an ORM, and instead uses the pymysql
module. This means developers need to write SQL queries, but can maximize the complexity of the queries they need to run on the database.
AWS is the cloud service which the application can be hosted on. We can host the entire software stack on the following services:
- AWS Lambda for hosting our applications on a serverless infrastructure. We can also choose to host our Flask APIs via Zappa, making deployment to production exceedingly easy.
- AWS RDS for hosting our database.
- AWS S3 for storing all sorts of other objects like images and files.
This means that developers can keep everything on one platform and minimize DevOps / IT work.
React is the framework which the web UI runs on. The React application may also be run on AWS Lambda with NodeJS.
This template uses JavaScript / JSX, but TypeScript may be used as well.
MySQL is the relational database which the web backend uses. This can also be hosted on AWS through its RDS service.
To run this web application, the following needs to be done:
- Setup a local MySQL instance using the schema in
db/
- Install modules for the API and UI
- Run the API and UI locally
To set up the MySQL instance, follow these steps:
- Create and connect to a MySQL database instance. The most common ways to do this are with MySQL Workbench or
mysql
on the Linux command line interface. - Run
sample.sql
within the instance. It will create a schema calledSampleInventory
and then initialize a table calledInventory
.
The codebase for the Flask API can be found in the api/
directory.
- Create a Python virtual environment with
virtualenv farm-stack
after navigating to that directory. - Activate it with
source farm-stack/bin/activate
- Navigate to
api/
and runpip3 install -r requirements.txt
to install all Python modules necessary for the API. - Open
dbcreds.py
in theapi/
directory and edit database credentials as needed.
- Activate the virtual environment from above.
- Run
python3 app.py
to run the API onhttp://localhost:8080
.
The codebase for the React UI can be found in the ui/
directory. This template uses yarn
as its package manager; it is crucial that developers do not mix other package managers like npm
when adding new modules.
Note that packages like react-bootstrap
are missing from this template.
- Run
yarn install
to install all dependencies required.
- Run
yarn start
to run in development mode. - Navigate to
http://localhost:3000
on the browser.