BAB 41. BACKEND ARCHITECTURE
Pendahuluan
Backend TemuBelajar dibangun menggunakan Laravel 12 (PHP 8.4) dengan pendekatan Modular Monolith. Pendekatan ini dipilih karena mudah dikembangkan oleh tim kecil, namun tetap siap dipisah menjadi microservice di masa depan.
Arsitektur Backend
flowchart TD
Client["📱 Flutter App"] --> API["🔌 Laravel API Gateway"]
Admin["🖥️ Web Admin"] --> API
API --> Auth["🔐 Auth Module"]
API --> User["👤 User Module"]
API --> Request["📝 Request Module"]
API --> Match["🤖 Matching Module"]
API --> Booking["📅 Booking Module"]
API --> Meeting["🤝 Meeting Module"]
API --> Chat["💬 Chat Module"]
API --> Rating["⭐ Rating Module"]
API --> SIS["🌟 SIS Module"]
API --> Report["📊 Report Module"]
Auth --> DB[("💾 MySQL")]
User --> DB
Request --> DB
Match --> DB
Booking --> DB
Meeting --> DB
Chat --> DB
Rating --> DB
SIS --> DB
Report --> DB
style API fill:#4f63d2,color:#fff
style DB fill:#1f2937,color:#9ca3af
style Match fill:#7c3aed,color:#fff
Layer Arsitektur
| Layer | Tanggung Jawab | Contoh |
|---|---|---|
| API Layer | Endpoint REST, routing | routes/api/requests.php |
| Controller Layer | Validasi awal, delegasi ke service | RequestController.php |
| Service Layer | Business logic, orkestrasi | RequestService.php |
| Repository Layer | Akses database, query | RequestRepository.php |
| Model Layer | Eloquent ORM, relasi | Request.php |
| Database Layer | Penyimpanan data | MySQL tables |
Prinsip Desain
| Prinsip | Penjelasan |
|---|---|
| Thin Controller | Controller hanya menerima request dan mendelegasikan ke service |
| Fat Service | Seluruh logika bisnis berada di Service Layer |
| Repository Pattern | Akses database diabstraksi melalui interface |
| DTO | Data Transfer Object untuk validasi dan transformasi data |
| Event Driven | Aksi penting men-dispatch event (RequestCreated, BookingAccepted) |
| Queue Based | Proses berat (AI Matching, Notifikasi) dijalankan via Queue |
Request Lifecycle
flowchart LR
R["📥 HTTP Request"] --> MW["🛡️ Middleware Stack\n(Auth, Role, School)"]
MW --> C["🎛️ Controller\n(Validate & Delegate)"]
C --> S["⚙️ Service\n(Business Logic)"]
S --> REPO["🗄️ Repository\n(Database Access)"]
REPO --> M["📋 Model\n(Eloquent)"]
M --> DB[("💾 MySQL")]
S --> Q["⏳ Queue\n(Heavy Jobs)"]
S --> E["📡 Events\n(Broadcast)"]
style MW fill:#dc2626,color:#fff
style S fill:#7c3aed,color:#fff
style Q fill:#b45309,color:#fff
Tech Stack Backend
| Komponen | Teknologi | Versi |
|---|---|---|
| Framework | Laravel | 12.x |
| Runtime | PHP | 8.4 |
| Database | MySQL | 8.0+ |
| Cache | Redis | 7.x |
| Queue | Laravel Horizon | latest |
| WebSocket | Laravel Reverb | latest |
| Auth | Laravel Sanctum | latest |
| Storage | Laravel Storage (S3/Local) | — |
| Testing | PHPUnit + Pest | latest |