# 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

Install dependencies

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

Login to expo

    npm run expo login

Run expo

    npm start

Install the expo client app on your phone, and scan the QR code

> or press `i` to run the simulator

# 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 PRs. 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][]
- submits the iOS build to TestFlight using [EAS Submit][]

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

Expo Go [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.

After you press 'Proceed' in [the jenkins pipeline][]

# 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 Delphi 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][]
- 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, iPhone 7, 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][]

# 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/blue/organizations/jenkins/ama%2Fama-frontend/branches
[the jenkins web ui]: https://jenkins.apollo.stream/blue/organizations/jenkins/ama%2Fama-frontend/activity
[auth0]: https://manage.auth0.com/dashboard/us/prod-dna-apps
[amplitude]: https://analytics.amplitude.com/sonymusic
[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
