Data Flow Overview
Data flows through the application in a unidirectional pattern, ensuring predictable behavior and making the system easier to reason about.Flow Diagram
Data Flow Patterns
Create Operation
Read Operation
Update Operation
Delete Operation (Soft Delete)
Complete Example: Creating a Record
Let’s trace a complete data flow for creating a new record:1. UI Component (Presentation Layer)
2. Custom Hook (Presentation Layer)
3. Service (Application Layer)
4. Repository (Infrastructure Layer)
5. Database (Infrastructure Layer)
Error Handling Flow
Errors propagate upward through the layers:State Management
Local Component State
- Form inputs
- Loading states
- Modal visibility
- Temporary UI state
Hook State
- Fetched data (records list)
- Loading indicators
- Error states
Global State (Zustand)
- User session
- App-wide settings
- Theme preferences
Database State (Source of Truth)
- Persisted records
- User data
- Application data
Data Refresh Strategy
The application uses a simple refresh strategy:- After any mutation (create, update, delete)
- Reload all data from the database
- Update component state
- Trigger re-render
This strategy is simple and reliable. For larger datasets, consider implementing optimistic updates or pagination.
Future: API Integration
When migrating to an API backend, the data flow remains similar:Related Pages
Clean Architecture
Understand the architectural layers
Folder Structure
See where each piece lives