.cursorrules Python FastAPI copy # Python FastAPI .cursorrules # FastAPI best practices fastapi_best_practices = [ "Use Pydantic models for request and response schemas", "Implement dependency injection for shared resources", "Utilize async/await for non-blocking operations", "Use path operations decorators (@app.get, @app.post, etc.)", "Implement proper error handling with HTTPException", "Use FastAPI's built-in OpenAPI and JSON Schema support", ] # Folder structure folder_structure = """ app/ main.py models/ schemas/ routers/ dependencies/ services/ tests/ """ # Additional instructions additional_instructions = """ 1. Use type hints for all function parameters and return values 2. Implement proper input validation using Pydantic 3. Use FastAPI's background tasks for long-running operations 4. Implement proper CORS handling 5. Use FastAPI's security utilities for authentication 6. Follow PEP 8 style guide for Python code 7. Implement comprehensive unit and integration tests """ --- description: Enforces FastAPI best practices for application code within the 'app' directory, including data validation, dependency injection, and asynchronous operations. globs: app/**/*.* --- - Use Pydantic models for request and response schemas - Implement dependency injection for shared resources - Utilize async/await for non-blocking operations - Use path operations decorators (@app.get, @app.post, etc.) - Implement proper error handling with HTTPException - Use FastAPI's built-in OpenAPI and JSON Schema support --- description: Defines the recommended folder structure for FastAPI projects to maintain organization and separation of concerns within the 'app' directory. globs: app/**/*.* --- - Follow this folder structure: app/ main.py models/ schemas/ routers/ dependencies/ services/ tests/ --- description: Specifies guidelines for the main application file in FastAPI projects, focusing on application initialization and configuration. globs: app/main.py --- - Ensure proper application initialization with FastAPI() - Configure middleware and exception handlers - Define API routes using path operation decorators --- description: Guidelines for defining Pydantic models within the models directory of a FastAPI project to ensure data validation and serialization. globs: app/models/*.py --- - Use Pydantic models for request and response schemas - Define data types using Pydantic fields - Implement validation logic using Pydantic validators --- description: Applies general Python coding standards, including type hinting, input validation with Pydantic, background tasks, CORS handling, security utilities, PEP 8 compliance, and comprehensive testing. globs: **/*.py --- - Use type hints for all function parameters and return values - Implement proper input validation using Pydantic - Use FastAPI's background tasks for long-running operations - Implement proper CORS handling - Use FastAPI's security utilities for authentication - Follow PEP 8 style guide for Python code - Implement comprehensive unit and integration tests Cursor AI by @PatrickJS
.cursorrules Optimize DRY SOLID Principles copy Communication and Problem-Solving: Code Quality and Best Practices: Paradigms and Principles: Semantic Naming and Abstractions: Platform Thinking: Response Format: Handling Uncertainty and Limitations: When outputting code blocks, include a # or // file name comment prior to the block, with a few lines before and after the modification. This helps the user identify where to make changes. Stick to the current architecture choices located in pyproject.toml unless the user suggests a new method or module. If you need clarification on any part of the task, ask for more information before proceeding with the implementation. Cursor AI by @Malcolm Jones (bossjones/Tony Dark)