Hero photograph
Blocks
 

Modular Design in Front End Development

Louis Fiddy —

Modular design in web development is continuing to evolve and improve with new tools and techniques. While these are extremely useful, it is still up to us, as developers to use them effectively and to keep our design and code organised and efficient.

Writing reusable, manageable and maintainable code is something that every developer should aspire to do. It's not always easy and even with the best intentions we can fall short to time and project pressures and our codebase can become messy and disjointed. A modular approach to front end development is not new and it is certainly not a panacea for these problems but it is an approach that can reduce the complexity of websites and web applications, ultimately leading to a better experience for both developers and users.

So what is modular design? For a quick definition, let's consult Wikipedia:

"Modular design is a design approach that subdivides a system into smaller parts called modules, that can be independently created and then used in different systems." 

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. A group of components such as these could be part of a more complex set of modules. The important factor is that these elements are self-contained and reusable.

As an example, let's take the styling of a button that performs an action in a web application. A modular approach to designing this button might involve creating a base structure first with padding, margin, font style and height. We could then extend this structure with colour to represent different actions. A green button might save some data, a red button might delete data. We would only write the code to style this button once, and then extend it to create the different coloured button types. This ensures that if we need to change the base design of our buttons we only need to change our module in one place and all our button variants are updated to maintain a consistent look and feel with minimal effort. We can now reuse this button module throughout our application without repeating a large amount of code every time. We could also take our button and easily import it into another project. 

This is, of course, a very simple example but hopefully, it shows the thinking behind modular front-end development and how it can save developers a lot of time and frustration when applied to a large application. In reality, our button might be far more complicated and include events and actions that occur when it is clicked. A modular code base with a well thought out structure makes this functionality easier to manage and maintain. This is especially useful in a team-based development environment like Firebrand. A well-organised, modular codebase means your colleagues spend less time figuring out the code that already exists and more time developing new functionality. Ultimately this filters down to clients, getting projects finished on time and on budget.

The release of SilverStripe 4 has allowed Firebrand to take a more modular approach to the design and structure of the CMS for client websites. We can now create customised, highly designed "blocks" within the CMS that clients can easily add, remove and re-order. This gives clients a greater amount of control over the structure of their website content while maintaining the beautifully designed, bespoke look and feel that they've come to expect from Firebrand. It's exciting to be able to provide clients with this flexibility when creating and editing content.

Front-end developers have an increasing number of tools to make a modular design more accessible. CSS preprocessors such as SASS and LESS have been around for a while but are still powerful and widely used tools in modular front development. Javascript tools such as CommonJS, RequireJS and the ES6 import/export syntax allow developers to easily contain functionality in distinct modules. Bootstrap, the popular front-end framework, relies heavily on a modular approach - and does so extremely well. State-based JavaScript libraries such as React, VueJS and Angular have modular design at their core and power the front-end of some of the world's biggest web applications including Netflix, Shopify and Instagram.

A good understanding of modular design is essential for any front-end developer. Taking this approach not only gives us a more efficient approach to the development of our own websites and applications but also gives a better understanding of the code libraries and frameworks that we rely on. 

- Louis