Skip to content

Commit 21b083f

Browse files
author
Mohaned Atef
committed
Merge branch 'Monolithic-Ecommerce'
2 parents 784d45e + 5b03784 commit 21b083f

File tree

20 files changed

+173
-15
lines changed

20 files changed

+173
-15
lines changed

Monolithic-Ecommerce/README.md renamed to monolithic-architecture/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
Real-world Example
99
> A traditional E-commerce website is the most straightforward example for a monolithic application as it is comprised of a catalogue of products, orders to be made, shopping carts, and payment processes that are all inseperable of each other.
1010
11+
In Plain words
12+
>The monolithic design pattern structures an application as a single unified unit, where all components are tightly coupled and run within a single process.
13+
1114
GeeksforGeeks states
1215
> Monolithic architecture, a traditional approach in system design, which contains all application components into a single codebase. This unified structure simplifies development and deployment processes, offering ease of management and tight integration. However, because of its rigidity, it is difficult to scale and maintain, which makes it difficult to adjust to changing needs.
1316
@@ -109,7 +112,14 @@ public class EcommerceApp implements CommandLineRunner {
109112
>* Deployment Risks: A single failure can crash the entire application.
110113
>* Complex Maintenance: Harder to manage as the codebase grows.
111114
>* Limited Flexibility: Difficult to adopt new technologies for specific parts.
112-
>
115+
116+
## Real-World Applications of Monolithic architecture Pattern in Java
117+
>* E-Commerce Platforms
118+
>* Content Management Systems (CMS)
119+
>* Banking and Financial Systems
120+
>* Enterprise Resource Planning (ERP) Systems
121+
>* Retail Point of Sale (POS) Systems
122+
113123
## References
114124
>* [GeeksforGeeks](https://www.geeksforgeeks.org/monolithic-architecture-system-design/)
115125
>* [Wikipedia](https://en.wikipedia.org/wiki/Monolithic_application)
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
@startuml
2+
package com.iluwatar.monolithic.model {
3+
class Orders {
4+
- id : Long
5+
- product : Products
6+
- quantity : Integer
7+
- totalPrice : Double
8+
- user : User
9+
+ Orders()
10+
+ Orders(id : Long, user : User, product : Products, quantity : Integer, totalPrice : Double)
11+
# canEqual(other : Object) : boolean
12+
+ equals(o : Object) : boolean
13+
+ getId() : Long
14+
+ getProduct() : Products
15+
+ getQuantity() : Integer
16+
+ getTotalPrice() : Double
17+
+ getUser() : User
18+
+ hashCode() : int
19+
+ setId(id : Long)
20+
+ setProduct(product : Products)
21+
+ setQuantity(quantity : Integer)
22+
+ setTotalPrice(totalPrice : Double)
23+
+ setUser(user : User)
24+
+ toString() : String
25+
}
26+
class Products {
27+
- description : String
28+
- id : Long
29+
- name : String
30+
- price : Double
31+
- stock : Integer
32+
+ Products()
33+
+ Products(id : Long, name : String, description : String, price : Double, stock : Integer)
34+
# canEqual(other : Object) : boolean
35+
+ equals(o : Object) : boolean
36+
+ getDescription() : String
37+
+ getId() : Long
38+
+ getName() : String
39+
+ getPrice() : Double
40+
+ getStock() : Integer
41+
+ hashCode() : int
42+
+ setDescription(description : String)
43+
+ setId(id : Long)
44+
+ setName(name : String)
45+
+ setPrice(price : Double)
46+
+ setStock(stock : Integer)
47+
+ toString() : String
48+
}
49+
class User {
50+
- email : String
51+
- id : Long
52+
- name : String
53+
- password : String
54+
+ User()
55+
+ User(id : Long, name : String, email : String, password : String)
56+
# canEqual(other : Object) : boolean
57+
+ equals(o : Object) : boolean
58+
+ getEmail() : String
59+
+ getId() : Long
60+
+ getName() : String
61+
+ getPassword() : String
62+
+ hashCode() : int
63+
+ setEmail(email : String)
64+
+ setId(id : Long)
65+
+ setName(name : String)
66+
+ setPassword(password : String)
67+
+ toString() : String
68+
}
69+
}
70+
package com.iluwatar.monolithic.repository {
71+
interface OrderRepo {
72+
}
73+
interface ProductRepo {
74+
}
75+
interface UserRepo {
76+
+ findByEmail(String) : User {abstract}
77+
}
78+
}
79+
package com.iluwatar.monolithic.controller {
80+
class OrderCon {
81+
- orderRepository : OrderRepo
82+
- productRepository : ProductRepo
83+
- userRepository : UserRepo
84+
+ OrderCon(orderRepository : OrderRepo, userRepository : UserRepo, productRepository : ProductRepo)
85+
+ placeOrder(userId : Long, productId : Long, quantity : Integer) : Orders
86+
}
87+
class ProductCon {
88+
- productRepository : ProductRepo
89+
+ ProductCon(productRepository : ProductRepo)
90+
+ addProduct(product : Products) : Products
91+
+ getAllProducts() : List<Products>
92+
}
93+
class UserCon {
94+
- userRepository : UserRepo
95+
+ UserCon(userRepository : UserRepo)
96+
+ registerUser(user : User) : User
97+
}
98+
}
99+
package com.iluwatar.monolithic {
100+
class EcommerceApp {
101+
- log : Logger {static}
102+
- orderService : OrderCon
103+
- productService : ProductCon
104+
- userService : UserCon
105+
+ EcommerceApp(userService : UserCon, productService : ProductCon, orderService : OrderCon)
106+
# addProduct(scanner : Scanner)
107+
+ main(args : String[]) {static}
108+
# placeOrder(scanner : Scanner)
109+
# registerUser(scanner : Scanner)
110+
+ run(args : String[])
111+
}
112+
}
113+
UserCon --> "-userRepository" UserRepo
114+
Orders --> "-user" User
115+
OrderCon --> "-productRepository" ProductRepo
116+
OrderCon --> "-userRepository" UserRepo
117+
OrderCon --> "-orderRepository" OrderRepo
118+
EcommerceApp --> "-userService" UserCon
119+
Orders --> "-product" Products
120+
ProductCon --> "-productRepository" ProductRepo
121+
EcommerceApp --> "-productService" ProductCon
122+
EcommerceApp --> "-orderService" OrderCon
123+
@enduml

Monolithic-Ecommerce/pom.xml renamed to monolithic-architecture/pom.xml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
-->
2828
<project xmlns="http://maven.apache.org/POM/4.0.0"
2929
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
30-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
30+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
3131
<modelVersion>4.0.0</modelVersion>
3232

3333
<parent>
@@ -36,8 +36,7 @@
3636
<version>1.26.0-SNAPSHOT</version>
3737
</parent>
3838

39-
<artifactId>Monolithic-Ecommerce</artifactId>
40-
39+
<artifactId>monolithic-architecture</artifactId>
4140

4241
<dependencies>
4342
<!-- Spring Boot Starter Web -->
@@ -80,6 +79,29 @@
8079
<scope>test</scope>
8180
</dependency>
8281
</dependencies>
82+
83+
<build>
84+
<plugins>
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-assembly-plugin</artifactId>
88+
<executions>
89+
<execution>
90+
<configuration>
91+
<archive>
92+
<manifest>
93+
<mainClass>com.iluwatar.monolithic.EcommerceApp</mainClass>
94+
</manifest>
95+
</archive>
96+
<descriptorRefs>
97+
<descriptorRef>jar-with-dependencies</descriptorRef>
98+
</descriptorRefs>
99+
</configuration>
100+
</execution>
101+
</executions>
102+
</plugin>
103+
</plugins>
104+
</build>
83105
</project>
84106

85107

Monolithic-Ecommerce/src/main/java/com/iluwatar/monolithic/EcommerceApp.java renamed to monolithic-architecture/src/main/java/com/iluwatar/monolithic/EcommerceApp.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,16 @@
3939

4040
/**
4141
* Main entry point for the Monolithic E-commerce application.
42+
* ------------------------------------------------------------------------
43+
* Monolithic architecture is a software design pattern where all components
44+
* of the application (presentation, business logic, and data access layers)
45+
* are part of a single unified codebase and deployable unit.
46+
* ------------------------------------------------------------------------
47+
* This example implements a monolithic architecture by integrating
48+
* user management, product management, and order placement within
49+
* the same application, sharing common resources and a single database.
4250
*/
51+
4352
@SpringBootApplication
4453
public class EcommerceApp implements CommandLineRunner {
4554

Monolithic-Ecommerce/src/main/java/com/iluwatar/monolithic/controller/OrderCon.java renamed to monolithic-architecture/src/main/java/com/iluwatar/monolithic/controller/OrderCon.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,18 @@ public OrderCon(OrderRepo orderRepository, UserRepo userRepository, ProductRepo
5353
* This function handles placing orders with all of its cases.
5454
* */
5555
public Orders placeOrder(Long userId, Long productId, Integer quantity) {
56-
User user = userRepository.findById(userId).orElse(null);
57-
if (user == null) {
58-
throw new NonExistentUserException("User with ID " + userId + " not found");
59-
}
60-
61-
Products product = productRepository.findById(productId).orElse(null);
62-
if (product == null) {
63-
throw new NonExistentProductException("Product with ID " + productId + " not found");
64-
}
56+
final User user = userRepository.findById(userId).orElseThrow(() -> new NonExistentUserException("User with ID " + userId + " not found"));
6557

58+
final Products product = productRepository.findById(productId).orElseThrow(() -> new NonExistentProductException("Product with ID " + productId + " not found"));
59+
6660
if (product.getStock() < quantity) {
6761
throw new InsufficientStockException("Not enough stock for product " + productId);
6862
}
6963

7064
product.setStock(product.getStock() - quantity);
7165
productRepository.save(product);
7266

73-
Orders order = new Orders(null, user, product, quantity, product.getPrice() * quantity);
67+
final Orders order = new Orders(null, user, product, quantity, product.getPrice() * quantity);
7468
return orderRepository.save(order);
7569
}
7670
}

0 commit comments

Comments
 (0)