backend-api

A set of rules for developing the FastAPI backend of DataFlow WebUI. FastAPI is a Python framework for building web-service endpoints.

In plain words
What is it for?
Use it when editing DataFlow WebUI backend endpoints, services, schemas, or configuration. It guides response envelopes, error handling, and checks required before adding backend resources.
Why use it?
It keeps backend changes consistent with the project’s response format and change policy. For example, errors are returned inside the project’s response structure rather than as ordinary HTTP error responses.

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/opendcai/dataflow-webui/backend-api
Clone the repo
git clone --depth 1 https://github.com/OpenDCAI/DataFlow-WebUI

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,689 The whole file, excluding the scripts and references it only reads on demand.
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.00000 $0.01689
Opus 5 $0.00000 $0.00844
Sonnet 5 $0.00000 $0.00338
Haiku 4.5 $0.00000 $0.00169

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

Security

Grade A, and why

backend-api 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/backend-api.mdc · 194 lines

How it starts

The opening of the file, as written. The whole thing — 194 lines — stays where its author put it; the contents beside it link to each section on GitHub.

DataFlow WebUI Backend (FastAPI)

⚠ CHANGE POLICY: Before creating any new endpoint, service, or registry, check webui-change-policy.mdc. Only operator rendering support and existing-resource CRUD fixes are allowed. New analytical endpoints, dashboards, and feature-level APIs are prohibited unless the user explicitly overrides.

Response Envelope — ALL responses return HTTP 200

This project wraps every response in ApiResponse[T]. Errors are NOT HTTP 4xx/5xx on the wire — they are success: false with the real status in meta.http_status.

from app.api.v1.resp import ok, created, no_content
from app.api.v1.envelope import ApiResponse

# Success
return ok(data)                    # {"success": true, "code": 200, "data": ...}
return created(data)               # Same shape, HTTP still 200
return no_content()                # Empty body, HTTP 200

# Errors — raise HTTPException or ApiError subclass, handler wraps into ApiResponse
from fastapi import HTTPException
raise HTTPException(404, "Pipeline not found")  # → {"success": false, "code": 40400, ...}

from app.api.v1.errors import NotFoundError, ConflictError, ValidationBizError
raise NotFoundError("Dataset not found")        # code=40401, meta.http_status=404

Endpoint Pattern

from fastapi import APIRouter, HTTPException
from app.api.v1.envelope import ApiResponse
from app.api.v1.resp import ok, created
from app.core.container import container
from app.schemas.my_resource import MyResourceIn, MyResourceOut

router = APIRouter(tags=["my_resource"])

# GET list
@router.get("/", response_model=ApiResponse[list[MyResourceOut]],
            operation_id="list_my_resources", summary="列出所有资源")
def list_my_resources():
    return ok(container.my_resource_registry.list())

# POST create
@router.post("/", response_model=ApiResponse[MyResourceOut],
             operation_id="create_my_resource", summary="创建新资源")
def create_my_resource(payload: MyResourceIn):
    try:
        result = container.my_resource_registry.add_or_update(payload.model_dump(mode="json"))
    except Exception as e:
        raise HTTPException(400, f"Failed to create: {e}")
    return created(result)

# GET by id
@router.get("/{resource_id}", response_model=ApiResponse[MyResourceOut],
            operation_id="get_my_resource", summary="获取单个资源")
def get_my_resource(resource_id: str):
    item = container.my_resource_registry.get(resource_id)
    if not item:
        raise HTTPException(404, "Resource not found")
    return ok(item)

# PUT update
@router.put("/{resource_id}", response_model=ApiResponse[MyResourceOut],
            operation_id="update_my_resource", summary="更新资源")
def update_my_resource(resource_id: str, payload: MyResourceUpdateIn):
    data = payload.model_dump(exclude_unset=True)
    updated = container.my_resource_registry.update(resource_id, data)
    return ok(updated)

# DELETE
@router.delete("/{resource_id}", response_model=ApiResponse[dict],
               operation_id="delete_my_resource", summary="删除资源")
def delete_my_resource(resource_id: str):
    item = container.my_resource_registry.get(resource_id)
    if not item:
        raise HTTPException(404, "Resource not found")
    container.my_resource_registry.remove(resource_id)
    return ok(message="Resource deleted")

Read the full file on GitHub · 194 lines

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 · 194 lines · 0 tokens per session scan A d71c423e3777

Subscribe to this mod's changes

backend-api is a cursor rule published in the GitHub repository OpenDCAI/DataFlow-WebUI (220 stars, last pushed 6d ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 1,689 tokens. 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-30.