Composable architecture example: Go headless (best practices)
Momcilo
Posted on April 30, 2024
No, this time I don’t want to talk about Lego blocks to explain what composable architecture is, rather I will use headless CMS as a composable architecture example which can help you understand why this concept you need to adapt as soon as you finish reading this article.
Composable architecture example: Why headless
Why headless?! 🤔
Because it represents the entire philosophy of flexible and scalable web development, that is why one of the main elements is the MACH architecture, which combines multiple technologies to provide a flexible, open environment for building a composable ecosystem.
Composable and headless are similar concepts with different focuses. While composable architecture encompasses the entire system design, headless focuses on content management.
So, let's use headless focus and try to understand composable building in content creation.
Composable architecture and headless CMS
Composable architecture was developed as a direct response to the shortcomings of earlier approaches. Guess who's evolutionary architecture journey offers insight into going from traditional to composable. Yup, it is CMS.
Traditional vs Headless vs Composable
Everything in CMS revolves around balancing the requirements of both editors and developers. Thanks to their needs, and dissatisfaction, CMS has evolved to adapt to the requirements of "both teams." Let's do a short timetable of CMS evolution.
Traditional CMS
Traditional CMS systems prioritize offering editors a user-friendly environment with access to templates and visual editing tools. However, developers often find themselves constrained by the rigid structure that tightly binds the CMS to the frontend.
Headless CMS
With headless CMSs, the frontend is decoupled from the CMS, giving developers more freedom to use whatever tools and frameworks they prefer. CMS serves as an API that facilitates communication and development.
Composable CMS
In the composable approach, CMS serves as a composer tool too, so it enchants the website's functionality. Creating content and pages in one tool eliminates the need for another solution or integration. Using CMS in a composable approach there are fewer systems to manage, developers are satisfied with the separated front-end, and both developers and editors can build the tech stack necessary for their everyday work.
Composable backend features
A headless CMS is designed to provide content management capabilities without dictating how the content is presented, allowing developers to build custom front-end experiences. Here are some composable building blocks commonly used in headless CMS architectures:
Content Types
Define the structure of content, such as articles, blog posts, products, etc. Each content type specifies the fields and their data types, like text, image, video, etc.
API Endpoints
Expose RESTful or GraphQL APIs to retrieve and manipulate content. These endpoints should support CRUD (Create, Read, Update, Delete) operations.
Webhooks
Trigger custom actions or notifications based on events, such as content creation, update, or deletion. This allows seamless integration with external services or custom workflows.
Integration with a CDN (Content Delivery Network)
During high-demand periods, CDNs prevent bottlenecks by distributing traffic across multiple global servers.
Localization
Support multiple languages and locales for content localization. Provide mechanisms to manage translations and serve content based on the user's language preferences.
User authentication & authorization
Implement user authentication and authorization mechanisms to control access to content and administrative features. This ensures that only authorized users can create, edit, or delete content.
Role-Based Access Control (RBAC)
Define roles and permissions to control what actions different users can perform within the CMS. This enhances security and ensures compliance with data protection regulations.
By leveraging these building blocks, developers can create powerful and flexible headless CMS solutions that cater to a wide range of content management needs while allowing for seamless integration with various front-end frameworks and platforms.
Composable frontend features
Headless CMS can also help build a successful architecture for your composable frontend, which allows you to create complex UIs using reusable, individual, and independent logic building blocks. Let’s explore these features:
Framework agnostic
Everything begins with choosing a framework/library to code the frontend.
Modern UIs are usually complex enough to benefit from being built with something like React or Vue.
Modern headless is compatible with all major web development frameworks and libraries to simplify your life. Therefore, you can choose from the following options when coding your website or app:
Composable architecture example: BCMS integration with Next.js, Nuxt and Gatsby
Integrating a headless CMS like BCMS with Next.js, Nuxt, or Gatsby is a common practice in modern web development. Here's a brief overview of how you can integrate each of these frameworks with BCMS.
There are official BCMS plugins for Next.js, Nuxt, or Gatsby.
In all cases, you'll typically follow these steps:
- Install necessary packages or plugins for your chosen framework.
- Configure the connection to BCMS, usually by providing API keys.
- Fetch data from the BCMS using previously installed plugin, or a pure REST API call.
- Render the fetched data in your application.
Each framework may have its own methodologies and best practices, so be sure to consult the BCMS documentation for detailed integration guides and examples.
For deeper insights, visit:
To kick off your journey with BCMS and headless CMS, you can use one of many well-designed, and well-optimised BCMS code starters. Using a starter, you’ll get a composable project in minutes.
Pulling data and features from 3rd party APIs
Thanks to the API-first approach you can pull data and features into your project using a headless CMS.
Pre-built frontend components
Headless CMS offers a collection of pre-built frontend components for content management, including user interfaces for creating, editing, and managing content.
Learn more: Reusable structured content - everything you need to know
Content modeling
Content modeling, also called structured content, defines content types, fields, and relationships. A composable front end organizes and stores content according to this blueprint.
Example: Blog page
For a blog page, inside BCMS, you can define a "Blog Post" content type (in BCMS they are called templates) with fields such as title, author, publication date, content body, and tags. Each field corresponds to a specific information associated with a blog post.
Customizable templates
Customizable templates allow developers to create predefined layouts and styles for different types of content. Editors can then choose and customize these templates when creating or updating content.
Example: BCMS templates
Templates in BCMS are a pre-defined content structure. Based on that structure, you can create entries.
Templates can be multi-entry or single-entry. For example, when you create a template for your website's Home page, you'll go with a single-entry template. When you create a template for your Blog posts, it will be a multi-entry template.
Dynamic content rendering
Dynamic content rendering allows developers to dynamically display content from the CMS, adapting its presentation based on various factors such as user interactions, device types, or contextual information.
Example: Product listings
Composable e-commerce is a great example of this. Frontend developers can dynamically adjust product listings display based on sorting preferences chosen by the user (e.g., price low to high, newest arrivals first).
Similar thing BCMS did for Basket e-commerce. In the case study below you can see how Basket used BCMS for managing product pages and adding/removing more variants for their product listings. For more insights take a look into a case study. Basket CASE STUDY.
Component-based architecture
Component-based architecture involves breaking down the user interface into reusable components, each summarizing its own functionality, styling, and behavior. This approach promotes code reusability and simplifies maintenance.
Example: Header navigation
A "Header Navigation" component containing navigation links, and a "Footer" component for site-wide information are reusable components that can be used across different website pages.
Check out how Superbet is editing its header with BCMS.
From monolithic to composable with headless BCMS
Implementing a composable architecture can be a game-changer for your development projects. Breaking down your application into small, reusable components enhances code maintainability and promotes scalability and flexibility in your system design.
Remember, the key principles of a composable architecture include separation of concerns, modularity, and loose coupling between components. And keep in mind one more thing: all this is much easier to achieve with the help of a headless CMS.
Posted on April 30, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.