Skip to main content

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:

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

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

  • 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)
  • Selalu define types di types/ folder
  • Hindari any type
  • Export types dari barrel export
  • Use strict TypeScript mode

Next Steps

12 Modules Structure

Detail 12 domain modules

State Management

Pinia state management patterns