# Sony Music for Artists

The bottom of this document contains [a glossary of acronyms and terms](#glossary) that is useful to familiarize yourself with the project.

# Getting Started

The full guide to getting started from scratch is available in [developing.md](./developing.md)

Install dependencies

    npm install
    export RELEASE_ENV=local FRESHDESK_API_KEY=<key> AMPLITUDE_API_KEY=<key> AUTH0_CLIENT_ID=<id>

Login to expo

    npm run expo login

When developing for the first time on a new device, register and create a new dev client build

    npm run eas -- device:create
    npm run build:dev

Run expo

    npm start

# Environments

|                      | qa delphi    | dev+demos   | qa next backend | qa next frontend | artists insights |
| -------------------- | ------------ | ----------- | --------------- | ---------------- | ---------------- |
| expo release channel | qa           | development | staging         | preview          | production-v3    |
| distrubution         | expo         | expo        | expo            | expo/testflight  | app store        |
| auth0 tenant         | sme-dna      | sme-dna     | prod-dna-apps   | prod-dna-apps    | prod-dna-apps    |
| backend api          | qa           | development | staging         | production       | production       |
| preferences api      | --           | dev         | stage           | production       | production       |
| backend delphi api   | stage-mobile | production  | production      | production       | production       |
| git branch or tag    | qa           | development | tag vX.Y.Z      | production-v3    | tag vX.Y.Z       |
| Intercom workspace   | testing      | testing     | production      | production       | production       |

# Releasing

There are two kinds of releases - over-the-air updates, and native app builds.

> Native app builds are only required for Expo SDK updates and app.config changes

We build stuff locally, make Pull Requests. We review each others work, and decide its good.

## Versioning

|                | MAJOR                           | MINOR           | PATCH           |
| -------------- | ------------------------------- | --------------- | --------------- |
| version number | **2**.0.0                       | 2.**1**.0       | 2.1.**1**       |
| delivery       | app store                       | app store + OTA | app store + OTA |
| content        | SDK updates, app.config changes | new features    | bugfixes        |

## Development OTA

On merging to development, Jenkins publishes code to [the expo 'development' release channel][].

QA makes sure there are no major regressions, confirms features and bug fixes, we get internal feedback, etc.

After some amount of time, we decide to release.

## Preview OTA + Production Shells

On merging to `production-v3`, Jenkins

- publishes code to [the expo 'preview' release channel][]
- creates new iOS and Android builds using [EAS Build][]

This version of the app is pointed towards the production backend.

We make sure there are no regressions or updates needed to the backend, and if so, move on to production.

### Testing

Insighs Dev Client [preview channel][] OTA updates can be tested on iOS and Android.

Full shell builds can be tested

- via TestFlight for iOS.
- via `bundletool` after downloading the `apks` and using [aab2apks.zsh][]

## Delivery

If we are convinced the app is ready

- Update the changelog with the new release date
- Manually release the new version in Jira
- Submit the new app using [app store connect][]
- Submit the new app using [play store console][]

## Production + Staging OTA

First increment the version with `npm version patch` or `npm version minor`

On pushing a new tag vX.Y.Z, [the jenkins web ui][] will ask a user if it should publish to ['production-v3'][] and ['staging'][] release channels.

> If you look at the [ama-frontend tags in Jenkins][], and there is no ✅, then you may have to click 'Build Now' to run this step.

After pressing 'Proceed' in [the jenkins pipeline][], the new updates will be live in about 20 minutes for most users.

# Documentation

## Architecture

![Architecture](./docs/sma_architecture.svg)

## Frontend

The SMA frontend app is a mobile app built using React Native and runs on both iOS and Android.

The code is mostly TypeScript, using Expo for providing a common api and build tooling.

The globe is built on top of Three.js.

The app requests data from the AMA backend. It doesn't communicate with the Delphi api directly.

## User Authentication

The app authenticates users against the Auth0 hosted user database using the authorization code flow with PKCE, and receives an access token.
The user sends the access token along with each request to the AMA backend.

## Dependencies

The frontend communicates directly with the following 3rd parties:

- Performs authentication flow with [Auth0][]
- Sends analytics events to [Amplitude][]
- Sends feedback to [Freshdesk][]
- Uploads logs to [DataDog][]
- Sends errors to [Sentry][]
- [Intercom][] for bulletins

The frontend depends on these first party services

- [ama-backend][] for data
- [rti-user-preferences-service][] for favoriting
- atlas for images (artist, album, playlists, etc)

## Testing

We currently test on iPhone X, iPhone Xs, and Pixel 2 hardware

### Erasing locally stored user data

Data stored on the devices can be erased by pressing the version string 20 times, then selecting "Erase", then reopening the app.
Stored state is still maintained in memory.

### Notifications

Notifications are triggered by [rti-notifications-service][]

## Storybook

[Storybook][] can be used for developing UI components in isolation. In order to develop using Storybook you have to both start Storybook itself and also the RTI application _Storybook mode_. Once that is done Storybook will display inside the Expo GO app on the iOS Simulator. Additonally one can also use a browser to navigate, but not render, the stories. The UI components can only render inside a Simulator, Emulator or a real device.

1. Start the two services:

```
npm run storybook
npm run start:storybook
```

2. Open the application inside Expo GO, e.g. on the iOS Simulator.

3. Either select stories inside Expo GO or in a browser on http://localhost:7007.

# Glossary

## App name

The name of the app has changed over time

- AMA -> Artist Music App
- SMA -> Sony Music for Artists
- RTI -> Real Time Insights

## Services

- Delphi -> main api to Sony's data store

[aab2apks.zsh]: https://github.com/filtr/rti-scripts/blob/aab2apks.zsh
[eas build]: https://expo.dev/accounts/data_analytics/projects/insights/builds
[the expo 'development' release channel]: https://expo.dev/@data_analytics/insights?release-channel=development
[preview channel]: https://expo.dev/@data_analytics/insights?release-channel=preview
[the expo 'preview' release channel]: https://expo.dev/@data_analytics/insights?release-channel=preview
['production-v3']: https://expo.dev/@data_analytics/insights?release-channel=production-v3
['staging']: https://expo.dev/@data_analytics/insights?release-channel=staging
[the jenkins pipeline]: https://jenkins.apollo.stream/job/RTI/job/pipelines/job/ama-frontend/
[the jenkins web ui]: https://jenkins.apollo.stream/job/RTI/job/pipelines/job/ama-frontend/view/tags/builds
[auth0]: https://manage.auth0.com/dashboard/us/prod-dna-apps
[amplitude]: https://analytics.amplitude.com/sonymusic
[freshdesk]: https://sonymusicdataanalytics.freshdesk.com
[datadog]: https://app.datadoghq.com/apm/service/artistapp-api-http-client/
[sentry]: https://sentry.delphiplatform.io/organizations/gdb/issues
[intercom]: https://intercom.io
[ama-backend]: https://github.com/filtr/ama-backend
[rti-user-preferences]: https://github.com/filtr/rti-user-preferences-service
[rti-notifications-service]: https://github.com/filtr/rti-notifications-service
[app store connect]: https://appstoreconnect.apple.com/apps/1511208600/appstore/ios/version/inflight
[play store console]: https://play.google.com/console/u/0/developers/7556569230361201207/app/4972763647812939596/publishing
[storybook]: https://storybook.js.org/
[ama-frontend tags in jenkins]: https://jenkins.apollo.stream/job/RTI/job/pipelines/job/ama-frontend/view/tags/
