api-design-and-implementation

A set of coding rules for building FastAPI web API endpoints in Python. FastAPI is a Python framework for creating services that receive and return data over the web.

In plain words
What is it for?
Defining Pydantic data models, organizing endpoint routers, documenting APIs, choosing HTTP status codes, and managing database connections.
Why use it?
It keeps request and response data validated and API structure consistent, reducing unclear contracts and poorly organized endpoint code.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/mrharishkumar/fastapi-cursor-boilerplate/api-design-and-implementation
Clone the repo
git clone --depth 1 https://github.com/mrharishkumar/fastapi-cursor-boilerplate

Made for: Cursor.

Per session 434 This file is loaded in full into every session.
When invoked 434 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00434 $0.00434
Opus 5 $0.00217 $0.00217
Sonnet 5 $0.00087 $0.00087
Haiku 4.5 $0.00043 $0.00043

Measured yesterday against content hash 7ef2c7ed94fd, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

api-design-and-implementation scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/api-design-and-implementation.mdc · 39 lines

What it actually says

API Design and Implementation

1. Pydantic Validation

  • Use Pydantic models for all incoming request bodies and outgoing responses. This ensures automatic data validation and clear API contracts.
  • Use response_model to define the schema for successful responses.
  • Use separate Pydantic schemas for creating, updating, and reading resources (e.g., UserCreate, UserUpdate, UserRead).

2. Router Structure

  • Create a single APIRouter instance per endpoint file.
  • Use descriptive prefixes when including routers in the main API router.
  • Always include proper HTTP status codes, response models, and documentation.
  • Use tags to group related endpoints in the API documentation.
  • Include docstrings for all endpoint functions.
  • Follow RESTful conventions for endpoint paths and HTTP methods.

3. API Router Aggregation

  • Import all endpoint routers in app/api/v1/api.py.
  • Use meaningful prefixes that match the feature domain.
  • Keep the main API router clean and focused on aggregation only.
  • Ensure all routers are properly included with appropriate prefixes.

4. Database Configuration and Connection Management

  • Database configuration is stored in app/core/config.py using Pydantic Settings.
  • Use database connection and session management from app/db/__init__.py.
  • Use SQLAlchemy's create_engine() with connection pooling for production.
  • Implement proper session lifecycle management with dependency injection.
  • Use get_db() dependency function for database sessions in endpoints.
  • Use database migrations with Alembic for schema changes.
  • Implement proper error handling for database connection failures.

5. Logging Standards

  • Use module-based naming: get_logger(__name__) for general module logging.
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 39 lines · 434 tokens per session scan A 7ef2c7ed94fd

Subscribe to this mod's changes

api-design-and-implementation is a cursor rule published in the GitHub repository mrharishkumar/fastapi-cursor-boilerplate (3 stars, last pushed 12mo ago), licensed MIT. It adds 434 tokens to every session, about $0.0022 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.