FastAPI .cursorrules prompt file guide
About .cursorrules prompt file
What you can build
- FastAPI Starter Template: A boilerplate project that follows all the best practices outlined, providing a quick start for building APIs with FastAPI, including Pydantic models, automatic Swagger documentation, JWT authentication, and SQLModel for data persistence.
- Python Code Style Linter: An online tool or VSCode extension that checks Python code against PEP 8 guidelines, suggests using list comprehensions, f-strings, type hints, and snake_case where applicable, ensuring developers maintain code quality.
- SQLModel Database Manager: A web-based interface for managing databases using SQLModel, allowing developers to visually create tables, define relationships, and generate migration scripts using Alembic.
- Security Best Practices Checker: An automated security auditing tool for Python FastAPI applications that checks for Common security flaws like improper JWT usage or insufficient bcrypt hashing configurations.
- Async Performance Optimizer: A tool that profiles FastAPI applications to identify blocking operations and suggests refactoring opportunities to enhance async performance or leveraging message queues.
- API Design Validator: A service that analyzes RESTful API design against set principles and offers suggestions to improve endpoint design consistency, error handling, and response modeling.
- Integrated Testing Suite: A web application that generates pytest and FastAPI TestClient compatible test cases, helping developers automate unit and integration testing with built-in data generation using Factory Boy.
- Docker CI/CD Pipeline Generator: An online app that guides developers through creating optimized Dockerfiles and setting up CI/CD pipelines with GitHub Actions or GitLab CI for FastAPI projects.
- Custom Exception and Logging Framework: A library that provides pre-built exception classes and logging configurations, ready to be integrated into FastAPI projects for consistent error handling and structured log analysis.
- Python Dependency Manager: An extension to help developers utilize Poetry for dependency management, seamlessly converting requirements.txt files and handling virtual environments effectively.
- API Documentation Sync Tool: A service that ensures FastAPI's Swagger and ReDoc documentation remain in sync with code changes by automatically updating Pydantic models and path functions documentation.
- Responsive Frontend Template Generator: A tool that generates responsive frontend templates in React or Vue.js, pre-configured to communicate with FastAPI backends and include authentication flows and routing.
- Code Performance Profiler: An in-depth profiling service for FastAPI applications that identifies bottlenecks and provides optimization techniques for both code execution and database interactions.
Benefits
- Extensive use of Pydantic and SQLModel for seamless integration between data models and API schemas, ensuring consistency and validation across the application.
- Emphasis on FastAPI's async capabilities for optimized performance and concurrent processing, catering to high-performance API needs.
- Holistic approach to security with JWT, bcrypt, CORS policies, and rate limiting, emphasizing robust and secure authentication practices.
Synopsis
This prompt is ideal for Python developers looking to build scalable, high-performance APIs and applications using FastAPI, SQLModel, and Pydantic, while adopting modern development practices.
Overview of .cursorrules prompt
The .cursorrules file provides a comprehensive set of guidelines for developing Python full-stack applications. It emphasizes following PEP 8 standards, utilizing meaningful naming conventions, and organizing code efficiently. The file suggests leveraging FastAPI for building APIs, incorporating Pydantic for data validation, and using SQLModel for data modeling combined with asynchronous support for optimized database interactions. The guidelines include implementing security measures such as JWT and bcrypt, employing testing practices with pytest, and managing asynchronous tasks with FastAPI's capabilities or Celery. The file also highlights Docker usage for deployment, CI/CD pipeline setup, performance optimization techniques like caching and query optimization, and maintaining API documentation using FastAPI's features. Additionally, it covers version control with Git and dependency management using pip or Poetry, emphasizing best practices like DRY, SOLID principles, readability, and maintainability.