Create a portal for micro-frontends by using AWS Amplify, Angular, and Module Federation
Created by Milena Godau (AWS) and Pedro Garcia (AWS)
Code repository: Angular Micro-frontend Portal | Environment: PoC or pilot | Technologies: Web & mobile apps; Infrastructure; Networking; Modernization |
Workload: Open-source | AWS services: AWS Amplify; AWS CLI |
Summary
A micro-frontend architecture enables multiple teams to work on different parts of a frontend application independently. Each team can develop, build, and deploy a fragment of the frontend without interfering with other parts of the application. From the end user's perspective, it appears to be a single, cohesive application. However, they are interacting with several independent applications that are published by different teams.
This document describes how to create a micro-frontend architecture by using AWS Amplify
The portal is split vertically. This means that the micro-frontends are entire views or groups of views, instead of parts of the same view. Therefore the shell application loads only one micro-frontend at a time.
The micro-frontends are implemented as remote modules. The shell application lazily loads these remote modules, which defers the micro-frontend initialization until it is required. This approach optimizes application performance by loading only the necessary modules. This reduces the initial load time and improves the overall user experience. Additionally, you share common dependencies across modules through the webpack configuration file (webpack.config.js). This practice promotes code reuse, reduces duplication, and streamlines the bundling process.
Prerequisites and limitations
Prerequisites
An active AWS account
Node.js and npm, installed
Amplify CLI, installed
Angular CLI, installed
Permissions to use AWS Amplify
Familiarity with Angular
Product versions
Angular CLI version 13.1.2 or later
@angular-architects/module-federation version 14.0.1 or later
webpack version 5.4.0 or later
AWS Amplify Gen 1
Limitations
A micro-frontend architecture is a powerful approach for building scalable and resilient web applications. However, it's crucial to understand the following potential challenges before adopting this approach:
Integration – One of the key challenges is the potential increase in complexity compared to monolithic frontends. Orchestrating multiple micro-frontends, handling communication between them, and managing shared dependencies can be more intricate. Additionally, there may be a performance overhead associated with communication between the micro-frontends. This communication can increase latency and reduce performance. This needs to be addressed through efficient messaging mechanisms and data-sharing strategies.
Code duplication – Because each micro-frontend is developed independently, there is a risk of duplicating code for common functionality or shared libraries. This can increase the overall application size and introduce maintenance challenges.
Coordination and management – Coordinating the development and deployment processes across multiple micro-frontends can be challenging. Ensuring consistent versioning, managing dependencies, and maintaining compatibility between components becomes more critical in a distributed architecture. Establishing clear governance, guidelines, and automated testing and deployment pipelines is essential for seamless collaboration and delivery.
Testing – Testing micro-frontend architectures can be more complex than testing monolithic frontends. It requires additional effort and specialized testing strategies to perform cross-component integration testing and end-to-end testing, and to validate consistent user experiences across multiple micro-frontends.
Before committing to the micro-frontend approach, we recommend that you review Understanding and implementing micro-frontends on AWS.
Architecture
In a micro-frontend architecture, each team develops and deploys features independently. The following image shows how multiple DevOps teams work together. The portal team develops the shell application. The shell application acts as a container. It retrieves, displays, and integrates the micro-frontend applications that are published by other DevOps teams. You use AWS Amplify to publish the shell application and micro-frontend applications.
The architecture diagram shows the following workflow:
The portal team develops and maintains the shell application. The shell application orchestrates the integration and rendering of the micro-frontends in order to compose the overall portal.
Teams A and B develop and maintain one or more micro-frontends or features that are integrated into the portal. Each team can work independently on their respective micro-frontends.
The end user authenticates by using Amazon Cognito.
The end user accesses the portal, and the shell application is loaded. As the user navigates, the shell application deals with the routing and retrieves the requested micro-frontend, loading its bundle.
Tools
AWS services
AWS Amplify
is a set of purpose-built tools and features that helps frontend web and mobile developers quickly build full-stack applications on AWS. In this pattern, you use the Amplify CLI to deploy the Amplify micro-frontend applications. AWS Command Line Interface (AWS CLI) is an open source tool that helps you interact with AWS services through commands in your command-line shell.
Other tools
@angular-architects/module-federation
is a plugin that integrates Angular with Module Federation. Angular
is an open source web application framework for building modern, scalable, and testable single-page applications. It follows a modular and component-based architecture that promotes code reuse and maintenance. Node.js
is an event-driven JavaScript runtime environment designed that is for building scalable network applications. npm
is a software registry that runs in a Node.js environment and is used to share or borrow packages and manage deployment of private packages. Webpack Module Federation
helps you load code that is independently compiled and deployed, such as micro-frontends or plugins, into an application.
Code repository
The code for this pattern is available in the Micro-frontend portal using Angular and Module Federation
shell-app
contains the code for the shell application.feature1-app
contains a sample micro-frontend. The shell application fetches this micro-frontend and displays it as a page within the portal application.
Best practices
Micro-frontend architectures offer numerous advantages, but they also introduce complexity. The following are some best practices for smooth development, high-quality code, and a great user experience:
Planning and communication – To streamline collaboration, invest in upfront planning, design, and clear communication channels.
Design consistency – Enforce a consistent visual style across micro-frontends by using design systems, style guides, and component libraries. This provides a cohesive user experience and accelerates development.
Dependency management – Because micro-frontends evolve independently, adopt standardized contracts and versioning strategies to manage dependencies effectively and prevent compatibility issues.
Micro-frontend architecture – To enable independent development and deployment, each micro-frontend should have a clear and well-defined responsibility for an encapsulated functionality.
Integration and communication – To facilitate smooth integration and minimize conflicts, define clear contracts and communication protocols between micro-frontends, including APIs, events, and shared data models.
Testing and quality assurance – Implement test automation and continuous integration pipelines for micro-frontends. This improves the overall quality, reduces manual testing effort, and validates functionality between micro-frontend interactions.
Performance optimization – Continuously monitor performance metrics and track dependencies between micro-frontends. This helps you identify bottlenecks and maintain optimal application performance. Use performance monitoring and dependency analysis tools for this purpose.
Developer experience – Focus on the developer experience by providing clear documentation, tooling, and examples. This helps you streamline development and onboard new team members.
Epics
Task | Description | Skills required |
---|---|---|
Create the shell application. |
| App developer |
Install the plugin. | In the Angular CLI, enter the following command to install the @angular-architects/module-federation
| App developer |
Add the micro-frontend URL as an environment variable. |
| App developer |
Define routing. |
| App developer |
Declare the |
| App developer |
Prepare preloading for the micro-frontend. | Preloading the micro-frontend helps the webpack properly negotiate the shared libraries and packages.
| App developer |
Adjust the HTML content. |
| App developer |
Task | Description | Skills required |
---|---|---|
Create the micro-frontend. |
| App developer |
Install the plugin. | Enter the following command to install the @angular-architects/module-federation plugin:
| App developer |
Create a module and component. | Enter the following commands to create a module and component and export them as the remote entry module:
| App developer |
Set the default routing path. |
| App developer |
Add the |
| App developer |
Edit the webpack.config.js file. |
| App developer |
Adjust the HTML content. |
| App developer |
Task | Description | Skills required |
---|---|---|
Run the |
| App developer |
Run the shell application. |
| App developer |
Task | Description | Skills required |
---|---|---|
Create a module and component. | In the root folder of the shell application, enter the following commands to create a module and component for an error page:
| App developer |
Adjust the HTML content. |
| App developer |
Set the default routing path. |
| App developer |
Create a function to load micro-frontends. |
| App developer |
Test the error handling. |
| App developer |
Task | Description | Skills required |
---|---|---|
Deploy the micro-frontend. |
| App developer, AWS DevOps |
Deploy the shell application. |
| App developer, App owner |
Enable CORS. | Because the shell and micro-frontend applications are hosted independently on different domains, you must enable cross-origin resource sharing (CORS) on the micro-frontend. This allows the shell application to load the content from a different origin. To enable CORS, you add custom headers.
| App developer, AWS DevOps |
Create a rewrite rule on the shell application. | The Angular shell application is configured to use HTML5 routing. If the user performs a hard refresh, Amplify tries to load a page from the current URL. This generates a 403 error. To avoid this, you add a rewrite rule in the Amplify console. To create the rewrite rule, follow these steps:
| App developer, AWS DevOps |
Test the web portal. |
| App developer |
Task | Description | Skills required |
---|---|---|
Delete the applications. | If you no longer need the shell and micro-frontend applications, delete them. This helps prevent charges for resources that you aren't using.
| General AWS |
Troubleshooting
Issue | Solution |
---|---|
No AWS profile available when running the | If you don't have an AWS profile configured, you can still proceed with the Alternatively, you can configure a named profile for the AWS CLI. For instructions, see Configuration and credential file settings in the AWS CLI documentation. |
Error loading remote entries | If you encounter an error when loading the remote entries in the main.ts file of the shell application, make sure that the |
404 error when accessing the micro-frontend | If you get a 404 error when trying to access the local micro-frontend, such as at
|
Additional information
AWS documentation
Understanding and implementing micro-frontends on AWS (AWS Prescriptive Guidance)
Amplify CLI
(Amplify documentation) Amplify Hosting (Amplify documentation)
Other references