Agent Skills › fmaclen/canutin › pocketbase

pocketbase

GitHub

PocketBase后端开发规范,涵盖Schema管理、Go自定义钩子、认证流程及集合API规则。指导开发者在canutin项目中正确使用PocketBase进行数据操作与扩展。

.agents/skills/pocketbase/SKILL.md fmaclen/canutin

Trigger Scenarios

需要查询或修改PocketBase数据库结构 实现基于PocketBase的自定义业务逻辑或API 处理用户认证与权限控制 调试后端服务连接问题

Install

npx skills add fmaclen/canutin --skill pocketbase -g -y
More Options

Non-standard path

npx skills add https://github.com/fmaclen/canutin/tree/master/.agents/skills/pocketbase -g -y

Use without installing

npx skills use fmaclen/canutin@pocketbase

指定 Agent (Claude Code)

npx skills add fmaclen/canutin --skill pocketbase -a claude-code -g -y

安装 repo 全部 skill

npx skills add fmaclen/canutin --all -g -y

预览 repo 内 skill

npx skills add fmaclen/canutin --list

SKILL.md

Frontmatter
{
    "name": "pocketbase",
    "description": "PocketBase backend - schema, Go hooks, admin API, dev credentials, collections"
}

PocketBase Conventions

Overview

Backend runtime and database for canutin. Custom Go hooks extend PocketBase with balance-calculation logic and custom API routes. A single binary serves HTTP, realtime, and the admin UI.

Dev Environment

  • Base URL: $PUBLIC_PB_URL — each checkout has its own port, so read it from the generated .env rather than assuming the default
  • Server ownership, ports, and start/reset commands: see local-servers
  • Types auto-generated in src/lib/pocketbase.schema.ts on schema changes

Authentication

  • Superuser (dev only): superadmin@example.com / 123qweasdzxc — auto-upserted on server start via scripts/pb-server.ts
  • Regular user auth: POST /api/collections/users/auth-with-password
  • Superuser auth: POST /api/collections/_superusers/auth-with-password
  • Include token in Authorization: Bearer <token> for subsequent requests
  • Test helpers in e2e/pocketbase.helpers.ts already handle auth — use them instead of reimplementing

Collections

Source of truth: src/lib/pocketbase.schema.ts (generated from live schema).

Core collections: users, accounts, transactions, assets, accountBalances, assetBalances, balanceTypes, transactionLabels, accountShares, assetShares.

  • All collections are queryable by superadmins
  • Regular users are scoped via collection API rules (see the admin UI)
  • Filter syntax: field='value', &&, ||, >=, etc.

List and view rules that authorize through reverse relations must begin with @request.auth.id != '' && (...), wrapping the entire owner/sharing expression. PocketBase treats a missing relation and missing auth ID as equal, so an unguarded sharing clause can admit anonymous reads of records with no shares. Cover both list and direct-record access when changing these rules.

The latestAccountBalances, latestAssetBalances, and latestSecurityBalances views copy the list and view rules of accountBalances, assetBalances, and securityBalances. When a balance collection's rule changes, change its view's rule in the same migration flow.

Available APIs

All PocketBase APIs are available to authenticated clients with the appropriate scope:

API Docs
Records https://pocketbase.io/docs/api-records/
Realtime https://pocketbase.io/docs/api-realtime/
Files https://pocketbase.io/docs/api-files/
Collections https://pocketbase.io/docs/api-collections/
Settings https://pocketbase.io/docs/api-settings/
Logs https://pocketbase.io/docs/api-logs/
Crons https://pocketbase.io/docs/api-crons/
Backups https://pocketbase.io/docs/api-backups/
Health https://pocketbase.io/docs/api-health/

Custom Go Hooks

Location: pocketbase/main.go (split into balance.go, shares.go, import.go).

Current hooks:

  • Balance calculation — after transaction create/update/delete, enqueues affected account(s) for balance recalculation with a 250ms trailing-edge debounce
  • Shares — ownership/permission extensions on accounts and assets
  • Bulk import — /api/canutin/import and /api/canutin/import/revert (see pb-import.md)

Pattern for new hooks:

  • Use OnRecordAfter*Success hooks for post-mutation logic
  • Debounce expensive operations using the worker + ticker pattern
  • Handle account reassignment in update hooks (old and new account)
  • Split into multiple files when main.go becomes unwieldy

Served Skill Reference

pocketbase/skill.go hand-maintains the behavioral semantics — custom endpoints, behavioral constraints, auth — of the /api/canutin/skill reference; the import payload shape is generated from the Go structs. Update the hand-maintained sections whenever custom routes or backend hooks change. CI enforces this: a change under pocketbase/**/*.go without a matching pocketbase/skill.go or .agents/skills/ update fails the PR unless labeled skip-skill-check.

Schema Changes

  • Never write migration files by hand
  • Migrations are auto-generated via the admin API (POST /api/collections, PATCH /api/collections/<id>) because Automigrate: true is set with TemplateLangJS — see pb-migrate.md
  • Migrations land in pocketbase/pb_migrations/ as JS files

Anti-patterns

  • Dev credentials in production — these are for local development only
  • Hand-written migrations — always go through the admin API
  • Starting PocketBase by default — follow the ownership rules in local-servers
  • Raw app.Save() Go calls for schema — use the collection API endpoints so automigrate hooks fire
  • Original Ozzo validation module — use PocketBase's maintained fork (github.com/pocketbase/ozzo-validation/v4) so custom validation errors use the same types PocketBase recognizes

See Also

Version History

  • b491bd7 Current 2026-09-28 12:22

    修复了仅加载最新余额的问题,确保净资产显示完整(#452)。

  • 28eb754 2026-09-23 01:22

Same Skill Collection

.agents/skills/architecture/SKILL.md
.agents/skills/auth-system/SKILL.md
.agents/skills/code-quality/SKILL.md
.agents/skills/code-review/SKILL.md
.agents/skills/deployment/SKILL.md
.agents/skills/failure-discipline/SKILL.md
.agents/skills/failures-and-logs/SKILL.md
.agents/skills/frontend-design/SKILL.md
.agents/skills/issue-writing/SKILL.md
.agents/skills/local-servers/SKILL.md
.agents/skills/pb-import/SKILL.md
.agents/skills/pb-migrate/SKILL.md
.agents/skills/realtime/SKILL.md
.agents/skills/setup/SKILL.md
.agents/skills/svelte5/SKILL.md
.agents/skills/testing/SKILL.md
.agents/skills/verify/SKILL.md
.agents/skills/commits-and-prs/SKILL.md

Metadata

Files
0
Version
b491bd7
Hash
b134347f
Indexed
2026-09-23 01:22

ホーム - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-28 17:42
浙ICP备14020137号-1