timelesslounge / timelessis

35 stars 21 forks source link

Timeless IS

Timeless IS is a web-based management software for a franchise of hookah bars called "Timeless Lounge"

Current state

Timeless Lounge is currently using a set of software tools were developed around an external application called Poster that is also providing APi to access data. This application is not flexible enough, does not cover all the needs for process automation, therefore there is a need to develop full-fledged information system designed to combine the experience gained in automating processes in lounge bars and support the expansion of the franchise network.

Non-functional requirements

Technology stack

Usability

The application should be able to work on any computer displays as well as mobile devices (smartphones and tablets). The interface of the application should be sophisticated, but simple, self-explanatory and intuitive.

A good example on how should be developed the frontend is the GetSling webapp.

Security

Fault tolerance

Very important for us in case of serious software/hardware failure. The system should not lose/corrupt data (regular database backups) and we should able to restore system performance within 15 minutes (master-slave replication and failover should be configured).

Sketches

At the following link you can find the updated sketches for the UI/UX part

https://drive.google.com/drive/folders/1f6aH1qlOL5Ek6Zo4b2rW2f6pkDz5jnp9

Functional Requirements

Admin Module

General Information

Involved Entities

Privileges by Role

Reservation Module

General Information

Timeline-based table

Floorplan

Involved Entities

Reservation Life Cycle

Privileges by Role

Development Guidelines

Setup Development Environment

# Install RVM (for pdd)
curl -sSL https://get.rvm.io | bash -s stable --ruby
gem install pdd

# Download Python
wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tgz
tar xvzf Python-3.6.7.tgz
cd Python-3.6.7
./configure
make
make test
sudo make install

# Create workspace and virtual environment
mkdir timelessis-project
mkdir timelessis-project/venv
python3 -m venv timelessis-project/venv

# Clone the repository
cd timelessis-project
git clone https://github.com/<your-github-username>/timelessis.git
cd timelessis

# Activate virtual environment
. ../venv/bin/activate

Dependency Install

pip install -r requirements.txt

Setup PostgreSQL for Debian / Ubuntu

Debian / Ubuntu repositories include PostgreSQL by default. To install PostgreSQL, use the apt-get (or other apt-driving) command:

sudo apt-get update
sudo apt-get install postgresql-10

If packages are not found, do the following steps:

  1. Create the file /etc/apt/sources.list.d/pgdg.list and add a line for the repository:

    sudo deb http://apt.postgresql.org/pub/repos/apt/ {DEBIAN_OR_UBUNTU_VERSION}-pgdg main

    NOTE: DEBIAN_OR_UBUNTU_VERSION is a code name, like trusty (ubuntu 14.01), xenial (16.04) and so on.

  2. Import the repository signing key, and update the package lists

    wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

    and then repeat apt-get update and apt-get install commands.

Database Setup

sudo -u postgres createuser --superuser timeless_user
sudo -u postgres createdb timelessdb_dev
sudo -u postgres createdb timelessdb_test
psql -U postgres -d timelessdb_dev
> alter user timeless_user with encrypted password 'timeless_pwd';
psql -U timeless_user -d timelessdb_dev

Redis Installation

We use Redis for cache storage. For installing Redis:

sudo apt install make gcc libc6-dev tcl
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
sudo make install
src/redis-server

Database backups

Backup scripts (pg_backup.sh and pg_restore.sh) are used for save storage of database. Both of those scripts keep the configuration inside pg_backup.config file. Password for those scripts can be provided using standard Postgres methods like PGPASSWORD environment variable or ~/.pgpass file.

Database backups are uploaded to Google Drive. Note that in order to do backup (and restore), you have to install GDrive and configure Service Account credentials. Set SERVICE_ACCOUNT_CREDENTIALS in pg_backup.config to the location of your service account credentials JSON file.

Note that the Google Drive API needs a file ID, not file name, e.g.

FILE_ID=0B-Iak7O9SfIpYk9zTjZvY2xreVU

Running tests

export FLASK_ENV=testing
pytest

NOTE: To skip integration tests run:

pytest -k 'not it'

Generating migrations

python manage.py db migrate
python manage.py db upgrade

Running the webserver in development

export FLASK_APP=main.py
export FLASK_ENV=development
flask run

Running the webserver locally using Docker

You should have Docker and Docker Compose installed. In other case go through official tutorial to install:

  1. https://www.docker.com/get-started
  2. https://docs.docker.com/compose/install/

To start up the docker exec the following commands:

docker-compose build
docker-compose up app

and check that http://127.0.0.1:5000/ works. To run tests execute:

docker-compose run app_test

Credential files

The file credentials/credentials.json.asc is a JSON file containing all the credentials for the external services used in Timeless IS. This file is decrypted during deploy phase by rultor.

This is the sample file:

{
  "credentials": {
    "server": {
      "staging": {
        "address": "...",
        "username": "...",
        "password": "..."
      }
    },
    "postgres": {
      "staging": {
        "username": "..."
        "password": "..."
      }
    },
    "googledrive": {
      "staging": {
        "username": "...",
        "password": "..."
      }
    },
    "redsms": {
      "staging": {
        "username": "...",
        "password": "..."
      }
    },
    "poster": {
      "staging": {
        "domain": "...",
        "username": "...",
        "password": "...",
        "token": "..."
      }
    }
  }
}

Under staging.id_rsa and staging.id_rsa.pub are stored the keys to log into the staging server without username and password

See Rultor manual on how to use it decrypted files

React Frontend

You’ll need to have Node 8.10.0 or later on your local development machine. You can use nvm (macOS/Linux) or nvm-windows to easily switch Node versions between different projects.

The React frontend code can be found in "frontend" dir. There you need to run npm install.

Then: