# Notification Service

# Notification Service (Port 8012) {#notification-service-port-8012}


The **notification-service** handles multi-channel notification delivery (email, SMS, Slack) with template management, delivery tracking, and automatic retry.


## Database {#database}


**Database:** `notification_db`

| Table | Purpose |
|-------|---------|
| `notifications` | Notification records |
| `notification_templates` | Email/SMS/Slack templates |
| `user_preferences` | Per-user notification preferences |


## API Endpoints {#api-endpoints}


| Method | Path | Purpose |
|--------|------|---------|
| POST | `/notification/send` | Send single notification |
| POST | `/notification/send/batch` | Send batch notifications |
| GET | `/notification/history` | List notification history |
| GET | `/notification/templates` | List templates |
| POST | `/notification/templates` | Create template |
| PUT | `/notification/settings` | Update provider settings |
| DELETE | `/notification/preferences/{id}` | Delete preference |


## Channels {#channels}


| Channel | Driver | Configuration |
|---------|--------|---------------|
| Email | SMTP | SMTP server credentials |
| SMS | AWS/Twilio/MSG91/Kaleyra/Africa's Talking | Provider API keys |
| Slack | Webhook | Slack webhook URL |


## Template Seeding {#template-seeding}


11 default auth templates (Magic Link, Activation, etc.) are seeded on startup:

```python
# Automatic seeding in api/tasks/seed_data.py
DEFAULT_TEMPLATES = [
    {"name": "magic_link", "channel": "email", "subject": "Your Login Link"},
    {"name": "account_activation", "channel": "email", "subject": "Activate Your Account"},
    # ... 9 more templates
]
```


## Retry Logic {#retry-logic}


The `notification-beat` Celery Beat container retries failed notifications every 2 minutes:

```python
celery_app.conf.beat_schedule = {
    "retry_failed_notifications": {
        "task": "api.tasks.retry_notifications.retry_failed_notifications",
        "schedule": timedelta(minutes=2),
    },
}
```
