Architecture Principles
21. Separation of Architecture and Implementation
Definition. Keep architectural decisions independent of implementation details; architecture should outlive any particular technology choice.
Rationale. Technologies change faster than business needs. If architecture is expressed in framework terms, every technology shift becomes an architecture rewrite. Separating them preserves intent across migrations.
Example. Express “orders are validated before persistence” as a rule, not as a Spring interceptor or Rails filter.
Anti-pattern / failure mode. Architecture diagrams that name specific frameworks; business rules embedded in framework callbacks. Review signal: cannot describe the system without naming a framework.
Related. Dependency Rule (#22), Clean Architecture (#24).
22. Dependency Rule
Definition. Source-code dependencies should point toward more stable, higher-level policies; inner layers must not know about outer layers.
Rationale. Stable core policy should not be broken by volatile details like UI or databases. Inward dependencies keep the core testable and reusable across delivery mechanisms.
Example. Domain entities have no imports from the web or persistence packages; adapters depend on domain interfaces.
Anti-pattern / failure mode. Domain code importing ORM entities or HTTP types. Review signal: changing a database forces domain edits.
Related. Clean Architecture (#24), Onion Architecture (#25), Hexagonal (#23).
23. Hexagonal Architecture (Ports and Adapters)
Canonical treatment: Hexagonal architecture. This entry is a summary — see the canonical page for structure, rules, and trade-offs.
Definition. Isolate business logic from external systems through ports and adapters; the domain depends on interfaces, not infrastructure.
Rationale. External systems (DB, messaging, HTTP) change and are hard to test. Ports define what the domain needs; adapters implement it, keeping the domain pure and testable with fakes.
Example. A PaymentPort interface with a StripeAdapter and a FakePaymentAdapter for tests.
Anti-pattern / failure mode. Domain code calling third-party SDKs directly. Review signal: tests that require real network or database.
Related. Dependency Inversion (#5), Clean Architecture (#24), Dependency Rule (#22), canonical Hexagonal.
24. Clean Architecture Principle
Canonical treatment: Clean architecture. This entry is a summary — see the canonical page for rings, dependency rule, and trade-offs.
Definition. Keep business rules independent of frameworks, databases, and delivery mechanisms; the core should be testable without its surroundings.
Rationale. Frameworks and databases are details; business rules are the value. Isolating them lets you test rules in milliseconds and swap details freely.
Example. Use cases and entities in a core package with no framework imports; frameworks live in outer adapter packages.
Anti-pattern / failure mode. Business logic scattered across controllers and ORM entities. Review signal: cannot run business tests without booting the framework.
Related. Hexagonal (#23), Onion (#25), Dependency Rule (#22), canonical Clean.
25. Onion Architecture
Canonical treatment: Onion architecture. This entry is a summary — see the canonical page for rings and dependency rules.
Definition. Organize dependencies toward the application core; each layer depends only on the layers inside it.
Rationale. Concentric layers make the direction of dependency explicit and prevent outer concerns from leaking inward. The core remains stable and framework-free.
Example. UI and infrastructure depend on application services, which depend on domain; domain depends on nothing.
Anti-pattern / failure mode. Inner layers referencing outer ones; circular dependencies between layers. Review signal: domain package importing application or infrastructure.
Related. Clean Architecture (#24), Dependency Rule (#22), canonical Onion.
26. Domain-Driven Design (DDD)
Definition. Model software around business domains and their language; align code structure with the problem domain.
Rationale. Software that mirrors the domain is easier for experts and developers to discuss and evolve. Ubiquitous language reduces translation errors between business and code.
Example. Name classes Order, Shipment, Invoice after domain concepts, with methods like ship() rather than updateStatus(3).
Anti-pattern / failure mode. Anemic domain models with logic in services; generic “Manager”/“Handler” classes disconnected from domain terms. Review signal: developers and domain experts use different vocabularies.
Related. Bounded Context (#27), High Cohesion, Low Coupling (#28).
27. Bounded Context Principle
Definition. Define explicit boundaries for domain models and their meanings; keep each model consistent within its own context.
Rationale. The same word means different things in different parts of a business (“Customer” in sales vs. billing). Explicit boundaries prevent one model from being stretched to mean everything.
Example. Separate Sales.Customer and Billing.Customer models, each with its own attributes, integrated via events or translation.
Anti-pattern / failure mode. A single shared Customer entity used by every module, growing fields for all of them. Review signal: a core entity with dozens of optional fields used by different teams.
Related. DDD (#26), Modularity (#29).
28. High Cohesion, Low Coupling
Definition. Keep related responsibilities together while minimizing dependencies between modules.
Rationale. Cohesive modules are easy to understand and change; low coupling means a change in one module rarely forces changes in others. Together they make systems maintainable.
Example. Group all order-pricing logic in one module instead of spreading it across checkout, invoice, and report modules.
Anti-pattern / failure mode. “Shotgun surgery”: one feature change touches many modules; or “feature envy” where a module constantly uses another’s data. Review signal: changes that ripple across the codebase.
Related. Single Responsibility (#1), Modularity (#29).
29. Modularity Principle
Definition. Divide systems into independently understandable and maintainable components with clear, narrow interfaces.
Rationale. Modules limit the scope of change and enable parallel work. Narrow interfaces reduce the chance that a change in one module breaks others.
Example. A payments module exposing only charge() and refund(), hiding its provider details.
Anti-pattern / failure mode. “Big ball of mud”: no clear module boundaries; everything depends on everything. Review signal: cannot build or test a component in isolation.
Related. High Cohesion, Low Coupling (#28), Bounded Context (#27).
30. Stable Dependencies Principle (SDP)
Definition. Depend in the direction of stability; unstable modules may depend on stable ones, not the reverse.
Rationale. If a stable module depends on an unstable one, the stable module becomes fragile. Directing dependencies toward stability keeps core code robust.
Example. A volatile UI module may depend on a stable domain module, but the domain must not depend on the UI.
Anti-pattern / failure mode. A core library depending on a rapidly changing plugin or experimental module. Review signal: stable components break when volatile ones change.
Related. Stable Abstractions (#31), Dependency Rule (#22).
31. Stable Abstractions Principle (SAP)
Definition. Stable components should be abstract; high stability pairs with high abstraction to allow safe reuse.
Rationale. A stable but concrete component cannot evolve without breaking dependents. Making stable components abstract lets them be extended without modification.
Example. A stable PaymentGateway interface with concrete adapters that can change freely.
Anti-pattern / failure mode. A stable, concrete utility class that everyone depends on and that cannot be changed safely. Review signal: “don’t touch that file” folklore.
Related. Stable Dependencies (#30), Open/Closed (#2).
32. Common Closure Principle (CCP)
Definition. Group components that change together; a change to one component should not force changes scattered across many modules.
Rationale. When related changes land in one place, releases are simpler and conflicts fewer. Scattered changes increase coordination cost and risk.
Example. Put all tax-calculation code in one module so a tax-rule change touches one place.
Anti-pattern / failure mode. A single feature change requiring edits across ten modules in different packages. Review signal: PRs that touch many unrelated files.
Related. Common Reuse (#33), Single Responsibility (#1).
33. Common Reuse Principle (CRP)
Definition. Group components that are reused together; avoid forcing consumers to depend on things they do not use.
Rationale. If components are always used together, package them together; if not, split them so consumers take only what they need. This reduces unnecessary dependencies.
Example. Don’t bundle a rarely used reporting helper into the core domain package that every service depends on.
Anti-pattern / failure mode. A “utils” package that every module imports but each uses only a fraction of. Review signal: transitive dependencies pulling in large unused code.
Related. Common Closure (#32), Interface Segregation (#4).