Skip to content

NUMde/compass-numapp-backend

Repository files navigation

NUM-App Mobile Back End

Welcome

This repository provides the source code for the mobile back end of the Compass NUM-App Project. This project provides a set of open source components meant for the digital conduct of questionnaire based studies. The mobile back end itself is a part of COMPASS (Coordination On Mobile Pandemic Apps best practice and Solution Sharing).

The mobile back end provides study data for the NUM-App in form of FHIR Questionnaires. It also stores the study data that is uploaded from the mobile app. Additionally it makes the collected data accessible for other parties.

You can find an exemplary questionnaire here.

Development

Local Setup

  • Make sure you have a recent version (LTS recommended) of Node.js installed and run the following commands to download and prepare this repository:

git clone https://github.com/NUMde/compass-numapp-backend.git
cd compass-numapp-backend/
npm install
  • In case you use VSCode as your editor, install the recommended extensions

Run the back end locally

Generating RSA key pair

For local development we need an RSA key pair for the encryption with the client. Execute the following commands to create a key pair. The resulting files are picked automatically. But they can also be inserted into the .env file.

Create .env file

Some configuration values need to be present as environment variables during runtime. The application loads a file with the name .env during startup, if it is present.

To get started copy the file .env.sample to .env and add your values.

$ openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:4096
$ openssl rsa -pubout -in private_key.pem -out public_key.pem

Generating certificate

To submit the public key to the client, a certificate must be created. To create a self-signed certificate, which will be valid for 1 year, use the following command:

$ openssl req -x509 -days 365 -new -out self-signed-certificate.pem -key private_key.pem

The certificate must be put in the .env file. If no certificate is provided, the native app will default to a built-in one (defined in src/config/appConfig.js).

Scripts

npm run start

Start the built application

npm run dev

Start the application on the local machine in watch mode. This is the preferred command for local development.

npm run build

Build the application into the build folder.

npm run clean

Clean the dist folder.

npm run lint

Lint the source code.

npm run prettier-format

Have prettier format your code.

npm run test

Run your unit tests with jest.

Environment variables used by the application

There are many different environment variables used by the application. Most of them have default values, that can be overridden by exposing a different value as environment variable. All used variables can be found in the src/config folder.

Committing code changes

This app uses Husky to trigger some actions during a commit. Before each commit passes automatic tests and linting is run. If any action fails, the commit fails.

Deployment

The application should run in any environment that provides a Node.js runtime. The current configuration is suited for an OpenShift deployment. Find detailed instructions here OCP Deployment.

Database Setup

Dedicated documentation for the database setup can be found here DB Setup.