One Component, Many Products
Lead Application Developer · ADP
Published
My team inherited features whose components had been copied and adjusted for each product that used them. I consolidated them into shared Stencil.js micro frontends, published as an internal npm package, now used by three products across Angular, React and other micro frontends.
Problem
My team inherited several features whose components had grown a copy per product. Where two products needed slightly different behavior, the code had been duplicated and adjusted rather than shared. Every fix or change had to be made, and tested, in more than one place, and the copies drifted apart over time. The components were also tied to the Angular application they lived in, so a product built on anything else couldn't use them at all.
Context
The company already had a larger micro-frontend framework built on Stencil.js, which also handled authentication, styling and shared state for everything running inside it. Choosing Stencil wasn't my decision; the framework was the standard. My job was to move my team's inherited components onto it: deciding how they should be structured, consolidating the duplicated code, and making them something other teams could pick up and use.
Goals
- Replace each product's copy of a component with one shared implementation
- Make the components usable from any product, whatever it was built with
- Bring accessibility and the components themselves up to date during the move
- Keep existing users unaffected while the replacements shipped
Constraints
- Built on the company's existing Stencil.js micro-frontend framework, not a framework of my choosing
- Authentication, styling and shared state belonged to that framework, so they were out of scope
- Consumers used a mix of Angular, React and other micro frontends
- Existing features had to keep working for current users throughout
Architecture
Each feature's duplicated components became a single Stencil web component, which any framework, or another micro frontend, can render. Differences between products moved out of copied code and into the component's public API: properties in, events out. Each product passes in what it needs, including the viewer's role, so the same component serves both an administrator and an employee view, and listens for the events it cares about. The components shipped as an internal npm package, so consuming teams installed and upgraded them like any other dependency.
Implementation
Each component went through the same sequence, so the existing application proved it before any other team depended on it.
- Extract the logic from the duplicated Angular components into one shared implementation
- Build the Stencil component on the company framework, updating it and fixing accessibility along the way
- Swap it into the original application in place of the Angular version
- Publish it to the internal npm package and make it available to the consuming teams
Challenges
- Finding which differences between the copies were real product needs and which were just drift
- Designing one component that fit three products and two roles (administrator and employee) without turning into a pile of flags
- Keeping the original application's behavior identical while replacing what was under it
- Serving consumers on different stacks: Angular, React and other micro frontends
Decisions
One implementation instead of a copy per product
Merged each feature's duplicated components into a single shared one, with product and role differences handled through its properties and events.
Tradeoffs: One place to fix bugs and make changes, for every product. The cost was careful API design up front, and saying no to product-specific requests that didn't generalize.
Prove it in the original app before sharing it
Swapped each new component into my team's own application before publishing it for other teams.
Tradeoffs: Problems surfaced with the team that owned the code, not with another team that had just adopted it. The cost was a slower path to the other products.
Modernize while moving, not after
Updated the components and addressed accessibility as part of rebuilding them, rather than porting them as-is.
Tradeoffs: Every consumer got the improvements on day one, and nobody had to revisit the components later. The cost was a bigger change per component than a straight port.
Metrics
Products consuming the components
3
Result
The duplicated components became shared micro frontends, published as an internal npm package and used by three products owned by different teams, across Angular, React and other micro frontends. A fix or improvement now ships once and reaches every product. The move also brought the components up to date and improved their accessibility.
Lessons Learned
- Duplicated code is usually a missing API. The copies existed because there was no clean way to express the difference between products.
- Prove a shared component with its first owner before handing it to anyone else.
- A migration is the cheapest moment to fix accessibility. The component is already being rebuilt and retested.
What I can't show
This was internal work at ADP, so there are no screenshots, code or architecture diagrams here. The write-up sticks to the problem, the decisions and the outcome.