Structural Snippets
Components, classes, and modules
Ta treść nie jest jeszcze dostępna w Twoim języku.
Transform repetitive coding into intelligent, context-aware snippet workflows. Learn to build snippets that adapt to your project, leverage AI for dynamic generation, and integrate seamlessly with Cursor’s AI capabilities.
Traditional snippets are static. Cursor-powered snippets are:
Impact: Save 30-60 minutes daily on boilerplate code while maintaining consistency.
Structural Snippets
Components, classes, and modules
Pattern Snippets
Design patterns and architectures
Integration Snippets
API calls, database queries, configs
Testing Snippets
Test suites, mocks, and assertions
{ "Cursor React Component": { "prefix": "crc", "body": [ "// Use Cursor to complete this component", "// Context: Follow patterns in @file ${1:Button.tsx}", "export const ${2:ComponentName} = () => {", " // Cursor: implement ${3:component purpose}", " return <div>${0}</div>", "}" ], "description": "AI-assisted React component" }}
Create snippets that instruct AI to follow your patterns:
// Snippet: "cnc" - Cursor Next Component/** * @cursor Generate a Next.js component following these rules: * 1. Use the pattern from components/ui/Button.tsx * 2. Include TypeScript props interface * 3. Add Tailwind classes from our design system * 4. Include loading and error states * 5. Component name: ${1:ComponentName} * 6. Purpose: ${2:purpose} */
// After typing this, Ctrl+K to let AI complete
// Snippet: "capi" - Cursor API Endpoint/** * @cursor Create Express endpoint: * - Method: ${1|GET,POST,PUT,DELETE|} * - Path: ${2:/api/resource} * - Follow pattern in routes/users.js * - Include: validation, error handling, logging * - Response format: { success, data, error } */
// Cursor will generate complete endpoint
# Snippet: "cclass" - Cursor Python Class"""@cursor Generate Python class:- Name: ${1:ClassName}- Inherits: ${2:BaseClass}- Follow patterns in models/base.py- Include: __init__, __repr__, validation- Type hints required- Docstrings in Google format"""
# AI completes with your standards
Store project-specific snippets that understand your architecture:
## New Feature Snippet
When creating a new feature, generate:
1. **Model** (@file models/User.ts pattern) - TypeScript interface - Validation schema - Database model
2. **Service** (@file services/UserService.ts pattern) - CRUD operations - Business logic - Error handling
3. **Controller** (@file controllers/UserController.ts pattern) - Route handlers - Request validation - Response formatting
4. **Tests** (@file tests/user.test.ts pattern) - Unit tests for service - Integration tests for API - Mock data factories
Feature name: [FEATURE_NAME]
.cursor/├── snippets/│ ├── components/ # UI component snippets│ │ ├── react/│ │ ├── vue/│ │ └── angular/│ ├── backend/ # Server-side snippets│ │ ├── api/│ │ ├── database/│ │ └── services/│ ├── testing/ # Test snippets│ │ ├── unit/│ │ ├── integration/│ │ └── e2e/│ ├── patterns/ # Design pattern snippets│ │ ├── singleton/│ │ ├── factory/│ │ └── observer/│ └── project/ # Project-specific snippets│ ├── auth/│ ├── payments/│ └── analytics/
Trigger Base Snippet
Type: ccomp [Tab]Creates: Component skeleton with AI markers
AI Enhancement
Ctrl+K on skeletonPrompt: "Complete following our Card component pattern"
Auto-generate Tests
Ctrl+IPrompt: "Generate tests for this component"
Create Story
Use snippet: cstoryAI fills in based on component props
// Master snippet that generates full CRUD// Snippet: "crud-suite"
/** * @cursor Generate complete CRUD for ${1:Resource}: * * 1. Model: * - File: models/${1:Resource}.js * - Include: schema, validation, indexes * * 2. Routes: * - GET /api/${2:resources} (list with pagination) * - GET /api/${2:resources}/:id * - POST /api/${2:resources} * - PUT /api/${2:resources}/:id * - DELETE /api/${2:resources}/:id * * 3. Middleware: * - Authentication (use auth.js pattern) * - Validation (use validators/${1:Resource}.js) * - Error handling * * 4. Tests: * - Full coverage for all endpoints * - Mock database calls * - Edge cases */
-- Snippet: "cmig" - Cursor Migration-- @cursor Create migration:-- Table: ${1:table_name}-- Action: ${2|create,alter,drop|}-- Include: timestamps, indexes, constraints-- Follow pattern in: migrations/001_create_users.sql
-- AI generates complete migration
// Snippet detects and adds needed importsexport const MyComponent = () => { // @cursor: auto-import Button, useTheme, useState // based on usage below
const theme = useTheme(); const [open, setOpen] = useState(false);
return <Button onClick={() => setOpen(true)}>Click</Button>}
// Snippet reads existing patterns// @cursor: analyze getAllUsers() and create// getAllProducts() with same pattern:// - Error handling style// - Logging approach// - Response format// - Cache strategy
def ${1:function_name}(${2:parameters}): """ @cursor: Generate docstring by: 1. Analyzing function implementation 2. Following Google Python Style Guide 3. Including parameter types from hints 4. Adding usage examples 5. Listing possible exceptions """ ${0:# implementation}
# Ask Cursor to find patterns"Analyze all React components and create a snippettemplate that captures our common patterns"
# Cursor identifies:- Props interface pattern- State management approach- Error boundary usage- Loading state pattern- CSS module imports
// v1: Basic snippetconst ${1:name} = () => <div>${0}</div>
// v2: Add common patternsconst ${1:name} = () => { const [loading, setLoading] = useState(false); return <div>${0}</div>}
// v3: AI-enhancedconst ${1:name} = () => { // @cursor: add hooks commonly used in our components return <div>${0}</div>}
// Combine multiple snippets// @snippet: component-base// @snippet: error-boundary// @snippet: loading-state// @snippet: responsive-wrapper
// Cursor merges all patterns into cohesive component
version: 1.0team: frontendupdated: 2025-01-15
snippets: - id: react-component category: components languages: [typescript, javascript] dependencies: [react, tailwind]
- id: api-endpoint category: backend languages: [javascript] dependencies: [express, joi]
- id: python-test category: testing languages: [python] dependencies: [pytest, mock]
# Snippet: React Form Component
## UsageType `crform` and press Tab
## Generates- Controlled form component- Validation with react-hook-form- Error handling- Loading states- Accessibility attributes
## Customization Points- Form fields: Define in prompt- Validation rules: Specify requirements- Submit handler: Describe API call
## Example`crform` → Tab → "login form with email and password"
Metric | Without Snippets | With AI Snippets | Improvement |
---|---|---|---|
Component creation | 15 min | 2 min | 87% faster |
Consistency | Variable | High | 95% uniform |
Bug rate | Moderate | Low | 60% fewer |
Onboarding time | 2 weeks | 3 days | 78% faster |
// Snippet: "cstate"const [${1:name}, set${1/(.*)/${1:/capitalize}/}] = useState( // @cursor: if ${1} ends with "List", default to [] // @cursor: if ${1} ends with "Count", default to 0 // @cursor: if ${1} ends with "Flag", default to false // @cursor: otherwise, default to null);
# Snippet: "feature-complete"@cursor Create feature "${1:FeatureName}":
1. Create file: features/${1}/index.ts2. Create file: features/${1}/types.ts3. Create file: features/${1}/hooks.ts4. Create file: features/${1}/${1}.test.ts5. Update: features/index.ts with export
Follow structure in features/UserAuth/
// Define reusable snippet parts#macro ERROR_HANDLINGtry { $CONTENT} catch (error) { logger.error('$CONTEXT', error); throw new AppError('$MESSAGE', error);}#endmacro
// Use in snippetsasync function ${1:name}() { #ERROR_HANDLING{ CONTENT: ${0:// implementation} CONTEXT: ${1:name} failed MESSAGE: Failed to execute ${1:name} }}
Master snippet workflows to unlock:
Continue learning with:
Remember: The best snippets are living tools that evolve with your codebase. Regularly analyze your coding patterns and update snippets to match.