DDD + Clean Architecture
MStore Dashboard mengimplementasikan Domain-Driven Design (DDD) dengan Clean Architecture untuk memastikan codebase yang maintainable, testable, dan scalable.Architecture Overview
Directory Structure
Architecture Layers
1. Presentation Layer
Bertanggung jawab untuk:- Rendering UI
- Route handling
- User interactions
- Layout management
2. Feature Layer (Domain)
Setiap domain adalah bounded context yang berisi:| Component | Responsibility |
|---|---|
api/ | HTTP calls ke backend |
components/ | UI components khusus domain |
composables/ | Business logic dan page state |
store/ | Global state management |
types/ | TypeScript interfaces |
index.ts | Barrel export |
3. Data Layer
Menangani:- API communication
- Data transformation
- Caching (IndexedDB)
4. Backend Layer (Nitro)
Server-side logic:- API proxying
- Server middleware
- SSR data fetching
Key Principles
1. Separation of Concerns
Setiap layer memiliki tanggung jawab yang jelas:2. Single Responsibility
Setiap file memiliki satu alasan untuk berubah:3. Dependency Inversion
High-level modules tidak bergantung pada low-level modules:4. DRY (Don’t Repeat Yourself)
Reuse components dan utilities:Feature Module Structure
Setiap feature module mengikuti struktur yang sama:Decision Matrix
| Situation | Location | Reason |
|---|---|---|
| Shared across multiple pages | Pinia Store | Global state persistence |
| Used in single page only | Composable | Page-specific logic |
| Used in single component | Component ref | Local state |
| API calls | features/*/api/ | Centralized, testable |
| Business logic | Store or Composable | Reusable |
| UI state (modals, etc.) | Component ref | Local, temporary |
| Utility functions | utils/ | Cross-domain reuse |
| Type definitions | features/*/types/ or types/ | Type safety |
Cross-Domain Communication
Ketika satu domain perlu mengakses domain lain:Adding New Feature
1
Create Feature Folder
2
Define Types
3
Create API Layer
4
Create Store
5
Create Barrel Export
Best Practices
Naming Conventions
Naming Conventions
- Store:
use{Feature}Store(e.g.,useInventoryStore) - Composable:
use{Feature}{Action}(e.g.,useInventoryList) - Component:
{Feature}{Type}(e.g.,InventoryTable) - API:
{action}{Feature}(e.g.,getInventoryList)
Import Paths
Import Paths
Type Safety
Type Safety
- Selalu define types di
types/folder - Hindari
anytype - Export types dari barrel export
- Use strict TypeScript mode