Skip to content
Back to skills

Ape Add Module

ASecurity

Add a module (its tables, functions and routes) to a BuffCore product or to BuffCore: boundaries, the manifest, entities, sensitive marks, roles, jobs, privacy hooks, notification kinds, services, safety flags, tests.

  • 5 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
developmentgoshellsqltestingapidatabase

Works with

  • api
  • mcp

Security analysis

A100/100

Scanned December 3, 2026

npx -y skills add BuffApe/BuffApe --skill ape-add-module --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Ape Add Module?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Ape Add Module
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/buffape-ape-add-module/badge)](https://www.skillsdirectory.com/skills/buffape-ape-add-module)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: ape-add-module
description: "Add a module (its tables, functions and routes) to a BuffCore product or to BuffCore: boundaries, the manifest, entities, sensitive marks, roles, jobs, privacy hooks, notification kinds, services, safety flags, tests."
---

# Add a module

A module owns its tables and offers functions other modules call. Call other modules only through their public entry (`@buffcore/modules/<key>`, or a product module's `index.ts`), never their entities, other files or tables: `pnpm ape check boundaries` (in `pnpm lint`) names each import or SQL that reaches in and what to use instead. To ask another module a question, call a function it exports with your `ctx`, in a route or a job: `subscriptionOf(ctx, accountId)` from `@buffcore/payments` says whether an account's plan is paid up (what an extension exports is in its README). Name the module in your manifest's `requires: { modules: ['payments'] }`, so the app stops at start, naming it, when it isn't composed. For a whole feature (tables, routes, screens, strings, tests) in order, follow the ape-add-feature skill; its reference module, `tasks`, is the smallest product module to copy. In BuffCore's repository, `packages/modules/src/audit` is the smallest of BuffCore's modules and the playground's `apps/playground/src/modules/notes` uses most of what is below.

1. Create `apps/api/src/modules/<key>/` (in BuffCore: `packages/modules/src/<key>/`) with:
   - `entity.ts`: `defineEntity`, `p` and `primaryId` from `@buffcore/db`; every entity's ID is `id: primaryId()` (a UUIDv7 made when the row is created); camelCase names become `snake_case` columns. Mark sensitive fields next to the entity: `markSensitive('Note', { noteBody: 'content' })` from `@buffcore/db`. Marks redact by name everywhere, so a marked property gets a name nothing else uses (`noteBody`, not `body`). Reference other modules' rows by plain `uuid` columns, never relations. A column that is a day with no time is `p.date()` (the ape-add-feature skill).
   - **Typing the database in your own code:** a function that reads or writes rows takes `em: EntityManager` from `@buffcore/db` (the type of `ctx.em`) or the whole `ctx: Ctx` from `@buffcore/server`; a row's type is `InferEntity<typeof TaskEntity>` from `@buffcore/db` (tasks' `toTask`). A product never imports `@mikro-orm/*`.
   - `migrations/index.ts`: `export default [];`
   - `contract.ts`: the route schemas, with `route()` from `@buffcore/contracts` (the `ape-add-route` skill). The admin and the app import them from this file by a relative path (in BuffCore, they go in `packages/contracts/src/modules/<key>.ts`).
   - `manifest.ts`: `defineModule({ key, description, scope: 'app' /* products */, entities, migrations, seeds, routes, jobs, events, purposes, services, hooks, settings, contributes, catalog })` from `@buffcore/server`; `hooks` answers only the kernel's (`server.*`), and another package's registries and hook points take their owner's handle in `contributes`. Anything two modules declare (a table, a route, an event, a job, a registry entry) stops the app at start, naming both.
2. Add what the module needs beyond tables and routes (in BuffCore's repository, the playground's `notes` module has jobs, privacy hooks and a notification kind, and `packages/modules/src/notifications/providers/resend.ts` is a service):
   - **Roles, if its admin routes are for operators other than the Owner** (reuse a role when the same person does the job, declare a new one when another does; the `ape-add-route` skill): a route names them (`roles: ['support']`), and the product declares each where the app is composed: `buffcoreModules(product, { identity: { roles: ['support'] } })`. Name each in the admin catalog as `admin.roles.<role>`. The Owner is built in and may call every route.
   - **Seeds, for rows that must exist before anything happens** (a list a member picks from): `seeds: { minimal: async (em, app) => { em.create(Place, { id: '01928c6e-0000-7000-8000-000000000a01', accountId: MINIMAL.account.id, name: '…' }); } }` in the manifest, with fixed IDs so tests and screens find them, and synthetic data only (`MINIMAL` is the seeded owner, member and account, from `@buffcore/modules/identity`). `minimal` runs in every test app (`createProductTestApp`) and in `pnpm ape seed` (development only; `--reset` rebuilds the database first), so a list in a test starts with these rows: tests create every other row through the routes. Another scenario has a name of your own: `pnpm ape seed <scenario>`.
   - **Jobs** for work off the request path: `jobs: [{ name: 'notes.ready', run(payload, ctx) {…} }]`, queued with `enqueue(ctx, name, payload)` (the payload holds IDs, not content) through the context of the transaction that causes it (`{ ...ctx, em }`), so the job exists only if that commits; add `every` (a cron pattern, in UTC) to run one on a schedule, or `on: '<event>'` to run one for each event (the ape-add-event skill). A job's writes through `ctx.em` commit with its done mark; when it throws they roll back and it runs again later (five tries, then `ape jobs` lists it), so make it safe to run twice, and give `ctx.job.key` to an outside service (an email, a webhook) as its idempotency key.
   - **Privacy, if it keeps personal rows** (`privacy.ts`, listed under `contributes`), with privacy's handles (`@buffcore/modules/privacy`): `onExportAccount.add(fn)` answers `{ json: { 'notes/notes.json': rows }, files? }`; `onDeleteAccount.add(fn)` deletes through `ctx.em` (every module's deletion is one transaction), uses the IDs it is given (`userIds`, and `subjects.profile` and `subjects.device`; never look people up while deleting), answers `{ storageKeys? }` to remove after the commit, and gives a row that stays the `anonymousId` in place of a deleted ID; a module with rows about a profile answers profiles' `onDeleteProfile` from `@buffcore/modules/profiles` the same way (given `{ profileId, accountId, anonymousId }`); `onRetention.add(fn)` deletes rows older than `days.<kind>` (a product adds its kinds in `privacy: { retention }`). Test them on a made-up family.
   - **Settings, when the product chooses a value:** `settings: z.object({ … })` in the manifest; the product gives the values in `defineApp({ settings: { <key>: … } })`, checked at start; code reads them with `settingsOf(app, '<key>')` from `@buffcore/server`.
   - **Notification kinds, to message people:** `contributes: [notificationKinds.add({ 'notes.ready': { label, to: ['member'], channels: ['email', 'push', 'in-app'], email, text } }`: `to` names who may receive it (`notify` refuses anyone else), `optional: false` is for a message nobody may turn off, `urgent` skips quiet hours, `email` is made with `defineEmail` from `@buffcore/emails`, and `text(data, t)` gives the push and in-app `{ title, body, link }` })]`, with `notificationKinds` from `@buffcore/modules/notifications` (a kind with a mistake stops the app at start). Send with `notify(ctx, kind, to, data, { profileId? })` from `@buffcore/modules/notifications`, in a job; put only IDs and short values in `data`. Each recipient gets their own language.
   - **Services, to offer a provider an Owner turns on** in Admin › Services: `services: { key: { channel: 'email' | 'push', label, fields: { apiKey: { label, secret: true } }, test } }`, with the labels in the admin catalog. Code reads the fields with `serviceConfig(ctx, key)` from `@buffcore/modules/ops`, null while the service is off. Only the email and push channels exist; a new provider is one file in `notifications` or `push`.
   - **Safety flags, to put something in front of a person** (the `safety` feature): `raiseFlag(ctx, { type, severity, subject, ref, … })` from `@buffcore/modules/safety`, with the context of the transaction that found it (`{ ...ctx, em }`), so the flag commits or rolls back with that work. The subject never names a person and `detail` holds no one's words; keep the moment in your own tables and show it with `createAdmin({ inboxKinds: { flag: { Panel } } })` (the `ape-admin-screen` skill). Hear the decision with `contributes: [onFlagDecided.add(fn)]` (`@buffcore/modules/safety`); name "Report a problem" categories in `buffcoreModules(product, { inbox: { reports } })`.
   - **Lines on Operations › Status, if it runs something an operator watches** (a queue, an importer, an outside service): `contributes: [statusChecks.add({ 'notes.queue': { name: 'notes.status.queue', check: async (ctx) => ({ state, value?, lastSeenAt? }), screen: '/notes' } })]` with `statusChecks` from `@buffcore/modules/ops`, the key under the module's key, `name` and the group's name (`notes.name`) in its catalog, `value` formatted with `ctx.t` and `Intl`. It runs on read: answer within 2 seconds, and say `unknown` when nothing tells you, never `healthy` (`docs/ADMIN_SHELL.md`, Status).
   - **Actions machines and agents may call:** the `ape-add-route` skill (`name`, `action`, `mcp: true`, `carries`, `describe`), and the action's default rules (`defaultRules.add(…)` in `contributes`).
   - **Parts of an account, if people get rights on one of its records** (BuffApe: a project; `docs/IDENTITY_ACCESS.md`, rights): `contributes: [parts.add({ project: { description: 'A project of the account', accountOf: async (ctx, id) => accountIdOrNull } })]`, with `parts` from `@buffcore/modules/identity`, and its routes say `part: { type: 'project', param: 'projectId' }` (the `ape-add-route` skill). The product's presets name the actions each role gives: `buffcoreModules(product, { identity: { accountRoles: { builder: ['projects.start_change'] } } })`.
3. Add the module to the composition (`apps/api/src/app.ts`), after BuffCore's modules: `modules: [...buffcoreModules(product, {…}), notes]`. The next step needs it there.
4. Generate the first migration: `pnpm ape migrate create <key> init`, add it to `migrations/index.ts`, review `up` and `down`, then `pnpm ape migrate`, `pnpm ape migrate down`, `pnpm ape migrate` (the `ape-migration` skill).
5. Test it with the test kit: in a product, `createProductTestApp(composition)` from `@buffcore/modules/testing` on the composition in `apps/api/src/app.ts` (seeded, on its own database; `apps/api/src/app.test.ts` is one), and `server.inject({ url, headers: actAs(owner) })` with the seeded `owner` and `member`; in BuffCore, `createTestApp({ modules })` from `@buffcore/server/testing`. Cover every route's roles, validation and audit rows.
6. Check that `pnpm ape manifest` shows it as you expect, then run `pnpm verify`.

Keep it small: a column before a table, a function before a framework. If only one product needs it, it stays in the product. A module written apart from the products that use it, as its own package any product can add, is an extension: the ape-add-extension skill.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.