# Dev Environment

## Getting Started

1. Make sure you have node 21 installed: https://nodejs.org/en/download/current/
2. Run `npm install --global yarn` to install Yarn
3. Make sure you have docker installed. For Mac, install Docker Desktop: https://www.docker.com/products/docker-desktop/
4. You may need to restart your shell if you just installed docker to get the tooling into your PATH.
5. Clone this repo
6. Make sure you have AWS credentials set up in ~/.aws and a valid Kubernetes config in ~/.kube
7. Populate ./server/.env with the secrets and other config needed for local development. You can get a copy of this file from another developer.
8. Populate ./db/migrate/.env with the production database readonly user credentials. You can get a copy of this file from another developer.
9. If this is your first time running the application locally, you need to populate your database. Run `yarn migrate clone-prod` and wait for it to finish (this will take a few minutes)
10. Run `yarn up` to bring up the application

## Accessing the application

With the new docker setup, you can access the application at the following ports. Note the HTTPS protocol.

- Landing Page: https://localhost:3000
- Frontend: https://localhost:3002
- Server: https://localhost:3001
- Admin Panel: https://localhost:3001/admin

Refer to the troubleshooting section below if you encounter any issues.

## Running the tests

We only have frontend e2e tests right now.

1. `cd frontend`
2. `yarn e2e-tests-i` for interactive mode or
3. `yarn e2e-tests` for headless mode

## Database connection, management and migration

Refer to the `db/README.md` for instructions.

## Cronjobs

Refer to the `server/README.md` for instructions.

# Tech Stacks

There are 3 main servers in this project:

1. Landing Page
2. Frontend
3. Server

## Landing Page

This runs on nextjs and is deployed under wavtool.com.
It is a fully static site and does not have a server of it's own.
Locally, it runs on port 3000.

## Frontend

This is the main WavTool application that all the fun bits are in.
It is a static React app and is deployed under app.wavtool.com.
Locally, it runs on port 3002.

## Server

This is the main server that handles all the backend logic, auth, as well as interfacing with the database.
It is an express server and the deployment is a bit more complicated.
The main `/api` route is deployed under `api.wavtool.com`.
There is a URL shortener on the `/s` route that is deployed under `wav.link`
There are also special routes that will be redirected from `wavtool.com/<route>` for NextJS

The NextJS server allows for server side rendering of certain pages and to allow these NextJS pages access to the database before it's rendered.

Special Routes handled by NextJS:

- `/tracks` - Track sharing page
- `/admin` - Admin panel

Locally, the server runs on port 3001, so to access all the above routes, you would just access:

- `https://localhost:3001/api`
- `https://localhost:3001/s`
- `https://localhost:3001/tracks`
- `https://localhost:3001/admin`

# Infrastructure

Everything is deployed on AWS.

## `wavtool.com`

This is a static site hosted on S3 and served through CloudFront.

## `app.wavtool.com`

This is a static site hosted on S3 and served through CloudFront.

## `api.wavtool.com`

This is an EC2 instance running the server with a bunch of other bells and whistles I don't understand.

# Deployment

Deployments are handled automatically by GitHub Actions.

## Production

Whenever there is a change to the `master` branch, it will automatically be deployed to the production environment and can be accessed at these URLs:

https://wavtool.com
https://app.wavtool.com

## Staging

Whenever there is a change to the `staging` branch, it will automatically be deployed to the staging environment and can be accessed at these URLs:

https://staging.wavtool.com
https://appstaging.wavtool.com

## Beta

Whenever there is a change to the `beta` branch, it will automatically be deployed to the beta environment and can be accessed at these URLs:

https://beta.wavtool.com
https://appbeta.wavtool.com

# Troubleshooting

[Refer to this notion page for more troubleshooting steps](https://www.notion.so/a7564dad41fd4e90974f0564486b1f90)
