Git Product home page Git Product logo

shm's Introduction

SHM

Application Structure

The StakeHolderMap (SHM) uses a headless CMS approach, utilizing Python 3.6 and Flask.
For the Frontend TypeScript and ReactJs are used.
There are 4 different Docker Containers:

python-uwsgi
The flask application bundled with a uWSGI server as middleware to allow communication between flask and Nginx.
The uWSGI server is available on port 8080 (but unable to comprehend http requests with its current setup)

python-nginx
The Nginx server which handles requests from the frontend and passes them to the uWSGI server.
The Nginx server is available via localhost:8081 and should respond with alive, the health check.

tyepscript-nginx
The Nginx server which handles requests from the outside world.
The Nginx server is available via localhost:8082 and should respond with the ReactJS demo page.

adminer Database management webtool. Open localhost:8080 to connect to database. Use credentials from database.conf

postgres
The PostgreSQL database is available via port 5432.

Docker

Dockerfiles

The Dockerfiles are set up to avoid having build dependencies / files in the final docker image.

Docker Compose

The project uses docker-compose for the local stack. Relevant commands:

docker-compose build  
docker-compose up -d  
docker-compose stop

BackEnd Development

Virtual Environment

To keep dependencies between python applications clean, it is recommended to use python virtual environments. To install virtualenv, run the following command:

sudo pip3 install virtualenv

sudo is required so the flask binary is available system-wide. Installing in user-space requires you to add the binary manually to your path. virtualenv might also be available as a package provided by your linux distribution.
Once virtualenv is installed, head to ./app-backend. Inside execute the following commands:

virtualenv venv  
source venv/bin/activate

This will activate the virtual environment and set PATHs appropriately for the current terminal session. To deactivate use the command deactivate.
Once the virtual environment is activated, you can start installing dependencies via pip3. To get started, execute the following command:

pip3 install -r requirements.txt

This will install all existing dependencies for the project. When you add new dependencies update the requirements.txt with the following command:

pip3 freeze > requirements.txt

Development Server

If you don't need the full stack for your development, you can use flask's development server. To start it, run the following shell script (with your virtual environment activated):

./debug_server.sh

The development server is available on 127.0.0.1:5000 by default.

Testing

To run all tests, simply use the provided shell script:

./test.sh

If you don't want to use the script make sure the environment variables for the database connection are available.

Code Coverage

To keep an eye on our code test coverage, there is another shell script available:

./coverage.sh

Additionally, you can add the argument html to the script to open a html version of the coverage result in your browser, providing more in-depth feedback.

Database Migrations

To setup your database enter the docker container python-uwsgi, change to the /shm directory and execute the command flask db upgrade.
If you need to create a new migration, use the command flask db migrate. For further documentation see https://flask-migrate.readthedocs.io/en/latest/

Resources

Flask: http://flask.pocoo.org/docs/1.0/quickstart/
SQLAlchemy: https://www.pythoncentral.io/introductory-tutorial-python-sqlalchemy/
Flask SQLAlchemy: http://flask-sqlalchemy.pocoo.org/2.3/quickstart/
Flask Migrate: https://flask-migrate.readthedocs.io/en/latest/
Flask TDD: https://github.com/mjhea0/flaskr-tdd
Flask Mocking Part #1: https://medium.com/python-pandemonium/python-mocking-you-are-a-tricksy-beast-6c4a1f8d19b2
Flask Mocking Part #2: https://medium.com/python-pandemonium/surrender-python-mocking-i-have-you-now-5805e91cfbf4

FrontEnd Development

See the app-frontend README for infos

shm's People

Contributors

marlonschultz avatar phryneas avatar theninthfox avatar woodworker avatar

Watchers

 avatar  avatar

Forkers

phryneas

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.