Skip to main content
Platform: Flutter 3.x
State Management: Bloc/Cubit
Local Database: Isar
Last Updated: 2025-10-18

๐ŸŽฏ Architecture Overview

MStore Mobile menggunakan Pure Local + SWR (Stale-While-Revalidate) architecture untuk memastikan instant load dan offline-first experience.

๐Ÿ—๏ธ Layer Architecture

1. Presentation Layer (UI)

Widgets

  • StatelessWidget untuk UI statis
  • StatefulWidget untuk UI dengan state
  • Custom widgets untuk reusability

State Management

  • Bloc/Cubit untuk business logic
  • BlocBuilder untuk reactive UI
  • BlocListener untuk side effects
File Structure:

2. Business Logic Layer (Bloc)

Responsibilities:
  • Handle user interactions
  • Manage UI state
  • Call service layer
  • Transform data for UI
Example:

3. Service Layer (Pure Local + SWR)

Responsibilities:
  • Pure local data access (Isar)
  • Background sync orchestration
  • Connectivity management
  • Error handling
Pattern:

4. Repository Layer

Responsibilities:
  • API communication (Dio/Retrofit)
  • Data transformation (DTO โ†’ Model)
  • Error handling
  • Request/Response mapping
Example:

5. Data Layer (Isar)

Responsibilities:
  • Local data persistence
  • CRUD operations
  • Query & indexing
  • Reactive streams
Entity Example:

๐Ÿ”„ Data Flow

Read Flow (Pure Local)

1

User Action

User membuka screen โ†’ Bloc emit LoadData event
2

Service Call

Bloc call service.getData() โ†’ Service read dari Isar
3

Instant Return

Service return data dari Isar (< 10ms) โ†’ Bloc emit DataLoaded
4

Background Sync

Service trigger background refresh (non-blocking)
5

Silent Update

API fetch โ†’ Update Isar โ†’ Isar stream notify UI โ†’ Auto-update

Write Flow (Offline-First)

1

User Action

User submit form โ†’ Bloc emit SaveData event
2

Write to Isar

Service write to Isar immediately โ†’ Return success
3

Queue Sync

Service queue data untuk background sync
4

Background Sync

When online โ†’ Sync to API โ†’ Update Isar with server response
5

Conflict Resolution

If conflict โ†’ Show conflict resolution UI

๐Ÿ“Š Implementation Status


๐ŸŽจ UI Patterns

No Loading Spinner

JANGAN show loading spinner untuk data refresh!

Isar Stream for Auto-Update

Pull-to-Refresh


๐Ÿ”ง Key Technologies

Flutter 3.x

Cross-platform mobile framework

Bloc/Cubit

State management dengan reactive pattern

Isar Database

Fast, local NoSQL database

Dio + Retrofit

HTTP client dengan interceptors

Get_it

Dependency injection container

Freezed

Code generation untuk immutable models

Dartz

Functional programming (Either, Option)

Connectivity Plus

Network connectivity detection

๐Ÿ“ฑ Development Setup

Prerequisites

Installation

Code Generation


๐Ÿงช Testing

Unit Tests

Widget Tests

Integration Tests


Pure Local Architecture

Detailed SWR pattern implementation

State Management

Bloc/Cubit patterns & best practices

Isar Database

Local database schema & queries

Networking

Dio, Retrofit, interceptors

Offline Implementation

Step-by-step offline-first guide

Testing Guide

Unit, widget, integration tests

๐Ÿ“š Project Structure


๐ŸŽฏ Best Practices

  • Read dari Isar first (instant)
  • Trigger background sync (non-blocking)
  • Never wait for API response
  • Use Either<Failure, Success> pattern
  • Silent fail untuk background sync
  • Show error hanya untuk user actions
  • Keep Bloc logic simple
  • Use Cubit untuk simple state
  • Avoid nested BlocBuilders
  • Use indexes untuk frequent queries
  • Limit query results
  • Use lazy loading untuk large lists
  • Always run build_runner after model changes
  • Use freezed untuk immutable models
  • Use retrofit untuk type-safe API

๐Ÿš€ Performance Tips

Lazy Loading

Load data incrementally dengan pagination

Image Caching

Use cached_network_image untuk images

Widget Optimization

Use const constructors, avoid rebuilds

Background Isolates

Heavy computation di isolate terpisah

Dokumentasi ini adalah living document. Update sesuai dengan evolusi architecture dan best practices.