Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
iluwatar authored Jan 11, 2025
2 parents d317ca2 + bcad5b1 commit 9864495
Show file tree
Hide file tree
Showing 45 changed files with 2,426 additions and 66 deletions.
45 changes: 45 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -3312,6 +3312,51 @@
"contributions": [
"translation"
]
},
{
"login": "HabibaMekay",
"name": "HabibaMekay",
"avatar_url": "https://avatars.githubusercontent.com/u/133516736?v=4",
"profile": "https://github.com/HabibaMekay",
"contributions": [
"code"
]
},
{
"login": "Ahmed-Taha-981",
"name": "Ahmed-Taha-981",
"avatar_url": "https://avatars.githubusercontent.com/u/122402269?v=4",
"profile": "https://github.com/Ahmed-Taha-981",
"contributions": [
"code"
]
},
{
"login": "malak-elbanna",
"name": "Malak Elbanna",
"avatar_url": "https://avatars.githubusercontent.com/u/67643605?v=4",
"profile": "https://malakelbanna.netlify.app/",
"contributions": [
"code"
]
},
{
"login": "depthlending",
"name": "BiKangNing",
"avatar_url": "https://avatars.githubusercontent.com/u/164312726?v=4",
"profile": "https://github.com/depthlending",
"contributions": [
"doc"
]
},
{
"login": "TarunVishwakarma1",
"name": "Tarun Vishwakarma",
"avatar_url": "https://avatars.githubusercontent.com/u/138651451?v=4",
"profile": "https://github.com/TarunVishwakarma1",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 6,
Expand Down
61 changes: 0 additions & 61 deletions .github/stale.yml

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: 'Comment on stale issues and PRs'
on:
schedule:
- cron: '30 1 * * *'

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
stale-issue-message: 'This issue is stale because it has been open 60 days with no activity.'
stale-pr-message: 'This PR is stale because it has been open 60 days with no activity.'
close-issue-message: 'This issue was closed because it has been stalled for too long with no activity.'
close-pr-message: 'This PR was closed because it has been stalled for too long with no activity.'
days-before-issue-stale: 60
days-before-pr-stale: 60
days-before-issue-close: -1
days-before-pr-close: -1
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=iluwatar_java-design-patterns&metric=coverage)](https://sonarcloud.io/dashboard?id=iluwatar_java-design-patterns)
[![Join the chat at https://gitter.im/iluwatar/java-design-patterns](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-362-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-368-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

<br/>
Expand Down Expand Up @@ -544,6 +544,13 @@ This project is licensed under the terms of the MIT license.
<td align="center" valign="top" width="16.66%"><a href="https://github.com/SalmaAzeem"><img src="https://avatars.githubusercontent.com/u/121863224?v=4?s=100" width="100px;" alt="Salma"/><br /><sub><b>Salma</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=SalmaAzeem" title="Code">💻</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://codemaverick-143.github.io/My-Portfolio/"><img src="https://avatars.githubusercontent.com/u/182847716?v=4?s=100" width="100px;" alt="Arpit Sarang"/><br /><sub><b>Arpit Sarang</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=CodeMaverick-143" title="Code">💻</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/mayatarek"><img src="https://avatars.githubusercontent.com/u/111644421?v=4?s=100" width="100px;" alt="Maya"/><br /><sub><b>Maya</b></sub></a><br /><a href="#translation-mayatarek" title="Translation">🌍</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/HabibaMekay"><img src="https://avatars.githubusercontent.com/u/133516736?v=4?s=100" width="100px;" alt="HabibaMekay"/><br /><sub><b>HabibaMekay</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=HabibaMekay" title="Code">💻</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/Ahmed-Taha-981"><img src="https://avatars.githubusercontent.com/u/122402269?v=4?s=100" width="100px;" alt="Ahmed-Taha-981"/><br /><sub><b>Ahmed-Taha-981</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=Ahmed-Taha-981" title="Code">💻</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://malakelbanna.netlify.app/"><img src="https://avatars.githubusercontent.com/u/67643605?v=4?s=100" width="100px;" alt="Malak Elbanna"/><br /><sub><b>Malak Elbanna</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=malak-elbanna" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/depthlending"><img src="https://avatars.githubusercontent.com/u/164312726?v=4?s=100" width="100px;" alt="BiKangNing"/><br /><sub><b>BiKangNing</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=depthlending" title="Documentation">📖</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/TarunVishwakarma1"><img src="https://avatars.githubusercontent.com/u/138651451?v=4?s=100" width="100px;" alt="Tarun Vishwakarma"/><br /><sub><b>Tarun Vishwakarma</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=TarunVishwakarma1" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
2 changes: 1 addition & 1 deletion hexagonal-architecture/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Hexagonal Architecture is particularly beneficial in scenarios:
* There is a requirement for high testability and maintainability.
* The application should remain unaffected by changes in external interfaces.

## Real-World Applications of Hexagonal Architecure Pattern in Java
## Real-World Applications of Hexagonal Architecture Pattern in Java

* Implemented extensively within enterprise applications that leverage frameworks like Spring.
* Used in microservices architectures to maintain clear boundaries and protocols between services.
Expand Down
2 changes: 1 addition & 1 deletion hexagonal-architecture/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>4.18.0</version>
<version>4.18.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
136 changes: 136 additions & 0 deletions microservices-client-side-ui-composition/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
---
title: "Client-Side UI Composition Pattern: Assembling Modular UIs in Microservices Architecture"
shortTitle: Client-Side UI Composition Pattern
description: "Learn how the Client-Side UI Composition pattern allows the assembly of modular UIs on the client side, enabling independent teams to develop, deploy, and scale UI components in a microservices architecture. Discover the benefits, implementation examples, and best practices."
category: User Interface
language: en
tag:
- Micro Frontends
- API Gateway
- Asynchronous Data Fetching
- UI Integration
- Microservices Architecture
- Scalability
---

## **Intent of Client-Side UI Composition Design Pattern**

The Client-Side UI Composition Pattern allows the assembly of UIs on the client side by composing independent UI components (Micro Frontends). Each component is developed, tested, and deployed independently by separate teams, ensuring flexibility and scalability in microservices architecture.

---

## **Also Known As**

- Micro Frontends
- Modular UI Assembly
- Client-Side Integration

---

## **Detailed Explanation of Client-Side UI Composition Pattern with Real-World Examples**

### **Real-world Example**
> In a SaaS dashboard, a client-side composition pattern enables various independent modules like “Billing,” “Reports,” and “Account Settings” to be developed and deployed by separate teams. These modules are composed into a unified interface for the user, with each module independently fetching data from its respective microservice.
### **In Plain Words**
> The Client-Side UI Composition pattern breaks down the user interface into smaller, independent parts that can be developed, maintained, and scaled separately by different teams.
### **Wikipedia says**
>UI composition refers to the practice of building a user interface from modular components, each responsible for fetching its own data and rendering its own content. This approach enables faster development cycles, easier maintenance, and better scalability in large systems.
---

## **Programmatic Example of Client-Side UI Composition in JavaScript**

In this example, an e-commerce platform composes its frontend by integrating three independent modules: **CartService**, **ProductService**, and **OrderService**. Each module is served by a microservice and fetched on the client side through an API Gateway.

`ApiGateway` Implementation

```java
public class ApiGateway {

private final Map<String, FrontendComponent> routes = new HashMap<>();

public void registerRoute(String path, FrontendComponent component) {
routes.put(path, component);
}

public String handleRequest(String path, Map<String, String> params) {
if (routes.containsKey(path)) {
return routes.get(path).fetchData(params);
} else {
return "404 Not Found";
}
}
}

```

`FrontendComponent` Implementation
```java
public interface FrontendComponent {
String fetchData(Map<String, String> params);
}
```
## Example components
```java
public class ProductComponent implements FrontendComponent {
@Override
public String fetchData(Map<String, String> params) {
return "Displaying Products: " + params.getOrDefault("category", "all");
}
}

public class CartComponent implements FrontendComponent {
@Override
public String fetchData(Map<String, String> params) {
return "Displaying Cart for User: " + params.getOrDefault("userId", "unknown");
}
}
```
This approach dynamically assembles different UI components based on the route provided in the client-side request. Each component fetches its data asynchronously and renders it within the main interface.

---

## **When to Use the Client-Side UI Composition Pattern**

- When you have a microservices architecture where multiple teams develop different parts of the frontend.
- When you need to scale and deploy different UI modules independently.
- When you want to integrate multiple data sources or services into a cohesive frontend.

---

## **Client-Side UI Composition Pattern JavaScript Tutorials**

- [Micro Frontends in Action (O'Reilly)](https://www.oreilly.com/library/view/micro-frontends-in/9781617296873/)
- [Micro Frontends with React (ThoughtWorks)](https://www.thoughtworks.com/insights/articles/building-micro-frontends-using-react)
- [API Gateway in Microservices (Spring Cloud)](https://spring.io/guides/gs/gateway/)

---

## **Benefits and Trade-offs of Client-Side UI Composition Pattern**

### **Benefits**:
- **Modularity**: Each UI component is independent and can be developed by separate teams.
- **Scalability**: Micro Frontends allow for independent deployment and scaling of each component.
- **Flexibility**: Teams can choose different technologies to build components, offering flexibility in development.
- **Asynchronous Data Fetching**: Components can load data individually, improving performance.

### **Trade-offs**:
- **Increased Complexity**: Managing multiple micro frontends can increase overall system complexity.
- **Client-Side Performance**: Depending on the number of micro frontends, it may introduce a performance overhead due to multiple asynchronous requests.
- **Integration Overhead**: Client-side integration logic can become complex as the number of components grows.

---

## **Related Design Patterns**

- [Microservices API Gateway Pattern](https://java-design-patterns.com/patterns/microservices-api-gateway/) – API Gateway serves as a routing mechanism for client-side UI requests.
- [Backend for Frontend (BFF)](https://microservices.io/patterns/apigateway.html) – BFF pattern helps build custom backends for different UI experiences.

---

## **References and Credits**

- [Micro Frontends Architecture (Microfrontends.org)](https://micro-frontends.org/)
- [Building Microservices with Micro Frontends](https://martinfowler.com/articles/micro-frontends.html)
- [Client-Side UI Composition (Microservices.io)](https://microservices.io/patterns/client-side-ui-composition.html)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@startuml client_side_ui_composition_updated
skinparam classAttributeIconSize 0

class ApiGateway {
+registerRoute(path: String, component: FrontendComponent)
+handleRequest(path: String, params: Map<String, String>): String
}

class FrontendComponent {
+fetchData(params: Map<String, String>): String
#getData(params: Map<String, String>): String
}

class ProductFrontend {
+getData(params: Map<String, String>): String
}

class CartFrontend {
+getData(params: Map<String, String>): String
}

class ClientSideIntegrator {
+composeUI(path: String, params: Map<String, String>)
}

ApiGateway --> FrontendComponent
FrontendComponent <|-- ProductFrontend
FrontendComponent <|-- CartFrontend
ClientSideIntegrator --> ApiGateway

@enduml
50 changes: 50 additions & 0 deletions microservices-client-side-ui-composition/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
The MIT License
Copyright © 2014-2022 Ilkka Seppälä
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.26.0-SNAPSHOT</version>
</parent>

<artifactId>microservices-client-side-ui-composition</artifactId>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Loading

0 comments on commit 9864495

Please sign in to comment.