LLearnCode
Academy/web-systems/Node and workspaces

advanced · 26 minute study

Share a contract without making everything depend on everything

A monorepo can make shared rules easier to change consistently, but a folder called packages does not automatically create good boundaries.

Loading progressEvidence grows with practice
Useful preparation · 1 prerequisite

Use this as a map, not a lock. If these ideas are familiar, continue.

First, build a mental model

An application assembles behavior for users. A package exports a cohesive contract for consumers. Dependency direction tells you what must be understood or changed together.

  1. npm workspaces let one repository declare related local packages. Each package still needs a clear purpose, public entry points and explicit dependencies.
  2. Prefer a domain package that accepts facts and returns results without importing application screens. Presentation and infrastructure can depend on shared rules without the rules depending on every consumer.
  3. Imports through stable public exports keep consumers away from accidental internals. Dependency cycles make initialization, testing and change impact harder to reason about.
  4. A shared change must be checked in the package and its affected consumers. Not every project needs a monorepo: a cohesive single application can retain simpler structure until real reuse justifies more boundaries.
Read the codejson · educational example
{
  "name": "synthetic-workspace",
  "private": true,
  "workspaces": ["apps/*", "packages/*"]
}
  1. Consumers

    A shop interface and a CLI can call the same reviewed order-rule contract.

  2. Dependency direction

    Both applications depend on order-rules; order-rules does not import the shop's UI state.

  3. Change impact

    Updating the shared contract requires checking both consumers, even if only one initially requested the change.

Production thinking

Take this beyond the example.

The audited production reference uses multiple applications and shared packages; LearnLab is a useful contrasting single-application example. Teach dependency direction using synthetic contracts instead of copying private implementation.

Sources and further reading

Your evidence

unseen is a local learning signal, not a credential or proof of production competence.

Explain the mental model, then explicitly acknowledge it. Opening a page is not evidence.

Supported retries can complete this lesson. Independent evidence and delayed review determine the skill stage.

Next lesson · Deploy the artifact you actually verified →