Skip to content

Commit a25b6a0

Browse files
feat: Implemented Monolithic Architecture according to the guidelines provided by issue #2664 (#3111)
* added a pom.xml file for the monolithic structure, set up MVC file structure, and added basic model files using H2 database since its light and efficient * added a pom.xml file for the monolithic structure, set up MVC file structure, and added basic model files using H2 database since its light and efficient * Added "controllers" and repository classes to communicate with database to maintain code cleanliness * added application.properties file for springboot, added controller classes and used the CLI main class from the previous submission and enhanced upon it * fixed checkstyle comments * fixed testing class * automatically generated puml * Readme File Added Detailed Readme File in the md format * attempting to fix some debugging issues added more test cases, and tried to fix pom.xml * dropped change * another attempted fix * added more test cases * Fixes Renamed the main module/directory. Added more content to the readme.md file. fixed the orElseThrow statements Fixes Renamed the main module/directory. Added more content to the readme.md file. fixed the orElseThrow statements * fixed naming and readme file --------- Co-authored-by: Ilkka Seppälä <[email protected]>
1 parent 9ad38a4 commit a25b6a0

20 files changed

+1495
-1
lines changed

Diff for: monolithic-architecture/README.md

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
---
2+
title: "Monolithic Ecommerce App: A Cohesive Application Model"
3+
shortTitle: Monolithic Ecommerce
4+
description: "Explore the Monolithic Ecommerce application structure, its design intent, benefits, limitations, and real-world applications. Understand its simplicity and practical use cases."
5+
category: Architectural
6+
language: en
7+
tag:
8+
- Cohesion
9+
- Simplicity
10+
- Scalability
11+
- Deployment
12+
- Maintainability
13+
---
14+
15+
## Monolithic-Ecommerce App
16+
* A Monolithic Ecommerce example to showcase Monolithic Architecture
17+
18+
## The Intent of Monolithic Design pattern
19+
> the Monolithic Design Pattern structures an application as a single, cohesive unit where all components—such as business logic, user interface, and data access are tightly integrated and operate as part of a single executable.
20+
21+
## Detailed Explanation of the Monolithic Architecture
22+
Real-world Example
23+
> 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.
24+
25+
In Plain words
26+
>The monolithic design pattern structures an application as a single unified unit, where all components are tightly coupled and run within a single process.
27+
28+
GeeksforGeeks states
29+
> 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.
30+
31+
Why use MVC for a Monolithic Application ?
32+
>The Model-View-Controller (MVC) pattern is not inherently tied to microservices or distributed systems. It's a software design pattern that organizes the codebase by separating concerns into three distinct layers:
33+
>* Model
34+
>* View
35+
>* Controller
36+
>
37+
> this also helps maintain the principles of a Monolithic Architecture which are:
38+
>
39+
> Simple to
40+
>* Develop
41+
>* Test
42+
>* Deploy
43+
>* Scale
44+
>
45+
## We can clearly see that this is a Monolithic application through the main class
46+
This is a simplified version of the main application that shows the main interaction point with the CLI and how a user is registered
47+
```java
48+
@SpringBootApplication
49+
public class EcommerceApp implements CommandLineRunner {
50+
51+
private static final Logger log = LogManager.getLogger(EcommerceApp.class);
52+
private final UserCon userService;
53+
private final ProductCon productService;
54+
private final OrderCon orderService;
55+
public EcommerceApp(UserCon userService, ProductCon productService, OrderCon orderService) {
56+
this.userService = userService;
57+
this.productService = productService;
58+
this.orderService = orderService;
59+
}
60+
public static void main(String... args) {
61+
SpringApplication.run(EcommerceApp.class, args);
62+
}
63+
@Override
64+
public void run(String... args) {
65+
Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8);
66+
67+
log.info("Welcome to the Monolithic E-commerce CLI!");
68+
while (true) {
69+
log.info("\nChoose an option:");
70+
log.info("1. Register User");
71+
log.info("2. Add Product");
72+
log.info("3. Place Order");
73+
log.info("4. Exit");
74+
log.info("Enter your choice: ");
75+
76+
int userInput = scanner.nextInt();
77+
scanner.nextLine();
78+
79+
switch (userInput) {
80+
case 1 -> registerUser(scanner);
81+
case 2 -> addProduct(scanner);
82+
case 3 -> placeOrder(scanner);
83+
case 4 -> {
84+
log.info("Exiting the application. Goodbye!");
85+
return;
86+
}
87+
default -> log.info("Invalid choice! Please try again.");
88+
}
89+
}
90+
}
91+
protected void registerUser(Scanner scanner) {
92+
log.info("Enter user details:");
93+
log.info("Name: ");
94+
String name = scanner.nextLine();
95+
log.info("Email: ");
96+
String email = scanner.nextLine();
97+
log.info("Password: ");
98+
String password = scanner.nextLine();
99+
100+
User user = new User(null, name, email, password);
101+
userService.registerUser(user);
102+
log.info("User registered successfully!");
103+
}
104+
105+
}
106+
```
107+
### We can clearly reach the conclusion that all of these classes reside under the same module and are essential for each other's functionality, this is supported by the presence of all relevant classes as parts of the main application class.
108+
109+
## When should you resort to a Monolithic Architecture ?
110+
>* An enterprise Starting off with a relatively small team
111+
>* Simplicity is the most important factor of the project
112+
>* Maintaining less entry points to the system is cruical
113+
>* Prototyping ideas
114+
>
115+
## Pros & Cons of using Monolithic Architecture
116+
>### Pros:
117+
>* Simple Development: Easy to develop and deploy.
118+
>* Unified Codebase: All code in one place, simplifying debugging.
119+
>* Better Performance: No inter-service communication overhead.
120+
>* Lower Costs: Minimal infrastructure and tooling requirements.
121+
>* Ease of Testing: Single application makes end-to-end testing straightforward.
122+
> * This is also assisted by the MVC structure employed in this example.
123+
>### Cons:
124+
>* Scalability Issues: Cannot scale individual components.
125+
>* Tight Coupling: Changes in one area may impact the whole system.
126+
>* Deployment Risks: A single failure can crash the entire application.
127+
>* Complex Maintenance: Harder to manage as the codebase grows.
128+
>* Limited Flexibility: Difficult to adopt new technologies for specific parts.
129+
130+
## Real-World Applications of Monolithic architecture Pattern in Java
131+
>* E-Commerce Platforms
132+
>* Content Management Systems (CMS)
133+
>* Banking and Financial Systems
134+
>* Enterprise Resource Planning (ERP) Systems
135+
>* Retail Point of Sale (POS) Systems
136+
137+
## References
138+
>* [GeeksforGeeks](https://www.geeksforgeeks.org/monolithic-architecture-system-design/)
139+
>* [Wikipedia](https://en.wikipedia.org/wiki/Monolithic_application)
140+
>* [vFunction](https://vfunction.com/blog/what-is-monolithic-application/#:~:text=A%20traditional%20e%2Dcommerce%20platform,inseparable%20components%20of%20the%20system.) Blog post
141+
>* [Microservices.io](https://microservices.io/patterns/monolithic.html)
142+
>* [IBM](https://www.ibm.com/think/topics/monolithic-architecture)
143+
>#### References used to create the code
144+
>* [Mockito](https://site.mockito.org/) -Testing
145+
>* [Junit](https://junit.org/junit5/docs/current/user-guide/) -Testing
146+
>* [Springboot](https://docs.spring.io/spring-boot/index.html) -Web Application Initiation (implemented but not utilized in this example)
147+
>* [Sprint Data Jpa](https://docs.spring.io/spring-data/jpa/reference/index.html) -Database connection
148+
>* [Lombok](https://projectlombok.org/) -Simplifying Classes
149+
>* [Log4j](https://logging.apache.org/log4j/2.x/index.html) -Capturing Logs
150+
>* [H2 Databse](https://www.h2database.com/html/tutorial.html) -Efficient, Simple, Dynamic Databse
+123
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+
EcommerceApp --> "-productService" ProductCon
120+
ProductCon --> "-productRepository" ProductRepo
121+
Orders --> "-product" Products
122+
EcommerceApp --> "-orderService" OrderCon
123+
@enduml

0 commit comments

Comments
 (0)