# LegalCIA Deployment Checklist

## Server Specs

- PHP 8.2+ with extensions: BCMath, Ctype, cURL, DOM, Fileinfo, GD, JSON, Mbstring, OpenSSL, PDO MySQL, Tokenizer, XML, Zip.
- MySQL 8+ or MariaDB 10.6+.
- Composer 2+.
- Node.js 20+ for building assets.
- Web server: Nginx or Apache pointing to `public/`.
- Supervisor or systemd for queue workers.
- Cron access for Laravel scheduler.
- Disk backup for `storage/app/private`.

## Deploy Steps

1. Upload the project to the server.
2. Point the web server document root to `public/`.
3. Copy `.env.production.example` to `.env`.
4. Fill `APP_URL`, `APP_KEY`, database, mail, session domain, and queue values.
5. Install dependencies:

```bash
composer install --no-dev --optimize-autoloader
npm ci
npm run build
```

6. Generate app key if this is a new install:

```bash
php artisan key:generate
```

7. Run database setup:

```bash
php artisan migrate --force
php artisan db:seed --force
```

Use seeders only for demo or initial default data. Avoid reseeding demo users on a real production tenant unless intended.

8. Set permissions:

```bash
chmod -R ug+rw storage bootstrap/cache
```

On Windows/IIS, grant write access to `storage` and `bootstrap/cache`.

9. Optimize:

```bash
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

10. Queue worker:

```bash
php artisan queue:work --tries=3 --timeout=90
```

Run it under Supervisor/systemd so it restarts automatically.

11. Scheduler cron:

```cron
* * * * * cd /path/to/legalcia && php artisan schedule:run >> /dev/null 2>&1
```

`alerts:process` is registered daily in the scheduler.

12. Storage:

Contract documents are stored privately under `storage/app/private/contracts/...`.
Do not expose that folder publicly. Secure download routes are already used.

## Go-Live Checklist

- `APP_ENV=production`
- `APP_DEBUG=false`
- HTTPS enabled
- Database user has least privileges needed by app
- Mail SMTP tested
- Queue worker running
- Scheduler cron running
- Backups configured
- `/api/reports/contracts` token generated and stored securely
- Admin password changed from demo credentials
- Demo data removed if not needed

## Production Smoke Test

- Create a test company and test users.
- Login/logout and password reset.
- Create, edit, show, delete a contract.
- Create a project and an amendment.
- Upload/download a document.
- Run `php artisan alerts:process`.
- Check dashboard, alerts, calendar, partners, regulated agreements, business units.
- Export CSV/XLSX/PDF.
- Generate a reports API token:

```bash
php artisan reports:token <company_id> --name="Power BI"
```

Then test:

```bash
curl -H "Authorization: Bearer TOKEN" https://your-domain.example/api/reports/contracts
```

## Backup Strategy

- Daily database dumps retained at least 14-30 days.
- Daily backup of `storage/app/private`.
- Keep backups encrypted and off-server.
- Test restore procedure before go-live.

## Known Notes

- Some legacy UI labels still show encoding artifacts in older Blade files. They are visual-only and should be cleaned in a later copy pass.
- `storage:link` is not required for private contract files.
