Define dependency direction between application modules
Quick answer
An application boundary separates decisions about domain data from infrastructure and display. Keep business rules callable without the DOM or transport. Let the composition root assemble implementations and wire them to the UI.
How it works
Group functions by responsibility, not by file size alone. Domain code accepts plain data; adapters translate between domain contracts and external formats. UI code invokes the application service and renders its result. The outer layer imports or receives the inner contract, never the reverse. For small apps this can be ordinary functions; ES modules help enforce explicit imports but do not automatically enforce architecture.
Local examples
Run in Node.js v22.16.0 as a CommonJS script. Actual ByteMind editor support is unverified.
(async () => {const total=({qty,unit})=>qty*unit;const format=n=>`${n} credits`;console.log(total({qty:3,unit:4}),format(total({qty:0,unit:4})));})()Expected console output:
12 0 creditsThe calculation works without a display dependency, including zero.
Run in Node.js v22.16.0 as a CommonJS script. Actual ByteMind editor support is unverified.
(async () => {const calculate=n=>n*2;const messages=[];const render=n=>messages.push(`Total: ${n}`);function app(input){render(calculate(input));}app(5);console.log(JSON.stringify(messages));})()Expected console output:
["Total: 10"]The outer function coordinates calculation and the injected output.
Common mistakes
Do not let a calculation query DOM controls or read a global transport directly. Avoid layers that add no independent responsibility.
Practice
Separate quantity calculation, output formatting and displaying a result; test the calculation without creating a document.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Define dependency direction between application modules — Knowledge Check
Apply the concept and reason about local example output.
Which layer should assemble the domain and browser renderer?
What should a pure domain calculation accept?
Do ES modules alone guarantee good dependency direction?
What is the exact console output in Define dependency direction between application modules example 1?
(async () => {const total=({qty,unit})=>qty*unit;const format=n=>`${n} credits`;console.log(total({qty:3,unit:4}),format(total({qty:0,unit:4})));})()What is the exact console output in Define dependency direction between application modules example 2?
(async () => {const calculate=n=>n*2;const messages=[];const render=n=>messages.push(`Total: ${n}`);function app(input){render(calculate(input));}app(5);console.log(JSON.stringify(messages));})()