vibes-plug 1.0.0 → 2.11.0

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.
Files changed (183) hide show
  1. package/.claude/rules/vibes-plug-core.md +32 -0
  2. package/.cursor/rules/vibes-plug-core.mdc +51 -0
  3. package/.cursorrules +42 -0
  4. package/AGENTS.md +96 -0
  5. package/BLUEPRINT.md +309 -125
  6. package/CHANGELOG.md +183 -1
  7. package/CLAUDE.md +70 -0
  8. package/LICENSE +1 -1
  9. package/README.md +641 -263
  10. package/index.js +19 -0
  11. package/package.json +61 -25
  12. package/plugin.json +24 -7
  13. package/scripts/generate_swarm_gif.py +295 -0
  14. package/scripts/install.js +201 -0
  15. package/skills/accessibility-testing-expert/SKILL.md +116 -0
  16. package/skills/ai-cost-token-optimizer/SKILL.md +82 -0
  17. package/skills/ai-evals-benchmark-expert/SKILL.md +188 -0
  18. package/skills/ai-llm-integration-expert/SKILL.md +147 -122
  19. package/skills/ai-media-generation-expert/SKILL.md +172 -0
  20. package/skills/ai-prompt-engineering-expert/SKILL.md +84 -0
  21. package/skills/angular-expert/SKILL.md +148 -0
  22. package/skills/api-design-expert/SKILL.md +316 -309
  23. package/skills/api-gateway-proxy-expert/SKILL.md +81 -0
  24. package/skills/app-analyzer-optimizer/SKILL.md +195 -188
  25. package/skills/apple-ecosystem-expert/SKILL.md +145 -0
  26. package/skills/{asisten_ramah → asisten-ramah}/SKILL.md +7 -1
  27. package/skills/astro-framework-expert/SKILL.md +200 -0
  28. package/skills/async-queue-temporal-expert/SKILL.md +240 -0
  29. package/skills/authentication-identity-expert/SKILL.md +279 -45
  30. package/skills/auto-doc-updater/SKILL.md +219 -203
  31. package/skills/autonomous-chaos-monkey/SKILL.md +63 -0
  32. package/skills/autonomous-red-teamer/SKILL.md +203 -0
  33. package/skills/autonomous-tdd-debugger/SKILL.md +71 -0
  34. package/skills/background-jobs-queue-expert/SKILL.md +235 -0
  35. package/skills/biome-linter-formatter-expert/SKILL.md +89 -0
  36. package/skills/blockchain-web3-expert/SKILL.md +115 -0
  37. package/skills/bootstrap-to-modern/SKILL.md +93 -86
  38. package/skills/brainstorming/SKILL.md +381 -353
  39. package/skills/browser-automation-expert/SKILL.md +222 -0
  40. package/skills/bun-runtime-expert/SKILL.md +7 -1
  41. package/skills/chatbot-messaging-expert/SKILL.md +114 -0
  42. package/skills/ci-cd-devops-architect/SKILL.md +81 -45
  43. package/skills/cloud-hosting-expert/SKILL.md +249 -243
  44. package/skills/coderabbit/SKILL.md +197 -191
  45. package/skills/compliance-gdpr-privacy-expert/SKILL.md +85 -0
  46. package/skills/cron-scheduler-expert/SKILL.md +304 -0
  47. package/skills/data-pipeline-etl-expert/SKILL.md +84 -0
  48. package/skills/data-telemetry-expert/SKILL.md +218 -212
  49. package/skills/data-visualization-expert/SKILL.md +154 -0
  50. package/skills/database-migration-versioning-expert/SKILL.md +90 -0
  51. package/skills/database-orm-expert/SKILL.md +303 -293
  52. package/skills/dependency-upgrade-migrator/SKILL.md +301 -0
  53. package/skills/design-system-architect/SKILL.md +278 -242
  54. package/skills/desktop-electron-expert/SKILL.md +128 -0
  55. package/skills/documentation-site-expert/SKILL.md +59 -0
  56. package/skills/doku-mcp-server/SKILL.md +257 -0
  57. package/skills/doku-payment-gateway/SKILL.md +233 -0
  58. package/skills/domain-driven-design-expert/SKILL.md +82 -0
  59. package/skills/e2e-testing-expert/SKILL.md +320 -314
  60. package/skills/ecommerce-expert/SKILL.md +87 -0
  61. package/skills/edge-serverless-db-expert/SKILL.md +99 -0
  62. package/skills/email-notification-expert/SKILL.md +368 -0
  63. package/skills/error-resilience-expert/SKILL.md +486 -0
  64. package/skills/event-driven-architect/SKILL.md +86 -80
  65. package/skills/feature-flag-analytics-expert/SKILL.md +66 -0
  66. package/skills/file-upload-media-expert/SKILL.md +437 -0
  67. package/skills/firebase-security-expert/SKILL.md +7 -1
  68. package/skills/form-validation-expert/SKILL.md +407 -0
  69. package/skills/fullstack-expert/SKILL.md +260 -201
  70. package/skills/fullstack-expert/references/api_design_guide.md +466 -466
  71. package/skills/fullstack-expert/references/multi_language_backend.md +528 -528
  72. package/skills/fullstack-expert/scripts/api_contract_validator.py +253 -253
  73. package/skills/fullstack-expert/scripts/architecture_analyzer.py +326 -326
  74. package/skills/gemini-agent-booster/SKILL.md +142 -104
  75. package/skills/geospatial-maps-expert/SKILL.md +80 -0
  76. package/skills/global-a11y-i18n-expert/SKILL.md +86 -80
  77. package/skills/glsl-shader-expert/SKILL.md +107 -0
  78. package/skills/go-programming-expert/SKILL.md +300 -294
  79. package/skills/graph-rag-knowledge-expert/SKILL.md +159 -0
  80. package/skills/graphql-apollo-expert/SKILL.md +114 -0
  81. package/skills/headless-cms-expert/SKILL.md +181 -0
  82. package/skills/hig/SKILL.md +193 -187
  83. package/skills/js-backend-expert/SKILL.md +218 -191
  84. package/skills/legacy-code-translator/SKILL.md +71 -0
  85. package/skills/local-slm-edge-ai-expert/SKILL.md +167 -0
  86. package/skills/logging-error-tracking-expert/SKILL.md +344 -0
  87. package/skills/mcp-client-orchestrator/SKILL.md +76 -0
  88. package/skills/mcp-server-architect/SKILL.md +226 -126
  89. package/skills/micro-frontend-architect/SKILL.md +112 -0
  90. package/skills/mobile-expo-expert/SKILL.md +191 -185
  91. package/skills/mobile-push-notification-expert/SKILL.md +71 -0
  92. package/skills/modern-css-native-expert/SKILL.md +189 -0
  93. package/skills/monday-design-aesthetic/SKILL.md +72 -66
  94. package/skills/monorepo-architect/SKILL.md +232 -226
  95. package/skills/mpa-orchestrator/SKILL.md +120 -101
  96. package/skills/multi-agent-orchestration/SKILL.md +173 -153
  97. package/skills/multiple-entry-points/SKILL.md +91 -55
  98. package/skills/mvc-expert/SKILL.md +237 -231
  99. package/skills/n8n-automation-expert/SKILL.md +89 -0
  100. package/skills/nextjs-app-router-expert/SKILL.md +148 -0
  101. package/skills/openapi-swagger-codegen-expert/SKILL.md +67 -0
  102. package/skills/payment-gateway-expert/SKILL.md +129 -45
  103. package/skills/pdf-document-generation-expert/SKILL.md +91 -0
  104. package/skills/performance-web-vitals/SKILL.md +337 -331
  105. package/skills/post-quantum-crypto-migrator/SKILL.md +57 -0
  106. package/skills/prd-architect/SKILL.md +206 -190
  107. package/skills/proactive-background-watcher/SKILL.md +68 -0
  108. package/skills/production-ready-hardener/PRODUCTION_READINESS_REPORT.md +67 -0
  109. package/skills/production-ready-hardener/SKILL.md +461 -468
  110. package/skills/production-ready-hardener/references/production_checklist.md +161 -161
  111. package/skills/production-ready-hardener/scripts/production_readiness_scanner.py +881 -875
  112. package/skills/project-context-mapper/SKILL.md +85 -0
  113. package/skills/pwa-offline-first-expert/SKILL.md +185 -0
  114. package/skills/python-programming-expert/SKILL.md +407 -270
  115. package/skills/rate-limit-abuse-prevention/SKILL.md +377 -0
  116. package/skills/realtime-collaboration-expert/SKILL.md +99 -45
  117. package/skills/rich-text-editor-expert/SKILL.md +177 -0
  118. package/skills/rust-programming-expert/SKILL.md +240 -234
  119. package/skills/saas-billing/SKILL.md +382 -376
  120. package/skills/saas-multi-tenant/SKILL.md +256 -236
  121. package/skills/saas-mvp-launcher/SKILL.md +30 -1
  122. package/skills/saas-transformer/SKILL.md +499 -445
  123. package/skills/saas-transformer/references/billing_integration_guide.md +401 -401
  124. package/skills/saas-transformer/references/feature_gating_patterns.md +137 -137
  125. package/skills/saas-transformer/references/saas_transformation_checklist.md +121 -121
  126. package/skills/saas-transformer/scripts/saas_transformation_scanner.py +39 -29
  127. package/skills/scalability-clean-code/SKILL.md +234 -228
  128. package/skills/search-engine-expert/SKILL.md +89 -0
  129. package/skills/secure-fuzz-testing/SKILL.md +7 -1
  130. package/skills/self-evolving-memory-graph/SKILL.md +91 -0
  131. package/skills/self-healing-cloud-orchestrator/SKILL.md +57 -0
  132. package/skills/senior-frontend/SKILL.md +85 -105
  133. package/skills/seo/SKILL.md +258 -224
  134. package/skills/session-context-loader/SKILL.md +83 -0
  135. package/skills/session-handoff-resume/SKILL.md +163 -157
  136. package/skills/{skill_baru → skill-baru}/SKILL.md +177 -146
  137. package/skills/solidjs-expert/SKILL.md +80 -0
  138. package/skills/spa-orchestrator/SKILL.md +306 -287
  139. package/skills/sse-websocket-streaming-expert/SKILL.md +93 -0
  140. package/skills/state-management-expert/SKILL.md +277 -271
  141. package/skills/supabase-migration/SKILL.md +47 -1
  142. package/skills/supabase-security-expert/SKILL.md +248 -242
  143. package/skills/svelte-sveltekit-expert/SKILL.md +91 -0
  144. package/skills/svg-animation-motion-expert/SKILL.md +115 -0
  145. package/skills/tailwind-expert/SKILL.md +139 -187
  146. package/skills/tanstack-query-expert/SKILL.md +204 -198
  147. package/skills/tauri-expert/SKILL.md +7 -1
  148. package/skills/token-saver/SKILL.md +118 -110
  149. package/skills/typescript-expert/SKILL.md +329 -278
  150. package/skills/ui-components-expert/SKILL.md +166 -63
  151. package/skills/ui-ux-pro-max/SKILL.md +221 -200
  152. package/skills/vector-db-rag-expert/SKILL.md +208 -0
  153. package/skills/vibe-code-gardener/SKILL.md +180 -172
  154. package/skills/visual-qa-vision-agent/SKILL.md +71 -0
  155. package/skills/voice-ai-realtime-agent/SKILL.md +202 -0
  156. package/skills/vue-frontend-expert/SKILL.md +132 -0
  157. package/skills/wasm-edge-computing-expert/SKILL.md +97 -0
  158. package/skills/web-3d-graphics-expert/SKILL.md +137 -0
  159. package/skills/web-game-engine-expert/SKILL.md +102 -0
  160. package/skills/web-scraper/SKILL.md +98 -146
  161. package/skills/website-design-cloner/SKILL.md +180 -0
  162. package/skills/webxr-ar-vr-expert/SKILL.md +123 -0
  163. package/skills/wordpress-headless-expert/SKILL.md +144 -0
  164. package/skills/zero-to-prod-orchestrator/SKILL.md +231 -180
  165. package/skills/zero-trust-secret-vault/SKILL.md +88 -0
  166. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  167. package/CONTRIBUTING.md +0 -199
  168. package/SECURITY.md +0 -21
  169. package/banner.png +0 -0
  170. package/skills/senior-fullstack/SKILL.md +0 -167
  171. package/skills/senior-fullstack/references/architecture_patterns.md +0 -160
  172. package/skills/senior-fullstack/references/development_workflows.md +0 -222
  173. package/skills/senior-fullstack/references/tech_stack_guide.md +0 -190
  174. package/skills/senior-fullstack/scripts/code_quality_analyzer.py +0 -114
  175. package/skills/senior-fullstack/scripts/fullstack_scaffolder.py +0 -114
  176. package/skills/senior-fullstack/scripts/project_scaffolder.py +0 -114
  177. package/skills/seo-aeo-landing-page-writer/SKILL.md +0 -97
  178. package/skills/seo-geo/SKILL.md +0 -188
  179. package/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-310.pyc +0 -0
  180. package/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-312.pyc +0 -0
  181. package/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-310.pyc +0 -0
  182. package/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-312.pyc +0 -0
  183. package/skills/ui_ux_expert/SKILL.md +0 -114
@@ -1,272 +1,278 @@
1
- ---
2
- name: state-management-expert
3
- description: "Expert guide for modern client-side state management: Zustand, Jotai, Valtio, TanStack Store, Redux Toolkit, and server state patterns with TanStack Query / Panduan ahli untuk manajemen state client-side modern: Zustand, Jotai, Valtio, TanStack Store, Redux Toolkit, dan pola server state dengan TanStack Query."
1
+ ---
2
+ name: state-management-expert
3
+ description: "Expert guide for modern client-side state management: Zustand, Jotai, Valtio, TanStack Store, Redux Toolkit, and server state patterns with TanStack Query / Panduan ahli untuk manajemen state client-side modern: Zustand, Jotai, Valtio, TanStack Store, Redux Toolkit, dan pola server state dengan TanStack Query."
4
4
  author: "Roedy Rustam"
5
- ---
6
-
7
- # State Management Expert (Modern React Edition)
8
-
9
- [English](#english) | [Bahasa Indonesia](#bahasa-indonesia)
10
-
11
- ---
12
-
13
- <a name="english"></a>
14
- ## English
15
-
16
- ### Description
17
- Expert guide for selecting and implementing the right state management solution for React and Next.js applications. Covers **Zustand 5**, **Jotai 2**, **Valtio**, **TanStack Store**, and **Redux Toolkit 2**, with clear guidance on when to use each, proper separation of server state (TanStack Query) from client state, and advanced patterns like slices, persistence, and devtools integration.
18
-
19
- ### Trigger Conditions
20
- - Choosing a state management library for a new React/Next.js project.
21
- - Refactoring prop drilling or complex Context API usage.
22
- - Implementing global UI state (modals, drawers, theme, auth session).
23
- - Managing complex form state across multiple steps.
24
- - Implementing undo/redo, optimistic updates, or derived state.
25
- - Migrating from Redux to a lighter alternative.
26
-
27
- ---
28
-
29
- ### State Category Separation (Critical First Step)
30
-
31
- Before choosing a library, categorize your state:
32
-
33
- | Category | Description | Solution |
34
- |---|---|---|
35
- | **Server State** | Data from APIs, databases | TanStack Query / SWR |
36
- | **URL State** | Route params, search filters | `useSearchParams`, nuqs |
37
- | **Form State** | Input values, validation errors | React Hook Form + Zod |
38
- | **UI/Local State** | Modals, drawers, toggles | `useState` / `useReducer` |
39
- | **Global Client State** | Theme, auth, shopping cart | Zustand / Jotai |
40
- | **Cross-tab State** | Sync across browser tabs | Zustand + BroadcastChannel |
41
-
42
- **Rule**: Do NOT store server data in client state. Let TanStack Query own all async data.
43
-
44
- ---
45
-
46
- ### Library Selection Guide
47
-
48
- | Criteria | Zustand 5 | Jotai 2 | Valtio | Redux Toolkit |
49
- |---|---|---|---|---|
50
- | **Mental Model** | Single store, actions | Atomic, bottom-up | Proxy-based, mutable | Flux, reducers |
51
- | **Bundle Size** | ~1KB | ~3KB | ~3KB | ~15KB+ |
52
- | **DevTools** | Redux DevTools | Jotai DevTools | Redux DevTools | Built-in |
53
- | **Async** | Manual or middleware | `atomWithQuery` | `snapshot` | `createAsyncThunk` |
54
- | **Best For** | General global state | Atomic derived state | Simple mutable state | Large teams, strict patterns |
55
-
56
- **Recommendation**: Use **Zustand** as the default. Use **Jotai** for fine-grained reactive atoms. Use **Redux Toolkit** only for large enterprise teams with strict conventions.
57
-
58
- ---
59
-
60
- ### Zustand 5 — Best Practices
61
-
62
- #### Basic Store with TypeScript
63
- ```typescript
64
- // stores/ui.store.ts
65
- import { create } from 'zustand';
66
- import { devtools, persist, subscribeWithSelector } from 'zustand/middleware';
67
- import { immer } from 'zustand/middleware/immer';
68
-
69
- interface UiState {
70
- theme: 'light' | 'dark' | 'system';
71
- sidebarOpen: boolean;
72
- activeModal: string | null;
73
- setTheme: (theme: UiState['theme']) => void;
74
- toggleSidebar: () => void;
75
- openModal: (modalId: string) => void;
76
- closeModal: () => void;
77
- }
78
-
79
- export const useUiStore = create<UiState>()(
80
- devtools(
81
- persist(
82
- subscribeWithSelector(
83
- immer((set) => ({
84
- theme: 'system',
85
- sidebarOpen: true,
86
- activeModal: null,
87
- setTheme: (theme) => set((state) => { state.theme = theme; }),
88
- toggleSidebar: () => set((state) => { state.sidebarOpen = !state.sidebarOpen; }),
89
- openModal: (modalId) => set((state) => { state.activeModal = modalId; }),
90
- closeModal: () => set((state) => { state.activeModal = null; }),
91
- }))
92
- ),
93
- { name: 'ui-store', partialize: (s) => ({ theme: s.theme }) }
94
- ),
95
- { name: 'UiStore' }
96
- )
97
- );
98
- ```
99
-
100
- #### Slice Pattern for Large Stores
101
- ```typescript
102
- // Pattern: separate slices, combine into one store
103
- import { StateCreator } from 'zustand';
104
-
105
- interface AuthSlice {
106
- user: User | null;
107
- isAuthenticated: boolean;
108
- login: (user: User) => void;
109
- logout: () => void;
110
- }
111
-
112
- interface CartSlice {
113
- items: CartItem[];
114
- addItem: (item: CartItem) => void;
115
- removeItem: (id: string) => void;
116
- total: () => number;
117
- }
118
-
119
- type AppStore = AuthSlice & CartSlice;
120
-
121
- const createAuthSlice: StateCreator<AppStore, [], [], AuthSlice> = (set) => ({
122
- user: null,
123
- isAuthenticated: false,
124
- login: (user) => set({ user, isAuthenticated: true }),
125
- logout: () => set({ user: null, isAuthenticated: false }),
126
- });
127
-
128
- const createCartSlice: StateCreator<AppStore, [], [], CartSlice> = (set, get) => ({
129
- items: [],
130
- addItem: (item) => set((s) => ({ items: [...s.items, item] })),
131
- removeItem: (id) => set((s) => ({ items: s.items.filter((i) => i.id !== id) })),
132
- total: () => get().items.reduce((sum, item) => sum + item.price * item.qty, 0),
133
- });
134
-
135
- export const useAppStore = create<AppStore>()(
136
- devtools((...args) => ({
137
- ...createAuthSlice(...args),
138
- ...createCartSlice(...args),
139
- }))
140
- );
141
- ```
142
-
143
- #### Selective Subscriptions (Prevent Unnecessary Rerenders)
144
- ```typescript
145
- // Only re-render when `theme` changes, not the entire store
146
- const theme = useUiStore((s) => s.theme);
147
- const isModalOpen = useUiStore((s) => s.activeModal === 'confirm-delete');
148
-
149
- // Subscribe outside React (side effects, non-component code)
150
- useUiStore.subscribe(
151
- (s) => s.theme,
152
- (theme) => document.documentElement.dataset.theme = theme,
153
- { fireImmediately: true }
154
- );
155
- ```
156
-
157
- ---
158
-
159
- ### Jotai 2 — Atomic State Patterns
160
-
161
- ```typescript
162
- // atoms/user.atoms.ts
163
- import { atom, loadable } from 'jotai';
164
- import { atomWithStorage, atomWithReset } from 'jotai/utils';
165
-
166
- // Primitive atom
167
- export const themeAtom = atomWithStorage<'light' | 'dark'>('theme', 'light');
168
-
169
- // Derived (read-only) atom
170
- export const isDarkAtom = atom((get) => get(themeAtom) === 'dark');
171
-
172
- // Async atom with loadable for Suspense-free usage
173
- export const userAtom = atom(async () => {
174
- const res = await fetch('/api/me');
175
- if (!res.ok) throw new Error('Failed to fetch user');
176
- return res.json() as Promise<User>;
177
- });
178
-
179
- export const loadableUserAtom = loadable(userAtom);
180
-
181
- // In component:
182
- function UserWidget() {
183
- const loadableUser = useAtomValue(loadableUserAtom);
184
- if (loadableUser.state === 'loading') return <Spinner />;
185
- if (loadableUser.state === 'hasError') return <Error />;
186
- return <div>{loadableUser.data.name}</div>;
187
- }
188
- ```
189
-
190
- ---
191
-
192
- ### Redux Toolkit 2 — Modern Patterns
193
-
194
- ```typescript
195
- // features/cart/cartSlice.ts
196
- import { createSlice, PayloadAction, createSelector } from '@reduxjs/toolkit';
197
-
198
- interface CartState {
199
- items: CartItem[];
200
- status: 'idle' | 'loading' | 'failed';
201
- }
202
-
203
- const cartSlice = createSlice({
204
- name: 'cart',
205
- initialState: { items: [], status: 'idle' } as CartState,
206
- reducers: {
207
- addItem(state, action: PayloadAction<CartItem>) {
208
- state.items.push(action.payload); // Immer handles immutability
209
- },
210
- removeItem(state, action: PayloadAction<string>) {
211
- state.items = state.items.filter((i) => i.id !== action.payload);
212
- },
213
- },
214
- });
215
-
216
- // Memoized selector
217
- export const selectCartTotal = createSelector(
218
- (state: RootState) => state.cart.items,
219
- (items) => items.reduce((sum, i) => sum + i.price * i.qty, 0)
220
- );
221
-
222
- export const { addItem, removeItem } = cartSlice.actions;
223
- export default cartSlice.reducer;
224
- ```
225
-
226
- ---
227
-
228
- ### Integration with Next.js App Router
229
-
230
- - **Server Components**: No client state. Fetch directly.
231
- - **Client Components**: Use Zustand/Jotai wrapped in providers.
232
- - **Hydration**: Initialize Zustand store from server-fetched data using `useHydrateAtoms` (Jotai) or a `HydrationBoundary` pattern.
233
-
234
- ```typescript
235
- // providers/store-provider.tsx (App Router pattern)
236
- 'use client';
237
- import { createStore, Provider } from 'jotai';
238
- import { useRef } from 'react';
239
-
240
- type Props = { children: React.ReactNode; initialUser?: User };
241
-
242
- export function StoreProvider({ children, initialUser }: Props) {
243
- const store = useRef(createStore());
244
- if (initialUser) store.current.set(userAtom, initialUser);
245
- return <Provider store={store.current}>{children}</Provider>;
246
- }
247
- ```
248
-
249
- ---
250
-
251
- <a name="bahasa-indonesia"></a>
252
- ## Bahasa Indonesia
253
-
254
- ### Deskripsi
255
- Panduan ahli untuk memilih dan mengimplementasikan solusi manajemen state yang tepat untuk aplikasi React dan Next.js. Mencakup **Zustand 5**, **Jotai 2**, **Valtio**, dan **Redux Toolkit 2**, dengan panduan pemilihan yang jelas, pemisahan server state (TanStack Query) dari client state, dan pola lanjutan seperti slices, persistensi, dan integrasi devtools.
256
-
257
- ### Kondisi Pemicu
258
- - Memilih library state management untuk proyek React/Next.js baru.
259
- - Refaktor prop drilling atau penggunaan Context API yang rumit.
260
- - Mengimplementasikan global UI state (modal, drawer, tema, sesi auth).
261
- - Mengelola state form kompleks di beberapa langkah.
262
- - Mengimplementasikan undo/redo, optimistic update, atau derived state.
263
- - Migrasi dari Redux ke alternatif yang lebih ringan.
264
-
265
- ### Prinsip Utama
266
-
267
- - **Pisahkan server state dari client state**: Server state (data dari API) dikelola TanStack Query. Client state (UI, preferensi) dikelola Zustand/Jotai.
268
- - **Gunakan Zustand sebagai default** untuk state global umum.
269
- - **Gunakan Jotai** untuk state atomik yang sangat granular dan reaktif.
270
- - **Hindari menyimpan data server di client state** — ini adalah sumber bug terbesar di aplikasi React.
271
- - **Selective subscription**: Selalu gunakan selector untuk menghindari re-render yang tidak perlu.
272
- - **DevTools**: Selalu integrasikan devtools di development untuk debugging yang efektif.
5
+ ---
6
+
7
+ # State Management Expert (Modern React Edition)
8
+
9
+ [English](#english) | [Bahasa Indonesia](#bahasa-indonesia)
10
+
11
+ ---
12
+
13
+ <a name="english"></a>
14
+ ## English
15
+
16
+ ### Orchestration & Integration
17
+ Connects and orchestrates with relevant domain skills like `brainstorming`, `zero-to-prod-orchestrator`, and `project-context-mapper` to ensure cohesive execution.
18
+
19
+ ### Description
20
+ Expert guide for selecting and implementing the right state management solution for React and Next.js applications. Covers **Zustand 5**, **Jotai 2**, **Valtio**, **TanStack Store**, and **Redux Toolkit 2**, with clear guidance on when to use each, proper separation of server state (TanStack Query) from client state, and advanced patterns like slices, persistence, and devtools integration.
21
+
22
+ ### Trigger Conditions
23
+ - Choosing a state management library for a new React/Next.js project.
24
+ - Refactoring prop drilling or complex Context API usage.
25
+ - Implementing global UI state (modals, drawers, theme, auth session).
26
+ - Managing complex form state across multiple steps.
27
+ - Implementing undo/redo, optimistic updates, or derived state.
28
+ - Migrating from Redux to a lighter alternative.
29
+
30
+ ---
31
+
32
+ ### State Category Separation (Critical First Step)
33
+
34
+ Before choosing a library, categorize your state:
35
+
36
+ | Category | Description | Solution |
37
+ |---|---|---|
38
+ | **Server State** | Data from APIs, databases | TanStack Query / SWR |
39
+ | **URL State** | Route params, search filters | `useSearchParams`, nuqs |
40
+ | **Form State** | Input values, validation errors | React Hook Form + Zod |
41
+ | **UI/Local State** | Modals, drawers, toggles | `useState` / `useReducer` |
42
+ | **Global Client State** | Theme, auth, shopping cart | Zustand / Jotai |
43
+ | **Cross-tab State** | Sync across browser tabs | Zustand + BroadcastChannel |
44
+
45
+ **Rule**: Do NOT store server data in client state. Let TanStack Query own all async data.
46
+
47
+ ---
48
+
49
+ ### Library Selection Guide
50
+
51
+ | Criteria | Zustand 5 | Jotai 2 | Valtio | Redux Toolkit |
52
+ |---|---|---|---|---|
53
+ | **Mental Model** | Single store, actions | Atomic, bottom-up | Proxy-based, mutable | Flux, reducers |
54
+ | **Bundle Size** | ~1KB | ~3KB | ~3KB | ~15KB+ |
55
+ | **DevTools** | Redux DevTools | Jotai DevTools | Redux DevTools | Built-in |
56
+ | **Async** | Manual or middleware | `atomWithQuery` | `snapshot` | `createAsyncThunk` |
57
+ | **Best For** | General global state | Atomic derived state | Simple mutable state | Large teams, strict patterns |
58
+
59
+ **Recommendation**: Use **Zustand** as the default. Use **Jotai** for fine-grained reactive atoms. Use **Redux Toolkit** only for large enterprise teams with strict conventions.
60
+
61
+ ---
62
+
63
+ ### Zustand 5 — Best Practices
64
+
65
+ #### Basic Store with TypeScript
66
+ ```typescript
67
+ // stores/ui.store.ts
68
+ import { create } from 'zustand';
69
+ import { devtools, persist, subscribeWithSelector } from 'zustand/middleware';
70
+ import { immer } from 'zustand/middleware/immer';
71
+
72
+ interface UiState {
73
+ theme: 'light' | 'dark' | 'system';
74
+ sidebarOpen: boolean;
75
+ activeModal: string | null;
76
+ setTheme: (theme: UiState['theme']) => void;
77
+ toggleSidebar: () => void;
78
+ openModal: (modalId: string) => void;
79
+ closeModal: () => void;
80
+ }
81
+
82
+ export const useUiStore = create<UiState>()(
83
+ devtools(
84
+ persist(
85
+ subscribeWithSelector(
86
+ immer((set) => ({
87
+ theme: 'system',
88
+ sidebarOpen: true,
89
+ activeModal: null,
90
+ setTheme: (theme) => set((state) => { state.theme = theme; }),
91
+ toggleSidebar: () => set((state) => { state.sidebarOpen = !state.sidebarOpen; }),
92
+ openModal: (modalId) => set((state) => { state.activeModal = modalId; }),
93
+ closeModal: () => set((state) => { state.activeModal = null; }),
94
+ }))
95
+ ),
96
+ { name: 'ui-store', partialize: (s) => ({ theme: s.theme }) }
97
+ ),
98
+ { name: 'UiStore' }
99
+ )
100
+ );
101
+ ```
102
+
103
+ #### Slice Pattern for Large Stores
104
+ ```typescript
105
+ // Pattern: separate slices, combine into one store
106
+ import { StateCreator } from 'zustand';
107
+
108
+ interface AuthSlice {
109
+ user: User | null;
110
+ isAuthenticated: boolean;
111
+ login: (user: User) => void;
112
+ logout: () => void;
113
+ }
114
+
115
+ interface CartSlice {
116
+ items: CartItem[];
117
+ addItem: (item: CartItem) => void;
118
+ removeItem: (id: string) => void;
119
+ total: () => number;
120
+ }
121
+
122
+ type AppStore = AuthSlice & CartSlice;
123
+
124
+ const createAuthSlice: StateCreator<AppStore, [], [], AuthSlice> = (set) => ({
125
+ user: null,
126
+ isAuthenticated: false,
127
+ login: (user) => set({ user, isAuthenticated: true }),
128
+ logout: () => set({ user: null, isAuthenticated: false }),
129
+ });
130
+
131
+ const createCartSlice: StateCreator<AppStore, [], [], CartSlice> = (set, get) => ({
132
+ items: [],
133
+ addItem: (item) => set((s) => ({ items: [...s.items, item] })),
134
+ removeItem: (id) => set((s) => ({ items: s.items.filter((i) => i.id !== id) })),
135
+ total: () => get().items.reduce((sum, item) => sum + item.price * item.qty, 0),
136
+ });
137
+
138
+ export const useAppStore = create<AppStore>()(
139
+ devtools((...args) => ({
140
+ ...createAuthSlice(...args),
141
+ ...createCartSlice(...args),
142
+ }))
143
+ );
144
+ ```
145
+
146
+ #### Selective Subscriptions (Prevent Unnecessary Rerenders)
147
+ ```typescript
148
+ // Only re-render when `theme` changes, not the entire store
149
+ const theme = useUiStore((s) => s.theme);
150
+ const isModalOpen = useUiStore((s) => s.activeModal === 'confirm-delete');
151
+
152
+ // Subscribe outside React (side effects, non-component code)
153
+ useUiStore.subscribe(
154
+ (s) => s.theme,
155
+ (theme) => document.documentElement.dataset.theme = theme,
156
+ { fireImmediately: true }
157
+ );
158
+ ```
159
+
160
+ ---
161
+
162
+ ### Jotai 2 — Atomic State Patterns
163
+
164
+ ```typescript
165
+ // atoms/user.atoms.ts
166
+ import { atom, loadable } from 'jotai';
167
+ import { atomWithStorage, atomWithReset } from 'jotai/utils';
168
+
169
+ // Primitive atom
170
+ export const themeAtom = atomWithStorage<'light' | 'dark'>('theme', 'light');
171
+
172
+ // Derived (read-only) atom
173
+ export const isDarkAtom = atom((get) => get(themeAtom) === 'dark');
174
+
175
+ // Async atom with loadable for Suspense-free usage
176
+ export const userAtom = atom(async () => {
177
+ const res = await fetch('/api/me');
178
+ if (!res.ok) throw new Error('Failed to fetch user');
179
+ return res.json() as Promise<User>;
180
+ });
181
+
182
+ export const loadableUserAtom = loadable(userAtom);
183
+
184
+ // In component:
185
+ function UserWidget() {
186
+ const loadableUser = useAtomValue(loadableUserAtom);
187
+ if (loadableUser.state === 'loading') return <Spinner />;
188
+ if (loadableUser.state === 'hasError') return <Error />;
189
+ return <div>{loadableUser.data.name}</div>;
190
+ }
191
+ ```
192
+
193
+ ---
194
+
195
+ ### Redux Toolkit 2 — Modern Patterns
196
+
197
+ ```typescript
198
+ // features/cart/cartSlice.ts
199
+ import { createSlice, PayloadAction, createSelector } from '@reduxjs/toolkit';
200
+
201
+ interface CartState {
202
+ items: CartItem[];
203
+ status: 'idle' | 'loading' | 'failed';
204
+ }
205
+
206
+ const cartSlice = createSlice({
207
+ name: 'cart',
208
+ initialState: { items: [], status: 'idle' } as CartState,
209
+ reducers: {
210
+ addItem(state, action: PayloadAction<CartItem>) {
211
+ state.items.push(action.payload); // Immer handles immutability
212
+ },
213
+ removeItem(state, action: PayloadAction<string>) {
214
+ state.items = state.items.filter((i) => i.id !== action.payload);
215
+ },
216
+ },
217
+ });
218
+
219
+ // Memoized selector
220
+ export const selectCartTotal = createSelector(
221
+ (state: RootState) => state.cart.items,
222
+ (items) => items.reduce((sum, i) => sum + i.price * i.qty, 0)
223
+ );
224
+
225
+ export const { addItem, removeItem } = cartSlice.actions;
226
+ export default cartSlice.reducer;
227
+ ```
228
+
229
+ ---
230
+
231
+ ### Integration with Next.js App Router
232
+
233
+ - **Server Components**: No client state. Fetch directly.
234
+ - **Client Components**: Use Zustand/Jotai wrapped in providers.
235
+ - **Hydration**: Initialize Zustand store from server-fetched data using `useHydrateAtoms` (Jotai) or a `HydrationBoundary` pattern.
236
+
237
+ ```typescript
238
+ // providers/store-provider.tsx (App Router pattern)
239
+ 'use client';
240
+ import { createStore, Provider } from 'jotai';
241
+ import { useRef } from 'react';
242
+
243
+ type Props = { children: React.ReactNode; initialUser?: User };
244
+
245
+ export function StoreProvider({ children, initialUser }: Props) {
246
+ const store = useRef(createStore());
247
+ if (initialUser) store.current.set(userAtom, initialUser);
248
+ return <Provider store={store.current}>{children}</Provider>;
249
+ }
250
+ ```
251
+
252
+ ---
253
+
254
+ <a name="bahasa-indonesia"></a>
255
+ ## Bahasa Indonesia
256
+
257
+ ### Integrasi Orkestrasi
258
+ Terhubung dan mengorkestrasi skill domain yang relevan seperti `brainstorming`, `zero-to-prod-orchestrator`, dan `project-context-mapper` untuk memastikan eksekusi yang kohesif.
259
+
260
+ ### Deskripsi
261
+ Panduan ahli untuk memilih dan mengimplementasikan solusi manajemen state yang tepat untuk aplikasi React dan Next.js. Mencakup **Zustand 5**, **Jotai 2**, **Valtio**, dan **Redux Toolkit 2**, dengan panduan pemilihan yang jelas, pemisahan server state (TanStack Query) dari client state, dan pola lanjutan seperti slices, persistensi, dan integrasi devtools.
262
+
263
+ ### Kondisi Pemicu
264
+ - Memilih library state management untuk proyek React/Next.js baru.
265
+ - Refaktor prop drilling atau penggunaan Context API yang rumit.
266
+ - Mengimplementasikan global UI state (modal, drawer, tema, sesi auth).
267
+ - Mengelola state form kompleks di beberapa langkah.
268
+ - Mengimplementasikan undo/redo, optimistic update, atau derived state.
269
+ - Migrasi dari Redux ke alternatif yang lebih ringan.
270
+
271
+ ### Prinsip Utama
272
+
273
+ - **Pisahkan server state dari client state**: Server state (data dari API) dikelola TanStack Query. Client state (UI, preferensi) dikelola Zustand/Jotai.
274
+ - **Gunakan Zustand sebagai default** untuk state global umum.
275
+ - **Gunakan Jotai** untuk state atomik yang sangat granular dan reaktif.
276
+ - **Hindari menyimpan data server di client state** — ini adalah sumber bug terbesar di aplikasi React.
277
+ - **Selective subscription**: Selalu gunakan selector untuk menghindari re-render yang tidak perlu.
278
+ - **DevTools**: Selalu integrasikan devtools di development untuk debugging yang efektif.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: supabase-migration
3
3
  description: "A skill to create or apply a Supabase database migration / Kemampuan untuk membuat atau menerapkan migrasi database Supabase."
4
- author: "Roedy Rustam"
4
+ author: "Roedy Rustam"
5
5
  ---
6
6
 
7
7
  # Supabase Migration Skill
@@ -26,6 +26,29 @@ When the user asks to create or apply a database migration for Supabase, follow
26
26
  - Run `npx supabase migration up` to test locally or use the remote MCP `apply_migration` if the user wants it applied remotely.
27
27
  4. **Final Step**: Confirm with the user that the migration successfully completed.
28
28
 
29
+ ### Implementation Checklist
30
+ - [ ] Generate a new migration file: `npx supabase migration new [name]`
31
+ - [ ] Write raw SQL in the generated migration file (DDL and DML).
32
+ - [ ] Test the migration locally: `npx supabase db reset` or `npx supabase migration up`.
33
+ - [ ] If using RLS, explicitly add policies to the new tables.
34
+ - [ ] Commit the migration file to version control.
35
+
36
+ ### Example: Supabase Migration Command Flow
37
+ ```bash
38
+ # 1. Create a new migration file
39
+ npx supabase migration new create_users_table
40
+
41
+ # 2. Write SQL to supabase/migrations/<timestamp>_create_users_table.sql
42
+ # 3. Apply to local database
43
+ npx supabase migration up
44
+
45
+ # 4. Apply to remote production database
46
+ npx supabase db push
47
+ ```
48
+
49
+ ## Orchestration & Integration
50
+ - Integrates with: `supabase-security-expert`, `database-orm-expert`, `ci-cd-devops-architect`.
51
+
29
52
  ---
30
53
 
31
54
  <a name="bahasa-indonesia"></a>
@@ -43,3 +66,26 @@ Ketika pengguna meminta untuk membuat atau menerapkan migrasi database untuk Sup
43
66
  - Tulis skrip SQL ke file migrasi lokal yang terletak di `supabase/migrations/` menggunakan `write_to_file`. Gunakan timestamp standar atau perintah `supabase migration new` untuk mendapatkan nama file.
44
67
  - Jalankan `npx supabase migration up` untuk menguji secara lokal atau gunakan MCP remote `apply_migration` jika pengguna ingin menerapkannya secara remote.
45
68
  4. **Langkah Terakhir**: Konfirmasikan dengan pengguna bahwa migrasi telah berhasil diselesaikan.
69
+
70
+ ### Checklist Implementasi
71
+ - [ ] Buat file migrasi baru: `npx supabase migration new [nama]`
72
+ - [ ] Tulis SQL mentah di file migrasi yang dihasilkan (DDL dan DML).
73
+ - [ ] Uji migrasi secara lokal: `npx supabase db reset` atau `npx supabase migration up`.
74
+ - [ ] Jika menggunakan RLS, tambahkan kebijakan secara eksplisit ke tabel baru.
75
+ - [ ] Commit file migrasi ke sistem kontrol versi.
76
+
77
+ ### Contoh: Alur Perintah Migrasi Supabase
78
+ ```bash
79
+ # 1. Buat file migrasi baru
80
+ npx supabase migration new create_users_table
81
+
82
+ # 2. Tulis SQL ke supabase/migrations/<timestamp>_create_users_table.sql
83
+ # 3. Terapkan ke database lokal
84
+ npx supabase migration up
85
+
86
+ # 4. Terapkan ke database remote produksi
87
+ npx supabase db push
88
+ ```
89
+
90
+ ## Integrasi Orkestrasi
91
+ - Terintegrasi dengan: `supabase-security-expert`, `database-orm-expert`, `ci-cd-devops-architect`.