> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fonoster.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Hacking the Backend

> A quick guide to contributing to Fonoster's backend

This guide contains the development environment setup for Fonoster. It includes the API Server and supporting infrastructure.

### Prerequisites

* Docker and Docker Compose
* NodeJS >= v20
* Git (Optional)

### Hacking the Backend

To start hacking the backend, start by cloning the project, and copying the *.env.example.dev* and *./config/integrations.example.json*

Here is an example:

```bash theme={"system"}
git clone https://github.com/fonoster/fonoster
cd fonoster
cp .env.example.dev .env
cp config/integrations.example.json config/integrations.json
```

In the *.env* file you will need to find and update the following variables. All variables will need to be updated to a routable IP within your local environment.

| Variable                        | Description                                                          |
| ------------------------------- | -------------------------------------------------------------------- |
| ROUTR\_EXTERNAL\_ADDRS          | The IP used by Routr to advertise it's address to othe SIP endpoints |
| ROUTR\_RTPENGINE\_HOST          | The address of RTPEngine                                             |
| ASTERISK\_SIPPROXY\_HOST        | Address pointing to Routr SIP Server                                 |
| APISERVER\_ROUTR\_API\_ENDPOINT | The entrypoint to Routr's API                                        |
| DOCKER\_HOST\_ADDRESS           | The address of the host machine                                      |

<Tip>
  With `ifconfig | grep "en0" -A 5` on Linux or Mac you will see a good candidate to use as the IP.
</Tip>

Next, you need to install and build the project.

```bash theme={"system"}
npm install
npm run build
npm run test
```

Then, you need to start the infrastructure and initialize the database using the following commands:

```bash theme={"system"}
npm run start:services
npm run db:migrate
npm run db:seed
```

The previous command will start all the services including `envoy`, `mailhog`, `adminer`, `influxdb`, `postgres`, and `asterisk`.

Finally, start the API Server with:

```bash theme={"system"}
npm run start:apiserver
```

### Running the Integration Tests

A good indicator that your environment is correctly setup is having ALL passing in your integration tests. Run the integration test, on a separate terminal, with the following command:

```bash theme={"system"}
npm run integration
```
