Est.

Module Boundary Enforcement in Large Codebases

Linters, compilers, and CI gates can enforce boundaries that reviewers and agents miss.

Sponsored by Graphide

Shipped by Agents Editors
· 9 min read · Updated
Cover illustration for “Module Boundary Enforcement in Large Codebases”
Software Architecture · October 17, 2026 · 9 min read · 2,048 words

Module boundary enforcement in large codebases turns decisions about the architecture into rules that the code must follow. Documentation, convention, and review cannot preserve those decisions at the speed of modern development, especially when agents write the code. Boundaries survive when linters, language and runtime controls, and CI gates enforce them mechanically, while a live architectural model exposes harmful changes that remain legal.

Why conventions alone cannot hold module boundaries as codebases grow

A team decides that one module may use another only through its public interface, but never encodes that decision. A downstream module then imports an upstream implementation directly. The import compiles, the tests pass, and the pull request ships because nothing evaluates whether the dependency is allowed. The resulting circular entanglement becomes visible only when it blocks another team’s work. By then, the architectural decision and the code disagree.

This failure does not require careless engineers. A reviewer reading a diff sees the changed files and may miss the cross-module coupling those changes introduce. As the codebase grows, its dependency graph becomes too large for a person to keep in mind, and the growing review queue leaves each reviewer with more code to judge. Even careful design leaves a boundary at risk when someone has to spot every violation to enforce it. The missing mechanism is a check against the declared architecture.

Shopify demonstrates that such checks are achievable at scale without making this an argument for microservices. Shopify developed Packwerk to enforce boundaries between packages of Ruby files in its Rails monolith through static analysis. The distinction is between decisions that the development process checks and decisions it merely asks people to remember.

How AI agents accelerate boundary decay specifically

Agents intensify this failure because their output can look architecturally sound while ignoring the architecture. A generated service class may have clean syntax and passing tests yet violate a bounded context defined only in a document. Its functional plausibility conceals the missing constraint. Compilation and test success show only that the checks being run have passed, leaving respect for an unencoded boundary unverified.

Prose instructions do not reliably close that gap. Constraint decay describes how an agent’s correctness on architectural requirements degrades as those requirements accumulate in its instructions. A controlled study gave the same hexagonal/ports-and-adapters specification to three models and found sharply different results. One model violated the declared architecture on four of five runs, while another violated it on zero, yet both produced code that compiled.

The review queue compounds the problem. AI-heavy periods produce more and substantially larger pull requests, which wait longer to be picked up despite being created faster. Shopify’s VP & Head of Engineering Farhan Thawar acknowledged that human PR review “is now becoming a big bottleneck”, even with sophisticated modular enforcement in place. Research also found that reviewers felt better about approving agent-generated code even though it had more redundancy than human-written code, which the authors linked to technical debt that had built up unseen. The human backstop is becoming less dependable precisely when more code reaches it, so architectural constraints cannot rest on reviewer confidence.

What a boundary worth enforcing actually looks like before any tooling touches it

Mechanical enforcement needs a rule it can evaluate. An allowed import set, an ownership declaration, or an interface contract supplies that rule, whereas a design principle still requires interpretation. Each module thus needs a clear public contract that lists the types, interfaces, or entry points other modules may use. Its implementation must be hidden from unrelated modules rather than merely marked as something they should avoid.

Domain-Driven Design bounded contexts provide the conceptual input, but structural artifacts make those contexts enforceable. These artifacts include package tags, module descriptors, access modifiers, and schema ownership declarations. In an Nx monorepo, tags such as scope:data-access and domain:catalog turn a library’s role into machine-readable facts. A configured ESLint rule can then evaluate those facts against its imports, relieving a reviewer of the need to infer intent.

FullWorth’s modular-monolith architecture issue makes the contract concrete. It specifies explicit public interfaces, hidden implementation, owned persistence models, authorization at every user-data entry point, and validated DTO/event boundaries that exclude shared mutable internals. Negative tests must also prove that forbidden cross-module access is still blocked. Persistence belongs in this definition because module B reading a table owned by module A bypasses the boundary even when application imports look correct. FullWorth tracks direct cross-owner DbSet reads as violations to freeze and remove incrementally.

Spelling this out takes work, but leaving ownership unclear makes it harder to fix the code later. Precision need not arrive through a rewrite. FullWorth’s ratchet approach freezes violations and removes them one by one, with boundary checkpoints enforced in CI.

Linter-layer enforcement — catching violations before code is committed

Linting gives the fastest automated feedback on import boundaries and can catch violations before the code goes into version control. Nx’s @nx/enforce-module-boundaries ESLint rule analyzes imports across a monorepo against tag-based dependency constraints. When a library imports from a library its tags do not permit, the lint check fails. The decision follows the declared rule rather than a reviewer’s interpretation of the change.

In the Nx Angular pattern, these constraints prevent a feature library from importing a feature library in another domain. They also prevent a data-access library from importing a feature library, which would invert the intended layers. A domain-scoped library must go through an explicit shared intermediary to depend on a sibling domain.

When two domains need the same data type, the repair is not to loosen the constraint. The shared type can move to a utility library tagged domain:shared, which both domains are allowed to read. IntelliJ IDEA’s Modulith inspections bring similar feedback into Java/Spring editing by underlining boundary violations as code is typed.

That speed does not make linting complete. An import rule evaluates only the import graph. Access through a shared mutable object, a global singleton, or a direct database read can bypass its view of the boundary entirely.

Compiler- and runtime-layer enforcement — making violations structurally impossible

Language visibility can make forbidden access impossible to compile, while a linter can detect it. Package-private or internal visibility restricts which code may name an implementation type. Java, C#, and Kotlin have forms of this control. Where the language itself does not constrain import resolution in the same way, as in TypeScript or Python, linter and CI checks carry more of the enforcement burden.

Spring Modulith 2.0 GA, released in November 2025 on Spring Boot 4, maps packages to modules and treats types as internal if they fall outside a module’s public API. Its boundary verification fails at test time, or optionally at startup, rather than forcing a compiler error for an otherwise public Java type. These checks are architectural fitness functions that run as build tasks. They enforce a logical boundary that Java visibility alone may not express.

Spring Modulith also supports module-scoped integration tests, module-specific database migrations, and a transactional event publication registry. Its C4-style documentation is generated from code, allowing the boundary declaration to serve both verification and documentation. These capabilities keep the declared module structure connected to how the system is tested and described.

Giving each module its own PostgreSQL schema and login role, with privileges on that schema alone, makes unauthorized cross-module access a runtime database error. Cross-module reads then go through an explicit view or API. This closes the persistence gap that import checks leave open and gives concrete force to module ownership.

CI gate enforcement — the layer that cannot be bypassed locally

Local checks provide feedback, but CI provides uniform application. A developer or agent can create a commit without running the configured linter or build checks locally. CI evaluates the submitted artifact regardless of the author’s editor, environment, or workflow. When an architecture failure blocks merging, a missed local check no longer becomes an accepted dependency.

Cloudflare’s CI-native review orchestration in 2026 shows that automated review at this stage is already a production practice at scale. Opening a merge request launches up to seven specialized reviewers covering security, performance, code quality, documentation, release management, and compliance with its internal Engineering Codex. Risk tiering routes trivial changes to two agents, lite changes to four, and full-tier changes to all seven. This is evidence of investment in the CI gate, with agent review distinct from deterministic boundary checks. The architectural rule still needs a test with a clear pass-or-fail result.

Pre-generation constraints complement that gate by giving an agent the declared architecture before it writes code. Embedding boundary rules in its context reduces violations, but constraint decay prevents those instructions from replacing post-generation validation. The build must judge the result independently of how clearly the agent was instructed. That separation also keeps the same standard for human-written and generated changes.

The hardest decision is organizational. The constraint loses its value when a team relaxes it whenever compliance becomes inconvenient. A CI check that can be overridden by a comment or a flag is a suggestion with extra steps.

What the enforcement stack does not catch, and what to do about it

An unconditional gate is necessary, but it cannot establish that every allowed change is architecturally healthy. Import and access checks reject forbidden relationships. They do not necessarily reject duplicated logic, oversized methods, or a permitted dependency chain that increases global complexity. A change can satisfy its module’s interface while making the whole system harder to maintain.

Research into agent-generated code identifies this distinction in the code’s “machine signature”. More capable models introduce procedural bloat, including Long Method, in algorithmic tasks, while complex systems show increased architectural coupling. These patterns need not violate an import rule, a compiler restriction, or an encoded fitness function.

A published large-scale case study in 2026 describes an agent dismantling a core architectural invariant across 189 files without a test oracle or human code review. The authors raise governance questions about that change. A gate limited to module boundaries would not have caught an invariant spanning the full codebase.

The complementary capability is a live architectural model represented as a dependency graph. That map shows how changes affect the structure across files as well as whether each file’s imports pass. Developers can then examine legal changes that duplicate behavior or deepen coupling while mechanical checks continue to reject forbidden access.

A practical sequence for adding enforcement to a codebase that has none

Start by writing down the module structure as it stands and where it has boundary violations. This establishes a baseline rather than pretending that an existing codebase already conforms to its intended design. Next, use tags or module descriptors to state who owns each library or package. Identify each public API and mark the remaining implementation as internal so automated rules have something definite to evaluate.

Then introduce linter checks in warn mode to expose the violations before switching new violations to errors. Freeze the existing set and enforce zero new violations in CI. At this point, the team already has meaningful protection without first repairing every dependency or undertaking a rewrite. FullWorth’s ratchet pattern applies this approach to module, controller, and data-ownership boundaries.

With that baseline protected, add persistence ownership by identifying which module owns each table or schema. Send cross-module reads through explicit contracts or views, and keep track of direct cross-owner reads so they can be removed. Add these checks to the unconditional CI gate as they become enforceable, and run the boundary checks on every pull request with no way to override them. Each repaired module tightens the baseline rather than resetting the project around an all-or-nothing migration.

Finally, give agents the same declared boundary rules before they start writing code. This reduces avoidable failures while leaving CI responsible for accepting or rejecting the result. Existing violations can then be eliminated module by module while new work proceeds against a stable constraint. The sequence can proceed without a dedicated architecture sprint or a whole-system rewrite, but it needs a gate whose decisions still hold when agents write the code, and teams can run that gate through Graphide CI, which runs existing GitHub Actions jobs on faster runners with warm caches, splitting long test steps only where a check shows every result stays the same, so a failing boundary test still fails the job.

Sources

  1. Architecture Without Architects: How AI Coding Agents Shape Software Architecture

More in Software Architecture