# Set up your Smartr. Gateway

## Create a Gateway Folder

Start of by creating a new folder on your system to hold the gateway configuration files, for example, `smartr-gateway-setup`.

If you want to use the Docker version of SQL version, use the Tab Docker (Quickest). If you already have the SQL Server Locally then use the second option.

{% tabs %}
{% tab title="Docker (Quickest)" %}

### Create docker-compose.yaml file

```yaml
services:
  smartr-gateway:
    image: smartrcode/gateway:latest
    env_file:
    - .env
    container_name: smartr-gateway
    ports:
    - ${SMARTR_GATEWAY_PORT}:${SMARTR_GATEWAY_PORT}
    hostname: smartr-gateway
    restart: always
    volumes:
    - /etc/timezone:/etc/timezone:ro
    - /etc/localtime:/etc/localtime:ro
    - ${ROOT_USER_DIRECTORY}/.smartr:/home/node/.smartr
    - ${MOUNTED_PROJECTS_DIRECTORY}:${DOCKER_PROJECTS_DIRECTORY}
    networks:
    - smartr_default

  sql-server:
    container_name: sql-server
    hostname: smartr-sql
    image: mcr.microsoft.com/mssql/server:2022-latest
    environment:
      ACCEPT_EULA: 'Y'
      MSSQL_SA_PASSWORD: ${MSSQL_SA_PASSWORD}
      MSSQL_DATA_DIR: /var/opt/mssql/data
      MSSQL_PID: 'Developer' 
      MSSQL_TCP_PORT: 1433 
    ports:
    - "1456:1433"
    networks:
    - smartr_default
    volumes:
      - sql_data:/var/opt/mssql

networks:
  smartr_default:

volumes:
  sql_data:
```

### Create a .env file

```
LOGGER_LEVEL=debug
NODE_ENV=production
SMARTR_GATEWAY_PORT=51988
SMARTR_GATEWAY_HOST=0.0.0.0

ROOT_USER_DIRECTORY=[User root directory ex: C:/Users/YourProfileName]
DOCKER_PROJECTS_DIRECTORY=/home/SmartrProjects
MOUNTED_PROJECTS_DIRECTORY=[Local Directory where the user wants the projects to be created in ex: C:/Projects]

OPENID_CLIENT_ID=SmartrAlpha
OPENID_WELL_KNOWN_URI=https://beta.auth.smartrcode.ai/realms/Smartr/.well-known/openid-configuration

MSSQL_SA_PASSWORD=[mssql password]
```

{% hint style="info" %}
**Variables to change:**

* ROOT\_USER\_DIRECTORY=*C:/Users/MyProfileName* *\<use "/">*
* MOUNTED\_PROJECTS\_DIRECTORY=*C:/Projects*
* MSSQL\_SA\_PASSWORD=*MyStr0ngP\@ssword (*&#x6D;ust be strong and compliant)
  {% endhint %}

### Run the Gateway

1. Open a command line or terminal, navigate to the `smartr-gateway-setup` folder, and run the following command to start the gateway:

```docker
docker compose up
```

or

```docker
docker compose up -d (to run in the background)
```

{% hint style="info" %}
This command will start the Smartr Gateway based on the configuration in the `docker-compose.yml` file.
{% endhint %}

2. To stop the gateway, run:

```docker
docker compose down
```

{% hint style="info" %}
This command will shut down the running Smartr Gateway and SQL Server containers.
{% endhint %}
{% endtab %}

{% tab title="Local" %}

### Create docker-compose.yaml file

```yaml
services:
  smartr-gateway:
    image: smartrcode/gateway:latest
    env_file:
    - .env
    container_name: smartr-gateway
    ports:
    - ${SMARTR_GATEWAY_PORT}:${SMARTR_GATEWAY_PORT}
    hostname: smartr-gateway
    restart: always
    volumes:
    - /etc/timezone:/etc/timezone:ro
    - /etc/localtime:/etc/localtime:ro
    - ${ROOT_USER_DIRECTORY}/.smartr:/home/node/.smartr
    - ${MOUNTED_PROJECTS_DIRECTORY}:${DOCKER_PROJECTS_DIRECTORY}
    networks:
    - smartr_default

networks:
  smartr_default:
```

### Create a .env file

```
LOGGER_LEVEL=debug
NODE_ENV=production
SMARTR_GATEWAY_PORT=51988
SMARTR_GATEWAY_HOST=0.0.0.0

ROOT_USER_DIRECTORY=[User root directory ex: C:/Users/YourProfileName]
DOCKER_PROJECTS_DIRECTORY=/home/SmartrProjects
MOUNTED_PROJECTS_DIRECTORY=[Local Directory where the user wants the projects to be created in ex: C:/Projects]

OPENID_CLIENT_ID=SmartrAlpha
OPENID_WELL_KNOWN_URI=https://beta.auth.smartrcode.ai/realms/Smartr/.well-known/openid-configuration
```

{% hint style="info" %}
**Variables to change:**

* ROOT\_USER\_DIRECTORY=*C:/Users/MyProfileName* *\<use "/">*
* MOUNTED\_PROJECTS\_DIRECTORY=*C:/Projects*
* MSSQL\_SA\_PASSWORD=*MyStr0ngP\@ssword (*&#x6D;ust be strong and compliant)
  {% endhint %}

### Run the Gateway

1. Open a command line or terminal, navigate to the `smartr-gateway-setup` folder, and run the following command to start the gateway:

```docker
docker compose up
```

or

```docker
docker compose up -d (to run in the background)
```

{% hint style="info" %}
This command will start the Smartr Gateway based on the configuration in the `docker-compose.yml` file.
{% endhint %}

2. To stop the gateway, run:

```docker
docker compose down
```

{% hint style="info" %}
This command will shut down the running Smartr Gateway container.
{% endhint %}
{% endtab %}
{% endtabs %}
