# Application Fullstack Environment

This is a Makefile/Docker project that provides a single command to clone, setup, and run the frontend and backend services that comprise the Abacus Fullstack. The dockerized environment facilitates the dev/debug/testing of fullstack features in Abacus such as adding new inputs, fields, GQL queries, and features that require frontend and backend changes, database/graphql PRs that might affect the frontend, etc.

The following subset of Abacus services are currently supported:

| Project | Description |
| ------- | ----------- |
| frontend-royalties | Abacus App - [Prod](https://abacus.theorchard.com) \| [QA](https://abacus.qaorch.com/) |
| frontend-documents.sh | [TODO] |
| graphql-router | Provides identity resources on top of routing and federation to specialized subgraphs. [Apollo Studio](https://qa-graphql-router.theorchard.io/graphql) |
| graphql-abacus | A specialized subgraph for Abacus. Abstracts over several OWS microservices. [Apollo Studio](https://qa-graphql-abacus.theorchard.io/graphql) |
| ows-abacus-account | Microservice for data model abstraction over Account related tables |
| ows-abacus-contract | Microservice for data model abstraction over Contract related tables |
| ows-royalties | Microservice for data model abstraction over Contract, RunController, and Account related tables |
| ows-state | [TODO] |
| ows-contracts | [TODO] |
| ows-royalties-workflows | The DAGs [TODO] |
| ows-abacus-legacy-sync | [TODO] |
| ows-abacus-worksheet | [TODO] |
| ows-ledger | [TODO] |
| ows-abacus-schedule | [TODO] |
| lambda-abacus | [TODO] |
| ecs-abacus | [TODO] |
| mysql + liquibase | The royalty_accounting database running from image directly |

## Requirements
1. [Abacus Onboarding](https://www.notion.so/ABACUS-Onboarding-System-Inventory-dd8b5d0996d840609c7c4af6f84c55d2)
1. `awsume` AWS MFA setup - [Notion doc](https://www.notion.so/AWS-Access-f841b9dd815d4443a80e96a86c92cd2f?#390fbb7939a646749331fe5218d68379)
1. `GITHUB_NPM_TOKEN` env var setup - [Notion doc](https://www.notion.so/JavaScript-Package-Setup-9553d5d491c94835aa787fdf0fc4838d)
1. [Docker](https://www.docker.com/products/docker-desktop)
1. Connected to VPN

Note: the install also assumes you have your Github ssh key setup. Otherwise change all the repo URLs in the [Makefile](Makefile#L32-L51) to use https.

## Setup
Copy this project to the same directory as any existing Abacus repos you may already have.

```shell
awsume prod
make build
```
That will authenticate to our AWS account (assuming you have `awsume prod` setup) and build a Docker container with the frontend available at `http://localhost:8080`. The liquibase runner migrates the database on start up and a seeder service runs the sql files in `./seeds` against the running mysql service to give it some data.

If you stop the containers you can bring them back up with:

```shell
make frontend-royalties
```

## Power On Self Test
```shell
zsh scripts/test-connectivity.sh
```
Should see all "good". If not, try restarting the failed services. Can also run `make wait_ready` in a separate shell and it will run the connectivity test automatically.

The database is running on `mysql://localhost:6051` and can be queried via your preferred SQL tools.

## Migrate/Seed DB
```shell
make seed_db
```
Run that after adding new SQL files to `./seeds`.

## Integrating Services
This section is specifically about adding ows-* services.

1. Run: `make integration NAME=<integration name>` to create a new integration script.
2. Optionally override the setup by defining the `setup_repo` function in your new integration script.
3. Add a service entry to the "Orchard Services Layer" section of the docker-compose.yml i.e. copy it from another service declaration.
4. Optionally add an entry to `scripts/test-connectivity.sh` to test the service on startup.
5. Stop the `app-fullstack-env` container and run `make build`.

## Rebasing Repos
If you are having trouble running the build due to code being out of date,
you can rebase all the repos with:

```shell
`make rebase_repos
```
This will set up upstream remotes for each repo,
fetch the latest code from upstream and rebase your local branches.
