Integrating Micro Frontends via Shared Types

Better micro frontend integrations through shared data typesSay you are part of the “host app” or “shell app” team. Your primary responsibility is to allow other teams to work and deliver their Micro Frontends independently without risking your applica…


This content originally appeared on Bits and Pieces - Medium and was authored by Eden Ella

Better micro frontend integrations through shared data types

Say you are part of the “host app” or “shell app” team. Your primary responsibility is to allow other teams to work and deliver their Micro Frontends independently without risking your application's overall integrity or compromising user experience.

One option is integrating Micro Frontends at build time; however, this option can reduce a Bit of each team's autonomy and may slow down the development process. It’s a good option in many cases, but not all.

A different approach, suitable for runtime integration of Micro Frontends, would be for the “shell app” team to define data types for various integrations. The MFE teams would implement and expose these data, allowing for more seamless, safer, and "natural” integration.

For example, our host application allows Micro Frontends to register a menu in the top navigation bar.

Our deployed solution: https://bit-bazaar.netlify.app/

The host app team created an interface for other teams to implement if they wish to use this type of integration.

For example:

export interface NavItem {
label: string;
path: string;
icon?: string;
children?: NavItem[];
}

The type would then be shared as a Bit component to make it available across projects, maintained in separate repositories (the various Micro frontends):

The ‘navigation’ Bit component

In our case, the interface was implemented by the “Storefront” and “Blog” teams:

The ‘navigation’ type graph of dependent components

The blog MFE would implement the type as follows:

https://bit.cloud/bit-bazaar/blog/blog/~code/navitem.tsx

It then exposes this data for the host app to consume. In this case, since the MFE is implemented using Module Federation, the navigation for the Blog Micro Frontend is exposed from the remote module (see the './blognav' ):

https://bit.cloud/bit-bazaar/blog/blog/~code/blog.bit-app.ts

The host app tries to fetch the exposed data from every MFE. If the data exists, it gets loaded and integrated; if it does not exist, it fails gracefully.

For example:

https://bit.cloud/bit-bazaar/shell-app/shell-app/~code/mfes/blog.tsx

The data loaded by the host app is then rendered by the “MFE Menu” component.

To learn more about the full ModFed with Bit solution, see:

Micro Frontends: A Practical Step-by-Step Guide


Integrating Micro Frontends via Shared Types was originally published in Bits and Pieces on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Bits and Pieces - Medium and was authored by Eden Ella


Print Share Comment Cite Upload Translate Updates
APA

Eden Ella | Sciencx (2024-07-03T20:14:47+00:00) Integrating Micro Frontends via Shared Types. Retrieved from https://www.scien.cx/2024/07/03/integrating-micro-frontends-via-shared-types/

MLA
" » Integrating Micro Frontends via Shared Types." Eden Ella | Sciencx - Wednesday July 3, 2024, https://www.scien.cx/2024/07/03/integrating-micro-frontends-via-shared-types/
HARVARD
Eden Ella | Sciencx Wednesday July 3, 2024 » Integrating Micro Frontends via Shared Types., viewed ,<https://www.scien.cx/2024/07/03/integrating-micro-frontends-via-shared-types/>
VANCOUVER
Eden Ella | Sciencx - » Integrating Micro Frontends via Shared Types. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/03/integrating-micro-frontends-via-shared-types/
CHICAGO
" » Integrating Micro Frontends via Shared Types." Eden Ella | Sciencx - Accessed . https://www.scien.cx/2024/07/03/integrating-micro-frontends-via-shared-types/
IEEE
" » Integrating Micro Frontends via Shared Types." Eden Ella | Sciencx [Online]. Available: https://www.scien.cx/2024/07/03/integrating-micro-frontends-via-shared-types/. [Accessed: ]
rf:citation
» Integrating Micro Frontends via Shared Types | Eden Ella | Sciencx | https://www.scien.cx/2024/07/03/integrating-micro-frontends-via-shared-types/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.