# Bonfire API

## Usage

```
npm start
```

### Configuration

Configuration is obtained either from environment variables or from `.env` file. Example configuration in the [`example.env` file](./example.env). Required config values:

-   `PORT` - Server port

---

-   `DB_HOST` - Database hostname
-   `DB_PORT` - Database port
-   `DB_DATABASE` - Database db name
-   `DB_USER` - Database username
-   `DB_PASSWORD` - Database password

---

-   `DB_SYNC` - Should typeorm synchronize changes to the database (`true` / `false`)

---

-   `PASSWORD_SECRET` - Secret for hashing session tokens

---

-   `SMTP_HOST` - SMTP server hostname
-   `SMTP_PORT` - SMTP server port
-   `SMTP_USER` - SMTP server username
-   `SMTP_PASSWORD` - SMTP server password

---

-   `SELF_URL` - URL of the API
-   `FRONTEND_URL` - URL of the frontend app

## Documentation

### Database model

![dbmodel](doc/database.svg)

This model is generated automatically from the TypeORM definitions by running the `generate-database-model` script.

### GraphQL documentation

Documentation is generated by running `generate-graphql-docs`. Generated documentation is available on [Github Pages](https://roseckyj.github.io/bonfire-api/)

## Scripts

### `generate-graphql-docs`

This script generates the documentation for GraphQL schema and deploys it to Github Pages. It requires the server to be running on localhost port 4000.

### `generate-database-model`

This script generates the database overview image (as seen higher) and downloads the SVG file into the static folder of the repository.

### `generate-graphql-typings`

When the graphql schema is updated, `generate-graphql-typings` script should be run in order to propagate the typings into the typescript server code.

### `populate-database`

This script clears the database populates it with randomized data for presentation purpouses. Because this script **clears the existing schema** it is required to put following value into your environment variables (or .env file):

```
_____UNSAFE_ALLOW_DATABASE_POPULATION = true
```
