BAB 35. FOLDER STRUCTURE LARAVEL
Pendekatan
Laravel 12 dengan Modular Domain Architecture — setiap domain bisnis terenkapsulasi dalam modulnya sendiri di dalam app/Modules/.
Struktur Utama
app/
├── Modules/ # Semua modul domain bisnis
├── Core/ # Layanan inti (AI, GPS, QR, Security)
├── Shared/ # Kode yang digunakan lintas modul
└── Providers/ # Service provider Laravel
Daftar Modul
app/Modules/
├── Auth/ # Login, logout, change password
├── Users/ # Manajemen data pengguna
├── Students/ # Data dan profil siswa
├── Teachers/ # Data dan dashboard guru
├── Requests/ # Request bantuan belajar
├── Matching/ # AI Matching Engine
├── Bookings/ # Penjadwalan booking
├── Meetings/ # Check-In, Check-Out, QR
├── Chat/ # Realtime messaging
├── Ratings/ # Rating dan feedback
├── Leaderboard/ # Leaderboard dan ranking
├── SIS/ # Social Impact Score
├── Notifications/ # Push & in-app notification
└── Reports/ # Dashboard & export laporan
Struktur Internal Setiap Modul
Setiap modul mengikuti pola Repository Pattern + Service Layer:
app/Modules/Requests/
├── Controllers/
│ └── RequestController.php
├── Services/
│ └── RequestService.php
├── Repositories/
│ ├── RequestRepository.php # Implementasi
│ └── RequestRepositoryInterface.php # Kontrak
├── DTO/
│ └── CreateRequestDTO.php
├── Models/
│ └── Request.php
├── Policies/
│ └── RequestPolicy.php
├── Requests/ # Form Request (validation)
│ └── CreateRequestRequest.php
├── Resources/
│ └── RequestResource.php # API Resource
└── Routes/
└── routes.php
Detail Folder Core/
Berisi layanan teknis yang tidak terkait domain bisnis:
app/Core/
├── AI/
│ ├── MatchingEngine.php
│ ├── ScoringEngine.php
│ ├── CandidateGenerator.php
│ └── NotificationCascade.php
├── GPS/
│ └── GpsValidator.php
├── QR/
│ └── QrCodeGenerator.php
├── Security/
│ ├── RateLimiter.php
│ └── AuditLogger.php
└── Logging/
└── ActivityLogger.php
Detail Folder Shared/
app/Shared/
├── Traits/
│ ├── HasSchool.php # Trait multi-tenant school_id
│ ├── HasAuditLog.php # Auto audit logging
│ └── HasSoftDeletes.php
├── Enums/
│ ├── RequestStatus.php
│ ├── BookingStatus.php
│ ├── UserRole.php
│ └── CompletionStatus.php
├── Helpers/
│ ├── DateHelper.php
│ └── ScoreHelper.php
└── Exceptions/
├── RequestNotFoundException.php
└── BookingConflictException.php
Contoh: Alur Request Bisnis di Laravel
flowchart LR
R["📥 HTTP Request"] --> C["RequestController"]
C --> V["CreateRequestRequest\n(Validation)"]
V --> S["RequestService"]
S --> RI["RequestRepositoryInterface"]
RI --> Repo["RequestRepository"]
Repo --> M["Request Model\n(Eloquent)"]
M --> DB[("MySQL")]
S --> AI["MatchingEngine\n(Core/AI)"]
AI --> Q["Job Queue\n(Horizon)"]
style R fill:#1f2937,color:#fff
style DB fill:#1f2937,color:#fff
style AI fill:#7c3aed,color:#fff
Struktur Lengkap Proyek
temubelajar-backend/
├── app/
│ ├── Modules/
│ ├── Core/
│ ├── Shared/
│ └── Providers/
├── database/
│ ├── migrations/
│ ├── seeders/
│ └── factories/
├── routes/
│ └── api.php # Include semua routes dari Modules
├── config/
├── resources/
│ └── views/ # Laravel Blade (Admin Panel)
├── storage/
├── tests/
│ ├── Unit/
│ └── Feature/
└── docker/
Keuntungan Modular Architecture
| Keuntungan | Penjelasan |
|---|---|
| Domain terpisah | Tidak ada ketergantungan antar modul yang tidak perlu |
| Mudah maintenance | Bug dan perubahan terlokalisir |
| Mudah testing | Setiap modul diuji secara independen |
| Siap microservice | Modul dapat dipisah menjadi service tersendiri |
| Tim paralel | Developer berbeda bisa garap modul berbeda |