OC-301d · Module 2
Module Composition
3 min read
Composition is the architecture of building complex capabilities from simple modules. A research pipeline is not a single research module — it is a composition of a source-finder module, an extraction module, a synthesis module, and a formatting module. Each module does one thing well. The composition connects them into a pipeline that does something complex.
The composition pattern has three rules. Rule one: modules communicate through events, not direct calls. Module A emits "extraction.complete" and Module B subscribes to it. They do not import each other. Rule two: composition logic lives outside the modules, in an orchestration layer that defines the pipeline sequence and handles failures. Rule three: any module in the composition is replaceable without modifying the other modules. If you upgrade the extraction module, the source-finder and synthesis modules should not need changes.
Do This
- Compose modules through events — loose coupling enables independent replacement
- Put orchestration logic in a separate composition layer — modules should not know the pipeline structure
- Design modules with single responsibility — a module that extracts and synthesizes is two modules in disguise
Avoid This
- Have modules call each other directly — tight coupling makes replacement a cascade of changes
- Embed pipeline logic inside individual modules — it becomes invisible and untestable
- Build monolithic modules that handle the entire pipeline — they are impossible to test, debug, or reuse