Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

backend-module-conventions

БесплатноБез исполняемых скриптовНе проверен

Where Metabase backend code goes and how it reaches the app DB. Covers module layout, the `<module>.db` rule, values in app-DB queries, module config, and…

metabaseот metabase★ 50 742 звезды на GitHub

Об этом скилле

Backend module conventions

This skill decides where a line of backend code lives and how it reaches the app DB. Project AGENTS.md covers the module config keys, nested modules, test commands, and ratchets. When the two disagree, the source tree wins. Read the linter or test that enforces a rule before you trust any prose about it, including this file.

Split a module into standard namespaces

A module is metabase.<module> (OSS, src/) or metabase-enterprise.<module> (EE, enterprise/backend/src/). Most modules split into these namespaces:

Namespace Holds
<module>.core The public API. Other modules call only this (plus anything else listed in the module's :api). Often a potemkin/import-vars facade.
<module>.db Every app-DB query the module makes. See the next section.
<module>.models.* Toucan 2 model definitions: methodical/defmethod t2/table-name, hooks, transforms, and the Writes section with the model's write functions (see backend-model-rules).
<module>.settings defsettings.
<module>.init Requires the namespaces that register things as a side effect: settings, tasks, event handlers, and every model file that implements a multimethod or defines hooks. metabase.core.init or metabase-enterprise.core.init requires it.
<module>.api, or the nested <module>.rest module (:ns-prefix "metabase.<module>-rest", dir <module>_rest/) HTTP endpoints. Domain logic stays in the base module. The .rest child calls the parent's .core.
enterprise/<module> The EE companion of an OSS module. It nests under the OSS module, which exports it automatically.

If a setting, task, event handler, hook or multimethod implementation never takes effect, look for a missing link in the .init chain. A namespace that implements a multimethod of another namespace (defmethod, a Toucan hook, a <feature>/spec) takes effect only once it is loaded, so its module's init.clj requires it; do not rely on some other namespace happening to load it first. A test that depends on such an implementation requires that namespace.

Keep app-DB access in <module>.db

Call Toucan 2 query functions (t2/select*, t2/insert!, t2/update!, t2/delete!, t2/count, t2/exists?, t2/query, ...) and the metabase.app-db.core wrappers (mdb/query, mdb/update-or-insert!, ...) only from metabase[-enterprise].<module>.db. Driver code uses metabase.driver.<driver>.db. Every other namespace calls functions from its own module's db. The kondo hook hooks.metabase.toucan.db-ns reports violations as :metabase/t2-query-namespace. Test files are exempt.

Write db functions in the style of src/metabase/settings/db.clj:

  • Make each function a thin mu/defn that wraps one query and adds no logic. Give it a docstring that says what it returns.
  • Name functions after the domain question (setting-value, delete-setting!), not after SQL.
  • Keep branching, permission checks, and data shaping in the caller. A db function that grows an if belongs somewhere else.
  • Get cross-module data through the other module's .core, not its db. A few modules list their db in :api as legacy exceptions. Don't add more.
  • A db function that inserts, updates or deletes a model is called only from that model's write functions, and it writes only models of its own module. To write another module's model, call that model's write function from its model namespace, which fix-modules-config then records in the owner's :api; a kondo rule reports a Toucan write on a model of another module. Write statements use t2/insert-returning-instances! and its counterparts, so the write function has the rows it publishes.
  • A statement count must not grow with the number of rows: a db function takes the ids or rows of a whole batch.

Values in app-DB queries

Funny SQL (metabase.funnysql.core) compiles every app-DB query and binds every value as a SQL parameter, except a keyword or a keyword-headed vector, which it reads as a column or a function call.

  1. Compare a value that can be a keyword as a string: [:= :perm_type (u/qualified-name perm-type)].
  2. Keep kv-arg style (:engine engine) for a column with a Toucan type transform. The transform turns a keyword into its stored string; in a raw {:where ...} map it is skipped, and the keyword compiles as a column name.
  3. An empty collection in :in compiles to FALSE.

Add app-DB migrations

Follow the app-db-migrations skill (.claude/skills/app-db-migrations/SKILL.md): changesets are version-less, live in year directories like resources/migrations/2026/ (./bin/mage new-migration <name>), and are backported by cherry-picking the same file to each release branch. ./bin/lint-migrations-file.sh enforces the rules. The versioned layout (0NN/ directories, vNN. ids) only holds changesets that already shipped.

Custom migrations (metabase.app-db.custom-migrations*) are exempt

Полный SKILL.md на GitHub

Установить backend-module-conventions в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл backend-module-conventions?

Where Metabase backend code goes and how it reaches the app DB. Covers module layout, the `<module>.db` rule, values in app-DB queries, module config, and pre-handoff checks. Use when adding or moving backend namespaces, writing app-DB queries, or touching module boundaries. Preloaded by every `*-backend-expert` agent.

Как установить скилл backend-module-conventions?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл backend-module-conventions запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить backend-module-conventions с