vibes-plug 1.0.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 (141) hide show
  1. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  2. package/BLUEPRINT.md +125 -0
  3. package/CHANGELOG.md +195 -0
  4. package/CONTRIBUTING.md +199 -0
  5. package/LICENSE +21 -0
  6. package/README.md +263 -0
  7. package/SECURITY.md +21 -0
  8. package/banner.png +0 -0
  9. package/package.json +25 -0
  10. package/plugin.json +8 -0
  11. package/scripts/update_skills.js +75 -0
  12. package/skills/ai-llm-integration-expert/SKILL.md +162 -0
  13. package/skills/api-design-expert/SKILL.md +310 -0
  14. package/skills/app-analyzer-optimizer/SKILL.md +189 -0
  15. package/skills/asisten_ramah/SKILL.md +41 -0
  16. package/skills/authentication-identity-expert/SKILL.md +45 -0
  17. package/skills/auto-doc-updater/SKILL.md +204 -0
  18. package/skills/bootstrap-to-modern/SKILL.md +87 -0
  19. package/skills/brainstorming/SKILL.md +353 -0
  20. package/skills/bun-runtime-expert/SKILL.md +211 -0
  21. package/skills/ci-cd-devops-architect/SKILL.md +45 -0
  22. package/skills/cloud-hosting-expert/SKILL.md +244 -0
  23. package/skills/coderabbit/SKILL.md +192 -0
  24. package/skills/data-telemetry-expert/SKILL.md +213 -0
  25. package/skills/database-orm-expert/SKILL.md +294 -0
  26. package/skills/design-system-architect/SKILL.md +243 -0
  27. package/skills/e2e-testing-expert/SKILL.md +315 -0
  28. package/skills/event-driven-architect/SKILL.md +81 -0
  29. package/skills/firebase-security-expert/SKILL.md +195 -0
  30. package/skills/fullstack-expert/SKILL.md +202 -0
  31. package/skills/fullstack-expert/references/api_design_guide.md +466 -0
  32. package/skills/fullstack-expert/references/devops_infrastructure.md +477 -0
  33. package/skills/fullstack-expert/references/multi_language_backend.md +528 -0
  34. package/skills/fullstack-expert/references/system_design_patterns.md +358 -0
  35. package/skills/fullstack-expert/scripts/api_contract_validator.py +253 -0
  36. package/skills/fullstack-expert/scripts/architecture_analyzer.py +326 -0
  37. package/skills/gemini-agent-booster/SKILL.md +135 -0
  38. package/skills/global-a11y-i18n-expert/SKILL.md +81 -0
  39. package/skills/go-programming-expert/SKILL.md +295 -0
  40. package/skills/hig/SKILL.md +188 -0
  41. package/skills/js-backend-expert/SKILL.md +192 -0
  42. package/skills/mcp-server-architect/SKILL.md +194 -0
  43. package/skills/mobile-expo-expert/SKILL.md +186 -0
  44. package/skills/monday-design-aesthetic/SKILL.md +67 -0
  45. package/skills/monorepo-architect/SKILL.md +227 -0
  46. package/skills/mpa-orchestrator/SKILL.md +101 -0
  47. package/skills/multi-agent-orchestration/SKILL.md +234 -0
  48. package/skills/multiple-entry-points/SKILL.md +55 -0
  49. package/skills/mvc-expert/SKILL.md +231 -0
  50. package/skills/payment-gateway-expert/SKILL.md +45 -0
  51. package/skills/performance-web-vitals/SKILL.md +332 -0
  52. package/skills/prd-architect/SKILL.md +191 -0
  53. package/skills/production-ready-hardener/SKILL.md +469 -0
  54. package/skills/production-ready-hardener/references/performance_optimization.md +441 -0
  55. package/skills/production-ready-hardener/references/production_checklist.md +161 -0
  56. package/skills/production-ready-hardener/references/security_hardening_guide.md +379 -0
  57. package/skills/production-ready-hardener/scripts/production_readiness_scanner.py +875 -0
  58. package/skills/python-programming-expert/SKILL.md +271 -0
  59. package/skills/realtime-collaboration-expert/SKILL.md +45 -0
  60. package/skills/rust-programming-expert/SKILL.md +235 -0
  61. package/skills/saas-billing/SKILL.md +377 -0
  62. package/skills/saas-multi-tenant/SKILL.md +237 -0
  63. package/skills/saas-mvp-launcher/SKILL.md +231 -0
  64. package/skills/saas-transformer/SKILL.md +446 -0
  65. package/skills/saas-transformer/references/billing_integration_guide.md +401 -0
  66. package/skills/saas-transformer/references/feature_gating_patterns.md +137 -0
  67. package/skills/saas-transformer/references/saas_transformation_checklist.md +121 -0
  68. package/skills/saas-transformer/scripts/saas_transformation_scanner.py +254 -0
  69. package/skills/scalability-clean-code/SKILL.md +229 -0
  70. package/skills/secure-fuzz-testing/SKILL.md +201 -0
  71. package/skills/senior-frontend/SKILL.md +161 -0
  72. package/skills/senior-frontend/references/frontend_best_practices.md +806 -0
  73. package/skills/senior-frontend/references/nextjs_optimization_guide.md +724 -0
  74. package/skills/senior-frontend/references/react_patterns.md +746 -0
  75. package/skills/senior-frontend/scripts/bundle_analyzer.py +407 -0
  76. package/skills/senior-frontend/scripts/component_generator.py +329 -0
  77. package/skills/senior-frontend/scripts/frontend_scaffolder.py +1005 -0
  78. package/skills/senior-fullstack/SKILL.md +167 -0
  79. package/skills/senior-fullstack/references/architecture_patterns.md +160 -0
  80. package/skills/senior-fullstack/references/development_workflows.md +222 -0
  81. package/skills/senior-fullstack/references/tech_stack_guide.md +190 -0
  82. package/skills/senior-fullstack/scripts/code_quality_analyzer.py +114 -0
  83. package/skills/senior-fullstack/scripts/fullstack_scaffolder.py +114 -0
  84. package/skills/senior-fullstack/scripts/project_scaffolder.py +114 -0
  85. package/skills/seo/SKILL.md +225 -0
  86. package/skills/seo/references/cwv-thresholds.md +108 -0
  87. package/skills/seo/references/eeat-framework.md +214 -0
  88. package/skills/seo/references/quality-gates.md +155 -0
  89. package/skills/seo/references/schema-types.md +118 -0
  90. package/skills/seo-aeo-landing-page-writer/SKILL.md +97 -0
  91. package/skills/seo-geo/SKILL.md +188 -0
  92. package/skills/session-handoff-resume/SKILL.md +158 -0
  93. package/skills/skill_baru/SKILL.md +147 -0
  94. package/skills/spa-orchestrator/SKILL.md +288 -0
  95. package/skills/state-management-expert/SKILL.md +272 -0
  96. package/skills/supabase-migration/SKILL.md +45 -0
  97. package/skills/supabase-security-expert/SKILL.md +243 -0
  98. package/skills/tailwind-expert/SKILL.md +188 -0
  99. package/skills/tanstack-query-expert/SKILL.md +199 -0
  100. package/skills/tauri-expert/SKILL.md +97 -0
  101. package/skills/token-saver/SKILL.md +111 -0
  102. package/skills/typescript-expert/SKILL.md +279 -0
  103. package/skills/ui-components-expert/SKILL.md +63 -0
  104. package/skills/ui-ux-pro-max/SKILL.md +201 -0
  105. package/skills/ui-ux-pro-max/data/charts.csv +26 -0
  106. package/skills/ui-ux-pro-max/data/colors.csv +97 -0
  107. package/skills/ui-ux-pro-max/data/icons.csv +101 -0
  108. package/skills/ui-ux-pro-max/data/landing.csv +31 -0
  109. package/skills/ui-ux-pro-max/data/products.csv +97 -0
  110. package/skills/ui-ux-pro-max/data/prompts.csv +24 -0
  111. package/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
  112. package/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
  113. package/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
  114. package/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
  115. package/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
  116. package/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
  117. package/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
  118. package/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
  119. package/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
  120. package/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
  121. package/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
  122. package/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
  123. package/skills/ui-ux-pro-max/data/styles.csv +59 -0
  124. package/skills/ui-ux-pro-max/data/typography.csv +58 -0
  125. package/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
  126. package/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  127. package/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
  128. package/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-310.pyc +0 -0
  129. package/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-312.pyc +0 -0
  130. package/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-310.pyc +0 -0
  131. package/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-312.pyc +0 -0
  132. package/skills/ui-ux-pro-max/scripts/core.py +257 -0
  133. package/skills/ui-ux-pro-max/scripts/design_system.py +493 -0
  134. package/skills/ui-ux-pro-max/scripts/search.py +81 -0
  135. package/skills/ui_ux_expert/SKILL.md +114 -0
  136. package/skills/vibe-code-gardener/SKILL.md +173 -0
  137. package/skills/web-scraper/SKILL.md +205 -0
  138. package/skills/web-scraper/references/data-transforms.md +397 -0
  139. package/skills/web-scraper/references/extraction-patterns.md +475 -0
  140. package/skills/web-scraper/references/output-templates.md +481 -0
  141. package/skills/zero-to-prod-orchestrator/SKILL.md +180 -0
@@ -0,0 +1,806 @@
1
+ # Frontend Best Practices
2
+
3
+ Modern frontend development standards for accessibility, testing, TypeScript, and Tailwind CSS.
4
+
5
+ ---
6
+
7
+ ## Table of Contents
8
+
9
+ - [Accessibility (a11y)](#accessibility-a11y)
10
+ - [Testing Strategies](#testing-strategies)
11
+ - [TypeScript Patterns](#typescript-patterns)
12
+ - [Tailwind CSS](#tailwind-css)
13
+ - [Project Structure](#project-structure)
14
+ - [Security](#security)
15
+
16
+ ---
17
+
18
+ ## Accessibility (a11y)
19
+
20
+ ### Semantic HTML
21
+
22
+ ```tsx
23
+ // BAD - Divs for everything
24
+ <div onClick={handleClick}>Click me</div>
25
+ <div class="header">...</div>
26
+ <div class="nav">...</div>
27
+
28
+ // GOOD - Semantic elements
29
+ <button onClick={handleClick}>Click me</button>
30
+ <header>...</header>
31
+ <nav>...</nav>
32
+ <main>...</main>
33
+ <article>...</article>
34
+ <aside>...</aside>
35
+ <footer>...</footer>
36
+ ```
37
+
38
+ ### Keyboard Navigation
39
+
40
+ ```tsx
41
+ // Ensure all interactive elements are keyboard accessible
42
+ function Modal({ isOpen, onClose, children }: ModalProps) {
43
+ const modalRef = useRef<HTMLDivElement>(null);
44
+
45
+ useEffect(() => {
46
+ if (isOpen) {
47
+ // Focus first focusable element
48
+ const focusable = modalRef.current?.querySelectorAll(
49
+ 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
50
+ );
51
+ (focusable?.[0] as HTMLElement)?.focus();
52
+
53
+ // Trap focus within modal
54
+ const handleTab = (e: KeyboardEvent) => {
55
+ if (e.key === 'Tab' && focusable) {
56
+ const first = focusable[0] as HTMLElement;
57
+ const last = focusable[focusable.length - 1] as HTMLElement;
58
+
59
+ if (e.shiftKey && document.activeElement === first) {
60
+ e.preventDefault();
61
+ last.focus();
62
+ } else if (!e.shiftKey && document.activeElement === last) {
63
+ e.preventDefault();
64
+ first.focus();
65
+ }
66
+ }
67
+
68
+ if (e.key === 'Escape') {
69
+ onClose();
70
+ }
71
+ };
72
+
73
+ document.addEventListener('keydown', handleTab);
74
+ return () => document.removeEventListener('keydown', handleTab);
75
+ }
76
+ }, [isOpen, onClose]);
77
+
78
+ if (!isOpen) return null;
79
+
80
+ return (
81
+ <div
82
+ ref={modalRef}
83
+ role="dialog"
84
+ aria-modal="true"
85
+ aria-labelledby="modal-title"
86
+ >
87
+ {children}
88
+ </div>
89
+ );
90
+ }
91
+ ```
92
+
93
+ ### ARIA Attributes
94
+
95
+ ```tsx
96
+ // Live regions for dynamic content
97
+ <div aria-live="polite" aria-atomic="true">
98
+ {status && <p>{status}</p>}
99
+ </div>
100
+
101
+ // Loading states
102
+ <button disabled={isLoading} aria-busy={isLoading}>
103
+ {isLoading ? 'Loading...' : 'Submit'}
104
+ </button>
105
+
106
+ // Form labels
107
+ <label htmlFor="email">Email address</label>
108
+ <input
109
+ id="email"
110
+ type="email"
111
+ aria-required="true"
112
+ aria-invalid={!!errors.email}
113
+ aria-describedby={errors.email ? 'email-error' : undefined}
114
+ />
115
+ {errors.email && (
116
+ <p id="email-error" role="alert">
117
+ {errors.email}
118
+ </p>
119
+ )}
120
+
121
+ // Navigation
122
+ <nav aria-label="Main navigation">
123
+ <ul>
124
+ <li><a href="/" aria-current={isHome ? 'page' : undefined}>Home</a></li>
125
+ <li><a href="/about" aria-current={isAbout ? 'page' : undefined}>About</a></li>
126
+ </ul>
127
+ </nav>
128
+
129
+ // Toggle buttons
130
+ <button
131
+ aria-pressed={isEnabled}
132
+ onClick={() => setIsEnabled(!isEnabled)}
133
+ >
134
+ {isEnabled ? 'Enabled' : 'Disabled'}
135
+ </button>
136
+
137
+ // Expandable sections
138
+ <button
139
+ aria-expanded={isOpen}
140
+ aria-controls="content-panel"
141
+ onClick={() => setIsOpen(!isOpen)}
142
+ >
143
+ Show details
144
+ </button>
145
+ <div id="content-panel" hidden={!isOpen}>
146
+ Content here
147
+ </div>
148
+ ```
149
+
150
+ ### Color Contrast
151
+
152
+ ```tsx
153
+ // Ensure 4.5:1 contrast ratio for text (WCAG AA)
154
+ // Use tools like @axe-core/react for testing
155
+
156
+ // tailwind.config.js - Define accessible colors
157
+ module.exports = {
158
+ theme: {
159
+ colors: {
160
+ // Primary with proper contrast
161
+ primary: {
162
+ DEFAULT: '#2563eb', // Blue 600
163
+ foreground: '#ffffff',
164
+ },
165
+ // Error state
166
+ error: {
167
+ DEFAULT: '#dc2626', // Red 600
168
+ foreground: '#ffffff',
169
+ },
170
+ // Text colors with proper contrast
171
+ foreground: '#0f172a', // Slate 900
172
+ muted: '#64748b', // Slate 500 - minimum 4.5:1 on white
173
+ },
174
+ },
175
+ };
176
+
177
+ // Never rely on color alone
178
+ <span className="text-red-600">
179
+ <ErrorIcon aria-hidden="true" />
180
+ <span>Error: Invalid input</span>
181
+ </span>
182
+ ```
183
+
184
+ ### Screen Reader Only Content
185
+
186
+ ```tsx
187
+ // Visually hidden but accessible to screen readers
188
+ const srOnly = 'absolute w-px h-px p-0 -m-px overflow-hidden whitespace-nowrap border-0';
189
+
190
+ // Skip link for keyboard users
191
+ <a href="#main-content" className={srOnly + ' focus:not-sr-only focus:absolute focus:top-0'}>
192
+ Skip to main content
193
+ </a>
194
+
195
+ // Icon buttons need labels
196
+ <button aria-label="Close menu">
197
+ <XIcon aria-hidden="true" />
198
+ </button>
199
+
200
+ // Or use visually hidden text
201
+ <button>
202
+ <XIcon aria-hidden="true" />
203
+ <span className={srOnly}>Close menu</span>
204
+ </button>
205
+ ```
206
+
207
+ ---
208
+
209
+ ## Testing Strategies
210
+
211
+ ### Component Testing with Testing Library
212
+
213
+ ```tsx
214
+ // Button.test.tsx
215
+ import { render, screen, fireEvent } from '@testing-library/react';
216
+ import userEvent from '@testing-library/user-event';
217
+ import { Button } from './Button';
218
+
219
+ describe('Button', () => {
220
+ it('renders with correct text', () => {
221
+ render(<Button>Click me</Button>);
222
+ expect(screen.getByRole('button', { name: 'Click me' })).toBeInTheDocument();
223
+ });
224
+
225
+ it('calls onClick when clicked', async () => {
226
+ const user = userEvent.setup();
227
+ const handleClick = jest.fn();
228
+
229
+ render(<Button onClick={handleClick}>Click me</Button>);
230
+ await user.click(screen.getByRole('button'));
231
+
232
+ expect(handleClick).toHaveBeenCalledTimes(1);
233
+ });
234
+
235
+ it('is disabled when loading', () => {
236
+ render(<Button isLoading>Submit</Button>);
237
+ expect(screen.getByRole('button')).toBeDisabled();
238
+ expect(screen.getByRole('button')).toHaveAttribute('aria-busy', 'true');
239
+ });
240
+
241
+ it('shows loading text when loading', () => {
242
+ render(<Button isLoading loadingText="Submitting...">Submit</Button>);
243
+ expect(screen.getByText('Submitting...')).toBeInTheDocument();
244
+ });
245
+ });
246
+ ```
247
+
248
+ ### Hook Testing
249
+
250
+ ```tsx
251
+ // useCounter.test.ts
252
+ import { renderHook, act } from '@testing-library/react';
253
+ import { useCounter } from './useCounter';
254
+
255
+ describe('useCounter', () => {
256
+ it('initializes with default value', () => {
257
+ const { result } = renderHook(() => useCounter());
258
+ expect(result.current.count).toBe(0);
259
+ });
260
+
261
+ it('initializes with custom value', () => {
262
+ const { result } = renderHook(() => useCounter(10));
263
+ expect(result.current.count).toBe(10);
264
+ });
265
+
266
+ it('increments count', () => {
267
+ const { result } = renderHook(() => useCounter());
268
+
269
+ act(() => {
270
+ result.current.increment();
271
+ });
272
+
273
+ expect(result.current.count).toBe(1);
274
+ });
275
+
276
+ it('resets to initial value', () => {
277
+ const { result } = renderHook(() => useCounter(5));
278
+
279
+ act(() => {
280
+ result.current.increment();
281
+ result.current.increment();
282
+ result.current.reset();
283
+ });
284
+
285
+ expect(result.current.count).toBe(5);
286
+ });
287
+ });
288
+ ```
289
+
290
+ ### Integration Testing
291
+
292
+ ```tsx
293
+ // LoginForm.test.tsx
294
+ import { render, screen, waitFor } from '@testing-library/react';
295
+ import userEvent from '@testing-library/user-event';
296
+ import { LoginForm } from './LoginForm';
297
+ import { AuthProvider } from '@/contexts/AuthContext';
298
+
299
+ const mockLogin = jest.fn();
300
+
301
+ jest.mock('@/lib/auth', () => ({
302
+ login: (...args: unknown[]) => mockLogin(...args),
303
+ }));
304
+
305
+ describe('LoginForm', () => {
306
+ beforeEach(() => {
307
+ mockLogin.mockReset();
308
+ });
309
+
310
+ it('submits form with valid credentials', async () => {
311
+ const user = userEvent.setup();
312
+ mockLogin.mockResolvedValueOnce({ user: { id: '1', name: 'Test' } });
313
+
314
+ render(
315
+ <AuthProvider>
316
+ <LoginForm />
317
+ </AuthProvider>
318
+ );
319
+
320
+ await user.type(screen.getByLabelText(/email/i), 'test@example.com');
321
+ await user.type(screen.getByLabelText(/password/i), 'password123');
322
+ await user.click(screen.getByRole('button', { name: /sign in/i }));
323
+
324
+ await waitFor(() => {
325
+ expect(mockLogin).toHaveBeenCalledWith('test@example.com', 'password123');
326
+ });
327
+ });
328
+
329
+ it('shows validation errors for empty fields', async () => {
330
+ const user = userEvent.setup();
331
+
332
+ render(
333
+ <AuthProvider>
334
+ <LoginForm />
335
+ </AuthProvider>
336
+ );
337
+
338
+ await user.click(screen.getByRole('button', { name: /sign in/i }));
339
+
340
+ expect(await screen.findByText(/email is required/i)).toBeInTheDocument();
341
+ expect(await screen.findByText(/password is required/i)).toBeInTheDocument();
342
+ expect(mockLogin).not.toHaveBeenCalled();
343
+ });
344
+ });
345
+ ```
346
+
347
+ ### E2E Testing with Playwright
348
+
349
+ ```typescript
350
+ // e2e/checkout.spec.ts
351
+ import { test, expect } from '@playwright/test';
352
+
353
+ test.describe('Checkout flow', () => {
354
+ test.beforeEach(async ({ page }) => {
355
+ await page.goto('/');
356
+ await page.click('[data-testid="product-1"] button');
357
+ await page.click('[data-testid="cart-button"]');
358
+ });
359
+
360
+ test('completes checkout with valid payment', async ({ page }) => {
361
+ await page.click('text=Proceed to Checkout');
362
+
363
+ // Fill shipping info
364
+ await page.fill('[name="email"]', 'test@example.com');
365
+ await page.fill('[name="address"]', '123 Test St');
366
+ await page.fill('[name="city"]', 'Test City');
367
+ await page.selectOption('[name="state"]', 'CA');
368
+ await page.fill('[name="zip"]', '90210');
369
+
370
+ await page.click('text=Continue to Payment');
371
+ await page.click('text=Place Order');
372
+
373
+ // Verify success
374
+ await expect(page).toHaveURL(/\/order\/confirmation/);
375
+ await expect(page.locator('h1')).toHaveText('Order Confirmed!');
376
+ });
377
+ });
378
+ ```
379
+
380
+ ---
381
+
382
+ ## TypeScript Patterns
383
+
384
+ ### Component Props
385
+
386
+ ```tsx
387
+ // Use interface for component props
388
+ interface ButtonProps {
389
+ variant?: 'primary' | 'secondary' | 'ghost';
390
+ size?: 'sm' | 'md' | 'lg';
391
+ isLoading?: boolean;
392
+ children: React.ReactNode;
393
+ onClick?: () => void;
394
+ }
395
+
396
+ // Extend HTML attributes
397
+ interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
398
+ variant?: 'primary' | 'secondary';
399
+ isLoading?: boolean;
400
+ }
401
+
402
+ function Button({ variant = 'primary', isLoading, children, ...props }: ButtonProps) {
403
+ return (
404
+ <button
405
+ {...props}
406
+ disabled={props.disabled || isLoading}
407
+ className={cn(variants[variant], props.className)}
408
+ >
409
+ {isLoading ? <Spinner /> : children}
410
+ </button>
411
+ );
412
+ }
413
+
414
+ // Polymorphic components
415
+ type PolymorphicProps<E extends React.ElementType> = {
416
+ as?: E;
417
+ } & React.ComponentPropsWithoutRef<E>;
418
+
419
+ function Box<E extends React.ElementType = 'div'>({
420
+ as,
421
+ children,
422
+ ...props
423
+ }: PolymorphicProps<E>) {
424
+ const Component = as || 'div';
425
+ return <Component {...props}>{children}</Component>;
426
+ }
427
+
428
+ // Usage
429
+ <Box as="section" id="hero">Content</Box>
430
+ <Box as="article">Article content</Box>
431
+ ```
432
+
433
+ ### Discriminated Unions
434
+
435
+ ```tsx
436
+ // State machines with exhaustive type checking
437
+ type AsyncState<T> =
438
+ | { status: 'idle' }
439
+ | { status: 'loading' }
440
+ | { status: 'success'; data: T }
441
+ | { status: 'error'; error: Error };
442
+
443
+ function DataDisplay<T>({ state, render }: {
444
+ state: AsyncState<T>;
445
+ render: (data: T) => React.ReactNode;
446
+ }) {
447
+ switch (state.status) {
448
+ case 'idle':
449
+ return null;
450
+ case 'loading':
451
+ return <Spinner />;
452
+ case 'success':
453
+ return <>{render(state.data)}</>;
454
+ case 'error':
455
+ return <ErrorMessage error={state.error} />;
456
+ // TypeScript ensures all cases are handled
457
+ }
458
+ }
459
+ ```
460
+
461
+ ### Generic Components
462
+
463
+ ```tsx
464
+ // Generic list component
465
+ interface ListProps<T> {
466
+ items: T[];
467
+ renderItem: (item: T, index: number) => React.ReactNode;
468
+ keyExtractor: (item: T) => string;
469
+ emptyMessage?: string;
470
+ }
471
+
472
+ function List<T>({ items, renderItem, keyExtractor, emptyMessage }: ListProps<T>) {
473
+ if (items.length === 0) {
474
+ return <p className="text-muted">{emptyMessage || 'No items'}</p>;
475
+ }
476
+
477
+ return (
478
+ <ul>
479
+ {items.map((item, index) => (
480
+ <li key={keyExtractor(item)}>{renderItem(item, index)}</li>
481
+ ))}
482
+ </ul>
483
+ );
484
+ }
485
+
486
+ // Usage
487
+ <List
488
+ items={users}
489
+ keyExtractor={(user) => user.id}
490
+ renderItem={(user) => <UserCard user={user} />}
491
+ />
492
+ ```
493
+
494
+ ### Type Guards
495
+
496
+ ```tsx
497
+ // User-defined type guards
498
+ interface User {
499
+ id: string;
500
+ name: string;
501
+ email: string;
502
+ }
503
+
504
+ interface Admin extends User {
505
+ role: 'admin';
506
+ permissions: string[];
507
+ }
508
+
509
+ function isAdmin(user: User): user is Admin {
510
+ return 'role' in user && user.role === 'admin';
511
+ }
512
+
513
+ function UserBadge({ user }: { user: User }) {
514
+ if (isAdmin(user)) {
515
+ // TypeScript knows user is Admin here
516
+ return <Badge variant="admin">Admin ({user.permissions.length} perms)</Badge>;
517
+ }
518
+
519
+ return <Badge>User</Badge>;
520
+ }
521
+
522
+ // API response type guards
523
+ interface ApiSuccess<T> {
524
+ success: true;
525
+ data: T;
526
+ }
527
+
528
+ interface ApiError {
529
+ success: false;
530
+ error: string;
531
+ }
532
+
533
+ type ApiResponse<T> = ApiSuccess<T> | ApiError;
534
+
535
+ function isApiSuccess<T>(response: ApiResponse<T>): response is ApiSuccess<T> {
536
+ return response.success === true;
537
+ }
538
+ ```
539
+
540
+ ---
541
+
542
+ ## Tailwind CSS
543
+
544
+ ### Component Variants with CVA
545
+
546
+ ```tsx
547
+ import { cva, type VariantProps } from 'class-variance-authority';
548
+ import { cn } from '@/lib/utils';
549
+
550
+ const buttonVariants = cva(
551
+ // Base styles
552
+ 'inline-flex items-center justify-center rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
553
+ {
554
+ variants: {
555
+ variant: {
556
+ primary: 'bg-blue-600 text-white hover:bg-blue-700 focus-visible:ring-blue-500',
557
+ secondary: 'bg-gray-100 text-gray-900 hover:bg-gray-200 focus-visible:ring-gray-500',
558
+ ghost: 'hover:bg-gray-100 hover:text-gray-900',
559
+ destructive: 'bg-red-600 text-white hover:bg-red-700 focus-visible:ring-red-500',
560
+ },
561
+ size: {
562
+ sm: 'h-8 px-3 text-sm',
563
+ md: 'h-10 px-4 text-sm',
564
+ lg: 'h-12 px-6 text-base',
565
+ icon: 'h-10 w-10',
566
+ },
567
+ },
568
+ defaultVariants: {
569
+ variant: 'primary',
570
+ size: 'md',
571
+ },
572
+ }
573
+ );
574
+
575
+ interface ButtonProps
576
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,
577
+ VariantProps<typeof buttonVariants> {}
578
+
579
+ function Button({ className, variant, size, ...props }: ButtonProps) {
580
+ return (
581
+ <button
582
+ className={cn(buttonVariants({ variant, size }), className)}
583
+ {...props}
584
+ />
585
+ );
586
+ }
587
+
588
+ // Usage
589
+ <Button variant="primary" size="lg">Large Primary</Button>
590
+ <Button variant="ghost" size="icon"><MenuIcon /></Button>
591
+ ```
592
+
593
+ ### Responsive Design
594
+
595
+ ```tsx
596
+ // Mobile-first responsive design
597
+ <div className="
598
+ grid
599
+ grid-cols-1 {/* Mobile: 1 column */}
600
+ sm:grid-cols-2 {/* 640px+: 2 columns */}
601
+ lg:grid-cols-3 {/* 1024px+: 3 columns */}
602
+ xl:grid-cols-4 {/* 1280px+: 4 columns */}
603
+ gap-4
604
+ sm:gap-6
605
+ lg:gap-8
606
+ ">
607
+ {products.map(product => <ProductCard key={product.id} product={product} />)}
608
+ </div>
609
+
610
+ // Container with responsive padding
611
+ <div className="container mx-auto px-4 sm:px-6 lg:px-8">
612
+ Content
613
+ </div>
614
+
615
+ // Hide/show based on breakpoint
616
+ <nav className="hidden md:flex">Desktop nav</nav>
617
+ <button className="md:hidden">Mobile menu</button>
618
+ ```
619
+
620
+ ### Animation Utilities
621
+
622
+ ```tsx
623
+ // Skeleton loading
624
+ <div className="animate-pulse space-y-4">
625
+ <div className="h-4 bg-gray-200 rounded w-3/4" />
626
+ <div className="h-4 bg-gray-200 rounded w-1/2" />
627
+ </div>
628
+
629
+ // Transitions
630
+ <button className="
631
+ transition-all
632
+ duration-200
633
+ ease-in-out
634
+ hover:scale-105
635
+ active:scale-95
636
+ ">
637
+ Hover me
638
+ </button>
639
+
640
+ // Custom animations in tailwind.config.js
641
+ module.exports = {
642
+ theme: {
643
+ extend: {
644
+ animation: {
645
+ 'fade-in': 'fadeIn 0.3s ease-out',
646
+ 'slide-up': 'slideUp 0.3s ease-out',
647
+ 'spin-slow': 'spin 3s linear infinite',
648
+ },
649
+ keyframes: {
650
+ fadeIn: {
651
+ '0%': { opacity: '0' },
652
+ '100%': { opacity: '1' },
653
+ },
654
+ slideUp: {
655
+ '0%': { transform: 'translateY(10px)', opacity: '0' },
656
+ '100%': { transform: 'translateY(0)', opacity: '1' },
657
+ },
658
+ },
659
+ },
660
+ },
661
+ };
662
+
663
+ // Usage
664
+ <div className="animate-fade-in">Fading in</div>
665
+ ```
666
+
667
+ ---
668
+
669
+ ## Project Structure
670
+
671
+ ### Feature-Based Structure
672
+
673
+ ```
674
+ src/
675
+ ├── app/ # Next.js App Router
676
+ │ ├── (auth)/ # Auth route group
677
+ │ │ ├── login/
678
+ │ │ └── register/
679
+ │ ├── dashboard/
680
+ │ │ ├── page.tsx
681
+ │ │ └── layout.tsx
682
+ │ └── layout.tsx
683
+ ├── components/
684
+ │ ├── ui/ # Shared UI components
685
+ │ │ ├── Button.tsx
686
+ │ │ ├── Input.tsx
687
+ │ │ └── index.ts
688
+ │ └── features/ # Feature-specific components
689
+ │ ├── auth/
690
+ │ │ ├── LoginForm.tsx
691
+ │ │ └── RegisterForm.tsx
692
+ │ └── dashboard/
693
+ │ ├── StatsCard.tsx
694
+ │ └── RecentActivity.tsx
695
+ ├── hooks/ # Custom React hooks
696
+ │ ├── useAuth.ts
697
+ │ ├── useDebounce.ts
698
+ │ └── useLocalStorage.ts
699
+ ├── lib/ # Utilities and configs
700
+ │ ├── utils.ts
701
+ │ ├── api.ts
702
+ │ └── constants.ts
703
+ ├── types/ # TypeScript types
704
+ │ ├── user.ts
705
+ │ └── api.ts
706
+ └── styles/
707
+ └── globals.css
708
+ ```
709
+
710
+ ### Barrel Exports
711
+
712
+ ```tsx
713
+ // components/ui/index.ts
714
+ export { Button } from './Button';
715
+ export { Input } from './Input';
716
+ export { Card, CardHeader, CardContent, CardFooter } from './Card';
717
+ export { Dialog, DialogTrigger, DialogContent } from './Dialog';
718
+
719
+ // Usage
720
+ import { Button, Input, Card } from '@/components/ui';
721
+ ```
722
+
723
+ ---
724
+
725
+ ## Security
726
+
727
+ ### XSS Prevention
728
+
729
+ React escapes content by default, which prevents most XSS attacks. When you need to render HTML content:
730
+
731
+ 1. **Avoid rendering raw HTML** when possible
732
+ 2. **Sanitize with DOMPurify** for trusted content sources
733
+ 3. **Use allow-lists** for permitted tags and attributes
734
+
735
+ ```tsx
736
+ // React escapes by default - this is safe
737
+ <div>{userInput}</div>
738
+
739
+ // When you must render HTML, sanitize first
740
+ import DOMPurify from 'dompurify';
741
+
742
+ function SafeHTML({ html }: { html: string }) {
743
+ const sanitized = DOMPurify.sanitize(html, {
744
+ ALLOWED_TAGS: ['b', 'i', 'em', 'strong', 'a', 'p'],
745
+ ALLOWED_ATTR: ['href'],
746
+ });
747
+
748
+ return <div dangerouslySetInnerHTML={{ __html: sanitized }} />;
749
+ }
750
+ ```
751
+
752
+ ### Input Validation
753
+
754
+ ```tsx
755
+ import { z } from 'zod';
756
+ import { useForm } from 'react-hook-form';
757
+ import { zodResolver } from '@hookform/resolvers/zod';
758
+
759
+ const schema = z.object({
760
+ email: z.string().email('Invalid email address'),
761
+ password: z.string()
762
+ .min(8, 'Password must be at least 8 characters')
763
+ .regex(/[A-Z]/, 'Password must contain uppercase letter')
764
+ .regex(/[0-9]/, 'Password must contain number'),
765
+ confirmPassword: z.string(),
766
+ }).refine((data) => data.password === data.confirmPassword, {
767
+ message: 'Passwords do not match',
768
+ path: ['confirmPassword'],
769
+ });
770
+
771
+ type FormData = z.infer<typeof schema>;
772
+
773
+ function RegisterForm() {
774
+ const { register, handleSubmit, formState: { errors } } = useForm<FormData>({
775
+ resolver: zodResolver(schema),
776
+ });
777
+
778
+ return (
779
+ <form onSubmit={handleSubmit(onSubmit)}>
780
+ <Input {...register('email')} error={errors.email?.message} />
781
+ <Input type="password" {...register('password')} error={errors.password?.message} />
782
+ <Input type="password" {...register('confirmPassword')} error={errors.confirmPassword?.message} />
783
+ <Button type="submit">Register</Button>
784
+ </form>
785
+ );
786
+ }
787
+ ```
788
+
789
+ ### Secure API Calls
790
+
791
+ ```tsx
792
+ // Use environment variables for API endpoints
793
+ const API_URL = process.env.NEXT_PUBLIC_API_URL;
794
+
795
+ // Never include secrets in client code - use server-side API routes
796
+ // app/api/data/route.ts
797
+ export async function GET() {
798
+ const response = await fetch('https://api.example.com/data', {
799
+ headers: {
800
+ 'Authorization': `Bearer ${process.env.API_SECRET}`, // Server-side only
801
+ },
802
+ });
803
+
804
+ return Response.json(await response.json());
805
+ }
806
+ ```