Cursor is the AI code editor that understands your entire codebase. These prompts help you master Composer, Chat, and inline editing to write better code faster than ever.
Generate complete features, components, and modules with Cursor Composer. Always reference existing files for consistent patterns.
@file:src/types/user.ts @file:src/components/Dashboard.tsx @file:src/lib/api.ts Build a complete user settings page with the following requirements: 1. Create a new SettingsPage component following the same patterns as Dashboard.tsx 2. Include sections for: profile info, notification preferences, and account security 3. Use the User type from types/user.ts for all data 4. Use the API client patterns from lib/api.ts for data fetching 5. Add form validation with error states 6. Include loading and error states matching our existing patterns 7. Add TypeScript types for all form data Follow our existing file structure and naming conventions. Do not modify any existing files.
@codebase I need to add a new "projects" feature to this app. Generate the following: 1. Database schema/migration for a projects table (id, name, description, owner_id, status, created_at, updated_at) 2. API routes for CRUD operations following our existing API patterns 3. TypeScript types and Zod validation schemas 4. A reusable API client function matching our existing fetch patterns Look at how other entities (like users or teams) are structured in the codebase and follow the same patterns exactly. List what files you will create and modify before generating code.
@file:src/components/ui/Button.tsx @file:src/components/ui/Card.tsx @file:tailwind.config.ts Create a PricingTable component with 3 tiers (Starter, Pro, Enterprise): - Each tier shows: name, price, feature list, and CTA button - Use our existing Button and Card components - Responsive: stack vertically on mobile, 3 columns on desktop - Highlight the "Pro" tier as recommended - Add a monthly/annual toggle that updates prices - Use our Tailwind theme colors from the config - TypeScript with proper prop types - Export as default from src/components/PricingTable.tsx
Paste errors into Chat with file references for context-aware debugging that actually understands your code.
@file:src/app/api/auth/route.ts I am getting this error in production: [PASTE YOUR ERROR AND STACK TRACE HERE] This happens when users try to [describe the action]. It worked fine until [what changed recently]. Please: 1. Identify the root cause based on my actual code 2. Explain why this error occurs 3. Provide the exact fix with code changes 4. Suggest how to prevent similar issues in the future
@file:src/components/DataTable.tsx @file:src/hooks/useData.ts This component re-renders excessively and the page feels sluggish with 500+ rows. Profile the component and tell me: 1. What is causing unnecessary re-renders? 2. Are there missing memoization opportunities (useMemo, useCallback, React.memo)? 3. Should I implement virtualization for this dataset size? 4. Are there any expensive computations that should be cached? 5. What is the optimal data fetching strategy for this pattern? Give me the optimized version of both files with explanations for each change.
@file:src/hooks/useSearch.ts @file:src/lib/api.ts My search feature has a race condition. When I type quickly, older API responses sometimes overwrite newer results. The search results flicker and show stale data. Current behavior: type "react" -> results for "r", "re", "rea" arrive out of order Expected behavior: only show results for the final query "react" Analyze the code and fix the race condition. Consider: AbortController, request cancellation, debouncing, and stale request detection. Show me the complete fixed implementation.
Generate comprehensive test suites that cover real scenarios, not just happy paths.
@file:src/components/CheckoutForm.tsx @file:src/lib/payments.ts @file:src/types/order.ts Generate a complete test suite for CheckoutForm using our existing test patterns: 1. Unit tests for form validation (valid/invalid inputs for each field) 2. Integration tests for the payment submission flow 3. Edge cases: network failures, duplicate submissions, timeout handling 4. Accessibility tests: keyboard navigation, screen reader labels, error announcements 5. Mock the payments API following our existing mock patterns Use the same test framework and assertion style as our other test files. Include both positive and negative test cases. Add descriptive test names that explain the expected behavior.
@file:src/services/OrderService.ts Review this code as a senior engineer. Check for: 1. Bug risks: null/undefined handling, off-by-one errors, race conditions 2. Security: input validation, SQL injection, XSS, data exposure 3. Performance: N+1 queries, unnecessary allocations, missing indexes 4. Maintainability: naming, single responsibility, testability, DRY violations 5. Error handling: are all failure modes covered? Are errors informative? For each issue found, explain the risk level (critical/medium/low), show the problematic line, and provide the exact fix. Do not suggest style changes unless they affect readability.
@codebase Generate end-to-end test scenarios for our user authentication flow. Cover these user stories: 1. New user signs up with email and password 2. Existing user logs in 3. User resets forgotten password 4. OAuth login with Google 5. Session expiry and automatic redirect to login 6. Rate limiting after 5 failed login attempts For each scenario, write the test using our existing E2E framework. Include setup, the user actions, assertions, and teardown. Make sure tests are independent and can run in any order.
Use Cursor Chat for architecture decisions and Composer for implementation. Let the AI reason about tradeoffs before writing code.
@codebase I need to add real-time notifications to this app. Before writing any code, analyze our current architecture and recommend an approach: 1. What real-time technology fits best? (WebSockets, SSE, polling, or a managed service like Pusher/Ably) 2. Where should the notification logic live in our current architecture? 3. How should we handle: delivery guarantees, offline users, notification preferences, and read/unread state? 4. What database changes are needed? 5. What are the scaling implications of each approach? Consider our current tech stack, deployment setup, and team size. Recommend the simplest solution that meets the requirements. Do not write code yet.
@file:src/app/api/orders/route.ts This API route has grown to 300+ lines with business logic, database queries, and validation all mixed together. Refactor it into clean architecture: 1. Extract business logic into a service layer (src/services/OrderService.ts) 2. Extract database operations into a repository (src/repositories/OrderRepository.ts) 3. Extract validation into schemas (src/schemas/order.ts) 4. Keep the route handler thin: validate -> call service -> return response 5. Add proper TypeScript interfaces for each layer boundary 6. Maintain all existing behavior and error handling Show me the complete refactored files. The route handler should be under 30 lines.
@file:prisma/schema.prisma Review my database schema for a multi-tenant SaaS application. Evaluate: 1. Are relationships properly defined with appropriate cascade rules? 2. Are indexes optimized for common query patterns? 3. Is the multi-tenancy model correct (shared database, tenant_id column)? 4. Are there any normalization issues or missing tables? 5. What fields need unique constraints that are currently missing? 6. Will this schema handle 100K+ tenants and millions of rows efficiently? For each suggestion, explain the problem it solves and provide the exact schema change.
Accelerate everyday development tasks with prompts designed for real-world workflows.
@git I just finished implementing [FEATURE_NAME]. Look at my recent git changes and generate: 1. A PR description with: summary, motivation, what changed (grouped by area), testing notes, and screenshots needed 2. Update the relevant README or docs to reflect the new feature 3. Add inline code comments for any complex logic that future developers might find confusing 4. Suggest if this PR should be split into smaller PRs for easier review Format the PR description in markdown with clear sections.
Refactor this function to: - Use early returns instead of nested if/else - Add TypeScript types for all parameters and return value - Handle the null/undefined edge cases - Add a JSDoc comment explaining what it does - Keep the same behavior, just cleaner code
@codebase I just joined this project. Give me a complete onboarding overview: 1. What is this application and what does it do? 2. What is the tech stack (frontend, backend, database, deployment)? 3. How is the codebase organized? Explain the folder structure and key directories. 4. What are the main data models and how do they relate? 5. Where are the API routes and what patterns do they follow? 6. What testing frameworks and patterns are used? 7. What are the most important files I should read first? Be specific and reference actual files and directories. Do not give generic advice.