# BroadcastPro - Installation Guide

## Requirements
- PHP 8.1+
- Composer
- Node.js & NPM
- MySQL 5.7+ or MariaDB
- Laravel 10

## 1. Composer Dependencies
```bash
composer install
```

Packages included: Laravel Breeze, Spatie Permission, Maatwebsite Excel, DomPDF, Twilio SDK.

## 2. NPM Dependencies
```bash
npm install
npm install alpinejs chart.js sweetalert2 --save
```

## 3. Environment Setup
Copy `.env.example` to `.env` and configure:

```env
APP_NAME=BroadcastPro
APP_URL=http://localhost/emailsms-system

# Database
DB_DATABASE=emailsms
DB_USERNAME=root
DB_PASSWORD=

# Queue (use database for campaign processing)
QUEUE_CONNECTION=database

# Mail (SMTP or Mailgun)
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your_username
MAIL_PASSWORD=your_password
MAIL_FROM_ADDRESS=noreply@broadcastpro.com
MAIL_FROM_NAME="BroadcastPro"

# Twilio (SMS)
TWILIO_SID=your_account_sid
TWILIO_TOKEN=your_auth_token
TWILIO_FROM=+1234567890
```

## 4. Generate Key & Run Migrations
```bash
php artisan key:generate
php artisan migrate
```

## 5. Seed Database
```bash
php artisan db:seed
```

Creates:
- Roles: Super Admin, Admin, User
- Permissions
- Subscription plans: Free, Pro, Enterprise
- Super Admin user: admin@broadcastpro.com / password

## 6. Build Assets
```bash
npm run build
```
Or for development: `npm run dev`

## 7. Queue Worker (Required for campaigns)
For email/SMS campaigns to send, run the queue worker:

```bash
php artisan queue:work --queue=campaigns,default
```

For production, use Supervisor or a process manager to keep the worker running.

## 8. Scheduler (Optional - for automation)
Add to crontab:
```
* * * * * cd /path-to-project && php artisan schedule:run >> /dev/null 2>&1
```

## 9. Assign Role to New Users
After registration, assign the "User" role:
```php
$user->assignRole('User');
```
Add this to `RegisteredUserController` or a listener.

## Directory Structure
- `app/Services/` - EmailService, SmsService, CampaignService
- `app/Jobs/` - ProcessCampaignBatch, ProcessSmsCampaignBatch
- `app/Models/` - Contact, Campaign, SmsCampaign, etc.
- `app/Policies/` - Authorization policies

## Permissions
- Super Admin: Full access
- Admin: Manage users, view admin dashboard
- User: Contacts, campaigns, templates, settings
