# Folder Structure

Note: In the controllers folder, each of the files has a small description of what that function is. You can use this to get an idea of the overview of the application.

Within the `src` folder:

- `main.ts` <br/> is one of the 2 files on the main directory and is the entry point of the application
- `routes.ts` <br/> is the other file on the main directory and contains all the routes of the application
- `auth/` <br/> contains all the authentication related code
- `conductor/` <br/> contains all the code related to conductor
- `controllers/` <br/> contains code that handles the endpoints of the application. Controllers is a rails concept that we have adopted
  - `controllers/helpers/` <br/> contains helper functions that are used exclusively by the controllers
- `external-services/` <br/> contains code and libraries that pertain to external services
- `generators/` <br/> contains utilities that generate anything, from IDs to images.
- `server-utils/` <br/> contains the utilities that are specific to the server application.
- `signal-processing/` <br/> contains audio processing code. Can also contain audio file processing code.
- `types/` <br/> contains all the types that are used in the application
- `utils/` <br/> contains all the other miscellaneous utilities that don't belong anywhere else.
- `cron/` <br/> contains all the cron jobs that are run by the server, Refer to the cronjobs section for more information

# Next.js

This server also runs a next.js application.

Everything in the `pages` folder will automatically map to a route in the application. This is a next.js feature.

Warning: If you create a folder called `api` it WILL break the rest of the server since this will override all the `/api/*` routes.

Caveat: Adding a new file will create a new route in this application, but will not be accessible on any environment except for the development environment. This is because we need to do some AWS configurations to make it work in production.

# Cronjobs

The files in the `cron` folder are meant to be run in a docker container. The same dockerfile used to run the server can be used to run the cronjobs.

To build the dockerfile, run the following command in the `server` directory
Note: this step is optional if you already have a docker image of the server running, but creating one specifically for the cronjobs is also fine.
You can use `docker

```bash
# Note this needs to be run after the server is built, which is done by running `yarn ts` or `yarn ts --watch`
docker build -f Dockerfile -t wavtool-cron .
```

To run the dockerfile, run the following command in the `server` directory:

```bash
# Replacing cron/test.js with the cronjob you want to run
docker run --rm -it --entrypoint node wavtool-cron 'cron/test.js'
```

# Stripe Testing

When testing business model things in local dev, use the stripe command line tools. The following command will get your local server receiving and handling stripe webhooks appropriately. (Get the API key from the "developers" section on stripe - **make sure stripe is in test mode!**)

`stripe listen --forward-to localhost:3001/webhook/stripe --api-key sk_test_api-key-goes-here`

# Database connection, management and migration

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