# Deployment

## Environment Variables

Key environment variables required (see `.env` and `.env.example`):

### Application
| Variable | Example | Description |
|----------|---------|-------------|
| `APP_NAME` | `Laravel` | Application name |
| `APP_ENV` | `local` / `production` | Environment |
| `APP_DEBUG` | `true` / `false` | Debug mode |
| `APP_URL` | `http://localhost:8000` | Application URL |
| `APP_KEY` | base64 key | Laravel app key |
| `APP_TIMEZONE` | `Asia/Kolkata` | Timezone |

### Database
| Variable | Example | Description |
|----------|---------|-------------|
| `DB_CONNECTION` | `mysql` | Database driver |
| `DB_HOST` | `127.0.0.1` | Database host |
| `DB_PORT` | `3306` | Database port |
| `DB_DATABASE` | `crm_app_db` | Database name |
| `DB_USERNAME` | `root` | Database username |
| `DB_PASSWORD` | - | Database password |

### Queue & Cache
| Variable | Example | Description |
|----------|---------|-------------|
| `QUEUE_CONNECTION` | `database` | Queue driver |
| `CACHE_STORE` | `database` | Cache driver |
| `SESSION_DRIVER` | `database` | Session driver |

### SMS (External API)
| Variable | Example | Description |
|----------|---------|-------------|
| `SMS_API_URL` | `https://sms.bluwaves.in/sendsms/bulk.php` | SMS provider endpoint |
| `SMS_API_USERNAME` | `bluewavesm` | SMS API username |
| `SMS_API_PASSWORD` | secret | SMS API password |
| `SMS_API_SENDER` | `BLUWAV` | SMS sender ID |
| `SMS_API_TYPE` | `TEXT` | SMS type |
| `SMS_API_ENTITY_ID` | `1301159074611947351` | DLT entity ID |
| `SMS_API_LOGIN_TEMPLATE_ID` | `1707164345457901569` | Login OTP template |
| `SMS_API_MEETING_TEMPLATE_ID` | `1707173278785814832` | Meeting OTP template |

### IVR (External API)
| Variable | Example | Description |
|----------|---------|-------------|
| `CTC_API_URL` | `https://portal.bluewavesmedia.in/api/v1/Ctc/CtcCall/MakeCtcCall` | IVR API endpoint |

### Mail
| Variable | Example | Description |
|----------|---------|-------------|
| `MAIL_MAILER` | `log` / `smtp` | Mail driver |
| `MAIL_HOST` | `127.0.0.1` | SMTP host |
| `MAIL_PORT` | `2525` | SMTP port |
| `MAIL_FROM_ADDRESS` | `hello@example.com` | From address |

## Server Requirements

- **PHP**: ^8.2 with extensions: curl, openssl, gd (for Intervention), mbstring, pdo_mysql, xml, bcmath, json
- **Database**: MySQL 8.0+
- **Web Server**: Apache/Nginx with URL rewriting
- **Composer**: 2.x
- **Node.js**: 22+ (for build only)
- **Queue Worker**: Required for background jobs (notifications, calendar sync, attendance)

## Queue Configuration

- **Driver**: Database (no Redis required in production)
- **Worker command**: `php artisan queue:work --stop-when-empty --tries=3 --timeout=90`
- **Supervisor config**: Should run the queue worker as a daemon

## Scheduler

Tasks are defined in `routes/console.php`:

| Task | Schedule | Command |
|------|----------|---------|
| Dispatch notifications | Every minute | `php artisan schedule:run` (triggered by cron) |
| Generate recurring tasks | Daily 1:00 AM | Same scheduler |
| Process attendance | Daily 2:00 AM | Same scheduler |
| Queue worker | Every minute | Runs within scheduler |

**Cron entry** (run every minute):
```
* * * * * cd /path-to-project && php artisan schedule:run >> /dev/null 2>&1
```

## Build Process

1. Copy `.env.example` to `.env` and configure
2. `composer install --no-dev --optimize-autoloader`
3. `php artisan key:generate`
4. `php artisan migrate --force`
5. `npm ci && npm run build` (build frontend assets)
6. `php artisan storage:link` (create public symlink)

## Production Checklist

- [ ] `APP_ENV=production`
- [ ] `APP_DEBUG=false`
- [ ] Generate app key: `php artisan key:generate`
- [ ] Run migrations: `php artisan migrate --force`
- [ ] Seed permissions: `php artisan db:seed --class=PermissionSeeder`
- [ ] Cache config: `php artisan config:cache`
- [ ] Cache routes: `php artisan route:cache`
- [ ] Optimize: `php artisan optimize`
- [ ] Create storage link: `php artisan storage:link`
- [ ] Set up queue worker (Supervisor/systemd)
- [ ] Set up cron for scheduler
- [ ] Set proper file permissions (storage, bootstrap/cache)
- [ ] Configure MySQL with proper indexes
- [ ] Set up monitoring (queue health, failed jobs)

## Storage Permissions

Directories that need write access:
- `storage/` (full tree)
- `bootstrap/cache/`
- `public/storage/` (symlink target)

## One-Click Setup

Defined in `composer.json`:
```bash
composer setup
```
This runs: `composer install`, copies `.env`, generates key, runs migrations, installs npm, and builds assets.

## Development Server

```bash
composer dev
```
Runs concurrently: `php artisan serve`, `php artisan queue:listen`, and `npm run dev`.

## Testing

```bash
composer test
# or
php artisan test
```

Uses SQLite in-memory database. Tests are written in Pest PHP.

## CI/CD

No CI/CD configuration found in the project. This needs to be set up. Suggested tools: GitHub Actions, Laravel Forge, or Envoyer.
