add .mdc file

This commit is contained in:
sanjeed5
2025-02-17 17:50:15 +05:30
parent 2087f9d628
commit 71ac7fc7cc
879 changed files with 7725 additions and 0 deletions
@@ -0,0 +1,7 @@
---
description: Specific rules for interacting with databases using async libraries within the db directory.
globs: **/db/*.py
---
- Async database libraries like asyncpg or aiomysql
- SQLAlchemy 2.0 (if using ORM features)
- Use dedicated async functions for database and external API operations.
@@ -0,0 +1,14 @@
---
description: Guidelines for handling errors and edge cases in Python and FastAPI applications.
globs: **/*.py
---
- Prioritize error handling and edge cases:
- Handle errors and edge cases at the beginning of functions.
- Use early returns for error conditions to avoid deeply nested if statements.
- Place the happy path last in the function for improved readability.
- Avoid unnecessary else statements; use the if-return pattern instead.
- Use guard clauses to handle preconditions and invalid states early.
- Implement proper error logging and user-friendly error messages.
- Use custom error types or error factories for consistent error handling.
- Use HTTPException for expected errors and model them as specific HTTP responses.
- Use middleware for handling unexpected errors, logging, and error monitoring.
@@ -0,0 +1,9 @@
---
description: Specific guidelines for FastAPI application structure and setup in the main application file.
globs: **/main.py
---
- Use functional components (plain functions) and Pydantic models for input validation and response schemas.
- Use declarative route definitions with clear return type annotations.
- Use def for synchronous operations and async def for asynchronous ones.
- Minimize @app.on_event("startup") and @app.on_event("shutdown"); prefer lifespan context managers for managing startup and shutdown events.
- Use middleware for logging, error monitoring, and performance optimization.
@@ -0,0 +1,9 @@
---
description: Guidelines for structuring routes and dependencies in FastAPI applications, stored in the routers directory.
globs: **/routers/*.py
---
- File structure: exported router, sub-routes, utilities, static content, types (models, schemas).
- Avoid unnecessary curly braces in conditional statements.
- For single-line statements in conditionals, omit curly braces.
- Use concise, one-line syntax for simple conditional statements (e.g., if condition: do_something()).
- Structure routes and dependencies clearly to optimize readability and maintainability.
@@ -0,0 +1,12 @@
---
description: Rules for optimizing performance in FastAPI applications, including asynchronous operations and caching.
globs: **/*.py
---
- Minimize blocking I/O operations; use asynchronous operations for all database calls and external API requests.
- Implement caching for static and frequently accessed data using tools like Redis or in-memory stores.
- Optimize data serialization and deserialization with Pydantic.
- Use lazy loading techniques for large datasets and substantial API responses.
- Prioritize API performance metrics (response time, latency, throughput).
- Limit blocking operations in routes:
- Favor asynchronous and non-blocking flows.
- Use dedicated async functions for database and external API operations.
@@ -0,0 +1,7 @@
---
description: Specific rules for creating Pydantic models, focusing on versioning and usage within the project.
globs: **/models/*.py
---
- Use type hints for all function signatures. Prefer Pydantic models over raw dictionaries for input validation.
- Use Pydantic v2.
- Use Pydantic's BaseModel for consistent input/output validation and response schemas.
@@ -0,0 +1,11 @@
---
description: General Python coding principles for all Python files, focusing on code style and best practices.
globs: **/*.py
---
- Write concise, technical responses with accurate Python examples.
- Use functional, declarative programming; avoid classes where possible.
- Prefer iteration and modularization over code duplication.
- Use descriptive variable names with auxiliary verbs (e.g., is_active, has_permission).
- Use lowercase with underscores for directories and files (e.g., routers/user_routes.py).
- Favor named exports for routes and utility functions.
- Use the Receive an Object, Return an Object (RORO) pattern.