Nuxt 3 Development Recipes
Nuxt 3 development recipes in this cookbook are copy-paste prompts for building full-stack Nuxt 3 applications with server routes, composables, and edge deployment. They cover Zod-validated API routes, data-fetching composables built on useFetch and useAsyncData, JWT auth middleware, custom Nuxt modules, hybrid rendering configuration, a Drizzle ORM database layer, Nuxt Content blogging, and Cloudflare Workers edge deployment.
Nuxt 3 gives you file-based routing, auto-imports, server routes, and hybrid rendering out of the box. These recipes help you use AI tools to build on that foundation without fighting the framework’s conventions. Every prompt here produces code that respects Nuxt’s directory structure, leverages auto-imports, and handles SSR/CSR boundaries correctly.
What These Nuxt Recipes Give You
Section titled “What These Nuxt Recipes Give You”- Server route recipes that handle auth, validation, and database access
- Composable patterns for data fetching with
useFetchanduseAsyncData - Middleware and plugin recipes for auth guards and global state
- Deployment prompts for Vercel, Cloudflare, and Netlify edge
Recipe 1: Server API Route with Zod Validation
Section titled “Recipe 1: Server API Route with Zod Validation”Scenario: You need a POST endpoint for creating blog posts with Zod validation, auth checking, and proper error responses.
Expected output: Server route file, Zod schema, and test file with 4 test cases.
Recipe 2: Standardized Data Fetching Composable
Section titled “Recipe 2: Standardized Data Fetching Composable”Scenario: Your pages call useFetch directly with duplicated error handling. You need a composable that standardizes this.
Expected output: Composable file with typed wrappers, ApiError type, and tests.
Recipe 3: Auth Middleware with JWT Refresh
Section titled “Recipe 3: Auth Middleware with JWT Refresh”Scenario: Protected pages need to check authentication and transparently refresh expired tokens without redirecting the user.
This scaffold spans two middleware files, a plugin, and a composable — and the SSR-vs-client split (cookie on the server, useState on the client) is where AI tools quietly produce a hydration mismatch. Pick the workflow that lets you catch it.
Use agent mode to generate middleware/auth.ts, middleware/guest.ts, the plugin, and useAuth() together, then checkpoint before accepting. Auth refresh is the classic spot where the AI reads document.cookie during SSR — the inline diff lets you catch the browser-only API in setup before it crashes the server render.
Generate the whole auth surface headless, then guard the SSR boundary with a hook: add a PostToolUse hook on middleware/*.ts and plugins/*.ts that greps for document. or window. outside an onMounted/import.meta.client guard and fails the edit. Run claude -p "build the auth middleware, guest middleware, plugin, and useAuth composable" so the transparent-refresh path lands in one turn.
Develop the auth layer in a worktree so a half-finished plugin never breaks your running dev branch, then push and let the Cloud reviewer focus on the token-refresh and redirect-preservation logic — the silent-refresh edge cases are exactly what a fresh review pass surfaces.
Expected output: Two middleware files, one plugin, one composable, and integration tests.
Recipe 4: Custom Nuxt Module for SEO
Section titled “Recipe 4: Custom Nuxt Module for SEO”Scenario: Every page needs consistent meta tags, structured data, and an auto-generated sitemap.
Expected output: Module directory with index.ts, composable, Nitro plugins for sitemap and robots, and tests.
Recipe 5: Hybrid Rendering Configuration
Section titled “Recipe 5: Hybrid Rendering Configuration”Scenario: Your marketing pages should be static, your dashboard SSR, and your blog ISR with 1-hour revalidation.
Expected output: Updated nuxt.config.ts, render mode composable, and debug page.
Recipe 6: Real-Time Updates with Server-Sent Events
Section titled “Recipe 6: Real-Time Updates with Server-Sent Events”Scenario: Your dashboard needs live updates for order status changes without WebSocket complexity.
Expected output: SSE server route, two composables, Pinia integration, and tests.
Recipe 7: Shared Nuxt Layer for Multi-App Reuse
Section titled “Recipe 7: Shared Nuxt Layer for Multi-App Reuse”Scenario: Three Nuxt apps share components, composables, and styles. You need a shared layer.
Expected output: Layer directory with config, 7 components, 3 composables, Tailwind preset, and integration test.
Recipe 8: Database Layer with Drizzle ORM
Section titled “Recipe 8: Database Layer with Drizzle ORM”Scenario: Your Nuxt app needs type-safe database queries, migrations, and seeding.
The database layer is schema plus typed queries plus a seed script plus migration config — a lot of files that must agree on the same types. The relations and the migration step are where tooling choice matters.
Use agent mode to generate schema.ts, the query functions, and seed.ts in one pass, watching the inline diffs so the foreign-key references (authorId references users) actually line up. Run drizzle-kit generate from the integrated terminal and review the produced SQL migration before applying.
Generate the schema and queries headless, then make the contract enforceable: add a PostToolUse hook on server/db/schema.ts that runs drizzle-kit generate so the migration never drifts from the schema. Pipe the seed run’s output back in if Faker data violates a constraint — the terminal loop makes that one command.
Build the DB layer in a worktree so an in-progress migration never touches your shared dev database, then push and let the Cloud reviewer check that every query is parameterized and the getPostsWithAuthor join paginates correctly before merge.
Expected output: Schema file, query functions, config, seed script, and query tests.
Recipe 9: Blog with Nuxt Content
Section titled “Recipe 9: Blog with Nuxt Content”Scenario: You want a blog powered by Markdown files with frontmatter, code highlighting, and table of contents.
Expected output: Nuxt Content config, sample posts, blog pages, custom prose component, RSS route, and tests.
Recipe 10: Cloudflare Workers Edge Deployment
Section titled “Recipe 10: Cloudflare Workers Edge Deployment”Scenario: Deploy your Nuxt app to Cloudflare Workers with D1 database, KV caching, and R2 storage.
Expected output: Nitro config, wrangler.toml, binding utilities, session middleware, upload route, and D1 queries.
Recipe 11: Testing Strategy for Nuxt Apps
Section titled “Recipe 11: Testing Strategy for Nuxt Apps”Scenario: Your Nuxt app has zero tests. You need coverage for components, server routes, and composables.
Standing up a test harness is config plus utilities plus the first batch of tests — and the value only lands when those tests actually run on every change, which is where the tool workflows diverge.
Use agent mode to write vitest.config.ts, the tests/utils/ helpers, and the first component tests, then run them in the integrated terminal and feed any mountSuspended failures back inline. The visual diff helps you confirm the test utilities match how your real pages mount.
The natural fit: generate the harness headless, then make tests non-optional with a PostToolUse hook that runs npm run test:unit after edits to *.vue or server/**. Use claude -p "write @nuxt/test-utils tests for these three composables and two server routes" and let it iterate against the failing output until green.
Have a Cloud task add the test suite and open a PR with coverage reported, so reviewers see the 70%-server-route threshold enforced. Generating tests in a worktree keeps the noisy new test files off your feature branch until they pass.
Expected output: Vitest config, test utilities, component tests, server route tests, composable tests, and updated scripts.
Recipe 12: Performance Optimization Audit
Section titled “Recipe 12: Performance Optimization Audit”Scenario: Your Nuxt app scores 60 on Lighthouse. Page transitions feel slow and the bundle is over 1 MB.
Expected output: Updated nuxt.config, NuxtImg replacements, chunk splitting config, and performance comparison.
When Recipes Break
Section titled “When Recipes Break”Where to Go Next From These Nuxt Recipes
Section titled “Where to Go Next From These Nuxt Recipes”- Vue.js patterns for component-level recipes
- API patterns for designing APIs your Nuxt server routes consume
- Database recipes for optimizing queries behind your server routes