# RealTime Expert 

## Table of Contents

- [RealTime Expert](#realtime-expert)
  - [Table of Contents](#table-of-contents)
  - [Useful information for project deployment](#useful-information-for-project-deployment)
    - [PHP configurations](#php-configurations)
      - [php.ini Settings](#phpini-settings)
        - [File Upload Limits](#file-upload-limits)
        - [Required Extensions](#required-extensions)
    - [Laravel Reverb](#laravel-reverb)
      - [Overview](#overview)
      - [Setting Up Reverb as a Linux Service](#setting-up-reverb-as-a-linux-service)
        - [Installation](#installation)
        - [HTTP Server Proxy Configuration](#http-server-proxy-configuration)
    - [Laravel Task Scheduler](#laravel-task-scheduler)
      - [Overview](#overview-1)
      - [Setting Up the Scheduler](#setting-up-the-scheduler)
        - [Installation](#installation-1)
    - [Working with Translations](#working-with-translations)



## Useful information for project deployment

This section describes the details of the project architecture.

### PHP configurations

#### php.ini Settings

##### File Upload Limits

The application requires specific PHP configuration for file uploads. Edit your `php.ini` file and set the following values:
```ini
upload_max_filesize = 50M
post_max_size = 50M
```

##### Required Extensions

This project requires several PHP extensions to function properly. To ensure all necessary extensions are installed, run the following command:
```bash
sudo apt-get install -y php8.4-mysql php8.4-pgsql php8.4-opcache php8.4-intl php8.4-zip php8.4-bcmath php8.4-soap php8.4-gd php8.4-curl php8.4-mbstring php8.4-xml php8.4-redis php8.4-imagick php8.4-dev php-pear
```

⚠️ **Note:** If you're using a different PHP version, replace `php8.4` with your version number (e.g., `php8.2`, `php8.3`).


### Laravel Reverb

#### Overview

This project relies on **Laravel Reverb WebSocket Server** for real-time communication. The project includes basic Reverb configuration and can be started with:
```bash
php artisan reverb:start
```

However, for production deployment and persistent operation, it's recommended to run Reverb as a Linux service.

#### Setting Up Reverb as a Linux Service

##### Installation

1. Copy the service configuration file:
```bash
sudo cp environment/reverb.service /etc/systemd/system/reverb.service
```

2. Check configuration file:
```bash
sudo vim /etc/systemd/system/reverb.service
```

Especially the paths in the following variables. Modify them according to your installation.

```ini
WorkingDirectory=/var/www/rte
ExecStart=/usr/bin/php /var/www/rte/artisan reverb:start
```



3. Reload systemd:
```bash
sudo systemctl daemon-reload
```

4. Enable the service to start on boot:
```bash
sudo systemctl enable reverb
```

5. Start the service:
```bash
sudo systemctl start reverb
```


##### HTTP Server Proxy Configuration

⚠️ **Important:** Reverb requires HTTP server proxy configuration for WebSocket connections.

An example Apache configuration is provided at:
```
environment/apache2-conf-example.conf
```


### Laravel Task Scheduler

#### Overview

This project uses **Laravel's Task Scheduler** to handle scheduled tasks and background jobs.

#### Setting Up the Scheduler

##### Installation

1. Open your server's crontab:
```bash
crontab -e
```

2. Add the following cron entry:
```bash
* * * * * cd /path/to/your/project && php artisan schedule:run >> /dev/null 2>&1
```
or with logging
```bash
* * * * * cd /path/to/your/project && php artisan schedule:run >> /path/to/scheduler.log 2>&1
```

Replace `/path/to/your/project` and `/path/to/scheduler.log` with the absolute paths.


### Working with Translations

In the current version of the project, the translation system operates autonomously and does not
retrieve translations from the IdP translation service. To update the translation database, execute
the following commands in sequence:

- `php artisan translation:extract` - scans the project, updates the lang files, and also creates
  a `translations.yaml` file in the project root containing a list of all missing translations.
  This file can be filled either manually or using any LLM.

- After completing the `translations.yaml` file, run `php artisan translation:apply`, which will
  save all new translations into the lang files.

- By default, the `translation:extract` command stores strings that already have translations but
  are no longer used in the project in separate `unused.php` files. Optionally, you can remove all
  these files by running `php artisan translation:clear-unused`.