← 返回
未分类

admin-crud-mandates

Enforces mandatory defaults for fullstack admin/management system CRUD features — pagination, keyword search, default sorting, loading/empty/error states, logging/audit trails, three-layer permission checks, and transactions/idempotency — automatically applied even when the user did not explicitly request them. Use when implementing any list page, table view, query interface, CRUD feature, or any mutation touching business data, or when the user mentions 管理系统/后台/列表页/查询/CRUD/增删改查/权限/事务.
admin-crud-mandates 是一份给 AI 用的"管理系统开发默认清单"。它解决的问题是:AI 在做后台增删改查功能时,经常会漏掉一些所有开发者心里都知道"肯定要有"但 AI 不提就想不起来的细节,比如分页、关键字搜索、权限校验、日志、事务等等。 这份 skill 被激活的条件是,用户在对话里涉及到管理系统、后台、列表页、查询、增删改查、CRUD、权限、事务这类场景。只要触发,AI 就会在写代码时强制落实七条硬规则。 第一条是分页。任何返回列表的接口和页面都必须分页,不能因为"目前数据少"就省略。前端要有翻页控件和 URL 同步,后端要在数据库层用 LIMIT 或游标,不能全量拉取再切片。第二条是关键字搜索。任何业务列表都要带搜索框和后端 keyword 参数,明确列出可搜字段,走索引友好的查询。第三条是默认排序。没有确定排序的分页会在翻页时产生重复或漏数据,默认用 createdAt 倒序。第四条是加载态、空状态、错误态三种 UI 必须都写,不能只写数据成功的场景。 第五条是日志。每个接口都要有结构化请求日志,包含 method、path、userId、耗时、状态码、traceId;traceId 要从 HTTP 入口一路贯穿到数据库、外部调用、后台任务;每次业务数据的增删改都要记录,敏感操作还要额外写入独立的 audit_log 表;错误在最外层中间件统一捕获带堆栈;密码、token、完整身份证号永远不能写进日志。第六条是权限。每个 CRUD 操作都要在路由级、接口级、行级三个层面分别校验,不能只靠前端藏按钮就算做权限。第七条是事务和幂等。涉及多表的写操作必须放进事务,create 接口必须有防重机制(幂等键或业务唯一约束),update 接口必须带版本号或 updatedAt 检查,防止并发覆盖。 除了规则本身,这份 skill 还约束了 AI 的沟通方式。AI 不会再反复问用户"要不要加分页、要不要权限",而是直接按默认加上;但会在回复末尾明确列出自己加了哪些默认项,比如"Applied by default: 分页、按 name/email 搜索、行级归属校验、请求日志",让用户一眼看到做了什么,方便用户当场说"这个不需要"然后 AI 再撤掉。 整个设计的核心意图是:把团队里约定俗成的"这种功能本来就应该这样做"变成 AI 的默认行为,减少用户反复提醒同样的事情,也减少 AI 写出"只跑通 demo 但上线就出问题"的代码。
user_482ca615
未分类 community v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 107
下载
💾 1
安装
1
版本
#latest

概述

Admin CRUD Mandates

When implementing list / table / query features, the following are mandatory defaults. Apply them without asking, even if the request only says "做一个列表页".

After implementing, your response summary MUST explicitly list which defaults were applied (pagination, keyword search, audit log, transaction, permission checks, etc.) so the user can opt out if a default doesn't fit their edge case.

If the user's request directly contradicts a rule, confirm once; if they insist, leave a code comment explaining why the default was skipped.


Rule 1 — Pagination is mandatory

Any API or page returning a list MUST paginate. No exceptions for "就几条数据".

Backend

  • Accept page (default 1) and pageSize (default 20, hard cap 100)
  • Return shape: { list: T[], total: number, page: number, pageSize: number }
  • Apply LIMIT/OFFSET (or cursor) at the DB layer — never fetch-all-then-slice
  • Whitelist sortBy fields to prevent injection
  • Add DB index on the default sort column

Frontend

  • Pager control with current page + total pages + total count
  • pageSize selector [10, 20, 50, 100]
  • Sync page and pageSize to URL query
  • Reset to page 1 when keyword/filters change

Skip only if ALL true

  • Dataset is bounded small (<100 rows) forever by business rule
  • Purely static config/reference data
  • User explicitly says "no pagination"

Rule 2 — Keyword search is mandatory

Any list of user/business records MUST have keyword search.

Backend

  • Accept keyword query param; trim input; ignore empty
  • Define explicit searchable fields in the handler (not "all columns")
  • Index-friendly query:
  • Small/medium table → LIKE 'keyword%' on indexed columns
  • Large table → full-text index or search engine
  • Combine with pagination + filters via AND

Frontend

  • Search input above the table
  • Debounce 300ms
  • Sync keyword to URL query
  • Reset page to 1 on keyword change
  • Clear button to reset

Skip only if

List is <20 rows of pure static config.


Rule 3 — Default sorting

Every list MUST have a deterministic default sort. If the user does not specify, use createdAt DESC. Pagination without a deterministic ORDER BY produces duplicate/missing rows across pages.


Rule 4 — Loading / empty / error states

Every list page MUST render all three:

  • Loading: skeleton or spinner while fetching
  • Empty: friendly message + primary CTA when total === 0
  • Error: message + retry button on request failure

Do not ship "only the happy path".


Rule 5 — Logging is mandatory

Every API endpoint and every user-facing mutation MUST leave a trace. "没日志" = 线上出事只能靠猜。

Request log (every HTTP handler)

  • Structured log (JSON), fields: method, path, userId, duration_ms, status, traceId
  • Generate traceId at HTTP entry if not present; propagate it to DB calls, outbound HTTP, enqueued jobs, and queue message headers — every downstream log line must carry it
  • Use log levels deliberately: debug / info / warn / error — not everything at info

Business-mutation log (every create / update / delete)

  • Record: who (userId), what entity (type + id), which action, when
  • For updates: log the diff, or at minimum the changed field names
  • For sensitive operations, write to a dedicated audit_log table (separate from app logs, longer retention):
  • permission / role changes
  • delete (including soft delete)
  • money / balance / payment changes
  • data export

Error log

  • Catch at top-level middleware; log stack trace + sanitized inputs + userId + traceId
  • No empty catch {} — never swallow exceptions silently

Other backend log points (same structured-log rules apply)

  • Outbound calls: log target, method, duration_ms, status, retry count, traceId; mask sensitive headers/body
  • Database: log slow queries (threshold per project); use parameter placeholders — never inline PII into the SQL string
  • Background jobs / workers / queue consumers: log jobName, jobId, start/end/duration_ms/status/traceId; failures with stack + retry count; DLQ entries at error

Never log

  • Passwords, tokens, API keys, session cookies
  • Full card numbers / ID numbers — mask them
  • Raw request body if it contains any of the above

Frontend

  • Report unhandled errors + unhandled promise rejections to an error-tracking service (Sentry or equivalent)
  • Strip console.log noise from production builds
  • When an API call fails, log endpoint + params + status for debugging

Skip only if

Never. Even a throwaway demo needs a request log and an error log.


Rule 6 — Permission checks (three levels)

Every CRUD operation MUST verify access at all three layers. AI commonly does only layer 1 and ships privilege-escalation bugs.

  • Route / page level: can this user reach this page at all?
  • API handler level: the handler MUST re-check role/permission — never trust the frontend gate
  • Row level: for any record access (view / edit / delete), verify the user owns it or has explicit grant (multi-tenant isolation, team scoping, ownership)

For write operations, check permission before loading data and again before persisting — TOCTOU gaps are real.

Skip only if

Public-facing, read-only endpoint with no data-isolation requirement.


Rule 7 — Transactions & idempotency

Multi-table writes MUST run in a transaction

  • Create with related records (user + profile + default role)
  • Update that also writes an audit row
  • Delete that cascades or cleans up related data

Without a transaction: partial failures leave orphans / dangling state.

Create endpoints MUST be idempotent — pick one

  • Client-supplied idempotency key (recommended for external API surfaces)
  • Business-level unique constraint (e.g. UNIQUE(userId, resourceId))
  • Deduplication window keyed on meaningful business fields

Users double-click submit. Networks retry. Without idempotency you get duplicate records.

Update endpoints MUST guard against concurrent modification

  • Client sends version / updatedAt along with the payload
  • Server rejects on mismatch with 409 Conflict — do NOT silently overwrite

Skip only if

The operation is genuinely single-row, single-table, non-financial, and retry-safe by nature.


How to apply

  1. Detect the trigger: user asks for a list / table / query / admin / 后台 / 列表 / 查询 / CRUD feature, or any mutation touching business data.
  2. Implement Rules 1–7 unconditionally.
  3. If you are about to write a list endpoint, a mutation, or a component without any of these, stop and add them.
  4. Before declaring "done", confirm all seven rules are present end-to-end (API + UI + DB index + logs + permissions + transaction).
  5. In your response summary, explicitly list the defaults applied in a short bullet list, e.g.:

> Applied by default: ✓ pagination (page/pageSize) ✓ keyword search on name,email ✓ audit log on delete ✓ row-level ownership check ✓ transaction around user+profile create.

This lets the user spot and opt out of any default that does not fit.


What NOT to do

  • ❌ Ask "do you need pagination?" — just add it
  • ❌ Return an unpaginated array because "demo 数据少"
  • ❌ Add a search input on the frontend but forget the keyword param in the API
  • ❌ Paginate without a deterministic ORDER BY
  • ❌ Ship the list without loading / empty / error states
  • ❌ Fetch all rows and filter on the frontend
  • ❌ Empty catch {} that swallows exceptions
  • ❌ Logging passwords / tokens / PII in plaintext
  • ❌ Deleting a record with no audit trail
  • ❌ Only console.log — no structured server logs
  • traceId only on the HTTP handler, lost across DB / outbound / job calls
  • ❌ Background jobs / cron tasks running silently with no start/end/failure log
  • ❌ Permission check only at the route level, not re-checked in the API handler
  • ❌ Relying on frontend to hide a button as a "permission" — backend still accepts the call
  • ❌ Multi-table write without a transaction — partial failure leaves dangling rows
  • ❌ Create endpoint with no idempotency — user double-clicks submit → two records
  • ❌ Update endpoint with no version check — last write silently clobbers concurrent edits
  • ❌ Implementing defaults silently without listing them in the response summary

版本历史

共 1 个版本

  • v1.0.0 Initial release 当前
    2026-04-18 12:30 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 197 📥 67,981
dev-programming

YouTube

byungkyu
使用托管OAuth集成YouTube Data API,支持搜索视频、管理播放列表、获取频道数据及评论互动,适用于用户需要时使用此技能。
★ 142 📥 41,906
dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 681 📥 329,618