@@ -189,6 +189,33 @@ StoryPad uses a three-tier state management approach:
189189### Database
190190Uses ObjectBox for local storage with model definitions in ` lib/core/ ` and generated code via build_runner.
191191
192+ ## MVVM Flow Standard
193+ StoryPad follows a strict MVVM architecture for consistency and testability:
194+
195+ - Model: raw data structures (entities, DTOs), only serialization/deserialization logic.
196+ - Repository / Service / Storage (Data Layer):
197+ - Repository: combines data from one or more sources (local DB, storage, remote service). Single source of truth.
198+ - Service: remote API calls using http. Services may raise exceptions.
199+ - Storage: local persistence (databases, shared preferences, files). Should not raise exceptions in normal flow.
200+ - ViewModel: coordinates between Repository and View. Handles exceptions, exposes UIState (Loading, Success, Error).
201+ - View: Flutter Widgets only. Listens to ViewModel state. No business logic.
202+
203+ ### Exception Handling
204+ - Services can raise exceptions (network failures, parsing).
205+ - Repositories should not pass raw exceptions. Convert to safe return types (Result/Either/nullable).
206+ - ViewModels interpret safe results and decide what to show in the UI.
207+ - Local databases & storages act like repositories, generally no exceptions in normal flow.
208+
209+ ### Testing Guidelines
210+ - Models: test serialization/deserialization only.
211+ - Services: test with mocked http responses (using http.MockClient).
212+ - Repositories: mock Service/Storage, verify combination and exception handling.
213+ - ViewModels: mock Repository, verify state transitions (Loading → Success → Error).
214+ - Views: widget tests to ensure UI updates based on ViewModel state.
215+
216+ ### Reference
217+ - https://docs.flutter.dev/app-architecture/guide
218+
192219## Common Issues & Solutions
193220
194221### Network Requirements
0 commit comments