# System Architecture

## Core Components

### Frontend Admin Dashboard
- Next.js
- TailwindCSS
- shadcn/ui
- TanStack Table
- Recharts

### Backend API
- NestJS
- Prisma ORM
- PostgreSQL

### Webhook Receiver
- Public HTTPS endpoint
- Signature validation
- Raw payload logging
- Queue handoff for processing

### Worker / Queue
- Redis
- BullMQ
- Handles bulk send, scheduled send, webhook processing, retries

### Storage
- S3 compatible or local object storage for media, import/export files

## Logical Flow
1. Admin uses dashboard
2. Frontend calls backend API
3. Backend stores data in PostgreSQL
4. Bulk and async jobs go to Redis/BullMQ
5. Worker sends outbound messages to provider
6. Provider calls webhook endpoint
7. Webhook receiver stores raw events and dispatches processing jobs
8. Processed statuses update messages, conversations, and campaign recipients

## Security
- JWT + refresh token
- Role-based access control
- Secret encryption at rest
- Webhook signature validation
- Audit logs
- Rate limiting on public endpoints

## Deployment Recommendation
- Dockerized services
- Reverse proxy via Nginx
- HTTPS domain for webhook
- Separate worker process
