Skip to content

Project Setup

This guide walks through the process of setting up Zebbra locally for development.

Prerequisites

To run Zebbra you will have to make sure the following is given on your machine (the versions matter!):

  • Python 3.10 is installed, we recommend pyenv (how to)
  • Node 16 is installed (how to)
  • MongoDB Community Edition 5.0 is installed and running (how to)

Repository

Start by cloning the repository, setting up a virtual environment and installing the required dependencies.

# clone the repository
git clone git@github.com:leo-pfeiffer/zebbra.git

Backend setup

We start by setting up the backend, that is the API server, as well as the database.

First, create a virtual environment in the server directory

# zebbra/server

python -m venv venv
source venv/bin/activate

Next, use the make command to install all package requirements via pip.

# zebbra/server

# install dependencies
make requirements

.env file

Next, create the .env file with the environment variables. Run the following to create a file with the starter template. You will have to fill out the missing variable assignments (e.g. secrets etc.).

# zebbra/server

cat <<EOF > .env
# VALIDATION
ENV_SET="true"

# BASE URL
ZEBBRA_BASE_URL="http://localhost:8000"

# SETTINGS
ENV_ENCRYPT_PASS=

# AUTH
AUTH_SECRET=
AUTH_ALGO="HS256"
# 30 days in minutes
AUTH_TOKEN_EXPIRE=43200

# MONGO DB
MONGODB_USER=
MONGODB_DB=
MONGODB_PW=
MONGODB_URL="127.0.0.1:27017"

# XERO
XERO_CLIENT_ID=
XERO_CLIENT_SECRET=

# GUSTO
GUSTO_CLIENT_ID=
GUSTO_CLIENT_SECRET=

# CACHE
# 24 hrs in seconds
CACHE_TTL=86400
EOF

Database

If you've set up the .env file correctly, you can use the default script to set up the database.

# zebbra/server

make setup_db

This creates the required users, sets up the indexes for caching, and loads some demo data.

Run the server

At this point you should be able to run the app with the provided run_server command on port 8000.

# zebbra/server

make run_server

Zebbra API

Testing

If you want to run the unit tests for the backend you can now do so like this:

# zebbra/server

make test

Backend tests

Client setup

Setting up the client is comparatively straightforward.

Install requirements

Start by installing the node modules from the webclient directory.

# zebbra/webclient

npm install

.env file

Like the server, the client requires a simple .env file. You can create it with the following command.

# zebbra/webclient

cat <<EOF > .env
# URLS
FRONTEND_URL_BASE="http://localhost:3000"
BACKEND_URL_BASE="http://localhost:8000"
EOF

Build and run the client

Lastly, we can build and run the client, like so:

# zebbra/webclient

npm run dev

The client will be served on http://localhost:3000.

Zebbra client

Testing

If you want to run the unit tests for the frontend you can now do so like this.

# zebbra/webclient

npm run test