Skip to main content

Data Flow Patterns

Dokumentasi lengkap tentang alur data dari UI layer hingga backend API di MStore Dashboard.

Overview

Layer Responsibilities

1. Page Component

Responsibility: Render UI dan handle user interactions

2. Composable

Responsibility: Page-specific logic, koordinasi antara UI dan store

3. Pinia Store

Responsibility: Global state management, API coordination

4. API Layer

Responsibility: HTTP communication dengan backend

Complete Data Flow Example

Creating New Item

Error Handling Flow

Optimistic Updates

Untuk UX yang lebih baik, update UI sebelum server response:

Best Practices

  • Store adalah single source of truth untuk domain state
  • Composables hanya membaca dari store
  • Components tidak langsung memodifikasi store state
  • API layer: Transform HTTP errors ke user-friendly messages
  • Store: Simpan error state untuk UI
  • Composable: Handle errors dengan toast/notifications
  • Component: Display error UI
  • Gunakan loading state di store
  • Show skeleton/spinner saat loading
  • Disable form buttons saat submitting
  • Prevent double-submission
  • Validate di form level (composable)
  • Validate lagi di API level (backend)
  • Show validation errors per field
  • Clear errors on input change

Next Steps

API Interceptors

JWT auto-refresh dan error handling

Authentication

Complete auth flow