On composable, modular frontends – Increment: Frontend (2024)

Think about your favorite retailer’s e-commerce platform. There’s a lot of complexity in that application: the product catalog, the cart module, the checkout page, the review system, the shipping tracking page, and so on. Each component of the web application has a distinct set of features, but they all connect in some way. The cart module is tied to the checkout page, and the product catalog is tied to the review system. So, how do e-commerce sites manage this complexity in their frontendapplications?

Composability and modularity are appealing design principles for engineering systems. When employed properly, they can supercharge the development process and ease the maintenance burden of software. But they can be rather difficult to implement, especially as systems age and new business requirements are introduced. While these principles are often considered in the design of backend components, they’re equally relevant in thefrontend.

With great complexity comes great bugs and even greater maintenance burdens.

With the growing intricacy of user experiences in different clients and an increasing set of frontend technologies, modern frontend engineering is a complex and sophisticated landscape. As clients do more heavy lifting in web applications and more state is stored on the client side, state machines increasingly manage more and more scenarios, such as the contents and status of a registration form. Furthermore, web applications need to support a variety of targets across mobile and desktop. With great complexity come great bugs and even greater maintenance burdens—but there’s a solution forthis.

To build scalable and maintainable frontend systems, we need a strategy for managing and organizing the complexity that exists in the user interface. Scalable and maintainable systems are easier to test, reduce the cost associated with adding new features to an application, and make it easier to upgrade and change certain parts of theUIwithout degrading the experience for others. Thankfully, a growing number of technologies, such as React, Redux, Vue, and more, are making it easier for engineers to build frontend systems that can scale to meet their needs. But frameworks alone won’t solve these problems. We also need to bring the principles of composable design to thefrontend.

The what

The principles of composability and modularity are often interlinked. Modular systems consist of subcomponents with well-defined interfaces and functions that can be consumed independently of each other. Composability is the degree to which these subcomponents can be combined to form more complex systems. Despite the similarities in these definitions, a modular system isn’t automatically composable. A system’s subcomponents can have well-defined interfaces and scopes but be difficult to integrate because data types aren’t generic enough across subcomponents, or because certain subcomponents may have unexpected sideeffects.

The why

When implemented in frontend systems, these principles offer many benefits to both developers and end users. For starters, it’s much easier to introduce new features or deprecate unnecessary ones in a modular system because the subcomponents aren’t deeply coupled; changes are much easier toisolate.

Composability and modularity also make it easier to maintain (and document) existing code. Instead of sifting through hundreds of source files to establish the relationships between different components in a system when making a feature change, an engineer only needs to examine one component of the system and understand the interface of others. You can imagine how much time that saves during both development andonboarding!

Last but not least, modular systems, in which components have limited scope and their internal complexity is obfuscated from other components, are much easier to unit test than monolithic systems. Since modular components are less likely to hold extraneous internal state and more likely to operate deterministically, there is less unexpected behavior and fewer side effects to account for whentesting.

The how

The UI

Now, this is all fine and dandy, but how do you actually get it done? There are several fundamental elements to a frontend application to which we can introduce modularity and composability, including styling, event management, andDOMmanagement.

For the purpose of this article, we won’t be prescriptive about what a component is; it could, for instance, be a React component, an Angular view, or a Vue component. We’ll focus on general principles that can apply to any rendering orUIlibrary.

Styling frontends with CSS can quickly become a gnarly affair.

Let’s start off by covering something universal to all rendering libraries: styling. Styling frontends withCSScan quickly become a gnarly affair. Often, the styles applied toHTMLdepend largely on the structure of the page. In the example below, thenavelement is aware of its position on the page and has a childbuttonthat’s aware of its inner content. This pattern doesn’t lend itself to modularity or stylereuse.

<nav class='side-panel'>
<button id='settings'>Settings</button>
</nav>

nav.side-panel {
background-color: green;
}

button {
color: white;
}

button#settings {
font-family: Arial;
}

An alternative approach is to implement styles based on the intended effect in isolation and then compose styles by applying several effects on the same element, as opposed to within the context of an existingUIlayout.

<nav class='green-bg'>
<button class='white-fg arial-font'>Settings</button>
</nav>

.green-bg {
background-color: green;
}

.white-fg {
color: white;
}

.arial-font {
font-family: Arial;
}

This pattern might ring a bell. It’s implemented by popular styling frameworks like Bootstrap and Foundation because they’re designed to be used across different frontend implementations.

In addition to avoiding context-dependent styles, composableCSSpatterns avoid applying styles to tag-basedselectors.

h1, h2 {
font-family: Arial;
}

The first of the three previous patterns is a global-level style that modifies allUIcomponents within a page, as opposed to the approach in the second code snippet, which can be appliedselectively.

Modularity requires subcomponents within a system to be easy to swap out or assemble in sequence. To do this, a composable frontend system should rely on native and standardizedAPIs, when possible. This makes the frontend system resistant to breaking changes in third-partyAPIsfor fundamental logic such as manipulating theDOM:for example, relying on thegetElementByIdmethod provided by theDOMAPIacross browsers instead of the$(#id-here)accessor exposed in jQuery. Historically, developers had to rely on libraries to provide support for functionality that wasn’t standardized across browsers. However, with technologies like polyfills, more uniform support forAPIsacross browsers, and advancements in JavaScript language features, it’s more feasible for developers to rely heavily onstandards.

Among the tougher elements to modularize on web pages are events that cause changes in different components. For example, a user might click on a button that will update a form field and submit a request to a backendAPIin a single interaction. Oftentimes, this is managed by integrating all of the related elements, the button and the form field, in one component and leveraging state to toggle the view or contents of each element. But this can quickly get out of hand. What if, in addition to updating a form field, we need to render a newUIelement?

In lieu of adding more and more logic to our button component, we can implement a standardized interface for sending messages across different components within our page. In fact, the browser already supports this scenario via event listeners. Instead of coupling the logic into one component, the button element can dispatch an event that other components can listen and respondto.

The state

How do we structure the state of an application to improvemodularity?

So far, we’ve covered styling and event handling, but there’s one thorny topic we’ve yet to discuss: state. Frontend applications store a lot of state, such as the contents of a user’s timeline or their current application settings. How do we structure the state of an application to improvemodularity?

First, we can ensure that state is only associated with the components it’s related to. For example, a sign-in/sign-out button doesn’t need to access state about the contents of a timeline, so this information should be completely opaque to thebutton.

For scenarios in which state doesn’t need to be shared across multiple components, state modules can be implemented to manage the state for a particular class of components. The state module provides a set of getters and setters that each component can access and ensures that components cannot make conflicting or unexpected changes to thestate.

Underpinning styles, state, and event handling is the structure of the frontend itself. This is often determined during the design of the user interface. To lend itself to modularity, the design of a web page should isolate related state into a singular component on the page. For example, the list of products a user recently purchased should be rendered independently of the list of products currently for sale. Also, user actions, such as liking a post or deleting a comment, should only be executed via a singularUIelement.

The future

Also in this issueMicro-frontends in contextWhen—and why—should developers consider this newer, smaller frontend architecturepattern?

The principles of modularity and composability are codified in the implementation of micro-frontends. Micro-frontends are structures for creating frontends in which each component is isolated into its own application and rendered collectively on a page using mechanisms such as Web Components or iframes. While this approach maximizes the composability and modularity of a web application, it can be difficult to migrate existing frontends to this pattern. Furthermore, it takes a fair bit of work to integrate all of the subcomponents and ensure that they work properly. Leveraging some of the implementation patterns we’ve discussed provides a good migration store for existing frontends and strikes a balance between the technical benefits of modularity and the cost of migrating existingsystems.

As the web advances and users demand more and more from the frontend experiences applications provide, we’ll need to design frontend systems with composability and modularity in mind. Favoring these design characteristics makes it easier to onboard engineers to existing frontend components—and to maintain and grow successful frontendsystems.

On composable, modular frontends – Increment: Frontend (2024)

FAQs

What is the difference between composable and modular? ›

Modular systems consist of subcomponents with well-defined interfaces and functions that can be consumed independently of each other. Composability is the degree to which these subcomponents can be combined to form more complex systems.

What is a composable front-end? ›

Composable front ends provide a structured approach to building modular, reusable and independently deployable user interface components. Imagine being able to break down your front-end architecture into smaller, self-contained modules — micro-front ends — each responsible for a specific part of your application.

What is a modular frontend? ›

Frontend Modular Development is a software design paradigm that promotes the separation of an application's user interface (UI) into individual, reusable, and independent modules.

What is composable software? ›

Composable software is an approach to building system infrastructure through modules. By deploying a composable architecture, companies can repurpose existing code with the intent to streamline toolsets with agility. Composable software components can be swapped easily when needed.

What is the difference between modular and incremental? ›

Incremental innovation: Small, gradual improvements to existing products, processes, or services. Example: Ongoing updates in software applications such as Microsoft Office. Modular innovation: Development of independent components that can be easily combined or exchanged. Example: Lego building blocks.

What is the difference between modular and non-modular UPS? ›

Modular UPS: Users can scale the UPS systems by adding or removing modules as needed, thanks to their designed modular architecture. This makes it easier to expand the capacity of the UPS to meet changing power requirements. Conventional UPS: Conventional UPS systems have a fixed capacity and are not easily scalable.

What is the difference between front-end and frontend? ›

Front end: As two separate words, 'front end' refers to the part of a system or process, like “The user interacts with the front end of the application.” It's more about positioning than describing technology or roles. Frontend: This newer, streamlined version is often used in branding or modern stylistic choices.

What are front-end modules? ›

The front-end module is a key design element for a vehicle and its identity. The module's outline contributes to the vehicle's characteristic look, while the equipment it contains adds directly to its safety and reliable operation.

How many types of front-end are there? ›

These three main front-end coding languages are HTML, CSS and JavaScript. Together, they create the underlying scaffolding that web browsers use to render the web pages that we interact with every day.

What is the difference between end to end and modular? ›

End-to-End is a single pipeline that generates the control signal directly from perception input, whereas a modular pipeline consists of various sub-modules, each with taskspecific functionalities.

Why is it called modular? ›

Rather than being built all at once, they are built in separate parts that get assembled into a finished product. The word modular has been used this way since the 1930s — earlier, it was a purely mathematical term, from the Latin word modulus, or "small measure."

What is a module in frontend? ›

In front-end development, we can define a module as a piece of functionality that is independent of and not intrinsically tied to a specific layout of a website or web application. It could be a UI component such as a button or form element, for example.

What is composable meaning? ›

: capable of being composed. … music expressive of a feeling is clearly composable by one who is not experiencing that feeling and has perhaps never experienced it … Edward Craig, Routledge Encyclopedia of Philosophy, 1998.

What are composable components? ›

Composability is the art of building systems in a modular and flexible way. It emphasizes creating components that are not only reusable but can seamlessly fit together, forming a cohesive and adaptable architecture.

What is the difference between composition and modularity? ›

Many cyber-physical systems are actually systems of systems, compositions of diverse subsystems, typically developed by diverse teams, often from different organizations. Modularity is the problem of designing subsystems (modules) with well-defined interfaces that can be used in a variety of contexts.

What is the difference between modular and component? ›

A module is a smaller part that handles specific tasks or functions in a program. A software component is a bigger, independent unit dealing with a wider range of functions in a program or system. Modules are finer, focusing on individual tasks.

What is the difference between module and modular? ›

Modular design, or modularity in design, is a design principle that subdivides a system into smaller parts called modules (such as modular process skids), which can be independently created, modified, replaced, or exchanged with other modules or between different systems.

What is the difference between modular and modulus? ›

In mathematics, modular arithmetic is a system of arithmetic for integers, where numbers "wrap around" when reaching a certain value, called the modulus.

Top Articles
Five Trends Shaping the Future of ESG Reporting - ESG Investor
Are Target-Date Funds Good Investments?
Walgreens Harry Edgemoor
Davita Internet
Combat level
King Fields Mortuary
Devourer Of Gods Resprite
Wunderground Huntington Beach
R/Altfeet
Dallas’ 10 Best Dressed Women Turn Out for Crystal Charity Ball Event at Neiman Marcus
Labor Gigs On Craigslist
Tcu Jaggaer
London Ups Store
"Une héroïne" : les funérailles de Rebecca Cheptegei, athlète olympique immolée par son compagnon | TF1 INFO
使用 RHEL 8 时的注意事项 | Red Hat Product Documentation
De beste uitvaartdiensten die goede rituele diensten aanbieden voor de laatste rituelen
Scream Queens Parents Guide
Yog-Sothoth
Rust Belt Revival Auctions
Which Sentence is Punctuated Correctly?
The best brunch spots in Berlin
Reicks View Farms Grain Bids
Southwest Flight 238
Craigslist Wilkes Barre Pa Pets
Margaret Shelton Jeopardy Age
Temu Seat Covers
Maisons près d'une ville - Štanga - Location de vacances à proximité d'une ville - Štanga | Résultats 201
Dtlr On 87Th Cottage Grove
Loopnet Properties For Sale
Whas Golf Card
Lake Dunson Robertson Funeral Home Lagrange Georgia Obituary
How to Watch the X Trilogy Starring Mia Goth in Chronological Order
Magicseaweed Capitola
Craigslist List Albuquerque: Your Ultimate Guide to Buying, Selling, and Finding Everything - First Republic Craigslist
Cbs Fantasy Mlb
Devotion Showtimes Near The Grand 16 - Pier Park
Fototour verlassener Fliegerhorst Schönwald [Lost Place Brandenburg]
craigslist: modesto jobs, apartments, for sale, services, community, and events
Download Diablo 2 From Blizzard
Dcilottery Login
Directions To The Closest Auto Parts Store
Trivago Sf
California Craigslist Cars For Sale By Owner
13 Fun &amp; Best Things to Do in Hurricane, Utah
Gli italiani buttano sempre più cibo, quasi 7 etti a settimana (a testa)
Crigslist Tucson
Ciara Rose Scalia-Hirschman
Helpers Needed At Once Bug Fables
Deviantart Rwby
Worlds Hardest Game Tyrone
Latest Posts
Article information

Author: Fredrick Kertzmann

Last Updated:

Views: 5908

Rating: 4.6 / 5 (66 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Fredrick Kertzmann

Birthday: 2000-04-29

Address: Apt. 203 613 Huels Gateway, Ralphtown, LA 40204

Phone: +2135150832870

Job: Regional Design Producer

Hobby: Nordic skating, Lacemaking, Mountain biking, Rowing, Gardening, Water sports, role-playing games

Introduction: My name is Fredrick Kertzmann, I am a gleaming, encouraging, inexpensive, thankful, tender, quaint, precious person who loves writing and wants to share my knowledge and understanding with you.