ai-flow-dev 2.1.3 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -38
- package/dist/cli.js +68 -46
- package/dist/cli.js.map +1 -1
- package/package.json +5 -5
- package/prompts/backend/flow-build-phase-0.md +31 -63
- package/prompts/backend/flow-build-phase-1.md +9 -17
- package/prompts/backend/flow-build-phase-10.md +199 -585
- package/prompts/backend/flow-build-phase-2.md +152 -86
- package/prompts/backend/flow-build-phase-3.md +108 -68
- package/prompts/backend/flow-build-phase-4.md +5 -8
- package/prompts/backend/flow-build-phase-5.md +39 -12
- package/prompts/backend/flow-build-phase-6.md +29 -8
- package/prompts/backend/flow-build-phase-7.md +120 -40
- package/prompts/backend/flow-build-phase-8.md +28 -65
- package/prompts/backend/flow-build-phase-9.md +267 -1298
- package/prompts/backend/flow-build.md +881 -957
- package/prompts/backend/flow-dev-commit.md +27 -50
- package/prompts/backend/flow-dev-feature.md +1929 -2017
- package/prompts/backend/flow-dev-fix.md +936 -964
- package/prompts/backend/flow-dev-refactor.md +672 -701
- package/prompts/backend/flow-dev-review.md +356 -389
- package/prompts/backend/flow-dev-work.md +1066 -1118
- package/prompts/backend/flow-docs-sync.md +20 -196
- package/prompts/frontend/flow-build-phase-0.md +503 -484
- package/prompts/frontend/flow-build-phase-1.md +445 -433
- package/prompts/frontend/flow-build-phase-2.md +910 -957
- package/prompts/frontend/flow-build-phase-3.md +692 -664
- package/prompts/frontend/flow-build-phase-4.md +478 -463
- package/prompts/frontend/flow-build-phase-5.md +488 -467
- package/prompts/frontend/flow-build-phase-6.md +571 -550
- package/prompts/frontend/flow-build-phase-7.md +560 -592
- package/prompts/frontend/flow-build-phase-8.md +17 -42
- package/prompts/frontend/flow-build.md +457 -503
- package/prompts/frontend/flow-docs-sync.md +14 -35
- package/prompts/mobile/flow-build-phase-0.md +104 -97
- package/prompts/mobile/flow-build-phase-1.md +137 -122
- package/prompts/mobile/flow-build-phase-2.md +123 -130
- package/prompts/mobile/flow-build-phase-3.md +144 -149
- package/prompts/mobile/flow-build-phase-4.md +140 -132
- package/prompts/mobile/flow-build-phase-5.md +70 -70
- package/prompts/mobile/flow-build-phase-6.md +136 -134
- package/prompts/mobile/flow-build-phase-7.md +24 -58
- package/prompts/mobile/flow-build-phase-8.md +17 -42
- package/prompts/mobile/flow-build.md +47 -97
- package/prompts/mobile/flow-docs-sync.md +13 -32
- package/prompts/shared/mermaid-guidelines.md +106 -0
- package/prompts/shared/scope-levels.md +126 -0
- package/prompts/shared/story-points.md +65 -0
- package/prompts/shared/task-format.md +86 -0
- package/templates/AGENT.template.md +194 -15
- package/templates/backend/README.template.md +2 -32
- package/templates/backend/ai-instructions.template.md +2 -32
- package/templates/backend/copilot-instructions.template.md +2 -22
- package/templates/backend/docs/api.template.md +89 -20
- package/templates/backend/docs/architecture.template.md +165 -53
- package/templates/backend/docs/business-flows.template.md +7 -14
- package/templates/backend/docs/code-standards.template.md +2 -38
- package/templates/backend/docs/contributing.template.md +2 -16
- package/templates/backend/docs/data-model.template.md +125 -21
- package/templates/backend/docs/operations.template.md +179 -50
- package/templates/backend/docs/testing.template.md +2 -42
- package/templates/backend/project-brief.template.md +2 -28
- package/templates/backend/specs/configuration.template.md +2 -14
- package/templates/backend/specs/security.template.md +2 -32
- package/templates/frontend/README.template.md +2 -18
- package/templates/frontend/ai-instructions.template.md +2 -20
- package/templates/frontend/docs/api-integration.template.md +12 -30
- package/templates/frontend/docs/components.template.md +2 -28
- package/templates/frontend/docs/error-handling.template.md +11 -27
- package/templates/frontend/docs/operations.template.md +8 -18
- package/templates/frontend/docs/performance.template.md +8 -18
- package/templates/frontend/docs/pwa.template.md +8 -18
- package/templates/frontend/docs/state-management.template.md +2 -28
- package/templates/frontend/docs/styling.template.md +2 -26
- package/templates/frontend/docs/testing.template.md +2 -28
- package/templates/frontend/project-brief.template.md +2 -16
- package/templates/frontend/specs/accessibility.template.md +8 -18
- package/templates/frontend/specs/configuration.template.md +2 -24
- package/templates/frontend/specs/security.template.md +10 -24
- package/templates/fullstack/README.template.md +17 -47
- package/templates/fullstack/ai-instructions.template.md +17 -45
- package/templates/fullstack/project-brief.template.md +16 -42
- package/templates/fullstack/specs/configuration.template.md +16 -42
- package/templates/mobile/README.template.md +11 -29
- package/templates/mobile/ai-instructions.template.md +11 -27
- package/templates/mobile/docs/app-store.template.md +11 -29
- package/templates/mobile/docs/architecture.template.md +14 -38
- package/templates/mobile/docs/native-features.template.md +16 -44
- package/templates/mobile/docs/navigation.template.md +9 -23
- package/templates/mobile/docs/offline-strategy.template.md +10 -26
- package/templates/mobile/docs/permissions.template.md +9 -23
- package/templates/mobile/docs/state-management.template.md +12 -32
- package/templates/mobile/docs/testing.template.md +14 -38
- package/templates/mobile/project-brief.template.md +12 -30
- package/templates/mobile/specs/build-configuration.template.md +10 -26
- package/templates/mobile/specs/deployment.template.md +9 -23
|
@@ -1,687 +1,715 @@
|
|
|
1
|
-
# Phase 3: State Management
|
|
2
|
-
|
|
3
|
-
**Duration:** 15-20 minutes
|
|
4
|
-
**Questions:** ~10 questions
|
|
5
|
-
**Output:** docs/state-management.md, parts of ai-instructions.md
|
|
6
|
-
|
|
1
|
+
# Phase 3: State Management
|
|
2
|
+
|
|
3
|
+
**Duration:** 15-20 minutes
|
|
4
|
+
**Questions:** ~10 questions
|
|
5
|
+
**Output:** docs/state-management.md, parts of ai-instructions.md
|
|
6
|
+
---
|
|
7
|
+
## 🎯 Objective
|
|
8
|
+
|
|
9
|
+
Define how your application will manage state across four categories:
|
|
10
|
+
|
|
11
|
+
1. **Server State** - Remote data from APIs
|
|
12
|
+
2. **Client State** - Local UI state
|
|
13
|
+
3. **URL State** - Query params and routes
|
|
14
|
+
4. **Form State** - Form data and validation
|
|
15
|
+
---
|
|
16
|
+
## 📋 Questions
|
|
17
|
+
|
|
18
|
+
### Question 3.1: Server State Management
|
|
19
|
+
|
|
20
|
+
**How will you fetch and cache data from APIs?**
|
|
21
|
+
|
|
22
|
+
#### React Options
|
|
23
|
+
|
|
24
|
+
A) ⭐ **TanStack Query (React Query)** (Recommended)
|
|
25
|
+
|
|
26
|
+
- Features: Auto caching, background refetching, optimistic updates
|
|
27
|
+
- Best for: REST APIs, GraphQL (via custom fetcher)
|
|
28
|
+
- Bundle: ~12KB (gzipped)
|
|
29
|
+
|
|
30
|
+
B) 🔥 **SWR (Vercel)**
|
|
31
|
+
|
|
32
|
+
- Features: Stale-while-revalidate, automatic deduplication
|
|
33
|
+
- Best for: REST APIs, simple data fetching
|
|
34
|
+
- Bundle: ~5KB (gzipped)
|
|
35
|
+
|
|
36
|
+
C) **Apollo Client**
|
|
37
|
+
|
|
38
|
+
- Features: GraphQL-specific, normalized cache, subscriptions
|
|
39
|
+
- Best for: GraphQL APIs only
|
|
40
|
+
- Bundle: ~33KB (gzipped)
|
|
41
|
+
|
|
42
|
+
D) **urql**
|
|
43
|
+
|
|
44
|
+
- Features: Lightweight GraphQL client, extensible
|
|
45
|
+
- Best for: GraphQL, smaller bundle than Apollo
|
|
46
|
+
- Bundle: ~16KB (gzipped)
|
|
47
|
+
|
|
48
|
+
E) **Redux Toolkit + RTK Query**
|
|
49
|
+
|
|
50
|
+
- Features: Integrated with Redux, powerful caching
|
|
51
|
+
- Best for: Complex apps already using Redux
|
|
52
|
+
- Bundle: ~15KB (gzipped, with Redux)
|
|
53
|
+
|
|
54
|
+
F) **Plain fetch + Custom Hooks**
|
|
55
|
+
|
|
56
|
+
- Features: Full control, no dependencies
|
|
57
|
+
- Best for: Very simple apps
|
|
58
|
+
- Bundle: 0KB (native)
|
|
59
|
+
|
|
60
|
+
#### Vue Options
|
|
61
|
+
|
|
62
|
+
A) ⭐ **TanStack Query (Vue Query)** (Recommended)
|
|
63
|
+
|
|
64
|
+
- Same as React version, Vue adapter
|
|
65
|
+
|
|
66
|
+
B) **Pinia + Custom Composables**
|
|
67
|
+
|
|
68
|
+
- Features: Reactive state management
|
|
69
|
+
- Best for: Vue 3 apps with complex state
|
|
70
|
+
|
|
71
|
+
C) **Villus (GraphQL)**
|
|
72
|
+
|
|
73
|
+
- Features: Lightweight GraphQL client for Vue
|
|
74
|
+
- Best for: Vue + GraphQL
|
|
75
|
+
|
|
76
|
+
#### Angular Options
|
|
77
|
+
|
|
78
|
+
A) ⭐ **TanStack Query (Angular Query)**
|
|
79
|
+
|
|
80
|
+
- Same as React version, Angular adapter
|
|
81
|
+
|
|
82
|
+
B) **NgRx + Custom Effects**
|
|
83
|
+
|
|
84
|
+
- Features: Redux pattern for Angular
|
|
85
|
+
- Best for: Enterprise Angular apps
|
|
86
|
+
|
|
87
|
+
C) **Apollo Angular**
|
|
88
|
+
|
|
89
|
+
- Features: GraphQL client for Angular
|
|
90
|
+
- Best for: Angular + GraphQL
|
|
91
|
+
|
|
92
|
+
**Your answer:**
|
|
7
93
|
---
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
94
|
+
### Question 3.2: Client State Management
|
|
95
|
+
|
|
96
|
+
**How will you manage local UI state?** (modals, themes, UI flags)
|
|
97
|
+
|
|
98
|
+
#### React Options
|
|
99
|
+
|
|
100
|
+
A) ⭐ **Zustand** (Recommended for most)
|
|
101
|
+
|
|
102
|
+
- Features: Minimal boilerplate, hooks-based, simple API
|
|
103
|
+
- Best for: Small to medium apps, simple global state
|
|
104
|
+
- Bundle: ~1KB (gzipped)
|
|
105
|
+
|
|
106
|
+
B) 🔥 **Redux Toolkit**
|
|
107
|
+
|
|
108
|
+
- Features: Redux with less boilerplate, DevTools, middleware
|
|
109
|
+
- Best for: Large apps, complex state logic, time-travel debugging
|
|
110
|
+
- Bundle: ~14KB (gzipped)
|
|
111
|
+
|
|
112
|
+
C) **Jotai**
|
|
113
|
+
|
|
114
|
+
- Features: Atomic state management, bottom-up approach
|
|
115
|
+
- Best for: Fine-grained reactivity, derived state
|
|
116
|
+
- Bundle: ~3KB (gzipped)
|
|
117
|
+
|
|
118
|
+
D) **Recoil**
|
|
119
|
+
|
|
120
|
+
- Features: Facebook's state library, atom-based
|
|
121
|
+
- Best for: Complex dependency graphs
|
|
122
|
+
- Bundle: ~21KB (gzipped)
|
|
123
|
+
|
|
124
|
+
E) **Context API + useReducer**
|
|
125
|
+
|
|
126
|
+
- Features: Built-in React, no dependencies
|
|
127
|
+
- Best for: Simple apps, small global state
|
|
128
|
+
- Bundle: 0KB (native)
|
|
129
|
+
|
|
130
|
+
F) **XState**
|
|
131
|
+
|
|
132
|
+
- Features: State machines, predictable state transitions
|
|
133
|
+
- Best for: Complex workflows, multi-step forms
|
|
134
|
+
- Bundle: ~18KB (gzipped)
|
|
135
|
+
|
|
136
|
+
#### Vue Options
|
|
137
|
+
|
|
138
|
+
A) ⭐ **Pinia** (Recommended)
|
|
139
|
+
|
|
140
|
+
- Features: Official Vue state library, TypeScript support
|
|
141
|
+
- Best for: Vue 3 apps
|
|
142
|
+
- Bundle: ~1.5KB (gzipped)
|
|
143
|
+
|
|
144
|
+
B) **Vuex**
|
|
145
|
+
|
|
146
|
+
- Features: Traditional Vue state management
|
|
147
|
+
- Best for: Vue 2 apps, migration from Vue 2
|
|
148
|
+
- Bundle: ~2KB (gzipped)
|
|
149
|
+
|
|
150
|
+
C) **Composition API (Built-in)**
|
|
151
|
+
|
|
152
|
+
- Features: `reactive()`, `ref()`, composables
|
|
153
|
+
- Best for: Simple apps
|
|
154
|
+
- Bundle: 0KB (native)
|
|
155
|
+
|
|
156
|
+
#### Angular Options
|
|
157
|
+
|
|
158
|
+
A) ⭐ **NgRx** (Recommended for large apps)
|
|
159
|
+
|
|
160
|
+
- Features: Redux pattern, RxJS integration
|
|
161
|
+
- Best for: Enterprise Angular apps
|
|
162
|
+
- Bundle: ~18KB (gzipped)
|
|
163
|
+
|
|
164
|
+
B) **Akita**
|
|
165
|
+
|
|
166
|
+
- Features: Simplified state management, RxJS-based
|
|
167
|
+
- Best for: Medium Angular apps
|
|
168
|
+
- Bundle: ~12KB (gzipped)
|
|
169
|
+
|
|
170
|
+
C) **Elf**
|
|
171
|
+
|
|
172
|
+
- Features: Reactive state management, modular
|
|
173
|
+
- Best for: Flexible architecture
|
|
174
|
+
- Bundle: ~8KB (gzipped)
|
|
175
|
+
|
|
176
|
+
D) **Services + RxJS (Built-in)**
|
|
177
|
+
|
|
178
|
+
- Features: Angular services with BehaviorSubject
|
|
179
|
+
- Best for: Simple apps
|
|
180
|
+
- Bundle: 0KB (native)
|
|
181
|
+
|
|
182
|
+
#### Svelte Options
|
|
183
|
+
|
|
184
|
+
A) ⭐ **Svelte Stores** (Recommended)
|
|
185
|
+
|
|
186
|
+
- Features: Built-in, writable/readable/derived stores
|
|
187
|
+
- Best for: All Svelte apps
|
|
188
|
+
- Bundle: 0KB (built-in)
|
|
189
|
+
|
|
190
|
+
B) **XState + Svelte**
|
|
191
|
+
|
|
192
|
+
- Features: State machines for complex flows
|
|
193
|
+
- Best for: Complex workflows
|
|
194
|
+
|
|
195
|
+
#### Solid Options
|
|
196
|
+
|
|
197
|
+
A) ⭐ **Solid Store** (Recommended)
|
|
198
|
+
|
|
199
|
+
- Features: Built-in, reactive store
|
|
200
|
+
- Best for: All Solid apps
|
|
201
|
+
- Bundle: 0KB (built-in)
|
|
202
|
+
|
|
203
|
+
**Your answer:**
|
|
18
204
|
---
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
D) **urql**
|
|
44
|
-
- Features: Lightweight GraphQL client, extensible
|
|
45
|
-
- Best for: GraphQL, smaller bundle than Apollo
|
|
46
|
-
- Bundle: ~16KB (gzipped)
|
|
47
|
-
|
|
48
|
-
E) **Redux Toolkit + RTK Query**
|
|
49
|
-
- Features: Integrated with Redux, powerful caching
|
|
50
|
-
- Best for: Complex apps already using Redux
|
|
51
|
-
- Bundle: ~15KB (gzipped, with Redux)
|
|
52
|
-
|
|
53
|
-
F) **Plain fetch + Custom Hooks**
|
|
54
|
-
- Features: Full control, no dependencies
|
|
55
|
-
- Best for: Very simple apps
|
|
56
|
-
- Bundle: 0KB (native)
|
|
57
|
-
|
|
58
|
-
#### Vue Options
|
|
59
|
-
|
|
60
|
-
A) ⭐ **TanStack Query (Vue Query)** (Recommended)
|
|
61
|
-
- Same as React version, Vue adapter
|
|
62
|
-
|
|
63
|
-
B) **Pinia + Custom Composables**
|
|
64
|
-
- Features: Reactive state management
|
|
65
|
-
- Best for: Vue 3 apps with complex state
|
|
66
|
-
|
|
67
|
-
C) **Villus (GraphQL)**
|
|
68
|
-
- Features: Lightweight GraphQL client for Vue
|
|
69
|
-
- Best for: Vue + GraphQL
|
|
70
|
-
|
|
71
|
-
#### Angular Options
|
|
72
|
-
|
|
73
|
-
A) ⭐ **TanStack Query (Angular Query)**
|
|
74
|
-
- Same as React version, Angular adapter
|
|
75
|
-
|
|
76
|
-
B) **NgRx + Custom Effects**
|
|
77
|
-
- Features: Redux pattern for Angular
|
|
78
|
-
- Best for: Enterprise Angular apps
|
|
79
|
-
|
|
80
|
-
C) **Apollo Angular**
|
|
81
|
-
- Features: GraphQL client for Angular
|
|
82
|
-
- Best for: Angular + GraphQL
|
|
83
|
-
|
|
84
|
-
**Your answer:**
|
|
85
|
-
|
|
205
|
+
### Question 3.3: State Persistence
|
|
206
|
+
|
|
207
|
+
**Do you need to persist state to localStorage/sessionStorage?**
|
|
208
|
+
|
|
209
|
+
A) ⭐ **No Persistence**
|
|
210
|
+
|
|
211
|
+
- State reset on page reload
|
|
212
|
+
- Best for: Most apps
|
|
213
|
+
|
|
214
|
+
B) **Selective Persistence**
|
|
215
|
+
|
|
216
|
+
- Persist specific state (e.g., theme, user preferences)
|
|
217
|
+
- Example: Zustand persist middleware, Pinia persist plugin
|
|
218
|
+
- Best for: User preferences, shopping cart
|
|
219
|
+
|
|
220
|
+
C) **Full Persistence**
|
|
221
|
+
|
|
222
|
+
- Persist entire state tree
|
|
223
|
+
- Best for: Offline-first apps, complex forms
|
|
224
|
+
|
|
225
|
+
**Your answer:**
|
|
226
|
+
|
|
227
|
+
**If persistence selected, what should be persisted?**
|
|
86
228
|
---
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
B)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
A) ⭐ **Svelte Stores** (Recommended)
|
|
166
|
-
- Features: Built-in, writable/readable/derived stores
|
|
167
|
-
- Best for: All Svelte apps
|
|
168
|
-
- Bundle: 0KB (built-in)
|
|
169
|
-
|
|
170
|
-
B) **XState + Svelte**
|
|
171
|
-
- Features: State machines for complex flows
|
|
172
|
-
- Best for: Complex workflows
|
|
173
|
-
|
|
174
|
-
#### Solid Options
|
|
175
|
-
|
|
176
|
-
A) ⭐ **Solid Store** (Recommended)
|
|
177
|
-
- Features: Built-in, reactive store
|
|
178
|
-
- Best for: All Solid apps
|
|
179
|
-
- Bundle: 0KB (built-in)
|
|
180
|
-
|
|
181
|
-
**Your answer:**
|
|
182
|
-
|
|
229
|
+
### Question 3.4: Form State Management
|
|
230
|
+
|
|
231
|
+
**How will you handle forms?**
|
|
232
|
+
|
|
233
|
+
#### React Options
|
|
234
|
+
|
|
235
|
+
A) ⭐ **React Hook Form** (Recommended)
|
|
236
|
+
|
|
237
|
+
- Features: Uncontrolled forms, minimal re-renders, validation
|
|
238
|
+
- Best for: Performance-critical forms, complex validation
|
|
239
|
+
- Bundle: ~9KB (gzipped)
|
|
240
|
+
|
|
241
|
+
B) **Formik**
|
|
242
|
+
|
|
243
|
+
- Features: Controlled forms, popular, mature
|
|
244
|
+
- Best for: Traditional React forms
|
|
245
|
+
- Bundle: ~15KB (gzipped)
|
|
246
|
+
|
|
247
|
+
C) **TanStack Form**
|
|
248
|
+
|
|
249
|
+
- Features: Framework-agnostic, type-safe
|
|
250
|
+
- Best for: Advanced form logic
|
|
251
|
+
- Bundle: ~12KB (gzipped)
|
|
252
|
+
|
|
253
|
+
D) **Controlled Components (Built-in)**
|
|
254
|
+
|
|
255
|
+
- Features: Manual useState management
|
|
256
|
+
- Best for: Simple forms (1-3 fields)
|
|
257
|
+
- Bundle: 0KB (native)
|
|
258
|
+
|
|
259
|
+
#### Vue Options
|
|
260
|
+
|
|
261
|
+
A) ⭐ **VeeValidate** (Recommended)
|
|
262
|
+
|
|
263
|
+
- Features: Composition API, Yup/Zod integration
|
|
264
|
+
- Best for: Vue 3 forms with validation
|
|
265
|
+
- Bundle: ~7KB (gzipped)
|
|
266
|
+
|
|
267
|
+
B) **FormKit**
|
|
268
|
+
|
|
269
|
+
- Features: All-in-one forms + UI components
|
|
270
|
+
- Best for: Rapid form development
|
|
271
|
+
- Bundle: ~25KB (gzipped)
|
|
272
|
+
|
|
273
|
+
C) **v-model (Built-in)**
|
|
274
|
+
|
|
275
|
+
- Features: Two-way binding
|
|
276
|
+
- Best for: Simple forms
|
|
277
|
+
- Bundle: 0KB (native)
|
|
278
|
+
|
|
279
|
+
#### Angular Options
|
|
280
|
+
|
|
281
|
+
A) ⭐ **Reactive Forms** (Recommended)
|
|
282
|
+
|
|
283
|
+
- Features: Built-in, powerful validation
|
|
284
|
+
- Best for: Complex Angular forms
|
|
285
|
+
- Bundle: 0KB (built-in)
|
|
286
|
+
|
|
287
|
+
B) **Template-Driven Forms**
|
|
288
|
+
|
|
289
|
+
- Features: Built-in, simpler API
|
|
290
|
+
- Best for: Simple Angular forms
|
|
291
|
+
- Bundle: 0KB (built-in)
|
|
292
|
+
|
|
293
|
+
#### Svelte/Solid Options
|
|
294
|
+
|
|
295
|
+
A) **Two-way binding (Built-in)**
|
|
296
|
+
|
|
297
|
+
- Features: Simple bind:value syntax
|
|
298
|
+
- Best for: Most forms
|
|
299
|
+
- Bundle: 0KB (built-in)
|
|
300
|
+
|
|
301
|
+
B) **Felte (Svelte) / Modular Forms (Solid)**
|
|
302
|
+
|
|
303
|
+
- Features: Advanced form libraries
|
|
304
|
+
- Best for: Complex validation
|
|
305
|
+
|
|
306
|
+
**Your answer:**
|
|
183
307
|
---
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
308
|
+
### Question 3.5: Form Validation
|
|
309
|
+
|
|
310
|
+
**What validation strategy will you use?**
|
|
311
|
+
|
|
312
|
+
A) ⭐ **Schema Validation (Zod/Yup)**
|
|
313
|
+
|
|
314
|
+
- Features: Type-safe, reusable schemas
|
|
315
|
+
- Best for: Complex validation, type safety
|
|
316
|
+
- Example: Zod for TypeScript projects
|
|
317
|
+
|
|
318
|
+
B) **Built-in HTML5 Validation**
|
|
319
|
+
|
|
320
|
+
- Features: Native browser validation
|
|
321
|
+
- Best for: Simple forms
|
|
322
|
+
- Example: `required`, `pattern`, `min`, `max`
|
|
323
|
+
|
|
324
|
+
C) **Custom Validation Functions**
|
|
325
|
+
|
|
326
|
+
- Features: Full control, no dependencies
|
|
327
|
+
- Best for: Unique validation rules
|
|
328
|
+
|
|
329
|
+
D) **Backend Validation Only**
|
|
330
|
+
|
|
331
|
+
- Features: Server-side validation
|
|
332
|
+
- Best for: Security-critical forms
|
|
333
|
+
- Note: Still need client-side for UX
|
|
334
|
+
|
|
335
|
+
E) **Combined (Client + Server)**
|
|
336
|
+
|
|
337
|
+
- Features: Client for UX, server for security
|
|
338
|
+
- Best for: Most production apps
|
|
339
|
+
|
|
340
|
+
**Your answer:**
|
|
206
341
|
---
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
B) **
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
C) **
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
D) **Controlled Components (Built-in)**
|
|
230
|
-
- Features: Manual useState management
|
|
231
|
-
- Best for: Simple forms (1-3 fields)
|
|
232
|
-
- Bundle: 0KB (native)
|
|
233
|
-
|
|
234
|
-
#### Vue Options
|
|
235
|
-
|
|
236
|
-
A) ⭐ **VeeValidate** (Recommended)
|
|
237
|
-
- Features: Composition API, Yup/Zod integration
|
|
238
|
-
- Best for: Vue 3 forms with validation
|
|
239
|
-
- Bundle: ~7KB (gzipped)
|
|
240
|
-
|
|
241
|
-
B) **FormKit**
|
|
242
|
-
- Features: All-in-one forms + UI components
|
|
243
|
-
- Best for: Rapid form development
|
|
244
|
-
- Bundle: ~25KB (gzipped)
|
|
245
|
-
|
|
246
|
-
C) **v-model (Built-in)**
|
|
247
|
-
- Features: Two-way binding
|
|
248
|
-
- Best for: Simple forms
|
|
249
|
-
- Bundle: 0KB (native)
|
|
250
|
-
|
|
251
|
-
#### Angular Options
|
|
252
|
-
|
|
253
|
-
A) ⭐ **Reactive Forms** (Recommended)
|
|
254
|
-
- Features: Built-in, powerful validation
|
|
255
|
-
- Best for: Complex Angular forms
|
|
256
|
-
- Bundle: 0KB (built-in)
|
|
257
|
-
|
|
258
|
-
B) **Template-Driven Forms**
|
|
259
|
-
- Features: Built-in, simpler API
|
|
260
|
-
- Best for: Simple Angular forms
|
|
261
|
-
- Bundle: 0KB (built-in)
|
|
262
|
-
|
|
263
|
-
#### Svelte/Solid Options
|
|
264
|
-
|
|
265
|
-
A) **Two-way binding (Built-in)**
|
|
266
|
-
- Features: Simple bind:value syntax
|
|
267
|
-
- Best for: Most forms
|
|
268
|
-
- Bundle: 0KB (built-in)
|
|
269
|
-
|
|
270
|
-
B) **Felte (Svelte) / Modular Forms (Solid)**
|
|
271
|
-
- Features: Advanced form libraries
|
|
272
|
-
- Best for: Complex validation
|
|
273
|
-
|
|
274
|
-
**Your answer:**
|
|
275
|
-
|
|
342
|
+
### Question 3.6: Optimistic Updates
|
|
343
|
+
|
|
344
|
+
**Will you use optimistic UI updates?**
|
|
345
|
+
|
|
346
|
+
Optimistic updates = Update UI before server confirms success
|
|
347
|
+
|
|
348
|
+
A) ⭐ **Yes, for common actions**
|
|
349
|
+
|
|
350
|
+
- Example: Like button, delete item, mark complete
|
|
351
|
+
- Best for: Interactive apps, real-time feel
|
|
352
|
+
- Requires: Rollback logic on error
|
|
353
|
+
|
|
354
|
+
B) **No, wait for server confirmation**
|
|
355
|
+
|
|
356
|
+
- Best for: Critical actions (payments, deletions)
|
|
357
|
+
- Safer but slower UX
|
|
358
|
+
|
|
359
|
+
C) **Selective (case-by-case)**
|
|
360
|
+
|
|
361
|
+
- Optimistic for safe actions, wait for critical ones
|
|
362
|
+
|
|
363
|
+
**Your answer:**
|
|
276
364
|
---
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
C) **
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
365
|
+
### Question 3.7: Real-Time Updates
|
|
366
|
+
|
|
367
|
+
**Do you need real-time data updates?**
|
|
368
|
+
|
|
369
|
+
A) ⭐ **No Real-Time**
|
|
370
|
+
|
|
371
|
+
- Data fetched on demand or on interval
|
|
372
|
+
- Best for: Most apps
|
|
373
|
+
|
|
374
|
+
B) **Polling (Short Intervals)**
|
|
375
|
+
|
|
376
|
+
- Refetch data every X seconds
|
|
377
|
+
- Best for: Near real-time, simple implementation
|
|
378
|
+
- Example: Every 10-30 seconds
|
|
379
|
+
|
|
380
|
+
C) **WebSockets**
|
|
381
|
+
|
|
382
|
+
- Bi-directional, persistent connection
|
|
383
|
+
- Best for: Chat, live dashboards, collaboration
|
|
384
|
+
- Technologies: Socket.io, native WebSockets
|
|
385
|
+
|
|
386
|
+
D) **Server-Sent Events (SSE)**
|
|
387
|
+
|
|
388
|
+
- Unidirectional, server pushes updates
|
|
389
|
+
- Best for: Live notifications, feeds
|
|
390
|
+
- Technologies: EventSource API
|
|
391
|
+
|
|
392
|
+
E) **GraphQL Subscriptions**
|
|
393
|
+
|
|
394
|
+
- Real-time GraphQL queries
|
|
395
|
+
- Best for: GraphQL apps with live data
|
|
396
|
+
|
|
397
|
+
**Your answer:**
|
|
307
398
|
---
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
399
|
+
### Question 3.8: State Normalization
|
|
400
|
+
|
|
401
|
+
**Will you normalize relational data?**
|
|
402
|
+
|
|
403
|
+
Normalization = Flatten nested data into lookup tables (like a database)
|
|
404
|
+
|
|
405
|
+
**Example:**
|
|
406
|
+
|
|
407
|
+
```javascript
|
|
408
|
+
// ❌ Nested (Not normalized)
|
|
409
|
+
{
|
|
410
|
+
posts: [
|
|
411
|
+
{ id: 1, title: 'Post 1', author: { id: 10, name: 'Alice' } },
|
|
412
|
+
{ id: 2, title: 'Post 2', author: { id: 10, name: 'Alice' } }
|
|
413
|
+
]
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// ✅ Normalized
|
|
417
|
+
{
|
|
418
|
+
posts: { 1: { id: 1, title: 'Post 1', authorId: 10 }, 2: { ... } },
|
|
419
|
+
authors: { 10: { id: 10, name: 'Alice' } }
|
|
420
|
+
}
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
A) ⭐ **Yes, normalize relational data**
|
|
424
|
+
|
|
425
|
+
- Best for: Complex data models, many-to-many relationships
|
|
426
|
+
- Tools: normalizr, Redux Toolkit (createEntityAdapter)
|
|
427
|
+
|
|
428
|
+
B) **No, keep data nested**
|
|
429
|
+
|
|
430
|
+
- Best for: Simple data structures, tree-like data
|
|
431
|
+
- Easier to reason about
|
|
432
|
+
|
|
433
|
+
**Your answer:**
|
|
329
434
|
---
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
- Best for: Live notifications, feeds
|
|
352
|
-
- Technologies: EventSource API
|
|
353
|
-
|
|
354
|
-
E) **GraphQL Subscriptions**
|
|
355
|
-
- Real-time GraphQL queries
|
|
356
|
-
- Best for: GraphQL apps with live data
|
|
357
|
-
|
|
358
|
-
**Your answer:**
|
|
359
|
-
|
|
435
|
+
### Question 3.9: Global vs Local State
|
|
436
|
+
|
|
437
|
+
**What's your default strategy for state placement?**
|
|
438
|
+
|
|
439
|
+
A) ⭐ **Local by default, global when shared** (Recommended)
|
|
440
|
+
|
|
441
|
+
- Start with component state (useState/reactive)
|
|
442
|
+
- Lift to global only when multiple components need it
|
|
443
|
+
- Best for: Most apps, avoid over-engineering
|
|
444
|
+
|
|
445
|
+
B) **Global by default**
|
|
446
|
+
|
|
447
|
+
- Most state in global store
|
|
448
|
+
- Best for: Complex apps with heavy state sharing
|
|
449
|
+
|
|
450
|
+
C) **URL-driven state**
|
|
451
|
+
|
|
452
|
+
- Prefer URL params over global state
|
|
453
|
+
- Best for: Multi-page apps, shareable state
|
|
454
|
+
|
|
455
|
+
**Your answer:**
|
|
360
456
|
---
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
**
|
|
394
|
-
|
|
457
|
+
### Question 3.10: Error Handling Strategy
|
|
458
|
+
|
|
459
|
+
**How will you handle API errors and failed requests?**
|
|
460
|
+
|
|
461
|
+
A) ⭐ **Toast Notifications**
|
|
462
|
+
|
|
463
|
+
- Show temporary error message
|
|
464
|
+
- Best for: Non-critical errors
|
|
465
|
+
- Libraries: react-hot-toast, vue-toastification
|
|
466
|
+
|
|
467
|
+
B) **Inline Error Messages**
|
|
468
|
+
|
|
469
|
+
- Display errors next to forms/components
|
|
470
|
+
- Best for: Form validation, input errors
|
|
471
|
+
|
|
472
|
+
C) **Error Boundary (Global)**
|
|
473
|
+
|
|
474
|
+
- Catch all errors, show fallback UI
|
|
475
|
+
- Best for: Unhandled errors, app crashes
|
|
476
|
+
- React: Error Boundaries, Vue: errorHandler
|
|
477
|
+
|
|
478
|
+
D) **Modal Dialogs**
|
|
479
|
+
|
|
480
|
+
- Show error in modal
|
|
481
|
+
- Best for: Critical errors requiring user action
|
|
482
|
+
|
|
483
|
+
E) **Retry Mechanism**
|
|
484
|
+
|
|
485
|
+
- Auto-retry failed requests
|
|
486
|
+
- Best for: Network errors, transient failures
|
|
487
|
+
- TanStack Query has built-in retry
|
|
488
|
+
|
|
489
|
+
F) **Combined Approach**
|
|
490
|
+
|
|
491
|
+
- Different strategies for different error types
|
|
492
|
+
|
|
493
|
+
**Your answer:**
|
|
395
494
|
---
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
**What's your default strategy for state placement?**
|
|
400
|
-
|
|
401
|
-
A) ⭐ **Local by default, global when shared** (Recommended)
|
|
402
|
-
- Start with component state (useState/reactive)
|
|
403
|
-
- Lift to global only when multiple components need it
|
|
404
|
-
- Best for: Most apps, avoid over-engineering
|
|
405
|
-
|
|
406
|
-
B) **Global by default**
|
|
407
|
-
- Most state in global store
|
|
408
|
-
- Best for: Complex apps with heavy state sharing
|
|
409
|
-
|
|
410
|
-
C) **URL-driven state**
|
|
411
|
-
- Prefer URL params over global state
|
|
412
|
-
- Best for: Multi-page apps, shareable state
|
|
413
|
-
|
|
414
|
-
**Your answer:**
|
|
415
|
-
|
|
495
|
+
#### 🎨 MERMAID STATE MANAGEMENT DIAGRAM FORMATS - CRITICAL
|
|
496
|
+
|
|
497
|
+
**Use these exact formats** for state management diagrams mentioned in documentation:
|
|
416
498
|
---
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
499
|
+
##### 1️⃣ State Categories & Store Organization
|
|
500
|
+
|
|
501
|
+
Use `graph LR` to show different state types and their tools:
|
|
502
|
+
|
|
503
|
+
````markdown
|
|
504
|
+
```mermaid
|
|
505
|
+
graph LR
|
|
506
|
+
subgraph "State Types"
|
|
507
|
+
SS[Server State<br/>TanStack Query<br/>React Query]
|
|
508
|
+
CS[Client State<br/>Zustand/Redux<br/>Context]
|
|
509
|
+
US[URL State<br/>React Router<br/>Query Params]
|
|
510
|
+
FS[Form State<br/>React Hook Form<br/>Formik]
|
|
511
|
+
LS[Local State<br/>useState<br/>useReducer]
|
|
512
|
+
end
|
|
513
|
+
|
|
514
|
+
subgraph "Components"
|
|
515
|
+
C1[ProductList]
|
|
516
|
+
C2[UserProfile]
|
|
517
|
+
C3[SearchPage]
|
|
518
|
+
C4[CheckoutForm]
|
|
519
|
+
C5[DropdownMenu]
|
|
520
|
+
end
|
|
521
|
+
|
|
522
|
+
SS -.->|products, users| C1
|
|
523
|
+
SS -.->|user data| C2
|
|
524
|
+
CS -.->|theme, auth| C1
|
|
525
|
+
CS -.->|auth| C2
|
|
526
|
+
US -.->|search query| C3
|
|
527
|
+
FS -.->|form data| C4
|
|
528
|
+
LS -.->|isOpen| C5
|
|
529
|
+
|
|
530
|
+
style SS fill:#e1f5ff
|
|
531
|
+
style CS fill:#fff4e6
|
|
532
|
+
style US fill:#e8f5e9
|
|
533
|
+
style FS fill:#fce4ec
|
|
534
|
+
style LS fill:#f3e5f5
|
|
535
|
+
```
|
|
536
|
+
````
|
|
537
|
+
|
|
538
|
+
**Use for:** Deciding where to store state, showing state architecture, documenting state tools
|
|
450
539
|
---
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
540
|
+
##### 2️⃣ Data Flow Sequence (API to UI)
|
|
541
|
+
|
|
542
|
+
Use `sequenceDiagram` to show step-by-step data flow:
|
|
543
|
+
|
|
544
|
+
````markdown
|
|
545
|
+
```mermaid
|
|
546
|
+
sequenceDiagram
|
|
547
|
+
participant U as User
|
|
548
|
+
participant C as Component
|
|
549
|
+
participant S as Store/Hook
|
|
550
|
+
participant API as API Service
|
|
551
|
+
participant BE as Backend
|
|
552
|
+
|
|
553
|
+
U->>C: Click "Load Products"
|
|
554
|
+
C->>S: useProducts() hook
|
|
555
|
+
S->>API: fetchProducts()
|
|
556
|
+
API->>BE: GET /api/products
|
|
557
|
+
BE-->>API: 200 OK + data
|
|
558
|
+
API-->>S: Return products[]
|
|
559
|
+
S->>S: Update cache
|
|
560
|
+
S-->>C: products data
|
|
561
|
+
C->>U: Render UI
|
|
562
|
+
|
|
563
|
+
Note over S: TanStack Query<br/>caches for 5min
|
|
564
|
+
|
|
565
|
+
U->>C: Click "Add to Cart"
|
|
566
|
+
C->>S: addToCart(productId)
|
|
567
|
+
S->>S: Update client state
|
|
568
|
+
S-->>C: cart updated
|
|
569
|
+
C->>U: Show cart badge
|
|
570
|
+
```
|
|
571
|
+
````
|
|
572
|
+
|
|
573
|
+
**Use for:** Showing request/response cycles, async operations, state updates, caching behavior
|
|
456
574
|
---
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
FS -.->|form data| C4
|
|
487
|
-
LS -.->|isOpen| C5
|
|
488
|
-
|
|
489
|
-
style SS fill:#e1f5ff
|
|
490
|
-
style CS fill:#fff4e6
|
|
491
|
-
style US fill:#e8f5e9
|
|
492
|
-
style FS fill:#fce4ec
|
|
493
|
-
style LS fill:#f3e5f5
|
|
494
|
-
```
|
|
495
|
-
````
|
|
496
|
-
|
|
497
|
-
**Use for:** Deciding where to store state, showing state architecture, documenting state tools
|
|
498
|
-
|
|
575
|
+
##### 3️⃣ State Location Decision Tree
|
|
576
|
+
|
|
577
|
+
Use `graph TD` to help developers choose where to store state:
|
|
578
|
+
|
|
579
|
+
````markdown
|
|
580
|
+
```mermaid
|
|
581
|
+
graph TD
|
|
582
|
+
A[New State Needed] --> B{From Server?}
|
|
583
|
+
B -->|Yes| C[Use TanStack Query<br/>Server State<br/>Auto-caching]
|
|
584
|
+
B -->|No| D{Shared Across<br/>Components?}
|
|
585
|
+
D -->|Yes| E{Needs to<br/>Persist?}
|
|
586
|
+
E -->|Yes| F[Use Zustand +<br/>localStorage<br/>Client State]
|
|
587
|
+
E -->|No| G[Use Zustand or<br/>Context<br/>Client State]
|
|
588
|
+
D -->|No| H{In URL?}
|
|
589
|
+
H -->|Yes| I[Use React Router<br/>searchParams<br/>URL State]
|
|
590
|
+
H -->|No| J{Form Data?}
|
|
591
|
+
J -->|Yes| K[Use React Hook Form<br/>Form State]
|
|
592
|
+
J -->|No| L[Use useState/useReducer<br/>Local Component State]
|
|
593
|
+
|
|
594
|
+
style C fill:#e1f5ff
|
|
595
|
+
style F fill:#fff4e6
|
|
596
|
+
style G fill:#fff4e6
|
|
597
|
+
style I fill:#e8f5e9
|
|
598
|
+
style K fill:#fce4ec
|
|
599
|
+
style L fill:#f3e5f5
|
|
600
|
+
```
|
|
601
|
+
````
|
|
602
|
+
|
|
603
|
+
**Use for:** Decision-making guide, onboarding new developers, documenting state strategy
|
|
499
604
|
---
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
C->>U: Show cart badge
|
|
531
|
-
```
|
|
532
|
-
````
|
|
533
|
-
|
|
534
|
-
**Use for:** Showing request/response cycles, async operations, state updates, caching behavior
|
|
535
|
-
|
|
605
|
+
**Best Practices for State Management Diagrams:**
|
|
606
|
+
|
|
607
|
+
1. **Use Sequence Diagrams for Time-Based Flows:**
|
|
608
|
+
- Show async operations step-by-step
|
|
609
|
+
- Include caching behavior
|
|
610
|
+
- Document timing (e.g., "caches for 5min")
|
|
611
|
+
|
|
612
|
+
2. **Use Graph Diagrams for Relationships:**
|
|
613
|
+
- State categories and their connections
|
|
614
|
+
- Decision trees for choosing state location
|
|
615
|
+
- Component-to-store relationships
|
|
616
|
+
|
|
617
|
+
3. **Color Code by State Type:**
|
|
618
|
+
- Server State: `#e1f5ff` (light blue)
|
|
619
|
+
- Client State: `#fff4e6` (light orange)
|
|
620
|
+
- URL State: `#e8f5e9` (light green)
|
|
621
|
+
- Form State: `#fce4ec` (light pink)
|
|
622
|
+
- Local State: `#f3e5f5` (light purple)
|
|
623
|
+
|
|
624
|
+
4. **Include Tool Names:** Always specify actual tools (TanStack Query, Zustand, React Hook Form, etc.)
|
|
625
|
+
|
|
626
|
+
5. **Show Data Flow Direction:** Use solid arrows for data flow, dotted for state updates
|
|
627
|
+
|
|
628
|
+
**Common Formatting Rules:**
|
|
629
|
+
|
|
630
|
+
- Code fence: ` ```mermaid ` (lowercase, no spaces, three backticks)
|
|
631
|
+
- Use `sequenceDiagram` for API calls and async flows
|
|
632
|
+
- Use `graph TD` for decision trees
|
|
633
|
+
- Use `graph LR` for category relationships
|
|
634
|
+
- Preview at https://mermaid.live/ before saving
|
|
536
635
|
---
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
Use `graph TD` to help developers choose where to store state:
|
|
541
|
-
|
|
542
|
-
````markdown
|
|
543
|
-
```mermaid
|
|
544
|
-
graph TD
|
|
545
|
-
A[New State Needed] --> B{From Server?}
|
|
546
|
-
B -->|Yes| C[Use TanStack Query<br/>Server State<br/>Auto-caching]
|
|
547
|
-
B -->|No| D{Shared Across<br/>Components?}
|
|
548
|
-
D -->|Yes| E{Needs to<br/>Persist?}
|
|
549
|
-
E -->|Yes| F[Use Zustand +<br/>localStorage<br/>Client State]
|
|
550
|
-
E -->|No| G[Use Zustand or<br/>Context<br/>Client State]
|
|
551
|
-
D -->|No| H{In URL?}
|
|
552
|
-
H -->|Yes| I[Use React Router<br/>searchParams<br/>URL State]
|
|
553
|
-
H -->|No| J{Form Data?}
|
|
554
|
-
J -->|Yes| K[Use React Hook Form<br/>Form State]
|
|
555
|
-
J -->|No| L[Use useState/useReducer<br/>Local Component State]
|
|
556
|
-
|
|
557
|
-
style C fill:#e1f5ff
|
|
558
|
-
style F fill:#fff4e6
|
|
559
|
-
style G fill:#fff4e6
|
|
560
|
-
style I fill:#e8f5e9
|
|
561
|
-
style K fill:#fce4ec
|
|
562
|
-
style L fill:#f3e5f5
|
|
563
|
-
```
|
|
564
|
-
````
|
|
565
|
-
|
|
566
|
-
**Use for:** Decision-making guide, onboarding new developers, documenting state strategy
|
|
567
|
-
|
|
636
|
+
## 📊 Phase 3 Summary
|
|
637
|
+
|
|
638
|
+
```
|
|
568
639
|
---
|
|
569
|
-
|
|
570
|
-
**Best Practices for State Management Diagrams:**
|
|
571
|
-
|
|
572
|
-
1. **Use Sequence Diagrams for Time-Based Flows:**
|
|
573
|
-
- Show async operations step-by-step
|
|
574
|
-
- Include caching behavior
|
|
575
|
-
- Document timing (e.g., "caches for 5min")
|
|
576
|
-
|
|
577
|
-
2. **Use Graph Diagrams for Relationships:**
|
|
578
|
-
- State categories and their connections
|
|
579
|
-
- Decision trees for choosing state location
|
|
580
|
-
- Component-to-store relationships
|
|
581
|
-
|
|
582
|
-
3. **Color Code by State Type:**
|
|
583
|
-
- Server State: `#e1f5ff` (light blue)
|
|
584
|
-
- Client State: `#fff4e6` (light orange)
|
|
585
|
-
- URL State: `#e8f5e9` (light green)
|
|
586
|
-
- Form State: `#fce4ec` (light pink)
|
|
587
|
-
- Local State: `#f3e5f5` (light purple)
|
|
588
|
-
|
|
589
|
-
4. **Include Tool Names:** Always specify actual tools (TanStack Query, Zustand, React Hook Form, etc.)
|
|
590
|
-
|
|
591
|
-
5. **Show Data Flow Direction:** Use solid arrows for data flow, dotted for state updates
|
|
592
|
-
|
|
593
|
-
**Common Formatting Rules:**
|
|
594
|
-
- Code fence: ` ```mermaid ` (lowercase, no spaces, three backticks)
|
|
595
|
-
- Use `sequenceDiagram` for API calls and async flows
|
|
596
|
-
- Use `graph TD` for decision trees
|
|
597
|
-
- Use `graph LR` for category relationships
|
|
598
|
-
- Preview at https://mermaid.live/ before saving
|
|
599
|
-
|
|
640
|
+
📋 PHASE 3 SUMMARY: STATE MANAGEMENT
|
|
600
641
|
---
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
State Normalization: [Answer from 3.8]
|
|
617
|
-
State Placement: [Answer from 3.9]
|
|
618
|
-
Error Handling: [Answer from 3.10]
|
|
619
|
-
API Error Handling: [Answer from 3.11]
|
|
620
|
-
Retry Strategy: [Answer from 3.12]
|
|
621
|
-
|
|
622
|
-
Is this correct? (Y/n)
|
|
623
|
-
```
|
|
624
|
-
|
|
642
|
+
Server State: [Answer from 3.1]
|
|
643
|
+
Client State: [Answer from 3.2]
|
|
644
|
+
State Persistence: [Answer from 3.3]
|
|
645
|
+
Form Management: [Answer from 3.4]
|
|
646
|
+
Form Validation: [Answer from 3.5]
|
|
647
|
+
Optimistic Updates: [Answer from 3.6]
|
|
648
|
+
Real-Time Updates: [Answer from 3.7]
|
|
649
|
+
State Normalization: [Answer from 3.8]
|
|
650
|
+
State Placement: [Answer from 3.9]
|
|
651
|
+
Error Handling: [Answer from 3.10]
|
|
652
|
+
API Error Handling: [Answer from 3.11]
|
|
653
|
+
Retry Strategy: [Answer from 3.12]
|
|
654
|
+
|
|
655
|
+
Is this correct? (Y/n)
|
|
656
|
+
```
|
|
625
657
|
---
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
- `{{
|
|
634
|
-
- `{{
|
|
635
|
-
- `{{
|
|
636
|
-
- `{{
|
|
637
|
-
- `{{
|
|
638
|
-
- `{{
|
|
639
|
-
- `{{
|
|
640
|
-
- `{{
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
- **
|
|
649
|
-
- **
|
|
650
|
-
- **
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
- ✅ ALWAYS
|
|
656
|
-
-
|
|
657
|
-
- ❌ NEVER
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
```
|
|
663
|
-
|
|
658
|
+
## 📝 Document Generation
|
|
659
|
+
|
|
660
|
+
Generate `docs/state-management.md` using the template:
|
|
661
|
+
|
|
662
|
+
Replace these placeholders:
|
|
663
|
+
|
|
664
|
+
- `{{STATE_MANAGEMENT}}` → Client state solution (e.g., "Zustand")
|
|
665
|
+
- `{{DATA_FETCHING}}` → Server state solution (e.g., "TanStack Query")
|
|
666
|
+
- `{{FORM_LIBRARY}}` → Form library (e.g., "React Hook Form")
|
|
667
|
+
- `{{FORM_VALIDATION}}` → Validation strategy (e.g., "Zod")
|
|
668
|
+
- `{{STATE_PERSISTENCE}}` → Persistence approach
|
|
669
|
+
- `{{OPTIMISTIC_UPDATES}}` → Yes/No
|
|
670
|
+
- `{{REAL_TIME_STRATEGY}}` → Real-time approach
|
|
671
|
+
- `{{STATE_NORMALIZATION}}` → Yes/No
|
|
672
|
+
- `{{ERROR_HANDLING_STRATEGY}}` → Error handling approach
|
|
673
|
+
|
|
674
|
+
Also update `ai-instructions.md`:
|
|
675
|
+
|
|
676
|
+
```markdown
|
|
677
|
+
## State Management
|
|
678
|
+
|
|
679
|
+
- **Server State:** {{DATA_FETCHING}}
|
|
680
|
+
- **Client State:** {{STATE_MANAGEMENT}}
|
|
681
|
+
- **Forms:** {{FORM_LIBRARY}} with {{FORM_VALIDATION}}
|
|
682
|
+
- **Real-Time:** {{REAL_TIME_STRATEGY}}
|
|
683
|
+
|
|
684
|
+
### Rules
|
|
685
|
+
|
|
686
|
+
- ✅ ALWAYS use {{DATA_FETCHING}} for server data
|
|
687
|
+
- ✅ ALWAYS validate forms with {{FORM_VALIDATION}}
|
|
688
|
+
- ❌ NEVER store derived data in state
|
|
689
|
+
- ❌ NEVER mutate state directly (use immutable updates)
|
|
690
|
+
{{#IF_OPTIMISTIC_UPDATES}}
|
|
691
|
+
- ✅ ALWAYS implement rollback for optimistic updates
|
|
692
|
+
{{/IF_OPTIMISTIC_UPDATES}}
|
|
693
|
+
```
|
|
664
694
|
---
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
```
|
|
679
|
-
|
|
695
|
+
## 🚀 Next Steps
|
|
696
|
+
|
|
697
|
+
```
|
|
698
|
+
✅ Phase 3 Complete!
|
|
699
|
+
|
|
700
|
+
Documents Generated:
|
|
701
|
+
- docs/state-management.md
|
|
702
|
+
- ai-instructions.md (updated)
|
|
703
|
+
|
|
704
|
+
Next: Phase 4 - Styling & Design
|
|
705
|
+
|
|
706
|
+
Read: .ai-flow/prompts/frontend/flow-build-phase-4-styling.md
|
|
707
|
+
```
|
|
680
708
|
---
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
709
|
+
**Last Updated:** 2025-01-XX
|
|
710
|
+
|
|
711
|
+
**Version:** 1.2.0
|
|
712
|
+
|
|
685
713
|
|
|
686
714
|
|
|
687
715
|
|