Modularization
Panduan memecah project menjadi module-module yang independen untuk meningkatkan build time, reusability, dan team scalability.
Kapan Perlu Modularization?
| Kriteria | Perlu | Belum Perlu |
|---|---|---|
| Tim > 3 orang | ✅ | — |
| Build time > 2 menit | ✅ | — |
| Shared code antar project | ✅ | — |
| Project kecil, 1-2 developer | — | ✅ |
Module Types
app/ # Application module (entry point)
├── feature-home/ # Feature module
├── feature-profile/ # Feature module
├── feature-auth/ # Feature module
├── core-network/ # Core module (networking)
├── core-database/ # Core module (local storage)
├── core-data/ # Core module (repository implementations)
├── core-ui/ # Core module (shared UI components)
├── core-common/ # Core module (utilities, extensions)
└── domain/ # Domain module (entities, repository interfaces, use cases)
Nama dan bentuk module mengikuti platform masing-masing (Gradle module di Android, target Swift Package di iOS, package Dart di Flutter). Lihat Folder Structure.
Rules
- Feature modules tidak boleh depend satu sama lain.
- Feature modules boleh depend ke domain dan core module non-data (
core-ui,core-common). Feature tidak boleh depend kecore-data,core-network, ataucore-database; implementasi data disambungkan di app module lewat DI. - Core modules tidak boleh depend ke feature modules.
- Domain module tidak boleh depend ke module lain (kecuali core-common).
- App module adalah satu-satunya module yang mengenal semua module lain, dan tempat wiring DI serta navigasi antar fitur.
Gradual Migration
Tidak perlu modularisasi seluruh project sekaligus. Mulai dengan mengekstrak core-network dan core-ui terlebih dahulu, lalu feature modules secara bertahap.