Skip to main content

Module rules

Module rules 

Source
Expand description

Architecture rules for ctx check.

Rules live in .ctx/rules.toml and are checked against the code intelligence index. The file declares named layers (glob patterns over indexed file paths) plus four kinds of rules:

  • [[rules.forbidden]] – layer A must not depend on layer B
  • [[rules.allowed_dependents]] – only the listed layers may depend on a layer
  • [[rules.limit]] – metric thresholds (fan-in/fan-out/complexity/file symbols)
  • [[rules.no_new_dependents]] – frozen paths that must not gain callers

This module contains the serde model, glob compilation/validation, and pure evaluation functions over a pre-built list of FileDeps, so the rule engine is unit-testable without a database.

Structs§

AllowedDependentsRule
[[rules.allowed_dependents]]: only layers in only may depend on layer.
CompiledRules
A RulesFile with all glob patterns compiled.
FileDep
A cross-file dependency (call/implements/extends/uses edge or resolved import).
ForbiddenRule
[[rules.forbidden]]: dependencies from from to to are violations.
LimitRule
[[rules.limit]]: a metric threshold over symbols or files.
NoNewDependentsRule
[[rules.no_new_dependents]]: frozen paths that must not gain dependents.
RuleGroups
The [rules] table.
RulesFile
Parsed .ctx/rules.toml.
Violation
One rule violation.

Enums§

Endpoint
One endpoint of a dependency: either a resolved symbol or a whole file (file-level endpoints come from import resolution).
Metric
Metric checked by a [[rules.limit]] rule.
RuleKind
Which rule group a violation belongs to.
Scope
Scope of a [[rules.limit]] rule.

Constants§

DEFAULT_RULES_PATH
Default location of the rules file, relative to the project root.
SUPPORTED_VERSION
The rules file format version this build understands.

Functions§

evaluate
Evaluate all rules and return the violations.