> ## Documentation Index
> Fetch the complete documentation index at: https://docs.learnway.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Notification Microservice

> Notification delivery architecture (learnway-notification-service/), Firebase Cloud Messaging (FCM), in-app inbox, and Resend email pipelines.

# Notification Microservice (`learnway-notification-service/`)

The **LearnWay Notification Microservice** (`learnway-notification-service/`) coordinates multi-channel message delivery: push notifications to mobile/web clients, in-app notification center inbox synchronization, and transactional emails.

***

## Architecture & Queue Processing

```mermaid theme={null}
graph TD
    EventSource["Core Backend Events / Cron Triggers"] -->|Push Job Event| Queue["BullMQ Notification Queue"]
    
    Queue --> Worker["Notification Worker Process"]
    Worker --> ChannelRouter{"Select Channel"}
    
    ChannelRouter -->|Push Notification| FCM["Firebase Cloud Messaging API"]
    ChannelRouter -->|Transactional Email| Resend["Resend Email API"]
    ChannelRouter -->|In-App Alert| DB[("Notifications Database")]
    
    FCM --> MobileDevice["iOS / Android Mobile Device"]
    Resend --> UserEmail["User Email Inbox"]
    DB --> WsBroadcast["WebSocket Gateway Broadcast"]
```

***

## Key Responsibilities

### 1. Push Notification Pipeline (FCM)

* **Device Token Management**: Manages device tokens per user across iOS (APNs via FCM), Android (FCM), and Web push.
* **Token Rotation & Pruning**: Automatically purges invalidated or unregistered tokens returned by FCM error payloads.
* **Notification Types**:
  * Streak Reminders (*"Don't lose your 5-day streak! Complete 1 lesson today 🔥"*)
  * Quiz Battle Match Found & Opponent Turn Alerts
  * Weekly Contest Announcements & Prize Distributions
  * NFT Minting and Certificate confirmations

### 2. Transactional Email Pipeline (Resend)

* High-deliverability transactional emails with responsive HTML templates:
  * 6-digit Email Authentication OTPs
  * Password Reset & Wallet PIN verification codes
  * Course Completion Certificates (with attached PDF / IPFS badge links)
  * Weekly Learning Digest & Leaderboard Recap

### 3. In-App Notification Center

* Persists read/unread notifications in the PostgreSQL notification database.
* Exposes read-receipt APIs (`PATCH /api/v2/notifications/:id/read`) and bulk read triggers.
* Emits real-time badge increments to active mobile WebSocket sessions.
