# Phantasm ERP Offloader Service

## Overview
This project serves as an offloader service for the main [Phantasm ERP](https://phantasm.in) application. It's designed to handle specific workloads and dependencies, particularly focusing on API traffic management and other resource-intensive operations to improve the main application's performance and scalability.

## Purpose
- Offload API traffic and processing from the main Phantasm ERP application
- Handle resource-intensive operations
- Improve overall system performance and scalability
- Manage specific dependencies and services

## Technology Stack
- Laravel 12
- React
- PHP ^8.2
- MySQL

## Prerequisites
- PHP ^8.2
- Composer
- Node.js and NPM
- MySQL/PostgreSQL
- Access to the main Phantasm ERP project

## Installation

1. Clone the repository:
```bash
git clone [repository-url]
cd [project-directory]
```

2. Install PHP dependencies:
```bash
composer install
```

3. Install Node.js dependencies:
```bash
npm install
```

4. Copy the environment file:
```bash
cp .env.example .env
```

5. Configure your environment variables in `.env` file as like Main Phantasm ERP:
```
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database
DB_USERNAME=your_username
DB_PASSWORD=your_password

# Main Phantasm ERP Connection
MAIN_ERP_URL=http://localhost:8000
MAIN_ERP_API_KEY=your_api_key
```

6. Generate application key:
```bash
php artisan key:generate
```

7. Run migrations:
```bash
NO Need to RUN any Migration
```

8. Start the development server:
```bash
php artisan serve
```

## Integration with Main Phantasm ERP

This service is designed to work alongside the main Phantasm ERP application. To ensure proper integration:

1. Configure the main ERP application to route specific API requests to this service
2. Set up proper authentication and API keys
3. Ensure both applications can communicate over the network
4. Configure load balancing if needed

## Development

### Running Tests
```bash
php artisan test
```

### Building Assets
```bash
npm run dev
```

## Deployment

1. Build the assets for production:
```bash
npm run build
```

2. Optimize the application:
```bash
php artisan optimize
```
3. Swoole + Octane Setup:
```bash
php -v

php -m | grep swoole

sudo apt update && sudo apt install -y software-properties-common && sudo add-apt-repository ppa:ondrej/php && sudo apt update && sudo apt install -y php8.2 php8.2-cli php8.2-common php8.2-curl php8.2-mbstring php8.2-xml php8.2-zip php8.2-mysql php8.2-fpm php8.2-dev

sudo apt install -y build-essential autoconf libssl-dev

sudo pecl install swoole


echo "extension=swoole.so" > /etc/php/8.2/fpm/conf.d/20-swoole.ini && systemctl restart php8.2-fpm

composer require laravel/octane

php artisan octane:install

php artisan octane:start --host=0.0.0.0 --port=8000
```

4. Use PM 2 to keep it live 
```
pm2 start ecosystem.config.js

```

pm2 list                    # List all processes
pm2 stop laravel-octane     # Stop the application
pm2 restart laravel-octane  # Restart the application
pm2 logs laravel-octane     # View logs
pm2 monit                   # Monitor CPU/Memory usage


```
pm2 startup
pm2 save
```




## License

This project is licensed under the same license as the main Phantasm ERP project.

## Support

For support, please refer to the main Phantasm ERP project's support channels or create an issue in this repository. 


General errors 

{
    "status": false,
    "message": "login function failed",
    "error": "Key path \"file:///var/www/primephantasmerp/storage/oauth-private.key\" does not exist or is not readable"
} or smilar errors 
```
php artisan passport:install

``` 
no need to migrate then give path permission

```
cd /var/www/primephantasmerp && chown www-data:www-data storage/oauth-*.key && chmod 640 storage/oauth-*.key
```