Skip to content

A node.js service to manage ethereum blockchain subscriptions and send email alerts on specific events

Notifications You must be signed in to change notification settings

aragonone/notification-service

Repository files navigation

Aragon Notification Service

A node.js service to manage ethereum blockchain subscriptions and alert on specific events.

Architecture

The service exposes a REST API for:

  • creating accounts
  • passwordless logins with email tokens
  • managing subscriptions

The service has two async jobs:

  • scan ethereum blockchain for new events, match with subscriptions and queue emails
  • send queued notifications emails

Stack

  • PostgreSQL as the main persistence layer.
  • Knex.js to build SQL queries
  • hapi.js for the REST API
  • jsonwebtoken for signing JWT auth tokens

Authentication / Authorisation

The system has no concept of passwords.

Authentication is done by calling the login endpoint which:

  1. Issues a short lived token
  2. Sends an email with the magic link (a link containing the JWT signed token)
  3. Once the magiclink token is send to the /verify endpoint a long lived auth token allows interaction with the full API

Hence, two auth scopes are defined:

  • MAGICLINK
  • API

Tokens are stateful, i.e. they're validated on every request. So even though we use JWT tokens, they can be invalidated from the DB.

Entities

diagram

Quick Start

Start Postgres and create a DB and user

$ docker run -d -p 5433:5432 --name postgres postgres
$ docker exec -i -t postgres createuser -h localhost -U postgres --superuser notification-service
$ docker exec -i -t postgres createdb -h localhost -U postgres --owner notification-service notification-service

Env vars

Secrets are stored in .env file. For a list of required environment variables check .env.example

$ cp .env.example .env
# update .env with secrets

Docker

Build image

docker build -t notification-service .

Run container

This will run the container and mount the .env runtime config at runtime docker run -it -p 5000:5000 -v $(pwd)/.env:/app/.env notification-service

DB relational model diagram

To update use https://draw.io and open the db.drawio file in the repository.

CI/CD

For CI/CD we are using GitHub Actions.

Production build is configured to trigger when creating v* tags in the master branch. Executing the following:

git tag v0.1.0
git push --tags

Will deploy the following container: docker.pkg.github.com/aragonone/notification-service/app:v0.1.0

About

A node.js service to manage ethereum blockchain subscriptions and send email alerts on specific events

Resources

Stars

Watchers

Forks

Packages