Git Product home page Git Product logo

cradle-platform's Introduction

Cradle VSA System: React Front-End and Python (Flask) Back-End

License

React front-end web application and Python back-end web server for the Cradle VSA System, a technological health care system to improve maternal care and reduce preventable maternal deaths in Ugandan villages.

Setup Instructions

Requirements

Development environments are supported on Windows, macOS, and Linux. If you are on Windows Home Edition, note that there may be some issues getting Docker to work correctly. Note that the use of Docker in development environments is entierly optional, and only really recommended for running the database.

To run the database inside docker, run the following command:

docker run --name cradle-db -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql:5.7

Note that you can name the container whatever you would like by changing "cradle-db", and set the password by changing "password" to something different.

Front-End Web Application

Setting up the frontend is simple so we'll cover it first.

Install npm.

Install the necessary packages:

npm install

Start the server locally:

npm run start

Build the files:

npm run build

Install virtualenv (Optional)

virtualenv is a tool which allows you to install all of your Python project's dependencies into an isolated location instead of installing them globably on your system which could conflict with dependencies used by other projects. We recommend setting it up for Cradle development but it is not necessary.

virtualenv can be installed via pip:

pip install virtualenv

Once installed, navigate to the server directory and run:

virtualenv venv

This creates a venv folder within the server directory which is used to store all the projects dependencies.

Now, each time you want to run the server you need to first load the environment into your terminal session. The command to do this varies depending on your shell (some common ones are listed bellow), but the general idea is that there is a script named activate somewhere in server/venv/ that you run to load the environment.

For Powershell it's the .ps1 file, and CMD the .bat file, the command for either is simply:

.\venv\Scripts\active

For bash:

source ./venv/bin/activate

For fish:

source ./venv/bin/activate.fish

If everything worked correctly, you should see a little (venv) before your usual prompt telling you that the virtual environment has been loaded. For example, in Powershell:

PS C:\U\j\D\f\c\server> .\venv\Scripts\activate
(venv) PS C:\U\j\D\f\c\server>

Install Dependencies

From the server directory, with virtualenv (optional) loaded:

pip install -r ./requirements.txt

Note that if you're on Windows, the uwsgi dependency will fail to install. It's not required for development builds so you can simply remove it from requirements.txt and run the command again. Remember to add it back once you've finished though as it is used when building for production.

Configuration

The server pulls configuration from a file named .env in the server directory. Create this file now and put the following into it:

DB_USERNAME=root
DB_PASSWORD=password
DB_HOSTNAME=localhost
DB_PORT=3306
DB_NAME=cradle
[email protected]
EMAIL_PASSWORD=password

If you have a different database user/password, make sure to update the corresponding variables here to match.

The EMAIL_USER and EMAIL_PASSWORD are required by some legacy code an may not be required in the future, but for now they are.

Database Setup

Creating The Database

Once you have MySQL installed an the MySQL service running, or have Docker installed and have created a MySQL container using the command mentioned in the requirements section, it's time to setup the database.

The database itself is simply named cradle and needs to be created manually before the schema can be applied. In a MySQL prompt, create a new database like so:

If running your database inside docker, you can get a MySQL prompt like so:

docker exec -it cradle-db mysql -u root -ppassword

This is assuming the container is named cradle-db and your root password is password. No -ppassword is not a typo, that's just how MySQL handles passwords on the command line.

mysql> create database cradle;

Once that's done you can exit the MySQL prompt.

Applying The Schema

The database schema is managed by flask, our backend framework. To create all the required tables, simply run the following from the server directory (with vertualenv loaded if you decided to use it):

flask db upgrade

This command runs though and applies all of our database migrations to the database that you just created in the previous step. If you're interested you can hop back into that MySQL prompt and view all the new tables.

Seeding Data

Data seeding is handled by the manage.py script in the server directory. There are 3 commands to seed data into the database, all of which give you different amounts of data:

  • python ./manage.py seed_minimal: seeds the bare minimum amount of data to get the application running, useful if you want to debug something without having to trudge through unrelated data
  • python ./manage.py seed_test_data: seeds data required to run the unit tests
  • python ./manage.py seed: seeds a generous amount of random data

Starting The Server

Finally it's time to start the server! To do so simply run:

flask run

cradle-platform's People

Contributors

iamwaswa avatar fazlalizadeh-faraz avatar vinsonly avatar j-schwar avatar aktoro avatar jleung51 avatar chloe0416 avatar kisubs avatar katcc avatar sraturi avatar dependabot[bot] avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.