BAB 37. MODULAR ARCHITECTURE
Tujuan
Mencegah kode menjadi monolitik — di mana semua logika tercampur dan sulit diubah tanpa mempengaruhi bagian lain. Modular Architecture memastikan setiap domain bisnis terisolasi dan berkomunikasi hanya melalui interface.
Modul Utama TemuBelajar
| Modul | Tanggung Jawab | Dependency |
|---|---|---|
Auth | Login, logout, ganti password | Users |
Users | Data dan manajemen pengguna | Schools |
Students | Profil, skill, XP, SIS | Users, Classrooms |
Teachers | Dashboard dan monitoring guru | Users |
Requests | Permintaan bantuan belajar | Students, Subjects |
Matching | AI Matching Engine | Requests, Students |
Bookings | Penjadwalan tutor | Requests, Students |
Meetings | Check-In, Check-Out, QR | Bookings |
Chat | Realtime messaging | Bookings, Users |
Ratings | Penilaian dan feedback | Meetings |
SIS | Social Impact Score | Ratings, Meetings |
Leaderboard | Ranking siswa | SIS, Students |
Notifications | Push dan in-app notif | Semua modul |
Reports | Dashboard dan ekspor | Semua modul |
Alur Antar Modul
flowchart LR
REQ["📝 Requests"] --> MATCH["🤖 Matching"]
MATCH --> BOOK["📅 Bookings"]
BOOK --> MEET["🤝 Meetings"]
BOOK --> CHAT["💬 Chat"]
MEET --> RATE["⭐ Ratings"]
RATE --> SIS["🌟 SIS"]
SIS --> LEAD["🏆 Leaderboard"]
MATCH -.->|"notify"| NOTIF["📲 Notifications"]
BOOK -.->|"notify"| NOTIF
MEET -.->|"notify"| NOTIF
RATE -.->|"notify"| NOTIF
style MATCH fill:#7c3aed,color:#fff
style NOTIF fill:#1f2937,color:#9ca3af
Prinsip Komunikasi Antar Modul
:::important Aturan Komunikasi Setiap modul hanya mengetahui interface (kontrak) dari modul lain, bukan implementasinya. Ini memastikan loose coupling. :::
Contoh — Modul Matching memanggil Notifications:
// Interface di Notifications module
interface NotificationServiceInterface
{
public function sendToUser(int $userId, string $title, string $body): void;
}
// Digunakan di Matching module — tanpa tahu implementasinya
class MatchingEngine
{
public function __construct(
private NotificationServiceInterface $notificationService
) {}
public function notifyTutor(Student $tutor, Request $request): void
{
$this->notificationService->sendToUser(
userId: $tutor->user_id,
title: 'Ada Request Bantuan Baru!',
body: "Siswa membutuhkan bantuan {$request->subject->name}"
);
}
}
Modul Boundaries
flowchart TD
subgraph AUTH ["🔐 Auth Module"]
L["Login"]
CP["Change Password"]
LO["Logout"]
end
subgraph REQ ["📝 Requests Module"]
CR["Create Request"]
VR["View Requests"]
UR["Update Request"]
end
subgraph MATCH ["🤖 Matching Module"]
CG["Candidate Generator"]
SE["Scoring Engine"]
NC["Notification Cascade"]
end
AUTH --> REQ
REQ --> MATCH
Keuntungan Modular Architecture
| Keuntungan | Penjelasan |
|---|---|
| Isolasi | Bug dalam satu modul tidak merembet ke modul lain |
| Independen | Modul dapat dikembangkan oleh tim berbeda |
| Reusable | Modul Notifications dipakai oleh semua modul lain |
| Testable | Setiap modul diuji secara unit |
| Scalable | Modul dapat diangkat menjadi microservice |
| Maintainable | Perubahan bisnis terlokalisir |
Contoh: Modul Chat (Realtime)
flowchart LR
App["📱 Flutter"] -->|"WebSocket"| Reverb["⚡ Laravel Reverb"]
Reverb -->|"Broadcast"| Channel["Private Channel\nper booking_id"]
Channel --> App2["📱 Flutter\n(Tutor)"]
App -->|"REST"| API["📤 POST /messages"]
API --> DB[("MySQL")]
DB -->|"Event"| Reverb
Chat modul menggunakan Laravel Reverb untuk WebSocket realtime, dengan setiap percakapan terisolasi pada channel privat booking.{id}.