ConceptChapter I · Principles · Building block 4 of 6

Module boundaries

A module boundary encapsulates data and rules of a business responsibility. Other modules work with her through published contracts. The core is information hiding according to David Parnas: A module hides the decisions that are likely to change behind a stable contract.

  1. Public contractThe only door in the module.
  2. InternaRules and data remain hidden.
  3. EnforcementA limit only applies if infringements are noticeable.

Context

Why this is important

Without an enforced limit, each module accesses the data of each other. Rules such as the inventory check can then be circumvented, and changes are drawing wide circles. The direction of dependencies deals with dependency inversion.

This building block explains boundaries within an application. For scopes of different specialist models, see Bounded Context.

At a glance · Module with public contract

Other modules reach rules and data only through the published contract; the internals stay hidden.
Shop example · Building blocks and relationships

Public boundary of the storage module

In the modular shop, the storage module has stocks and reservations. The ordering module may reserve stock, but does not directly change a storage table.

This is how you read the picture

  1. Public contract The box storage contract in the area of storage · public.
  2. Interna The boxes Inventory rules and storage data in the area of storage · internally.
  3. Enforcement The table: Stages 1 up to 5, from agreement to own service.
Directed contracts allow business cooperation while internal data remains in stock.
Read diagram as text
  • Order: Requests reservation (Shop application)
  • Storage contract: Reserve, release (Warehouses · Public)
  • Inventory rules: Check and modify (Warehouse · internal)
  • Storage data: stock and reservation (Warehouse · internal)
  • Order → Storage contract: Reserved
  • Storage contract → Inventory rules: Applying the rule
  • Inventory rules → Storage data: Stock change
Directed contracts allow business cooperation while internal data remains in stock.

How hard is the border?

How hard is the border?
StageThis is how the border is drawn.Protects againstCosts
1 · AgreementDocument: Do not use storage tables directlyNothing bindingAlmost nothing
2 · VisibilityInternals are not public in the code (packages, modules)Inadvertent callsLittle
3 · Architectural testBuild breaks when accessed to Lager-Interna (ArchUnit, Spring Modulith)All code accessesCare of the tests
4 · Database rightsown scheme, order without rights on stock tablesSQL accesses past the codeScheme management
5 · Own serviceWarehouse operates as a separate serviceEverything except the contractOperation, network, distributed errors
The higher the level, the more accesses the border protects – and the more it costs. In modular monoliths, stages are usually sufficient 2 up to 4; Stage 5 It is an architectural decision with a price.

Benefits & limitations

Helps if:

  • Multiple teams or parts access common internal structures and require clear ownership.
  • Internal changes should force consumers to adapt as rarely as possible.

Boundaries

  • An unenforced boundary gradually erodes: a 'temporary' shortcut becomes permanent (Architectural Erosion). Choose at least one level from the table above that exposes violations.
  • Poorly placed boundaries are costly. Overly fine-grained modules require substantial contract maintenance, and moving boundaries later is difficult. Start with coarser modules and split them according to real change patterns (Cohesion).

In practice

  1. Define ownership and responsibility. Identify the data and rules the module owns. This makes it clear who approves changes to them.
  2. Design the public contract. Describe business operations, permitted inputs and error states. Align dependencies with this contract as described in Dependency Inversion.
  3. Enforce access restrictions technically. Limit direct use of internal data and test the contract from the consumers' perspective. Also check whether the module has sufficient Cohesion.
  4. Compare the value stream with the module boundary. Follow a new delivery option from customer need to a usable shop feature. Examine shared rules, required knowledge and handovers; group related responsibilities and expose necessary coordination across module boundaries.
Read the detailed explanation

A module has a defined responsibility and controls how other building blocks use its capabilities. Its contract describes permitted operations and results, while internal data structures remain hidden. Coupling examines effects across the boundary; Dependency Inversion aligns source code dependencies with stable contracts.

A boundary is effective only when actual access respects it. Import rules, database permissions and contract tests can reveal bypasses. Granularity follows business coherence: oversized modules conceal independent responsibilities; overly small modules add unnecessary handovers and coordination.

An Independent Value Stream runs from a business need to a usable result. Shared terminology, rules and change patterns help determine module boundaries: do pricing and payment really belong together, or do they merely share the broad label 'money'? Then examine team ownership and cognitive load. Team Topologies provides a complementary organisational perspective.

Check your understanding

Test yourself in three stages

  1. ReadingCheck in the picture

    What operations does the storage contract offer according to the picture?

    View the solution with justification

    Reserve and release.

  2. ApplyingTransferred to a new situation

    A developer accesses the warehouse table directly via SQL, the architectural test remains green. Which stage is missing?

    View the solution with justification

    Stage 4, Database rights. The architecture test only checks code and does not see SQL accesses past the code.

  3. EvaluateWeighing an alternative

    The ordering module is intended to write reservations directly into the storage data in order to save a call. How do you rate that?

    View the solution with justification

    This saves an intermediate step. For this, the stock rules would be circumvented and any change in the storage data would affect the order. The border protects rules and data in the warehouse.