Production SaaS: dashboards, pricing pages, data tables, onboarding, role-based UI — with WCAG 2.1 AA accessibility and Core Web Vitals performance baked in.
npx create-next-app@latest my-app --typescript --tailwind --eslint --app --src-dir
cd my-app && npx shadcn@latest init
npx shadcn@latest add button card dialog table form
Tailwind v4 — CSS-First (No tailwind.config.js)
/* app/globals.css */
@import "tailwindcss";
@theme inline {
--color-background: oklch(1 0 0);
--color-foreground: oklch(0.145 0 0);
--color-primary: oklch(0.205 0.042 264.695);
--color-primary-foreground: oklch(0.985 0 0);
--radius-lg: 0.5rem;
--radius-md: calc(var(--radius-lg) - 2px);
--radius-sm: calc(var(--radius-lg) - 4px);
}
Component Anatomy (shadcn/ui 2026)
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
const buttonVariants = cva(
"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors",
{
variants: {
variant: { default: "bg-primary text-primary-foreground", outline: "border border-input" },
size: { default: "h-10 px-4 py-2", sm: "h-9 px-3", lg: "h-11 px-8" },
},
defaultVariants: { variant: "default", size: "default" },
}
)
// React 19: ref is a regular prop — no forwardRef
// data-slot: styling hook for parent overrides
function Button({ className, variant, size, ref, ...props }:
React.ComponentProps<"button"> & VariantProps<typeof buttonVariants>) {
return <button ref={ref} data-slot="button"
className={cn(buttonVariants({ variant, size, className }))} {...props} />
}
cn() Utility
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)) }
Vite SPA Alternative
npm create vite@latest my-app -- --template react-ts
cd my-app && npm i -D @tailwindcss/vite && npx shadcn@latest init
Key differences from Next.js:
@tailwindcss/vite plugin (not postcss) — faster HMR, native Vite integration
VITE_ env prefix (not NEXT_PUBLIC_), accessed via import.meta.env
- Client-only — no Server Components, use React Query for data fetching
React.lazy() + <Suspense> replaces dynamic() for code splitting
- Routing via React Router v7 or TanStack Router (not file-based)
Tailwind v4, shadcn/ui, component patterns, accessibility, forms, and performance guidance all apply equally to Vite SPAs. Only routing and data fetching genuinely differ.
See reference/vite-react-setup.md and reference/spa-routing.md.
- No
tailwind.config.js — All config via CSS @theme directive
@import "tailwindcss" — Replaces @tailwind base/components/utilities
- OKLCH colors — Perceptually uniform, replaces hex/HSL
- Container queries built-in —
@container, @md:, @lg: prefixes
@source — CSS-native file scanning (replaces content array)
- 70% smaller CSS — Automatic unused style elimination
@theme inline — shadcn/ui bridge: tokens without generated utilities
@theme {
--color-brand-500: oklch(0.55 0.15 250);
--font-sans: "Inter", system-ui, sans-serif;
--breakpoint-xs: 475px;
--animate-slide-in: slide-in 0.2s ease-out;
}
// Container queries — component-level responsive
<div className="@container">
<div className="grid grid-cols-1 @md:grid-cols-2 @lg:grid-cols-3 gap-4">
{items.map(item => <Card key={item.id} {...item} />)}
</div>
</div>
Migration: npx @tailwindcss/upgrade — See reference/tailwind-v4-setup.md.
@theme inline — Bridges tokens with Tailwind v4
data-slot — Attribute-based styling hooks (replaces className overrides)
- No
forwardRef — React 19 ref as prop
tw-animate-css — Replaces tailwindcss-animate for v4 compat
- Radix or Base UI — Choose primitive library
// data-slot: parent can target child styles
function Card({ className, ref, ...props }: React.ComponentProps<"div">) {
return <div ref={ref} data-slot="card" className={cn("rounded-xl border bg-card", className)} {...props} />
}
// Style from parent:
<div className="[&_[data-slot=card]]:shadow-lg">
<Card>...</Card>
</div>
Dark mode: CSS custom property swap with .dark class. See reference/shadcn-setup.md.
| Server Component (default) |
Client Component ("use client") |
| Async data fetching, DB access |
useState, useEffect, event handlers |
| Zero JS bundle, access to secrets |
Browser APIs, third-party client libs |
Rule: Push "use client" to smallest leaf possible.
// Server page with client island
export default async function DashboardPage() {
const metrics = await getMetrics()
return (
<main>
<KPICards data={metrics} /> {/* Server-rendered */}
<RevenueChart data={metrics} /> {/* Client island */}
</main>
)
}
Key Patterns
- Compound components —
<Table>/<TableRow>/<TableCell> namespace composition
- cva variants — Type-safe style variants with
class-variance-authority
- React.ComponentProps — Replace manual interfaces, ref as regular prop
- data-slot — External styling hooks for parent-child overrides
- Polymorphic (asChild) —
Slot pattern for rendering as different elements
- SPA code splitting —
React.lazy() + <Suspense> replaces Next.js dynamic()
See reference/component-patterns.md for complete examples.
Dashboard: Sidebar + Header + Main
<div className="flex h-screen">
<Sidebar className="w-64 hidden lg:flex" />
<div className="flex-1 flex flex-col">
<Header /> {/* Search, user menu, notifications */}
<main className="flex-1 overflow-auto p-6">
<KPIGrid metrics={metrics} />
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6 mt-6">
<RevenueChart data={revenue} />
<ActivityFeed items={activities} />
</div>
</main>
</div>
</div>
Pricing (3-Tier Conversion)
Anchor (low) | Conversion target (highlighted, "Most Popular") | Enterprise (custom)
Monthly/annual toggle, feature comparison table, social proof. See templates/pricing-page.tsx.
Data Tables — shadcn Table + TanStack Table for sort/filter/paginate
State Trio — Every data component needs: Loading (Skeleton) | Error (retry action) | Empty (guidance)
Role-Based UI — hasPermission(user, "scope") guard for conditional rendering
See reference/saas-dashboard.md and reference/saas-pricing-checkout.md.
Semantic HTML first — <header>, <nav>, <main>, <article>, <section>, <footer>
| Pattern |
Implementation |
| Keyboard nav |
Tab/Shift+Tab, Arrow keys in menus/tabs, Escape to close |
| Focus management |
Trap in dialogs, restore on close, skip link |
| ARIA live regions |
aria-live="polite" for dynamic content |
| Form errors |
aria-invalid, aria-describedby, role="alert" |
| Loading states |
aria-busy={true} on loading buttons |
| Contrast |
4.5:1 text, 3:1 UI components (OKLCH lightness channel) |
// Skip link
<a href="#main-content" className="sr-only focus:not-sr-only focus:absolute focus:z-50">
Skip to main content
</a>
See reference/accessibility-checklist.md for per-component ARIA patterns.
| State Type |
Solution |
Example |
| URL state |
nuqs / useSearchParams |
Filters, pagination, tabs |
| Server data |
React Query / SWR |
API data, user profile |
| Local UI |
useState |
Form inputs, toggles |
| Shared parent-child |
Lift state / Context |
Accordion groups |
| Complex cross-cutting |
Zustand |
Cart, wizard, notifications |
Prefer URL state — shareable, bookmarkable, survives refresh.
| Pattern |
When |
How |
| Server Components |
Default |
async function Page() { const data = await db.query() } |
| Suspense streaming |
Slow data |
<Suspense fallback={<Skeleton/>}><SlowComponent/></Suspense> |
| Server Actions |
Mutations |
"use server" + revalidatePath() |
| React Query |
Client real-time |
useQuery({ queryKey, queryFn, refetchInterval }) |
| React Query (SPA) |
Client-only apps |
useQuery({ queryKey, queryFn }) with loaders — replaces Server Components |
|
|
|
- Shared Zod schema — Single source of truth for client validation and server action
- React Hook Form —
useForm with zodResolver, mode: "onBlur"
- shadcn Form —
<Form>/<FormField>/<FormItem>/<FormLabel>/<FormMessage>
- Server Action —
safeParse on server, return field errors, revalidatePath
const schema = z.object({
name: z.string().min(2),
email: z.string().email(),
})
See reference/form-patterns.md and templates/form-with-server-action.tsx.
| Metric |
Target |
Quick Win |
| LCP < 2.5s |
Main content visible |
next/image with priority, next/font |
| INP < 200ms |
Responsive interactions |
Code-split heavy components with dynamic() |
| CLS < 0.1 |
No layout shift |
Reserve space for images/fonts, Skeleton loaders |
Tailwind v4 produces 70% smaller CSS automatically. See reference/performance-optimization.md.
Accessibility
Performance
Responsive
Security
UX
1---2name: frontend-ui-43description: Enterprise SaaS frontend — Tailwind v4, shadcn/ui, Next.js App Router or Vite SPA, accessibility, responsive design, component patterns. Use when: React component, Next.js page, frontend UI, Tailwind, shadcn, accessibility, a11y, responsive design, form validation, server component, client component, design system, dark mode, SaaS UI, dashboard, pricing page, enterprise UI, data table, landing page, Vite, React Router, SPA, single page app.4---5
6<objective>
7Enterprise-grade frontend skill for auditing and building world-class SaaS UIs. Covers Tailwind CSS v4 (CSS-first config), shadcn/ui (2026), Next.js 15+ App Router **or Vite SPA** with React 19.
8
9Production SaaS: dashboards, pricing pages, data tables, onboarding, role-based UI — with WCAG 2.1 AA accessibility and Core Web Vitals performance baked in.
10</objective>
11
12<quick_start>
13## Setup: Tailwind v4 + shadcn/ui
14
15```bash
16npx create-next-app@latest my-app --typescript --tailwind --eslint --app --src-dir
17cd my-app && npx shadcn@latest init
18npx shadcn@latest add button card dialog table form
19```
20
21### Tailwind v4 — CSS-First (No tailwind.config.js)
22
23```css
24/* app/globals.css */
25@import "tailwindcss";
26@theme inline {
27 --color-background: oklch(1 0 0);
28 --color-foreground: oklch(0.145 0 0);
29 --color-primary: oklch(0.205 0.042 264.695);
30 --color-primary-foreground: oklch(0.985 0 0);
31 --radius-lg: 0.5rem;
32 --radius-md: calc(var(--radius-lg) - 2px);
33 --radius-sm: calc(var(--radius-lg) - 4px);
34}
35```
36
37### Component Anatomy (shadcn/ui 2026)
38
39```tsx
40import { cva, type VariantProps } from "class-variance-authority"
41import { cn } from "@/lib/utils"
42
43const buttonVariants = cva(
44 "inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors",
45 {
46 variants: {
47 variant: { default: "bg-primary text-primary-foreground", outline: "border border-input" },
48 size: { default: "h-10 px-4 py-2", sm: "h-9 px-3", lg: "h-11 px-8" },
49 },
50 defaultVariants: { variant: "default", size: "default" },
51 }
52)
53
54// React 19: ref is a regular prop — no forwardRef
55// data-slot: styling hook for parent overrides
56function Button({ className, variant, size, ref, ...props }:
57 React.ComponentProps<"button"> & VariantProps<typeof buttonVariants>) {
58 return <button ref={ref} data-slot="button"
59 className={cn(buttonVariants({ variant, size, className }))} {...props} />
60}
61```
62
63### cn() Utility
64
65```ts
66import { clsx, type ClassValue } from "clsx"
67import { twMerge } from "tailwind-merge"
68export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)) }
69```
70
71### Vite SPA Alternative
72
73```bash
74npm create vite@latest my-app -- --template react-ts
75cd my-app && npm i -D @tailwindcss/vite && npx shadcn@latest init
76```
77
78Key differences from Next.js:
79- `@tailwindcss/vite` plugin (not postcss) — faster HMR, native Vite integration
80- `VITE_` env prefix (not `NEXT_PUBLIC_`), accessed via `import.meta.env`
81- Client-only — no Server Components, use React Query for data fetching
82- `React.lazy()` + `<Suspense>` replaces `dynamic()` for code splitting
83- Routing via React Router v7 or TanStack Router (not file-based)
84
85Tailwind v4, shadcn/ui, component patterns, accessibility, forms, and performance guidance all apply equally to Vite SPAs. Only routing and data fetching genuinely differ.
86
87See `reference/vite-react-setup.md` and `reference/spa-routing.md`.
88</quick_start>
89
90<success_criteria>
91Enterprise SaaS frontend is production-ready when:
92- **Accessible:** WCAG 2.1 AA — keyboard nav, screen reader, focus management, 4.5:1 contrast
93- **Performant:** LCP < 2.5s, INP < 200ms, CLS < 0.1 on 4G mobile
94- **Responsive:** Mobile-first, works 320px-2560px, container queries for components
95- **Secure:** No XSS vectors, CSP headers, sanitized user content
96- **Themed:** Dark mode via CSS, design tokens in @theme, consistent spacing/color
97- **Composable:** Server Components default, client boundary pushed to leaves
98- **Typed:** TypeScript strict, Zod validation on all forms, no `any`
99</success_criteria>
100
101<core_principles>
1021. **Server-First** — Default to Server Components. Add `"use client"` only for interactivity. Push client boundaries to leaf components.
1032. **Accessible-by-Default** — Semantic HTML first (`<nav>`, `<main>`, `<article>`). ARIA only when native semantics insufficient.
1043. **Composition Over Configuration** — Small composable components. Compound pattern for complex UI. Context at boundaries.
1054. **Progressive Disclosure** — Essential info first. Reveal complexity on demand. Reduce cognitive load.
1065. **Mobile-First** — Design for smallest screen, enhance upward. Container queries for components. Touch targets >= 44px.
1076. **Design Tokens** — All visual values in CSS `@theme`. Never hardcode. OKLCH for perceptual uniformity.
1087. **Type Safety E2E** — Zod schemas shared client/server. `React.ComponentProps<>` over manual interfaces.
109</core_principles>
110
111<tailwind_v4>
112## Tailwind CSS v4 — Key Changes from v3
113
114- **No `tailwind.config.js`** — All config via CSS `@theme` directive
115- **`@import "tailwindcss"`** — Replaces `@tailwind base/components/utilities`
116- **OKLCH colors** — Perceptually uniform, replaces hex/HSL
117- **Container queries built-in** — `@container`, `@md:`, `@lg:` prefixes
118- **`@source`** — CSS-native file scanning (replaces `content` array)
119- **70% smaller CSS** — Automatic unused style elimination
120- **`@theme inline`** — shadcn/ui bridge: tokens without generated utilities
121
122```css
123@theme {
124 --color-brand-500: oklch(0.55 0.15 250);
125 --font-sans: "Inter", system-ui, sans-serif;
126 --breakpoint-xs: 475px;
127 --animate-slide-in: slide-in 0.2s ease-out;
128}
129```
130
131```tsx
132// Container queries — component-level responsive
133<div className="@container">
134 <div className="grid grid-cols-1 @md:grid-cols-2 @lg:grid-cols-3 gap-4">
135 {items.map(item => <Card key={item.id} {...item} />)}
136 </div>
137</div>
138```
139
140**Migration:** `npx @tailwindcss/upgrade` — See `reference/tailwind-v4-setup.md`.
141</tailwind_v4>
142
143<shadcn_ui>
144## shadcn/ui 2026
145
146- **`@theme inline`** — Bridges tokens with Tailwind v4
147- **`data-slot`** — Attribute-based styling hooks (replaces className overrides)
148- **No `forwardRef`** — React 19 ref as prop
149- **`tw-animate-css`** — Replaces `tailwindcss-animate` for v4 compat
150- **Radix or Base UI** — Choose primitive library
151
152```tsx
153// data-slot: parent can target child styles
154function Card({ className, ref, ...props }: React.ComponentProps<"div">) {
155 return <div ref={ref} data-slot="card" className={cn("rounded-xl border bg-card", className)} {...props} />
156}
157
158// Style from parent:
159<div className="[&_[data-slot=card]]:shadow-lg">
160 <Card>...</Card>
161</div>
162```
163
164**Dark mode:** CSS custom property swap with `.dark` class. See `reference/shadcn-setup.md`.
165</shadcn_ui>
166
167<component_architecture>
168## Server vs Client Components
169
170| Server Component (default) | Client Component (`"use client"`) |
171|---|---|
172| Async data fetching, DB access | useState, useEffect, event handlers |
173| Zero JS bundle, access to secrets | Browser APIs, third-party client libs |
174
175**Rule:** Push `"use client"` to smallest leaf possible.
176
177```tsx
178// Server page with client island
179export default async function DashboardPage() {
180 const metrics = await getMetrics()
181 return (
182 <main>
183 <KPICards data={metrics} /> {/* Server-rendered */}
184 <RevenueChart data={metrics} /> {/* Client island */}
185 </main>
186 )
187}
188```
189
190### Key Patterns
191
192- **Compound components** — `<Table>/<TableRow>/<TableCell>` namespace composition
193- **cva variants** — Type-safe style variants with `class-variance-authority`
194- **React.ComponentProps** — Replace manual interfaces, ref as regular prop
195- **data-slot** — External styling hooks for parent-child overrides
196- **Polymorphic (asChild)** — `Slot` pattern for rendering as different elements
197- **SPA code splitting** — `React.lazy()` + `<Suspense>` replaces Next.js `dynamic()`
198
199See `reference/component-patterns.md` for complete examples.
200</component_architecture>
201
202<saas_patterns>
203## Enterprise SaaS Patterns
204
205### Dashboard: Sidebar + Header + Main
206
207```tsx
208<div className="flex h-screen">
209 <Sidebar className="w-64 hidden lg:flex" />
210 <div className="flex-1 flex flex-col">
211 <Header /> {/* Search, user menu, notifications */}
212 <main className="flex-1 overflow-auto p-6">
213 <KPIGrid metrics={metrics} />
214 <div className="grid grid-cols-1 lg:grid-cols-2 gap-6 mt-6">
215 <RevenueChart data={revenue} />
216 <ActivityFeed items={activities} />
217 </div>
218 </main>
219 </div>
220</div>
221```
222
223### Pricing (3-Tier Conversion)
224
225Anchor (low) | **Conversion target** (highlighted, "Most Popular") | Enterprise (custom)
226
227Monthly/annual toggle, feature comparison table, social proof. See `templates/pricing-page.tsx`.
228
229### Data Tables — shadcn Table + TanStack Table for sort/filter/paginate
230
231### State Trio — Every data component needs: Loading (Skeleton) | Error (retry action) | Empty (guidance)
232
233### Role-Based UI — `hasPermission(user, "scope")` guard for conditional rendering
234
235See `reference/saas-dashboard.md` and `reference/saas-pricing-checkout.md`.
236</saas_patterns>
237
238<accessibility>
239## WCAG 2.1 AA
240
241**Semantic HTML first** — `<header>`, `<nav>`, `<main>`, `<article>`, `<section>`, `<footer>`
242
243| Pattern | Implementation |
244|---------|---------------|
245| Keyboard nav | Tab/Shift+Tab, Arrow keys in menus/tabs, Escape to close |
246| Focus management | Trap in dialogs, restore on close, skip link |
247| ARIA live regions | `aria-live="polite"` for dynamic content |
248| Form errors | `aria-invalid`, `aria-describedby`, `role="alert"` |
249| Loading states | `aria-busy={true}` on loading buttons |
250| Contrast | 4.5:1 text, 3:1 UI components (OKLCH lightness channel) |
251
252```tsx
253// Skip link
254<a href="#main-content" className="sr-only focus:not-sr-only focus:absolute focus:z-50">
255 Skip to main content
256</a>
257```
258
259See `reference/accessibility-checklist.md` for per-component ARIA patterns.
260</accessibility>
261
262<state_management>
263## State Decision Tree
264
265| State Type | Solution | Example |
266|-----------|----------|---------|
267| URL state | `nuqs` / `useSearchParams` | Filters, pagination, tabs |
268| Server data | React Query / SWR | API data, user profile |
269| Local UI | `useState` | Form inputs, toggles |
270| Shared parent-child | Lift state / Context | Accordion groups |
271| Complex cross-cutting | Zustand | Cart, wizard, notifications |
272
273**Prefer URL state** — shareable, bookmarkable, survives refresh.
274</state_management>
275
276<data_fetching>
277## Data Fetching
278
279| Pattern | When | How |
280|---------|------|-----|
281| Server Components | Default | `async function Page() { const data = await db.query() }` |
282| Suspense streaming | Slow data | `<Suspense fallback={<Skeleton/>}><SlowComponent/></Suspense>` |
283| Server Actions | Mutations | `"use server"` + `revalidatePath()` |
284| React Query | Client real-time | `useQuery({ queryKey, queryFn, refetchInterval })` |
285| React Query (SPA) | Client-only apps | `useQuery({ queryKey, queryFn })` with loaders — replaces Server Components |
286</data_fetching>
287
288<forms>
289## Forms: RHF + Zod + shadcn Form + Server Actions
290
2911. **Shared Zod schema** — Single source of truth for client validation and server action
2922. **React Hook Form** — `useForm` with `zodResolver`, `mode: "onBlur"`
2933. **shadcn Form** — `<Form>/<FormField>/<FormItem>/<FormLabel>/<FormMessage>`
2944. **Server Action** — `safeParse` on server, return field errors, `revalidatePath`
295
296```tsx
297const schema = z.object({
298 name: z.string().min(2),
299 email: z.string().email(),
300})
301```
302
303See `reference/form-patterns.md` and `templates/form-with-server-action.tsx`.
304</forms>
305
306<performance>
307## Core Web Vitals
308
309| Metric | Target | Quick Win |
310|--------|--------|-----------|
311| LCP < 2.5s | Main content visible | `next/image` with `priority`, `next/font` |
312| INP < 200ms | Responsive interactions | Code-split heavy components with `dynamic()` |
313| CLS < 0.1 | No layout shift | Reserve space for images/fonts, Skeleton loaders |
314
315Tailwind v4 produces 70% smaller CSS automatically. See `reference/performance-optimization.md`.
316</performance>
317
318<references>
319| Topic | Reference File | When to Load |
320|-------|----------------|--------------|
321| Tailwind v4 setup | `reference/tailwind-v4-setup.md` | New project, v3 migration |
322| shadcn/ui setup | `reference/shadcn-setup.md` | Component library setup |
323| Component patterns | `reference/component-patterns.md` | Building custom components |
324| SaaS dashboard | `reference/saas-dashboard.md` | Dashboard layouts, KPI cards |
325| Pricing + checkout | `reference/saas-pricing-checkout.md` | Pricing pages, Stripe UI |
326| Accessibility | `reference/accessibility-checklist.md` | WCAG audit, ARIA patterns |
327| Form patterns | `reference/form-patterns.md` | Multi-step forms, file upload |
328| Performance | `reference/performance-optimization.md` | Core Web Vitals, Lighthouse |
329| Vite + React setup | `reference/vite-react-setup.md` | New Vite SPA project |
330| SPA routing | `reference/spa-routing.md` | React Router, TanStack Router |
331</references>
332
333<checklist>
334## Enterprise SaaS Pre-Ship Audit
335
336### Accessibility
337- [ ] Keyboard navigation for all interactive elements
338- [ ] Screen reader announces content meaningfully
339- [ ] Focus indicators visible, skip link present
340- [ ] Color contrast >= 4.5:1 (text), >= 3:1 (UI)
341
342### Performance
343- [ ] LCP < 2.5s, INP < 200ms, CLS < 0.1
344- [ ] Images via next/image, fonts via next/font
345- [ ] Heavy components code-split with dynamic()
346
347### Responsive
348- [ ] Works 320px-2560px, touch targets >= 44px
349- [ ] Container queries for reusable components
350
351### Security
352- [ ] No raw HTML injection without sanitization
353- [ ] CSP headers, Zod validation client AND server
354
355### UX
356- [ ] Loading / error / empty states for all data views
357- [ ] Toast for mutations, confirm for destructive actions
358</checklist>