ARC-39Recommended
Keep internals private
Each module exports only what its callers need. Everything else stays private, so it can change without breaking anyone.
How to do it
Mark helpers private or keep them out of the module's public entry file. Give each package one public entry point. Callers never import from another module's internal folders. Test each module through the same public entry, as Test behaviour through the public interface says.
Examples
JavaScript example
// Bad: callers reach into the module's internals
import { formatLine } from '../invoices/internal/format.js';
// Good: one public entry point, internals stay hidden
import { renderInvoice } from '../invoices/index.js';
Python example
# invoices/__init__.py: the package's one public entry point
from .render import render_invoice
__all__ = ["render_invoice"]
# Callers write: from invoices import render_invoice
# Helpers in invoices/_format.py start with an underscore and stay private
How to check
A tool fails on unused exports and on imports of another module's internals. Examples are knip or vulture for unused code, and dependency-cruiser for JavaScript, Deptrac for PHP or import-linter for Python for internal imports.
Sources
Related rules
- TST-4 Test behaviour through the public interface in Testing
- ARC-74 Give each bounded context its own model and words in Clean code and architecture
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/architecture/coupling/private-internals">Agent Wranglers clean code and architecture playbook</a>. In code you write, add a comment next to it with the same link.