Enforce custom architectural boundaries, companion test coverage, naming conventions, file size caps, prohibited regex tokens, and dependency restrictions in pure declarative YAML or JSON with zero arbitrary code execution.
01. Rule Packs & 4-Tier Inheritance Hierarchy
ELCODE Forge evaluates rules deterministically across a 4-tier precedence hierarchy: 1. Built-in Defaults < 2. Extended Packs < 3. Custom Local Rules (.eforge/rules/*) < 4. Per-Rule Overrides (eforge.config.yaml).
Projects without an explicit extends: list automatically extend the recommended pack.
| Built-in Pack Name | Engineering Focus | Included Rules & Thresholds |
|---|---|---|
| recommended | Standard Baseline | arch/no-direct-db-in-ui, arch/no-circular-dependencies, quality/require-service-tests, quality/max-file-lines (300 lines) |
| strict | Elevated Discipline | Critical architecture boundaries, 250-line file limit, strict test companions, and unpinned dependency version prevention |
| security | Code Hardening | Prohibits eval(), child_process.exec(), debugger statements, dangerouslySetInnerHTML, and deprecated packages |
| clean-architecture | Hexagonal / Onion Layers | Enforces 4-tier hexagonal boundaries (ui-no-infra, domain-pure, infra-no-ui, ui-no-db) |
02. Declarative Rule File Schema (.eforge/rules/*.yaml)
Initialize a starter rule file via eforge rules init. All rule files are path-guarded via resolve_safe_path to prevent directory traversal outside the repository root:
version: 1
pack: team-custom-rules
description: Organization-specific architectural and supply-chain rules
rules:
- id: arch/no-direct-db-in-ui
name: No Direct DB Imports in UI Layer
category: architecture # architecture (arch) | quality | security (sec) | dependencies (deps)
severity: critical # critical | high | medium | low | info
confidence: certain # certain | high | medium | low (default: high)
enabled: true # true | false (default: true)
description: "UI components must not import database clients or ORM drivers directly."
remediation: "Route data access through application services in src/services/."
matcher: # (also accepts alias 'match:')
type: forbidden_imports
files:
- "src/ui/**"
- "src/components/**"
forbidden:
- "src/db/**"
- "@prisma/client"
- "pg"| Field | Required | Validation Rule |
|---|---|---|
| id | Yes | Must strictly match <category>/<slug> where category is arch, quality, security, or deps. |
| name | Yes | Non-empty human-readable rule title. |
| category | Yes | architecture (alias arch), quality, security (alias sec), or dependencies (alias deps). |
| severity | Yes | critical, high, medium, low, or info. |
| confidence | Optional | certain, high (default), medium, or low. |
| description | Yes | Non-empty diagnostic explanation included in every emitted Finding. |
| remediation | Optional | Actionable remediation steps shown in terminal cards, SARIF help text, and the dashboard. |
| matcher / match | Yes | One of the 6 deterministic matcher objects documented below. |
03. The 6 Deterministic Rule Matchers
1. forbidden_imports
Layer BoundariesRequires forbidden (non-empty list of restricted module paths or package names) and optional files globs.
matcher:
type: forbidden_imports
files: ["src/domain/**"]
forbidden: ["src/infra/**", "src/ui/**", "axios"]2. required_companion
Test CoverageRequires companion pattern. Supports {name} interpolation of the source file stem.
matcher:
type: required_companion
files: ["src/services/**"]
companion: "tests/{name}.test.ts"3. file_naming
Naming DisciplineRequires convention (kebab-case, snake_case, camelCase, PascalCase, or wildcard *Controller.ts).
matcher:
type: file_naming
files: ["src/controllers/**"]
convention: "*Controller.ts"4. file_size
Cohesion & SizeRequires at least one of max_lines (line count limit) or max_bytes (byte size limit).
matcher:
type: file_size
files: ["src/**"]
max_lines: 300
max_bytes: 500005. regex_pattern
Banned TokensRequires pattern. Scans path-guarded source files for prohibited tokens or unsafe API calls.
matcher:
type: regex_pattern
files: ["**/*.ts", "**/*.js"]
pattern: "eval\s*\(|debugger"6. dependency_restriction
Supply-ChainRequires disallowed_packages (non-empty list of prohibited packages or wildcard-version).
matcher:
type: dependency_restriction
disallowed_packages:
- "left-pad"
- "moment"
- "wildcard-version"04. CLI Rules Workflow & MCP Querying
# 1. Generate starter .eforge/rules/custom-rules.yaml with all 6 matchers
eforge rules init
# 2. Validate rule YAML/JSON syntax and schema without scanning (exits 2 on error)
eforge rules check
eforge rules check .eforge/rules/custom-rules.yaml
# 3. Inspect active merged rule catalog (built-in + packs + custom + overrides)
eforge rules list
eforge rules list --category architecture --enabled-only --format markdown
# 4. Run full repository scan evaluating all active rules
eforge scan --fail-on high05. Topology & Boundary Inference (eforge rules infer)
ELCODE Forge analyzes the polyglot import graph using graph-theoretic metrics to automatically discover your project's architectural structure, layer instability, and boundary rules:
Classifies modules into UI, Service, Domain, Persistence, Infrastructure, and Shared layers using path semantics and coupling metrics.
Computes Martin's metric I = FanOut / (FanIn + FanOut) to verify that stable abstractions do not depend on unstable modules.
Identifies Clean / Hexagonal, Layered N-Tier, or Feature-Sliced architectures and recommends tailored forbidden_imports rules.
# Inspect inferred archetype and layer instability
eforge rules infer
# Export inferred boundary rules directly to rules pack
eforge rules infer --write
# Or initialize a new project with automatic inference
eforge init --infer06. Surgical Auto-Fix & Transactional Rollback (eforge fix)
Fix violations deterministically with byte-for-byte post-write BLAKE3 verification and atomic transaction records in .eforge/tx/<tx_id>/:
# 1. Preview codemods with unified diff previews without touching disk
eforge fix --dry-run
# 2. Apply fixes atomically with pre-write file backups in .eforge/tx/
eforge fix --apply
# 3. Scope fixes strictly to a specific rule ID
eforge fix --apply --rule quality/max-file-lines
# 4. Rollback transaction cleanly if needed
eforge fix --rollback