Your team copies the same date picker into several projects. Someone fixes its keyboard navigation in one application, but the others still have the bug. You’re no longer maintaining a single feature. You’re maintaining several slightly different versions of it.
A software library gives that shared code a home, but moving files into a package isn’t enough. Understanding the components of a library means understanding their dependencies: which parts provide behaviour, which define appearance, and which changes can break the applications using them.
Table of Contents
- The Parts of a Software Library at a Glance
- How Layers and Dependencies Fit Together
- Designing the Public Interface Users Rely On
- A Button Taken Apart Layer by Layer
- Common Mistakes When Splitting Code into Components
- Decide Which Components Your Library Needs
The Parts of a Software Library at a Glance
A software library is a bundle of reusable code that other projects import rather than rewrite. Its tested exports give those projects a supported way to use shared functionality without managing its implementation.
A library is code your project calls, while a framework calls your code. That distinction matters because a library should fit into its consumer’s application rather than take control of it.
Core parts of a software library
| Part | What It Holds | Role in Reuse |
|---|---|---|
| Modules and entry points | Exported files that apps import | Lets consumers import only what they use |
| Functions and classes (API) | Public methods and constructors | Defines the contract callers rely on |
| UI components | Reusable elements with markup and behaviour | Replaces repeated markup across screens |
| Props and parameters | Configurable inputs | Changes behaviour without copying code |
| Events and slots | Outputs and insertion points | Lets apps respond to or customise parts |
| Styles and theme tokens | Colours, spacing and typography values | Keeps appearance consistent across products |
| Documentation and examples | Usage guides and runnable samples | Shows how to adopt the part correctly |
| Tests and type definitions | Automated checks and type information | Protects the contract when code changes |
An entry point is a supported import location. The public API, or application programming interface, is the set of exports consumers are allowed to use. Props configure components, parameters supply inputs to functions, and a slot is a designated place for consumer-provided content.
Separate the essentials from the UI layer
A small utility library may need modules, functions and configurable parameters, but no visual components. A UI library usually needs the full inventory, including documentation and checks around interaction.
Security also needs explicit ownership. DevArmor’s discussion of component-level controls and threat modeling is useful context when deciding where to validate inputs or handle untrusted content.
Inventory first: List the parts your project already has, then mark what’s missing. A folder of reusable components without documented exports or tests is still unfinished infrastructure.
How Layers and Dependencies Fit Together
Components don’t work alone. A styled dialog needs behaviour and visual values; a settings page needs components that already work independently. Arrange those dependencies so higher layers use lower layers, without lower layers knowing which application will eventually consume them.
Think of a restaurant kitchen: the pantry holds ingredients such as tokens and utilities, the prep station turns them into reusable foundations, and the plated dish combines those foundations into a finished pattern. The menu describes what’s available, much as documentation describes the library’s supported features.
The diagram shows the broad dependency direction. Styled components sit between primitives and patterns in the more detailed model below.

Layers of reusable components
| Layer | What It Covers | Example | Reuse Scope |
|---|---|---|---|
| Design tokens | Colour, spacing and type scale values | A brand colour variable | Every product sharing those foundations |
| Headless primitives | Behaviour, focus and ARIA, with no styling | A dialog that traps focus | Different designs; framework reach depends on implementation |
| Styled components | Primitives with a visual design applied | A branded modal | One design system |
| Composed patterns | Several components combined for a task | A settings form with a dropdown and toggles | One product area |
| App templates | Full pages or flows | A checkout screen | One application |
Follow a dialog’s dependencies
A styled dialog imports a headless primitive, meaning reusable interaction logic without a prescribed appearance. That primitive calls a focus-management helper to move keyboard focus into the dialog and restore it when the dialog closes.
The styled layer separately reads theme tokens for its shadow and stacking order. Don’t make the focus helper depend on a colour theme: focus behaviour and presentation are separate branches of the dependency map. A documentation example then imports the public dialog to demonstrate the complete interaction.
Suppose someone renames the shadow token without updating its consumers. The dialog might still open and pass its keyboard tests, yet lose its visual separation from the page. That’s why a lower-layer change needs checks against the higher-layer behaviours and appearances it supports.
Give each layer a boundary
Design tokens hold named values, not click handlers. Primitives own keyboard handling, focus behaviour and appropriate ARIA semantics, the attributes that communicate interface meaning to assistive technology, but shouldn’t hard-code brand colours.
Styled components apply visual decisions without holding pricing rules. Patterns coordinate a task, while templates arrange page-level structure and connect application-specific services. Keep account permissions and checkout calculations out of a generic modal.
For practical composition choices, the guide to component composition provides a useful companion. A related coordination problem appears in Dograh’s explanation of coordinating STT, LLM and TTS pipelines: connected stages need explicit responsibilities and hand-offs.
Depend downwards, never upwards. Build at the lowest layer that serves the need, and extract a shared pattern only when separate uses reveal a stable common structure.
Circular imports, where modules import each other directly or indirectly, are a warning sign. Resolve them by moving shared responsibilities lower, not by hiding an import inside another function. Draw your dependency map with arrows, check for upward dependencies, and place a selection of your existing components into these layers.
Designing the Public Interface Users Rely On
The public contract includes everything a consumer can see and call: exported names, function signatures, prop names and types, default values, events and slots. Treat observable behaviour as part of that contract too. A component that unexpectedly changes when it emits an event can break an application without changing its types.
Name things by their purpose. Use nouns for components, such as Dialog, and verbs for actions, such as close. Keep related names consistent and avoid abbreviations developers must memorise.
Make the supported path easy
A component should work with only its required props. Give optional inputs sensible defaults, and document what happens when callers omit them or supply an unsupported value.
Events and slots are extension points. An event lets the application respond to an interaction; a slot lets it insert content without forking the component. Don’t expose private implementation details because a particular screen currently needs them.
Mallary.ai’s explanation of how to design API-first social publishing workflows offers a related perspective on describing interfaces before implementation. For component-specific guidance, use documentation best practices to keep examples aligned with the supported contract.
Change names without surprising consumers
Semantic versioning distinguishes compatible fixes, compatible additions and breaking changes. Use a patch release for compatible bug fixes, a minor release for additions such as optional props, and a major release for removed or renamed props.
Consider a hypothetical rename from size to variant. First check the meaning: dimensions and visual emphasis aren’t interchangeable, so this rename only makes sense if the original name was misleading.
During a minor-release migration window, accept both names, warn when callers use size, and specify which takes precedence if both appear. Publish the replacement example before removing the old name in a major release.
Run this checklist against your exports:
- Consistent names: Can developers predict related component and event names?
- Minimum configuration: Does each component work with only required inputs?
- Announced removals: Does every planned removal have a warning and migration example?
A deprecation warning is a maintenance policy, not something version numbers enforce automatically.
A Button Taken Apart Layer by Layer
A button is small enough to inspect completely, yet it connects appearance, browser behaviour and application state. Start with a native HTML button wherever possible rather than rebuilding its semantics on a generic element.
The illustration separates the visual ingredients that eventually become a single public component.

-
Define the tokens. Name the brand colour, spacing scale, typography and focus-ring values so the button can use shared design decisions. Avoid scattering literal colours and padding values through its selectors.
-
Build the primitive. Preserve native click, disabled-state and keyboard activation behaviour without prescribing colours, and make the button’s form-submission behaviour explicit. Don’t replace a native button with a clickable
divand assume an ARIA role supplies the missing interactions. -
Apply the styled component. Read the tokens and expose
variantandsizeprops with documented defaults. Keep hover, focus and disabled treatments here, but don’t use reduced opacity as the only indication that an action is unavailable. -
Compose a save bar. Place the primary save action beside a secondary cancel action, and let the parent supply whether a save is pending. Prevent repeated submissions and communicate progress without embedding network requests in the base button.
-
Document and test the result. Provide a usage example, props table and accessibility note, then test that user activation of a disabled button doesn’t invoke its action. Include keyboard checks and verify the accessible name rather than testing only CSS classes.
Inspect behaviour as well as appearance
Use a button component reference to compare the public inputs, examples and states you’d expect to document. The finished implementation should let you test or replace the visual layer without rewriting the save workflow.
For a complementary visual walkthrough, use the video alongside your own implementation checks.
Common Mistakes When Splitting Code into Components
A file becomes reusable because its responsibilities are suitable for different consumers, not because someone moved it into a components directory. Watch for symptoms that reveal where the boundary is wrong.
The abstraction requires constant exceptions
Premature abstraction looks like a component covered in switches for a single screen. Its author generalised imagined requirements rather than demonstrated similarities.
Keep the markup local until another use reveals what belongs together. If the component already exists, remove screen-specific branches before adding another configuration prop.
Leaky state appears when a dropdown changes a global selection even though the current form should remain isolated. The root cause is ownership: the component knows about application state it shouldn’t control.
Let the parent supply the value through a prop and receive changes through an event. Test separate instances together to catch accidental coupling.
Teams keep repairing the component outside it
A component with no loading, empty or disabled presentation forces each consumer to invent its own. The visible symptom is inconsistent wrappers and duplicated conditional markup.
The first fix is to define the supported states and their transitions before polishing another normal-state example. Decide which states belong to the component and which belong to its surrounding pattern.
Undocumented behaviour creates a different kind of repair. A developer may wrap a dialog in another focus trap because the documentation never says the dialog already manages focus.
Review prompt: Document what consumers must not override, not just what they can configure.
Use this diagnostic list during review:
- Repeated exceptions: Reconsider the abstraction’s scope.
- Unexpected cross-screen updates: Move state ownership to the caller.
- Different loading treatments: Specify shared edge states.
- Competing interaction handlers: Document and test behavioural ownership.
These problems are easier to correct before consumers depend on the existing interface. After release, even an awkward behaviour may require a migration path. Ask a developer unfamiliar with the implementation to use the component from its documentation alone, and record every point where they need help.
Decide Which Components Your Library Needs
Choose between building, adopting and copying based on responsibility, not preference. Building means owning the implementation; adopting means depending on maintained external code; copying means bringing code into your source tree and owning its subsequent changes.
Use the visual checklist as a starting point, then weigh maintenance and accessibility rather than counting answers.

- Repeated use: Build a shared component when separate screens need the same stable behaviour.
- Difficult accessibility: Favour adopting an evaluated primitive for complex keyboard or focus interactions.
- Long-term ownership: Build only when the team can maintain the implementation and its tests.
- Existing visual system: Adopt headless behaviour when you need to retain local styling.
- Suitable existing implementation: Adopt maintained code, or copy simple markup when local ownership is manageable and its licence permits it.
A branded date picker with keyboard navigation is a candidate for adopting behaviour and styling it locally. A one-off confirmation message can stay in the application.
At DOM Studio, our Headless library provides framework-neutral custom elements. Judge that option against the same checklist rather than assuming it fits every project.
Choose how updates will reach your code
Our components can be added by importing the npm package, copying individual components, or vendoring the workspace with git subtree, which brings an external repository into a directory you maintain. The same licence terms apply whichever method you use, so choose based on upkeep rather than an assumed licensing shortcut.
Before writing code, run the checklist against a component in your current project. Record the decision, its owner and how future fixes will reach your application.
DOM Studio offers Vue and Web Component interface software, source materials, examples and documentation for assembling your own component layers. Visit the library, inspect a component’s contract and examples, and compare its responsibilities with the dependency map you’ve drawn for your application.
