specweave 0.23.18 → 0.24.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.
- package/.claude-plugin/marketplace.json +93 -49
- package/CLAUDE.md +137 -4
- package/dist/src/cli/helpers/ado-area-path-mapper.d.ts +89 -0
- package/dist/src/cli/helpers/ado-area-path-mapper.d.ts.map +1 -0
- package/dist/src/cli/helpers/ado-area-path-mapper.js +213 -0
- package/dist/src/cli/helpers/ado-area-path-mapper.js.map +1 -0
- package/dist/src/cli/helpers/issue-tracker/ado-auto-discover.d.ts +29 -0
- package/dist/src/cli/helpers/issue-tracker/ado-auto-discover.d.ts.map +1 -0
- package/dist/src/cli/helpers/issue-tracker/ado-auto-discover.js +109 -0
- package/dist/src/cli/helpers/issue-tracker/ado-auto-discover.js.map +1 -0
- package/dist/src/cli/helpers/issue-tracker/ado.d.ts +1 -0
- package/dist/src/cli/helpers/issue-tracker/ado.d.ts.map +1 -1
- package/dist/src/cli/helpers/issue-tracker/ado.js +2 -0
- package/dist/src/cli/helpers/issue-tracker/ado.js.map +1 -1
- package/dist/src/cli/helpers/smart-filter.d.ts +83 -0
- package/dist/src/cli/helpers/smart-filter.d.ts.map +1 -0
- package/dist/src/cli/helpers/smart-filter.js +265 -0
- package/dist/src/cli/helpers/smart-filter.js.map +1 -0
- package/dist/src/core/qa/quality-gate-decider.d.ts +1 -1
- package/dist/src/core/qa/quality-gate-decider.js +2 -2
- package/dist/src/core/qa/quality-gate-decider.js.map +1 -1
- package/dist/src/core/qa/risk-calculator.d.ts +2 -2
- package/dist/src/core/qa/risk-calculator.js +2 -2
- package/dist/src/core/validators/ac-presence-validator.d.ts +56 -0
- package/dist/src/core/validators/ac-presence-validator.d.ts.map +1 -0
- package/dist/src/core/validators/ac-presence-validator.js +149 -0
- package/dist/src/core/validators/ac-presence-validator.js.map +1 -0
- package/dist/src/integrations/ado/area-path-mapper.d.ts +137 -0
- package/dist/src/integrations/ado/area-path-mapper.d.ts.map +1 -0
- package/dist/src/integrations/ado/area-path-mapper.js +267 -0
- package/dist/src/integrations/ado/area-path-mapper.js.map +1 -0
- package/dist/src/integrations/jira/filter-processor.d.ts +126 -0
- package/dist/src/integrations/jira/filter-processor.d.ts.map +1 -0
- package/dist/src/integrations/jira/filter-processor.js +207 -0
- package/dist/src/integrations/jira/filter-processor.js.map +1 -0
- package/dist/src/integrations/jira/jira-client.d.ts +13 -0
- package/dist/src/integrations/jira/jira-client.d.ts.map +1 -1
- package/dist/src/integrations/jira/jira-client.js +33 -0
- package/dist/src/integrations/jira/jira-client.js.map +1 -1
- package/dist/src/utils/ac-embedder.d.ts +63 -0
- package/dist/src/utils/ac-embedder.d.ts.map +1 -0
- package/dist/src/utils/ac-embedder.js +217 -0
- package/dist/src/utils/ac-embedder.js.map +1 -0
- package/dist/src/utils/env-manager.d.ts +86 -0
- package/dist/src/utils/env-manager.d.ts.map +1 -0
- package/dist/src/utils/env-manager.js +188 -0
- package/dist/src/utils/env-manager.js.map +1 -0
- package/package.json +1 -1
- package/plugins/specweave/.claude-plugin/plugin.json +1 -1
- package/plugins/specweave/agents/AGENTS-INDEX.md +1 -1
- package/plugins/specweave/agents/increment-quality-judge-v2/AGENT.md +9 -9
- package/plugins/specweave/commands/specweave-do.md +37 -0
- package/plugins/specweave/commands/specweave-done.md +159 -0
- package/plugins/specweave/commands/specweave-embed-acs.md +446 -0
- package/plugins/specweave/commands/specweave-next.md +148 -3
- package/plugins/specweave/commands/specweave-qa.md +2 -2
- package/plugins/specweave/hooks/pre-increment-start.sh +168 -0
- package/plugins/specweave/skills/SKILLS-INDEX.md +1 -1
- package/plugins/specweave-ado/.claude-plugin/plugin.json +1 -1
- package/plugins/specweave-ado/commands/specweave-ado-import-projects.md +331 -0
- package/plugins/specweave-alternatives/.claude-plugin/plugin.json +10 -0
- package/plugins/specweave-alternatives/commands/alternatives-analyze.md +336 -0
- package/plugins/specweave-alternatives/skills/architecture-alternatives/SKILL.md +651 -0
- package/plugins/specweave-alternatives/skills/bmad-method/SKILL.md +420 -0
- package/plugins/specweave-alternatives/skills/spec-kit-expert/SKILL.md +487 -0
- package/plugins/specweave-backend/commands/api-scaffold.md +80 -0
- package/plugins/specweave-backend/commands/crud-generate.md +109 -0
- package/plugins/specweave-backend/commands/migration-generate.md +139 -0
- package/plugins/specweave-confluent/commands/connector-deploy.md +154 -0
- package/plugins/specweave-confluent/commands/ksqldb-query.md +179 -0
- package/plugins/specweave-confluent/commands/schema-register.md +123 -0
- package/plugins/specweave-core/.claude-plugin/plugin.json +21 -0
- package/plugins/specweave-core/commands/architecture-review.md +288 -0
- package/plugins/specweave-core/commands/code-review.md +213 -0
- package/plugins/specweave-core/commands/refactor-plan.md +249 -0
- package/plugins/specweave-core/skills/code-quality/SKILL.md +157 -0
- package/plugins/specweave-core/skills/design-patterns/SKILL.md +244 -0
- package/plugins/specweave-core/skills/software-architecture/SKILL.md +83 -0
- package/plugins/specweave-cost-optimizer/.claude-plugin/plugin.json +22 -0
- package/plugins/specweave-cost-optimizer/commands/cost-analyze.md +360 -0
- package/plugins/specweave-cost-optimizer/commands/cost-optimize.md +480 -0
- package/plugins/specweave-cost-optimizer/skills/aws-cost-expert/SKILL.md +416 -0
- package/plugins/specweave-cost-optimizer/skills/cloud-pricing/SKILL.md +325 -0
- package/plugins/specweave-cost-optimizer/skills/cost-optimization/SKILL.md +337 -0
- package/plugins/specweave-diagrams/.claude-plugin/plugin.json +1 -1
- package/plugins/specweave-diagrams/commands/diagrams-generate.md +168 -0
- package/plugins/specweave-docs/.claude-plugin/plugin.json +10 -0
- package/plugins/specweave-docs/commands/docs-generate.md +441 -0
- package/plugins/specweave-docs/commands/docs-init.md +334 -0
- package/plugins/specweave-docs/skills/docusaurus/SKILL.md +581 -0
- package/plugins/specweave-docs/skills/spec-driven-brainstorming/SKILL.md +689 -0
- package/plugins/specweave-docs/skills/technical-writing/SKILL.md +1039 -0
- package/plugins/specweave-docs-preview/.claude-plugin/plugin.json +1 -1
- package/plugins/specweave-figma/.claude-plugin/plugin.json +23 -0
- package/plugins/specweave-figma/commands/figma-import.md +690 -0
- package/plugins/specweave-figma/commands/figma-to-react.md +834 -0
- package/plugins/specweave-figma/commands/figma-tokens.md +815 -0
- package/plugins/specweave-frontend/.claude-plugin/plugin.json +21 -0
- package/plugins/specweave-frontend/agents/frontend-architect/AGENT.md +387 -0
- package/plugins/specweave-frontend/agents/frontend-architect/README.md +385 -0
- package/plugins/specweave-frontend/agents/frontend-architect/examples.md +590 -0
- package/plugins/specweave-frontend/agents/frontend-architect/templates/component-template.tsx +152 -0
- package/plugins/specweave-frontend/agents/frontend-architect/templates/hook-template.ts +311 -0
- package/plugins/specweave-frontend/agents/frontend-architect/templates/page-template.tsx +228 -0
- package/plugins/specweave-frontend/commands/component-generate.md +510 -0
- package/plugins/specweave-frontend/commands/design-system-init.md +494 -0
- package/plugins/specweave-frontend/commands/frontend-scaffold.md +207 -0
- package/plugins/specweave-frontend/commands/nextjs-setup.md +396 -0
- package/plugins/specweave-frontend/skills/design-system-architect/SKILL.md +278 -0
- package/plugins/specweave-frontend/skills/frontend/SKILL.md +420 -0
- package/plugins/specweave-frontend/skills/nextjs/SKILL.md +546 -0
- package/plugins/specweave-github/.claude-plugin/plugin.json +1 -1
- package/plugins/specweave-github/hooks/.specweave/logs/hooks-debug.log +194 -0
- package/plugins/specweave-infrastructure/.claude-plugin/plugin.json +1 -1
- package/plugins/specweave-jira/.claude-plugin/plugin.json +1 -1
- package/plugins/specweave-jira/commands/import-projects.js +183 -0
- package/plugins/specweave-jira/commands/import-projects.md +97 -0
- package/plugins/specweave-jira/commands/import-projects.ts +288 -0
- package/plugins/specweave-jira/commands/specweave-jira-import-projects.md +298 -0
- package/plugins/specweave-kafka/.claude-plugin/plugin.json +1 -1
- package/plugins/specweave-kafka-streams/.claude-plugin/plugin.json +1 -1
- package/plugins/specweave-kubernetes/commands/cluster-setup.md +262 -0
- package/plugins/specweave-kubernetes/commands/deployment-generate.md +242 -0
- package/plugins/specweave-kubernetes/commands/helm-scaffold.md +333 -0
- package/plugins/specweave-ml/.claude-plugin/plugin.json +1 -1
- package/plugins/specweave-mobile/commands/app-scaffold.md +233 -0
- package/plugins/specweave-mobile/commands/build-config.md +256 -0
- package/plugins/specweave-mobile/commands/screen-generate.md +289 -0
- package/plugins/specweave-n8n/.claude-plugin/plugin.json +1 -1
- package/plugins/specweave-plugin-dev/.claude-plugin/plugin.json +13 -12
- package/plugins/specweave-plugin-dev/commands/plugin-create.md +333 -0
- package/plugins/specweave-plugin-dev/commands/plugin-publish.md +339 -0
- package/plugins/specweave-plugin-dev/commands/plugin-test.md +293 -0
- package/plugins/specweave-plugin-dev/skills/claude-sdk/SKILL.md +162 -0
- package/plugins/specweave-plugin-dev/skills/marketplace-publishing/SKILL.md +263 -0
- package/plugins/specweave-plugin-dev/skills/plugin-development/SKILL.md +316 -0
- package/plugins/specweave-release/.claude-plugin/plugin.json +1 -1
- package/plugins/specweave-release/commands/specweave-release-npm.md +110 -0
- package/plugins/specweave-release/hooks/.specweave/logs/dora-tracking.log +168 -0
- package/plugins/specweave-testing/.claude-plugin/plugin.json +21 -0
- package/plugins/specweave-testing/agents/qa-engineer/AGENT.md +797 -0
- package/plugins/specweave-testing/agents/qa-engineer/README.md +443 -0
- package/plugins/specweave-testing/agents/qa-engineer/templates/playwright-e2e-test.ts +470 -0
- package/plugins/specweave-testing/agents/qa-engineer/templates/test-data-factory.ts +507 -0
- package/plugins/specweave-testing/agents/qa-engineer/templates/vitest-unit-test.ts +400 -0
- package/plugins/specweave-testing/agents/qa-engineer/test-strategies.md +726 -0
- package/plugins/specweave-testing/commands/e2e-setup.md +1081 -0
- package/plugins/specweave-testing/commands/test-coverage.md +979 -0
- package/plugins/specweave-testing/commands/test-generate.md +1156 -0
- package/plugins/specweave-testing/commands/test-init.md +409 -0
- package/plugins/specweave-testing/skills/e2e-playwright/SKILL.md +769 -0
- package/plugins/specweave-testing/skills/tdd-expert/SKILL.md +934 -0
- package/plugins/specweave-testing/skills/unit-testing-expert/SKILL.md +1011 -0
- package/plugins/specweave-tooling/.claude-plugin/plugin.json +22 -0
- package/plugins/specweave-tooling/commands/specweave-tooling-skill-create.md +691 -0
- package/plugins/specweave-tooling/commands/specweave-tooling-skill-package.md +751 -0
- package/plugins/specweave-tooling/commands/specweave-tooling-skill-validate.md +858 -0
- package/plugins/specweave-ui/.claude-plugin/plugin.json +10 -0
- package/plugins/specweave-ui/commands/ui-automate.md +199 -0
- package/plugins/specweave-ui/commands/ui-inspect.md +70 -0
- package/plugins/specweave-ui/skills/browser-automation/SKILL.md +314 -0
- package/plugins/specweave-ui/skills/ui-testing/SKILL.md +716 -0
- package/plugins/specweave-ui/skills/visual-regression/SKILL.md +728 -0
- package/plugins/specweave/commands/check-hooks.md +0 -257
- package/plugins/specweave/commands/specweave-archive-increments.md +0 -82
- package/plugins/specweave-plugin-dev/skills/plugin-expert/SKILL.md +0 -1231
- /package/plugins/specweave/{agents/code-reviewer.md → skills/code-reviewer/SKILL.md} +0 -0
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
# Frontend Architect Agent - Real-World Examples
|
|
2
|
+
|
|
3
|
+
This document provides real-world examples of using the Frontend Architect agent for common scenarios.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
1. [E-Commerce Dashboard](#example-1-e-commerce-dashboard)
|
|
8
|
+
2. [SaaS Marketing Website](#example-2-saas-marketing-website)
|
|
9
|
+
3. [Real-Time Chat Application](#example-3-real-time-chat-application)
|
|
10
|
+
4. [Design System Migration](#example-4-design-system-migration)
|
|
11
|
+
5. [Performance Optimization](#example-5-performance-optimization)
|
|
12
|
+
6. [Micro-Frontend Setup](#example-6-micro-frontend-setup)
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Example 1: E-Commerce Dashboard
|
|
17
|
+
|
|
18
|
+
### Scenario
|
|
19
|
+
Building an admin dashboard for an e-commerce platform with inventory management, order tracking, and analytics.
|
|
20
|
+
|
|
21
|
+
### Prompt
|
|
22
|
+
```
|
|
23
|
+
Design a React-based admin dashboard for an e-commerce platform with:
|
|
24
|
+
|
|
25
|
+
Requirements:
|
|
26
|
+
- Real-time order notifications (WebSocket)
|
|
27
|
+
- Product inventory management (10,000+ SKUs)
|
|
28
|
+
- Analytics charts (sales, revenue, user activity)
|
|
29
|
+
- Multi-user role support (admin, manager, viewer)
|
|
30
|
+
- Mobile-responsive (tablet and desktop)
|
|
31
|
+
|
|
32
|
+
Technical Stack:
|
|
33
|
+
- Next.js 14 App Router
|
|
34
|
+
- TypeScript
|
|
35
|
+
- TailwindCSS
|
|
36
|
+
- React Query for data fetching
|
|
37
|
+
- Zustand for client state
|
|
38
|
+
- Recharts for visualization
|
|
39
|
+
|
|
40
|
+
Performance Targets:
|
|
41
|
+
- LCP < 2.5s
|
|
42
|
+
- Initial bundle < 300KB
|
|
43
|
+
- Smooth 60fps scrolling for large tables
|
|
44
|
+
|
|
45
|
+
Provide:
|
|
46
|
+
1. Component architecture (Atomic Design)
|
|
47
|
+
2. Folder structure
|
|
48
|
+
3. State management strategy
|
|
49
|
+
4. Data fetching patterns
|
|
50
|
+
5. Authentication flow
|
|
51
|
+
6. Optimization techniques
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Agent Output
|
|
55
|
+
|
|
56
|
+
#### 1. Component Architecture (Atomic Design)
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
atoms/
|
|
60
|
+
├── Button.tsx
|
|
61
|
+
├── Input.tsx
|
|
62
|
+
├── Badge.tsx
|
|
63
|
+
├── Icon.tsx
|
|
64
|
+
├── Avatar.tsx
|
|
65
|
+
├── Skeleton.tsx
|
|
66
|
+
└── Spinner.tsx
|
|
67
|
+
|
|
68
|
+
molecules/
|
|
69
|
+
├── FormField.tsx
|
|
70
|
+
├── SearchBar.tsx
|
|
71
|
+
├── Notification.tsx
|
|
72
|
+
├── Pagination.tsx
|
|
73
|
+
├── StatCard.tsx
|
|
74
|
+
├── DataTableHeader.tsx
|
|
75
|
+
└── FilterDropdown.tsx
|
|
76
|
+
|
|
77
|
+
organisms/
|
|
78
|
+
├── Sidebar.tsx
|
|
79
|
+
├── TopNav.tsx
|
|
80
|
+
├── OrderTable.tsx
|
|
81
|
+
├── ProductTable.tsx
|
|
82
|
+
├── AnalyticsChart.tsx
|
|
83
|
+
├── NotificationPanel.tsx
|
|
84
|
+
└── UserRoleSelector.tsx
|
|
85
|
+
|
|
86
|
+
templates/
|
|
87
|
+
├── DashboardLayout.tsx
|
|
88
|
+
├── AuthLayout.tsx
|
|
89
|
+
└── EmptyState.tsx
|
|
90
|
+
|
|
91
|
+
pages/
|
|
92
|
+
├── dashboard/
|
|
93
|
+
│ ├── page.tsx (Overview)
|
|
94
|
+
│ ├── orders/page.tsx
|
|
95
|
+
│ ├── products/page.tsx
|
|
96
|
+
│ └── analytics/page.tsx
|
|
97
|
+
└── login/page.tsx
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### 2. Folder Structure
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
src/
|
|
104
|
+
├── app/ # Next.js App Router
|
|
105
|
+
│ ├── (auth)/
|
|
106
|
+
│ │ └── login/
|
|
107
|
+
│ │ └── page.tsx
|
|
108
|
+
│ ├── (dashboard)/
|
|
109
|
+
│ │ ├── layout.tsx
|
|
110
|
+
│ │ ├── page.tsx
|
|
111
|
+
│ │ ├── orders/
|
|
112
|
+
│ │ │ └── page.tsx
|
|
113
|
+
│ │ ├── products/
|
|
114
|
+
│ │ │ └── page.tsx
|
|
115
|
+
│ │ └── analytics/
|
|
116
|
+
│ │ └── page.tsx
|
|
117
|
+
│ └── api/
|
|
118
|
+
│ └── auth/[...nextauth]/route.ts
|
|
119
|
+
│
|
|
120
|
+
├── components/ # React components
|
|
121
|
+
│ ├── atoms/
|
|
122
|
+
│ ├── molecules/
|
|
123
|
+
│ ├── organisms/
|
|
124
|
+
│ └── templates/
|
|
125
|
+
│
|
|
126
|
+
├── lib/ # Utilities & configuration
|
|
127
|
+
│ ├── api/
|
|
128
|
+
│ │ └── client.ts # API client setup
|
|
129
|
+
│ ├── hooks/
|
|
130
|
+
│ │ ├── useOrders.ts
|
|
131
|
+
│ │ ├── useProducts.ts
|
|
132
|
+
│ │ ├── useWebSocket.ts
|
|
133
|
+
│ │ └── useAuth.ts
|
|
134
|
+
│ ├── store/
|
|
135
|
+
│ │ └── index.ts # Zustand store
|
|
136
|
+
│ └── utils/
|
|
137
|
+
│ ├── formatters.ts
|
|
138
|
+
│ └── validators.ts
|
|
139
|
+
│
|
|
140
|
+
├── types/ # TypeScript types
|
|
141
|
+
│ ├── order.ts
|
|
142
|
+
│ ├── product.ts
|
|
143
|
+
│ ├── user.ts
|
|
144
|
+
│ └── api.ts
|
|
145
|
+
│
|
|
146
|
+
└── styles/ # Global styles
|
|
147
|
+
└── globals.css
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### 3. State Management Strategy
|
|
151
|
+
|
|
152
|
+
**Client State (Zustand)**:
|
|
153
|
+
```typescript
|
|
154
|
+
// lib/store/index.ts
|
|
155
|
+
import { create } from 'zustand';
|
|
156
|
+
import { devtools, persist } from 'zustand/middleware';
|
|
157
|
+
|
|
158
|
+
interface DashboardState {
|
|
159
|
+
// UI State
|
|
160
|
+
sidebarCollapsed: boolean;
|
|
161
|
+
theme: 'light' | 'dark';
|
|
162
|
+
|
|
163
|
+
// User State
|
|
164
|
+
user: User | null;
|
|
165
|
+
permissions: string[];
|
|
166
|
+
|
|
167
|
+
// Notifications
|
|
168
|
+
notifications: Notification[];
|
|
169
|
+
unreadCount: number;
|
|
170
|
+
|
|
171
|
+
// Actions
|
|
172
|
+
toggleSidebar: () => void;
|
|
173
|
+
setTheme: (theme: 'light' | 'dark') => void;
|
|
174
|
+
addNotification: (notification: Notification) => void;
|
|
175
|
+
markAsRead: (id: string) => void;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export const useDashboardStore = create<DashboardState>()(
|
|
179
|
+
devtools(
|
|
180
|
+
persist(
|
|
181
|
+
(set) => ({
|
|
182
|
+
sidebarCollapsed: false,
|
|
183
|
+
theme: 'light',
|
|
184
|
+
user: null,
|
|
185
|
+
permissions: [],
|
|
186
|
+
notifications: [],
|
|
187
|
+
unreadCount: 0,
|
|
188
|
+
|
|
189
|
+
toggleSidebar: () => set((state) => ({
|
|
190
|
+
sidebarCollapsed: !state.sidebarCollapsed
|
|
191
|
+
})),
|
|
192
|
+
|
|
193
|
+
setTheme: (theme) => set({ theme }),
|
|
194
|
+
|
|
195
|
+
addNotification: (notification) => set((state) => ({
|
|
196
|
+
notifications: [notification, ...state.notifications],
|
|
197
|
+
unreadCount: state.unreadCount + 1,
|
|
198
|
+
})),
|
|
199
|
+
|
|
200
|
+
markAsRead: (id) => set((state) => ({
|
|
201
|
+
notifications: state.notifications.map(n =>
|
|
202
|
+
n.id === id ? { ...n, read: true } : n
|
|
203
|
+
),
|
|
204
|
+
unreadCount: Math.max(0, state.unreadCount - 1),
|
|
205
|
+
})),
|
|
206
|
+
}),
|
|
207
|
+
{ name: 'dashboard-store' }
|
|
208
|
+
)
|
|
209
|
+
)
|
|
210
|
+
);
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
**Server State (React Query)**:
|
|
214
|
+
```typescript
|
|
215
|
+
// lib/hooks/useOrders.ts
|
|
216
|
+
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
217
|
+
import { apiClient } from '@/lib/api/client';
|
|
218
|
+
|
|
219
|
+
export function useOrders(filters: OrderFilters) {
|
|
220
|
+
return useQuery({
|
|
221
|
+
queryKey: ['orders', filters],
|
|
222
|
+
queryFn: () => apiClient.getOrders(filters),
|
|
223
|
+
staleTime: 30000, // 30 seconds
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function useUpdateOrderStatus() {
|
|
228
|
+
const queryClient = useQueryClient();
|
|
229
|
+
|
|
230
|
+
return useMutation({
|
|
231
|
+
mutationFn: (params: { orderId: string; status: string }) =>
|
|
232
|
+
apiClient.updateOrderStatus(params.orderId, params.status),
|
|
233
|
+
onSuccess: () => {
|
|
234
|
+
queryClient.invalidateQueries({ queryKey: ['orders'] });
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
#### 4. Data Fetching Patterns
|
|
241
|
+
|
|
242
|
+
**Server Components (Default)**:
|
|
243
|
+
```typescript
|
|
244
|
+
// app/(dashboard)/orders/page.tsx
|
|
245
|
+
import { Suspense } from 'react';
|
|
246
|
+
import { OrderTable } from '@/components/organisms/OrderTable';
|
|
247
|
+
import { Skeleton } from '@/components/atoms/Skeleton';
|
|
248
|
+
|
|
249
|
+
export default async function OrdersPage() {
|
|
250
|
+
// Fetch in Server Component (no client-side loading state needed)
|
|
251
|
+
const initialOrders = await fetch('https://api.example.com/orders', {
|
|
252
|
+
next: { revalidate: 60 }, // ISR: revalidate every 60 seconds
|
|
253
|
+
}).then(res => res.json());
|
|
254
|
+
|
|
255
|
+
return (
|
|
256
|
+
<div>
|
|
257
|
+
<h1>Orders</h1>
|
|
258
|
+
<Suspense fallback={<Skeleton />}>
|
|
259
|
+
<OrderTable initialData={initialOrders} />
|
|
260
|
+
</Suspense>
|
|
261
|
+
</div>
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
**Client Components (Interactive)**:
|
|
267
|
+
```typescript
|
|
268
|
+
// components/organisms/OrderTable.tsx
|
|
269
|
+
'use client';
|
|
270
|
+
|
|
271
|
+
import { useOrders } from '@/lib/hooks/useOrders';
|
|
272
|
+
import { useState } from 'react';
|
|
273
|
+
|
|
274
|
+
export function OrderTable({ initialData }: { initialData: Order[] }) {
|
|
275
|
+
const [filters, setFilters] = useState({ status: 'all', page: 1 });
|
|
276
|
+
|
|
277
|
+
const { data: orders, isLoading } = useOrders(filters, {
|
|
278
|
+
initialData, // Use server-fetched data as initial state
|
|
279
|
+
refetchInterval: 30000, // Refetch every 30s
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
return (
|
|
283
|
+
<div>
|
|
284
|
+
{/* Filters, pagination, etc. */}
|
|
285
|
+
{isLoading ? <Skeleton /> : <Table data={orders} />}
|
|
286
|
+
</div>
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
#### 5. Real-Time WebSocket Integration
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
// lib/hooks/useWebSocket.ts
|
|
295
|
+
import { useEffect } from 'react';
|
|
296
|
+
import { useDashboardStore } from '@/lib/store';
|
|
297
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
298
|
+
|
|
299
|
+
export function useWebSocket() {
|
|
300
|
+
const queryClient = useQueryClient();
|
|
301
|
+
const addNotification = useDashboardStore(state => state.addNotification);
|
|
302
|
+
|
|
303
|
+
useEffect(() => {
|
|
304
|
+
const ws = new WebSocket(process.env.NEXT_PUBLIC_WS_URL!);
|
|
305
|
+
|
|
306
|
+
ws.onmessage = (event) => {
|
|
307
|
+
const message = JSON.parse(event.data);
|
|
308
|
+
|
|
309
|
+
switch (message.type) {
|
|
310
|
+
case 'ORDER_CREATED':
|
|
311
|
+
addNotification({
|
|
312
|
+
id: Date.now().toString(),
|
|
313
|
+
type: 'info',
|
|
314
|
+
title: 'New Order',
|
|
315
|
+
message: `Order #${message.orderId} created`,
|
|
316
|
+
timestamp: Date.now(),
|
|
317
|
+
});
|
|
318
|
+
queryClient.invalidateQueries({ queryKey: ['orders'] });
|
|
319
|
+
break;
|
|
320
|
+
|
|
321
|
+
case 'INVENTORY_LOW':
|
|
322
|
+
addNotification({
|
|
323
|
+
id: Date.now().toString(),
|
|
324
|
+
type: 'warning',
|
|
325
|
+
title: 'Low Inventory',
|
|
326
|
+
message: `${message.productName} is running low`,
|
|
327
|
+
timestamp: Date.now(),
|
|
328
|
+
});
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
return () => ws.close();
|
|
334
|
+
}, [addNotification, queryClient]);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Usage in layout
|
|
338
|
+
// app/(dashboard)/layout.tsx
|
|
339
|
+
'use client';
|
|
340
|
+
|
|
341
|
+
import { useWebSocket } from '@/lib/hooks/useWebSocket';
|
|
342
|
+
|
|
343
|
+
export default function DashboardLayout({ children }: { children: React.ReactNode }) {
|
|
344
|
+
useWebSocket(); // Connect to WebSocket on mount
|
|
345
|
+
|
|
346
|
+
return <div>{children}</div>;
|
|
347
|
+
}
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
#### 6. Optimization Techniques
|
|
351
|
+
|
|
352
|
+
**Code Splitting**:
|
|
353
|
+
```typescript
|
|
354
|
+
// app/(dashboard)/analytics/page.tsx
|
|
355
|
+
import dynamic from 'next/dynamic';
|
|
356
|
+
import { Skeleton } from '@/components/atoms/Skeleton';
|
|
357
|
+
|
|
358
|
+
// Lazy load heavy chart library
|
|
359
|
+
const AnalyticsChart = dynamic(
|
|
360
|
+
() => import('@/components/organisms/AnalyticsChart'),
|
|
361
|
+
{
|
|
362
|
+
loading: () => <Skeleton className="h-96" />,
|
|
363
|
+
ssr: false, // Don't render on server (chart library is client-only)
|
|
364
|
+
}
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
export default function AnalyticsPage() {
|
|
368
|
+
return (
|
|
369
|
+
<div>
|
|
370
|
+
<h1>Analytics</h1>
|
|
371
|
+
<AnalyticsChart />
|
|
372
|
+
</div>
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
**Virtual Scrolling for Large Tables**:
|
|
378
|
+
```typescript
|
|
379
|
+
// components/organisms/ProductTable.tsx
|
|
380
|
+
'use client';
|
|
381
|
+
|
|
382
|
+
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
383
|
+
import { useRef } from 'react';
|
|
384
|
+
|
|
385
|
+
export function ProductTable({ products }: { products: Product[] }) {
|
|
386
|
+
const parentRef = useRef<HTMLDivElement>(null);
|
|
387
|
+
|
|
388
|
+
const virtualizer = useVirtualizer({
|
|
389
|
+
count: products.length,
|
|
390
|
+
getScrollElement: () => parentRef.current,
|
|
391
|
+
estimateSize: () => 50, // Row height
|
|
392
|
+
overscan: 10, // Render 10 extra rows for smooth scrolling
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
return (
|
|
396
|
+
<div ref={parentRef} className="h-96 overflow-auto">
|
|
397
|
+
<div style={{ height: `${virtualizer.getTotalSize()}px` }}>
|
|
398
|
+
{virtualizer.getVirtualItems().map((virtualRow) => (
|
|
399
|
+
<div
|
|
400
|
+
key={virtualRow.index}
|
|
401
|
+
style={{
|
|
402
|
+
position: 'absolute',
|
|
403
|
+
top: 0,
|
|
404
|
+
left: 0,
|
|
405
|
+
width: '100%',
|
|
406
|
+
height: `${virtualRow.size}px`,
|
|
407
|
+
transform: `translateY(${virtualRow.start}px)`,
|
|
408
|
+
}}
|
|
409
|
+
>
|
|
410
|
+
<ProductRow product={products[virtualRow.index]} />
|
|
411
|
+
</div>
|
|
412
|
+
))}
|
|
413
|
+
</div>
|
|
414
|
+
</div>
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
**Image Optimization**:
|
|
420
|
+
```typescript
|
|
421
|
+
// components/organisms/ProductCard.tsx
|
|
422
|
+
import Image from 'next/image';
|
|
423
|
+
|
|
424
|
+
export function ProductCard({ product }: { product: Product }) {
|
|
425
|
+
return (
|
|
426
|
+
<div>
|
|
427
|
+
<Image
|
|
428
|
+
src={product.imageUrl}
|
|
429
|
+
alt={product.name}
|
|
430
|
+
width={300}
|
|
431
|
+
height={300}
|
|
432
|
+
placeholder="blur"
|
|
433
|
+
blurDataURL={product.thumbnailUrl}
|
|
434
|
+
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
|
|
435
|
+
/>
|
|
436
|
+
</div>
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
## Example 2: SaaS Marketing Website
|
|
444
|
+
|
|
445
|
+
### Scenario
|
|
446
|
+
Building a high-performance marketing website for a SaaS product with SEO optimization and accessibility.
|
|
447
|
+
|
|
448
|
+
### Prompt
|
|
449
|
+
```
|
|
450
|
+
Design a Next.js marketing website for a B2B SaaS platform with:
|
|
451
|
+
|
|
452
|
+
Requirements:
|
|
453
|
+
- 10+ landing pages (home, features, pricing, about, blog)
|
|
454
|
+
- SEO optimized (meta tags, structured data, sitemap)
|
|
455
|
+
- Accessibility WCAG AA compliant
|
|
456
|
+
- Blog with MDX support
|
|
457
|
+
- Contact form with Resend integration
|
|
458
|
+
- Newsletter signup
|
|
459
|
+
- Dark mode support
|
|
460
|
+
- i18n support (English, Spanish, German)
|
|
461
|
+
|
|
462
|
+
Performance Targets:
|
|
463
|
+
- Lighthouse score 95+ (all categories)
|
|
464
|
+
- LCP < 2.5s
|
|
465
|
+
- CLS < 0.1
|
|
466
|
+
- 100% accessibility score
|
|
467
|
+
|
|
468
|
+
Technical Stack:
|
|
469
|
+
- Next.js 14 App Router
|
|
470
|
+
- TypeScript
|
|
471
|
+
- TailwindCSS
|
|
472
|
+
- shadcn/ui components
|
|
473
|
+
- MDX for blog
|
|
474
|
+
- next-intl for i18n
|
|
475
|
+
|
|
476
|
+
Provide component architecture and implementation examples.
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
### Agent Output
|
|
480
|
+
|
|
481
|
+
[Detailed architecture with folder structure, SEO setup, i18n configuration, MDX integration, and accessibility patterns]
|
|
482
|
+
|
|
483
|
+
---
|
|
484
|
+
|
|
485
|
+
## Example 3: Real-Time Chat Application
|
|
486
|
+
|
|
487
|
+
### Scenario
|
|
488
|
+
Building a real-time chat application with WebSocket, typing indicators, and message history.
|
|
489
|
+
|
|
490
|
+
[Full example with WebSocket setup, optimistic updates, and offline support]
|
|
491
|
+
|
|
492
|
+
---
|
|
493
|
+
|
|
494
|
+
## Example 4: Design System Migration
|
|
495
|
+
|
|
496
|
+
### Scenario
|
|
497
|
+
Migrating from Material-UI to a custom design system based on shadcn/ui.
|
|
498
|
+
|
|
499
|
+
[Step-by-step migration plan with component mapping and codemods]
|
|
500
|
+
|
|
501
|
+
---
|
|
502
|
+
|
|
503
|
+
## Example 5: Performance Optimization
|
|
504
|
+
|
|
505
|
+
### Scenario
|
|
506
|
+
Optimizing a slow Next.js application (LCP 8s → 2s target).
|
|
507
|
+
|
|
508
|
+
[Performance audit, bottleneck analysis, optimization implementation]
|
|
509
|
+
|
|
510
|
+
---
|
|
511
|
+
|
|
512
|
+
## Example 6: Micro-Frontend Setup
|
|
513
|
+
|
|
514
|
+
### Scenario
|
|
515
|
+
Setting up a micro-frontend architecture with Module Federation for a large enterprise application.
|
|
516
|
+
|
|
517
|
+
[Webpack 5 Module Federation setup, shared dependencies, independent deployments]
|
|
518
|
+
|
|
519
|
+
---
|
|
520
|
+
|
|
521
|
+
## Tips for Effective Prompts
|
|
522
|
+
|
|
523
|
+
1. **Be Specific**: Include framework versions, tech stack, and constraints
|
|
524
|
+
2. **Define Metrics**: Specify performance targets (LCP, bundle size, etc.)
|
|
525
|
+
3. **Provide Context**: Team size, timeline, existing infrastructure
|
|
526
|
+
4. **State Goals**: SEO, accessibility, mobile-first, etc.
|
|
527
|
+
5. **Include Examples**: Reference similar applications or patterns
|
|
528
|
+
|
|
529
|
+
## Common Patterns
|
|
530
|
+
|
|
531
|
+
### Pattern 1: Server + Client Component Split
|
|
532
|
+
|
|
533
|
+
```typescript
|
|
534
|
+
// Server Component (default in App Router)
|
|
535
|
+
export default async function Page() {
|
|
536
|
+
const data = await fetchData(); // Server-side fetch
|
|
537
|
+
return <ClientComponent initialData={data} />;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// Client Component (interactive)
|
|
541
|
+
'use client';
|
|
542
|
+
export function ClientComponent({ initialData }) {
|
|
543
|
+
const [state, setState] = useState(initialData);
|
|
544
|
+
// Interactive logic here
|
|
545
|
+
}
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
### Pattern 2: Optimistic Updates
|
|
549
|
+
|
|
550
|
+
```typescript
|
|
551
|
+
const mutation = useMutation({
|
|
552
|
+
mutationFn: updateTodo,
|
|
553
|
+
onMutate: async (newTodo) => {
|
|
554
|
+
await queryClient.cancelQueries({ queryKey: ['todos'] });
|
|
555
|
+
const previousTodos = queryClient.getQueryData(['todos']);
|
|
556
|
+
|
|
557
|
+
// Optimistically update UI
|
|
558
|
+
queryClient.setQueryData(['todos'], (old) => [...old, newTodo]);
|
|
559
|
+
|
|
560
|
+
return { previousTodos };
|
|
561
|
+
},
|
|
562
|
+
onError: (err, newTodo, context) => {
|
|
563
|
+
// Rollback on error
|
|
564
|
+
queryClient.setQueryData(['todos'], context.previousTodos);
|
|
565
|
+
},
|
|
566
|
+
});
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
### Pattern 3: Parallel Data Fetching
|
|
570
|
+
|
|
571
|
+
```typescript
|
|
572
|
+
// Fetch multiple resources in parallel (Server Component)
|
|
573
|
+
export default async function Page() {
|
|
574
|
+
const [user, posts, comments] = await Promise.all([
|
|
575
|
+
fetchUser(),
|
|
576
|
+
fetchPosts(),
|
|
577
|
+
fetchComments(),
|
|
578
|
+
]);
|
|
579
|
+
|
|
580
|
+
return <Dashboard user={user} posts={posts} comments={comments} />;
|
|
581
|
+
}
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
## Additional Resources
|
|
585
|
+
|
|
586
|
+
- **Next.js Examples**: https://github.com/vercel/next.js/tree/canary/examples
|
|
587
|
+
- **React Patterns**: https://patterns.dev
|
|
588
|
+
- **TailwindCSS Components**: https://tailwindui.com
|
|
589
|
+
- **shadcn/ui**: https://ui.shadcn.com
|
|
590
|
+
- **Radix UI**: https://radix-ui.com
|