Lewati ke konten utama

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

LayerTanggung JawabContoh
API LayerEndpoint REST, routingroutes/api/requests.php
Controller LayerValidasi awal, delegasi ke serviceRequestController.php
Service LayerBusiness logic, orkestrasiRequestService.php
Repository LayerAkses database, queryRequestRepository.php
Model LayerEloquent ORM, relasiRequest.php
Database LayerPenyimpanan dataMySQL tables

Prinsip Desain

PrinsipPenjelasan
Thin ControllerController hanya menerima request dan mendelegasikan ke service
Fat ServiceSeluruh logika bisnis berada di Service Layer
Repository PatternAkses database diabstraksi melalui interface
DTOData Transfer Object untuk validasi dan transformasi data
Event DrivenAksi penting men-dispatch event (RequestCreated, BookingAccepted)
Queue BasedProses 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

KomponenTeknologiVersi
FrameworkLaravel12.x
RuntimePHP8.4
DatabaseMySQL8.0+
CacheRedis7.x
QueueLaravel Horizonlatest
WebSocketLaravel Reverblatest
AuthLaravel Sanctumlatest
StorageLaravel Storage (S3/Local)
TestingPHPUnit + Pestlatest