npx agentspec-cli install 7a533ee7-4ea8-4fbc-bcdb-7dcce9bc1e0c --file-type clinerules→ .clinerules/
## Instructions
You are an expert in Python, FastAPI, and scalable API development. USE MCPS WHERE NEEDED
Step 1 : Get FastAPI and all Necessary Documentation by using Context7 MCP Server .
Key Principles
- 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.
Python/FastAPI
- Use def for pure functions and async def for asynchronous operations.
- Use type hints for all function signatures. Prefer Pydantic models over raw dictionaries for input validation.
- 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()).
Error Handling and Validation
- 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.
Dependencies
- FastAPI
- Pydantic v2
- Async database libraries like asyncpg or aiomysql
- SQLAlchemy 2.0 (if using ORM features)
FastAPI-Specific Guidelines
- 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.
- Optimize for performance using async functions for I/O-bound tasks, caching strategies, and lazy loading.
- Use HTTPException for expected errors and model them as specific HTTP responses.
- Use middleware for handling unexpected errors, logging, and error monitoring.
- Use Pydantic's BaseModel for consistent input/output validation and response schemas.
Performance Optimization
- 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.
Key Conventions
1. Rely on FastAPI’s dependency injection system for managing state and shared resources.
2. Prioritize API performance metrics (response time, latency, throughput).
3. Limit blocking operations in routes:
- Favor asynchronous and non-blocking flows.
- Use dedicated async functions for database and external API operations.
- Structure routes and dependencies clearly to optimize readability and maintainability.
Refer to FastAPI documentation for Data Models, Path Operations, and Middleware for best practices.
# Task List Management
Guidelines for creating and managing task lists in Markdown files to track project progress
## Task List Creation
1. Create task lists in a markdown file (in the project root):
- Use `TASKS.md` or a descriptive name relevant to the feature (e.g., `ASSISTANT_CHAT.md`)
- Include a clear title and description of the feature being implemented
2. Structure the file with these sections:
# Feature Name Implementation
Brief description of the feature and its purpose.
## Completed Tasks
- [x] Task 1 that has been completed
- [x] Task 2 that has been completed
## In Progress Tasks
- [ ] Task 3 currently being worked on
- [ ] Task 4 to be completed soon
## Future Tasks
- [ ] Task 5 planned for future implementation
- [ ] Task 6 planned for future implementation
## Implementation Plan
Detailed description of how the feature will be implemented.
### Relevant Files
- path/to/file1.ts - Description of purpose
- path/to/file2.ts - Description of purpose
## Task List Maintenance
1. Update the task list as you progress:
- Mark tasks as completed by changing `[ ]` to `[x]`
- Add new tasks as they are identified
- Move tasks between sections as appropriate
2. Keep "Relevant Files" section updated with:
- File paths that have been created or modified
- Brief descriptions of each file's purpose
- Status indicators (e.g., ✅) for completed components
3. Add implementation details:
- Architecture decisions
- Data flow descriptions
- Technical components needed
- Environment configuration
## AI Instructions
When working with task lists, the AI should:
1. Regularly update the task list file after implementing significant components
2. Mark completed tasks with [x] when finished
3. Add new tasks discovered during implementation
4. Maintain the "Relevant Files" section with accurate file paths and descriptions
5. Document implementation details, especially for complex features
6. When implementing tasks one by one, first check which task to implement next
7. After implementing a task, update the file to reflect progress
## Example Task Update
When updating a task from "In Progress" to "Completed":
## In Progress Tasks
- [ ] Implement database schema
- [ ] Create API endpoints for data access
## Completed Tasks
- [x] Set up project structure
- [x] Configure environment variables
Should become:
## In Progress Tasks
- [ ] Create API endpoints for data access
## Completed Tasks
- [x] Set up project structure
- [x] Configure environment variables
- [x] Implement database schema
---
trigger: model_decision
description: This rule defines how the AI agent should manage and utilize memory improve coding consistency.
---
# AI Memory Rule
This rule defines how the AI should manage and utilize its "memory" regarding this specific project, including user preferences, learned facts, and project-specific conventions.
## Purpose
The AI's memory helps maintain consistency and adapt to specific project needs or user preferences discovered during interactions. It prevents the AI from repeatedly asking for the same information or making suggestions contrary to established patterns.
## Storage
All learned project-specific knowledge and preferences should be stored and referenced in the `learned-memories.mdc` file located in `.cursor/rules`.
## Updating Memory
When new information relevant to the project's conventions, user preferences, or specific technical details is learned (either explicitly told by the user or inferred through conversation), the AI should:
1. **Identify Key Information:** Determine the core piece of knowledge to be stored.
2. **Check Existing Memory:** Review `learned-memories.mdc` to see if this information contradicts or updates existing entries.
3. **Propose Update:** Suggest an edit to `learned-memories.mdc` to add or modify the relevant information. Keep entries concise and clear.
## Using Memory
Before proposing solutions, code changes, or answering questions, the AI should consult `learned-memories.mdc` to ensure its response aligns with the recorded knowledge and preferences.
## Example Scenario
**User:** "We've decided to use Tailwind v4 for this project, not v3."
**AI Action:**
1. Recognize this as a project-specific technical decision.
2. Check `learned-memories.mdc` for existing Tailwind version information.
3. Propose adding or updating an entry in `learned-memories.mdc`:
## Technical Decisions
* **CSS Framework:** Tailwind v4 is used. Ensure usage aligns with v4 documentation and practices, noting differences from v3.
4. In subsequent interactions involving Tailwind, the AI will refer to this entry and consult v4 documentation if necessary.
## Memory File (`.cursor/rules/learned-memories.mdc`)
The basic structure:
# Project Memory
This file stores project-specific knowledge, conventions, and user preferences learned by the AI assistant.
## User Preferences
- [Preference 1]
- [Preference 2]
## Technical Decisions
- [Decision 1]
- [Decision 2]
## Project Conventions
- [Convention 1]
- [Convention 2]Python Fastapi Best Practices Cursorrules Prompt F Rules
Cursor IDE rules and conventions for AI-assisted development.
by AgentHub Crawler
Vp Scraping Configuration
Cursor IDE rules and conventions for AI-assisted development.
by AgentHub Crawler
Vp Scraping Configuration
Cursor IDE rules and conventions for AI-assisted development.
by AgentHub Crawler
Py Fast Api Rules
Cursor IDE rules and conventions for AI-assisted development.
Sign in to leave a comment.
by AgentHub Crawler