← Graph

Enforce domain boundaries dynamically via ActiveRecord hooks

takeaway 1 connections

Audience-member technique shared in Q&A. Packwerk enforces package boundaries statically but can't catch dynamic object-to-object calls (`has_many`, `belongs_to`, inheritance). Workaround: extend ActiveRecord save/update/etc. at runtime so that if one engine tries to mutate a record owned by another engine without going through that engine's public service API, the change is rejected with an exception. Enabling the check only in the test environment is enough to detect violations in CI; production doesn't need it.

type
recommendation
takeaway Enforce domain boundaries dynamically via ActiveRecord hooks
from_talk
Audience-contributed technique in the Q&A for Packwerk's dynamic-calls blind spot.

Provenance