BAB 46. NOTIFICATION ARCHITECTURE
Tujuan
Sistem notifikasi memastikan tutor, siswa, dan guru menerima informasi secara real-time tentang setiap peristiwa penting dalam siklus belajar.
Arsitektur
flowchart TD
E["📡 Domain Event\n(RequestCreated, BookingAccepted, etc.)"] --> NS["🔔 NotificationService"]
NS --> Q["⏳ Queue\nSendNotificationJob"]
Q --> FCM["🔥 Firebase Cloud\nMessaging (FCM)"]
Q --> DB[("💾 Simpan ke DB\ntabel notifications")]
FCM --> AND["🤖 Android"]
FCM --> IOS["🍎 iOS"]
style E fill:#4f63d2,color:#fff
style FCM fill:#f59e0b,color:#fff
Jenis Notifikasi
| Jenis | Trigger | Penerima |
|---|---|---|
| Request Baru | AI menemukan tutor cocok | Tutor |
| Booking Accepted | Tutor menerima request | Siswa |
| Booking Rejected | Tutor menolak request | Siswa |
| Reschedule Request | Tutor mengusulkan jadwal baru | Siswa |
| Reschedule Accepted | Siswa menerima jadwal baru | Tutor |
| Meeting Reminder | 15 menit sebelum jadwal | Semua peserta |
| Check-In Open | Waktu meeting tiba | Semua peserta |
| Check-Out Reminder | Setelah 5 menit melewati durasi | Semua peserta |
| Rating Reminder | Setelah check-out | Semua peserta |
| Badge Earned | XP mencapai threshold | Siswa |
| Leaderboard Update | Harian (cron job) | Semua siswa |
Channel Notifikasi
| Channel | Teknologi | Kondisi |
|---|---|---|
| Push Notification | Firebase Cloud Messaging | Selalu |
| In-App Notification | Disimpan di DB, ditampilkan saat buka app | Selalu |
| Laravel Mail + SMTP | Opsional (konfigurasi admin) |
Tabel notifications
| Kolom | Tipe | Deskripsi |
|---|---|---|
id | bigint | Primary Key |
user_id | bigint | FK → users (penerima) |
title | varchar | Judul notifikasi |
body | text | Isi notifikasi |
type | varchar | booking_accepted, meeting_reminder, dll |
data | json | Payload tambahan (booking_id, meeting_id, dll) |
is_read | tinyint | 0 = belum dibaca |
sent_at | timestamp | Waktu dikirim |
read_at | timestamp | Waktu dibaca (nullable) |
Implementasi NotificationService
// app/Modules/Notifications/Services/NotificationService.php
class NotificationService implements NotificationServiceInterface
{
public function sendToUser(
int $userId,
string $title,
string $body,
string $type = 'general',
array $data = []
): void {
// 1. Simpan ke database (in-app)
Notification::create([
'user_id' => $userId,
'title' => $title,
'body' => $body,
'type' => $type,
'data' => $data,
'sent_at' => now(),
]);
// 2. Dispatch push notification job
SendNotificationJob::dispatch($userId, $title, $body, $data)
->onQueue('high');
}
}
Flutter — Menerima Notifikasi
// core/services/fcm_service.dart
class FcmService {
Future<void> init() async {
// Request permission
await FirebaseMessaging.instance.requestPermission();
// Foreground notification
FirebaseMessaging.onMessage.listen((message) {
_showInAppBanner(message.notification);
_saveToLocalDB(message.data);
});
// Background / terminated
FirebaseMessaging.onMessageOpenedApp.listen((message) {
_navigateToRelatedScreen(message.data);
});
}
}