Skip to main content

Claude Prompt to Build a Vue 3 Composition API Feature

Scaffold a complete Vue 3 Composition API feature: composables, a Pinia store module, TypeScript interfaces and Vitest unit tests, following Vue best practices.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
Build a complete, production-ready Vue.js 3 feature for UserNotifications using the Composition API with TypeScript.

**Project context:**
- Vue version: 3.4+ with `<script setup>` syntax
- State management: Pinia
- Styling: Tailwind CSS with @apply in scoped styles
- Testing: Vitest + Vue Test Utils
- API layer: Axios with a typed API client wrapper and interceptors

**Feature requirements:**
Real-time notification bell with unread count badge, dropdown list with mark-as-read, infinite scroll loading, push notification opt-in, and notification preferences panel

**Generate the following files:**

1. **Composable (`use<FeatureName>.ts`):**
   - Reactive state with `ref`/`reactive` and proper TypeScript generics
   - Computed properties for derived state
   - Watcher for side effects with proper cleanup
   - Error and loading state management
   - Return typed object (not tuple) for IDE autocompletion

2. **Pinia Store (`UserNotificationsStore.ts`):**
   - Define store using `defineStore` with setup syntax
   - Actions for CRUD operations with optimistic updates
   - Getters with proper caching behavior
   - `$reset()` support for testing
   - Persist plugin integration if true for user preferences, false for notification data is enabled

3. **Component (`<FeatureName>.vue`):**
   - `<script setup lang="ts">` with proper prop/emit definitions using `defineProps`/`defineEmits`
   - Template with conditional rendering, list transitions, and `<Suspense>` boundaries
   - Scoped styles using Tailwind CSS with @apply in scoped styles
   - `provide`/`inject` for deeply nested child communication where appropriate

4. **TypeScript interfaces (`types/UserNotifications.ts`):**
   - Request/response DTOs
   - Component prop and emit types
   - Store state shape
   - API error union types

5. **Unit tests (`__tests__/UserNotifications.spec.ts`):**
   - Composable tests using `renderHook` pattern
   - Component mount tests with `vi.mock` for API calls
   - Pinia store tests with `createTestingPinia`
   - At least 12 test cases covering happy path, error states, and edge cases

6. **Integration notes:**
   - Router guard if the feature needs auth protection
   - Lazy-loaded route definition with `defineAsyncComponent`
   - i18n keys if multi-language support is needed

Ensure all code follows the Vue.js Style Guide (Priority A and B rules). Use `shallowRef` for large objects, `toRefs` for destructured store state, and `watchEffect` only when dependency tracking is preferred over explicit `watch`.

What this prompt does

This prompt scaffolds a complete, production-ready Vue 3 feature using the Composition API with TypeScript. You name the [feature_name], spell out [feature_requirements], and set your [styling_approach], [api_pattern], [persist_state], and [test_count], and it generates a coordinated set of files: a composable, a Pinia store, the component, TypeScript interfaces, and Vitest unit tests.

The structure works because it pins the output to modern Vue conventions instead of leaving them to chance. By requiring <script setup>, typed return objects (not tuples), defineProps/defineEmits, and adherence to the Vue Style Guide's Priority A and B rules, the generated code lands close to how an experienced Vue developer would hand-write it — which makes review fast. The [feature_requirements] field drives the actual behavior, while [persist_state] and [test_count] control the persistence plugin and how thoroughly the tests cover happy path, error states, and edge cases.

When to use it

  • You're building a new Vue 3 feature and want a full slice — composable, store, types, tests — in one pass.
  • You want to enforce <script setup> and Composition API patterns across a team's output.
  • You need typed Pinia stores with $reset() support and optimistic updates as a starting point.
  • You're adding a feature that needs [persist_state] for some data (like user preferences) but not others.
  • You want Vitest tests scaffolded alongside the code so coverage isn't an afterthought.
  • You're onboarding to a Vue codebase and want idiomatic reference code that follows the Style Guide.

Example output

You get five coordinated files: a use<FeatureName>.ts composable with reactive state, computed properties, watchers, and typed returns; a [feature_name]Store.ts Pinia store with CRUD actions, getters, and $reset(); a <FeatureName>.vue component using <script setup lang="ts"> with proper props, emits, and scoped styles in your [styling_approach]; a types/[feature_name].ts file with DTOs and union types; and a spec file with at least [test_count] Vitest cases plus integration notes for routing and i18n.

Pro tips

  • Make [feature_requirements] detailed and behavioral — the richer the requirements, the more complete the composable and component logic.
  • Set [test_count] to a realistic floor; bump it up if your feature has many error and edge-case branches.
  • Use [persist_state] to distinguish what belongs in localStorage (preferences) from transient data (live lists).
  • Match [styling_approach] to your real setup so the scoped styles don't need rewriting.
  • Specify your [api_pattern] precisely; the composable's loading and error handling is generated around it.
  • Review the generated tests for genuine assertions — regenerate or extend any that only check that something rendered.

Frequently Asked Questions

Does this generate Options API or Composition API code?
Composition API exclusively, using `<script setup lang="ts">` syntax with Vue 3.4+. It enforces typed return objects, `defineProps`/`defineEmits`, and Vue Style Guide Priority A and B rules, so the output matches modern idiomatic Vue rather than legacy Options API patterns.
Will it include tests, and how many?
Yes. It generates Vitest plus Vue Test Utils specs covering the composable, component, and Pinia store, with at least the number of cases you set in `[test_count]`. Review them to confirm the assertions are meaningful rather than shallow render checks.
Does it use Pinia or Vuex for state?
Pinia, written with the setup syntax via `defineStore`. The store includes CRUD actions with optimistic updates, cached getters, and `$reset()` support for testing, plus persistence wiring when you enable `[persist_state]`.
Can I control whether state persists to localStorage?
Yes, through the `[persist_state]` variable. You can persist some slices (like user preferences) while keeping volatile data (like a live notification list) in memory, and the store is generated with the persist plugin configured accordingly.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Frontend Development Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support