Dependency Rules

CODERU defines module structure and access rights through four reserved package names. Each name carries its own access semantics, enforced automatically at build time.

What is a Module?

In the CODERU context a module is a Java package together with all classes directly belonging to it and all its sub-packages (sub-modules). The package hierarchy therefore directly mirrors a module hierarchy.

A dependency from module A to module B exists whenever a class in A holds a static reference to a class in B — through a method call, inheritance, a field type, a parameter type, etc.

BASIS 1. Basic Rule

A module may only depend on its own direct sub-modules. Access to sibling modules or ancestor modules is not permitted.

Transitive access: If module A has access to module B, it also has access to all descendants of B (children, grandchildren, …) — except impl sub-modules (see IMPL rule).

Access right inheritance: Special access rights granted or revoked by the IMPL, COMMON, FACTORY, and API rules are inherited by all descendant modules. If module A gains access to module B through the COMMON rule, every sub-module of A also has that access.

In the diagram:

Basic Rule diagram

IMPL 2. IMPL Rule — private implementation

Only the direct parent module may access an impl package and all of its sub-packages. All other modules — including the grandparent — are excluded.

This enforces the Information Hiding principle (Parnas, 1972) at the package level. Move any class that is an internal implementation detail into an impl sub-package and it becomes invisible to the rest of the codebase.

In the diagram:

Example: If extractor.csv.CsvParser is a private detail of extractor, move it to extractor.impl.csv.CsvParser. The grandparent module importer can no longer reach it.

IMPL Rule diagram

COMMON 3. COMMON Rule — shared utilities

All sibling modules of a common package (and their descendants, by inheritance of access rights) may access it. Modules in other parts of the tree are not granted this access.

The position of a common package in the hierarchy determines its reach: a top-level common is accessible everywhere; a deeply nested common is accessible only within its immediate sibling subtrees.

In the diagram:

Use case: Shared utility classes (parsers, converters, value objects) that must be reused across sibling modules but should not be exposed globally.

COMMON Rule diagram

FACTORY 4. FACTORY Rule — wiring / DI

A factory module and all its descendants may access all sibling modules, including impl siblings that are otherwise restricted.

Think of factory as the counterpart to common: while every sibling can read common, factory can read every sibling.

In the diagram:

Use case: Dependency-injection / wiring code that must instantiate concrete implementation classes without leaking them to the rest of the module. The factory knows everything; callers only see the api.

FACTORY Rule diagram

API 5. API Rule — public interface

An api package is accessible from anywhere in the program — subject to the following restrictions:

In the diagram:

Use case: Independently deployable functional modules (adapters, domain modules, reusable toolboxes) that need to be consumed from across the entire application.

API Rule diagram

Rules at a glance

Package name Who can access it? What can it access?
impl Direct parent only (+ sibling factory) Own sub-modules
common All siblings (and their descendants) Own sub-modules
factory Parent only (like any normal package) All siblings including impl
api Everywhere (with cycle-prevention restrictions) Own sub-modules
any other name Parent module only Own direct sub-modules