# Real-Time Insights backend

Backend for the [Real-Time Insights app] and [Amadeus]

### Getting started

Install node

    nvm install
    nvm use

Install dependencies

    npm install

Setup env variables

    cp .env.example .env.local
    $EDITOR .env.local
    ln -s .env.local .env # symlinking makes it easier to switch envs

Develop

    npm run watch

## Deploying

To update the backend, we use [Jenkins](https://jenkins.apollo.stream) and [Octopus](https://octopus.delphi.zone)

### Development

Development deployments happen automatically when code gets pushed or merged to `develop` branch.

### Production

Production builds are triggered on changes to `master`, then deployed with Octopus.

First, get the code into `master`

    git switch develop
    gh pr create --base master

Review and merge the PR

    gh pr view --web

Next, bump the version to create a known release artifact

    git switch master
    npm version [major|minor|patch] # creates a new commit and tags it
    git show # review the patch
    git push --follow-tags # Jenkins will build when it sees a new tag, and put it in Octopus

Make sure to update develop with the version commit

    git switch develop
    git merge master
    git push

Once the build completes, use [Octopus](https://octopus.delphi.zone) to deploy the newly-tagged release to the dev and higher environments.

## Documentation

The RTI backend is an aggregating proxy. It accepts requests from the [RTI app] and [Amadeus] users, and requests general data from the Delphi API and returns application screen specific responses.

### User/Artist Authorization

For each request from a frontend, the backend checks that the user is authorized to access data for a requested artist, based on the token sent along with each request.

### Delphi

The backend authenticates itself directly with the Delphi API using a client id and secret, and receives an access token.
The access token is sent along with each request to Delphi.

### Third parties

- Sentry
- Datadog

## Frontends

The [RTI app] documentation is in the [frontend repository](https://github.com/filtr/ama-frontend)
[Amadeus] is our web frontend.

### Tech stack

- TypeScript
- Node.js
- Koa: Node.js web framework
- io-ts: Delphi response validation

[real-time insights app]: https://github.com/filtr/ama-frontend
[rti app]: https://github.com/filtr/ama-frontend
[amadeus]: https://github.com/filtr/rti-amadeus
