# WhatsApp Module Architecture

## Production Layer

Stage 5 adds operational services without changing the host Laravel application.

All heavy work is queued:

- webhook processing
- media downloads
- outgoing retries
- exports
- imports
- backups
- API monitoring
- security scans
- webhook recovery

## Queues

Default queue name comes from `config('whatsapp.queue')`.

Operational queues:

- retry queue: `wa_message_retries`
- dead queue: `wa_dead_queue`
- Laravel queue jobs for all heavy work

## Monitoring

- `wa_health_checks`: database, cache, queue health
- `wa_api_monitors`: Meta API and Telegram API checks
- `wa_logs`: operational logs and exceptions
- `wa_security_events`: security scan findings
- `wa_user_action_logs`: user activity audit

## Export / Import

Exports support PDF, CSV, JSON through queued jobs.
Imports support CSV and Excel-compatible files through queued jobs.

## Performance

The module contains cursor pagination and cache services for high-volume screens.
Searches should use indexed columns and cached repeated lookups.

## Permissions

`wa_permissions` stores module permission definitions without changing the host auth layer.

