@eventcatalog/fitness

中文文档
0.1.2发布于 2026/11/10MITTypeScriptESM + CJS构建来源已验证近 30 天下载 5783

Write architecture fitness functions for EventCatalog and run them locally or in CI

原始使用文档
文档目录12 节
  1. @eventcatalog/fitness
  2. Installation
  3. Write a fitness function
  4. Where fitness functions live
  5. The context
  6. Violations
  7. Run them
  8. In CI
  9. The report
  10. Trust
  11. Programmatic use
  12. Documentation

@eventcatalog/fitness

Architecture fitness functions for EventCatalog. Write your architecture rules in TypeScript, run them against your catalog locally or in CI, and get a report of what breaks them.

You decide what a healthy architecture looks like. EventCatalog gives each rule the catalog to inspect, runs it and reports the results.

Fitness functions check the architecture your catalog documents. They don't inspect your running systems.

Installation

npx eventcatalog fitness check runs fitness functions without installing anything else. Install the package for types and editor support:

npm install --save-dev @eventcatalog/fitness

Write a fitness function

A fitness function is the default export of a *.fitness.ts file in a fitness/ folder:

// fitness/events-have-owners.fitness.ts
import { defineFitnessFunction } from '@eventcatalog/fitness';

export default defineFitnessFunction({
  id: 'events-have-owners',
  name: 'Every event has an owner',
  severity: 'error', // or 'warning', which is reported without failing the check

  async run({ catalog }) {
    const events = (await catalog.getEvents({ latestOnly: true })) ?? [];

    // One violation per problem; an empty array means the rule passed
    return events
      .filter((event) => !event.owners?.length)
      .map((event) => ({
        message: `${event.name} has no owners`,
        resources: [{ type: 'event', id: event.id, version: event.version }],
        suggestion: 'Add the team responsible for the event to its owners.',
      }));
  },
});

Where fitness functions live

my-catalog/
├── fitness/                                  # Global rules: no `resource`
│   ├── events-have-owners.fitness.ts
│   └── naming/message-names.fitness.ts       # Folders inside fitness/ are fine
└── domains/
    └── Orders/
        ├── index.mdx
        └── fitness/
            └── domain-boundaries.fitness.ts  # `resource` is the Orders domain
  • Only *.fitness.ts files are run. Other files (for example shared helpers) can be imported by fitness functions.
  • A fitness/ folder inside a resource's folder (a domain, system, service, event, command, query, channel, flow, entity, data store, data product, ADR or diagram) gives its functions that resource as resource. A folder inside versioned/<version>/ gives that version.
  • The location sets resource, not what a function can see: every function can query the whole catalog.
  • *.fitness.ts files outside a fitness/ folder are not run, and are reported as diagnostics.

The context

run({ resource, catalog }) gets:

NameDescription
resourceThe resource the function sits alongside, with its type (domain, service, event, container, …), id, version and frontmatter. undefined for global functions.
catalogRead-only access to the catalog: the read methods of the EventCatalog SDK, such as getEvents, getService, getGraph and getOwnersForResource.

catalog has no methods that write to the catalog, and each call returns a copy, so changing what it returns doesn't change what other calls or functions see.

Violations

type FitnessViolation = {
  message: string;
  resources?: { type: string; id: string; version?: string }[]; // linked from the violation in EventCatalog
  details?: string;
  suggestion?: string;
};

Resources are matched to the catalog. References that don't match a resource are kept in the report, marked resolved: false.

Run them

npx eventcatalog fitness check
# or, without @eventcatalog/core installed
npx @eventcatalog/cli fitness check
OptionDescription
--output <path>Where to write the report, relative to the catalog (.eventcatalog/fitness/results.json)
--format <format>text (default) or json
Exit codeWhen
0Every function passed, or only warned
1A function found error-severity violations, or could not be evaluated
2The check could not run (for example, the catalog directory doesn't exist)

A function that throws, returns something that isn't a list of violations, or can't be loaded is reported as an error, separately from violations.

In CI

# .github/workflows/fitness.yml
name: Architecture fitness
on: pull_request
jobs:
  fitness:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npm ci
      - run: npx eventcatalog fitness check

The report

Each run writes .eventcatalog/fitness/results.json: the time, the catalog's git commit, a summary and every function's status (passed, warning, failed or error), resource, violations and errors.

Trust

Fitness functions are code from your catalog, run with the same access as any other script in your project. Only run fitness functions you trust, locally or in CI. EventCatalog never runs them in the browser or on page requests.

Programmatic use

import { evaluateFitness, formatFitnessReport, getFitnessExitCode } from '@eventcatalog/fitness';

const report = await evaluateFitness({ dir: './my-catalog' });
console.log(formatFitnessReport(report));
process.exitCode = getFitnessExitCode(report);

Documentation

See the EventCatalog documentation for more.

版本与发布记录

@eventcatalog/fitness 共发布 5 个版本,首次发布于 2026/10/19;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.2latest2026/11/103 天前
0.1.12026/10/2321 天前
0.1.02026/10/1925 天前
0.0.12026/10/1925 天前
0.0.0-stage2026/10/1925 天前

关于 @eventcatalog/fitness 的常见问题

@eventcatalog/fitness 是什么?

Write architecture fitness functions for EventCatalog and run them locally or in CI

如何安装 @eventcatalog/fitness?

在项目目录运行 npm install @eventcatalog/fitness,或使用 pnpm add / yarn add / bun add。

@eventcatalog/fitness 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@eventcatalog/fitness 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@eventcatalog/fitness 可以商用吗?

@eventcatalog/fitness 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@eventcatalog/fitness 的下载量有多少?

根据 npm 官方下载统计,@eventcatalog/fitness 在 2026/10/14 – 2026/11/12 这 30 天内被下载 5,783 次,日均约 193 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@eventcatalog/fitness 还在维护吗?

最新版本 0.1.2 发布于 2026/11/10(3 天前);至今共发布 5 个版本,其中过去 12 个月发布了 5 个;首次发布于 2026/10/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。