Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Monolithic Architecture according to the guidelines provided by issue #2664 #3111

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions monolithic-architecture/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
---
title: "Monolithic Ecommerce App: A Cohesive Application Model"
shortTitle: Monolithic Ecommerce
description: "Explore the Monolithic Ecommerce application structure, its design intent, benefits, limitations, and real-world applications. Understand its simplicity and practical use cases."
category: Architectural
language: en
tag:
- Cohesion
- Simplicity
- Scalability
- Deployment
- Maintainability
---

## Monolithic-Ecommerce App
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README.md has a very specific format that is common for all the patterns. See instructions at: https://github.com/iluwatar/java-design-patterns/wiki/01.-How-to-contribute

Specifically, take a look at the required front matter structure at the beginning of the file.

* A Monolithic Ecommerce example to showcase Monolithic Architecture

## The Intent of Monolithic Design pattern
> 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.

## Detailed Explanation of the Monolithic Architecture
Real-world Example
> 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.

In Plain words
>The monolithic design pattern structures an application as a single unified unit, where all components are tightly coupled and run within a single process.

GeeksforGeeks states
> 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.

Why use MVC for a Monolithic Application ?
>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:
>* Model
>* View
>* Controller
>
> this also helps maintain the principles of a Monolithic Architecture which are:
>
> Simple to
>* Develop
>* Test
>* Deploy
>* Scale
>
## We can clearly see that this is a Monolithic application through the main class
This is a simplified version of the main application that shows the main interaction point with the CLI and how a user is registered
```java
@SpringBootApplication
public class EcommerceApp implements CommandLineRunner {

private static final Logger log = LogManager.getLogger(EcommerceApp.class);
private final UserCon userService;
private final ProductCon productService;
private final OrderCon orderService;
public EcommerceApp(UserCon userService, ProductCon productService, OrderCon orderService) {
this.userService = userService;
this.productService = productService;
this.orderService = orderService;
}
public static void main(String... args) {
SpringApplication.run(EcommerceApp.class, args);
}
@Override
public void run(String... args) {
Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8);

log.info("Welcome to the Monolithic E-commerce CLI!");
while (true) {
log.info("\nChoose an option:");
log.info("1. Register User");
log.info("2. Add Product");
log.info("3. Place Order");
log.info("4. Exit");
log.info("Enter your choice: ");

int userInput = scanner.nextInt();
scanner.nextLine();

switch (userInput) {
case 1 -> registerUser(scanner);
case 2 -> addProduct(scanner);
case 3 -> placeOrder(scanner);
case 4 -> {
log.info("Exiting the application. Goodbye!");
return;
}
default -> log.info("Invalid choice! Please try again.");
}
}
}
protected void registerUser(Scanner scanner) {
log.info("Enter user details:");
log.info("Name: ");
String name = scanner.nextLine();
log.info("Email: ");
String email = scanner.nextLine();
log.info("Password: ");
String password = scanner.nextLine();

User user = new User(null, name, email, password);
userService.registerUser(user);
log.info("User registered successfully!");
}

}
```
### 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.

## When should you resort to a Monolithic Architecture ?
>* An enterprise Starting off with a relatively small team
>* Simplicity is the most important factor of the project
>* Maintaining less entry points to the system is cruical
>* Prototyping ideas
>
## Pros & Cons of using Monolithic Architecture
>### Pros:
>* Simple Development: Easy to develop and deploy.
>* Unified Codebase: All code in one place, simplifying debugging.
>* Better Performance: No inter-service communication overhead.
>* Lower Costs: Minimal infrastructure and tooling requirements.
>* Ease of Testing: Single application makes end-to-end testing straightforward.
> * This is also assisted by the MVC structure employed in this example.
>### Cons:
>* Scalability Issues: Cannot scale individual components.
>* Tight Coupling: Changes in one area may impact the whole system.
>* Deployment Risks: A single failure can crash the entire application.
>* Complex Maintenance: Harder to manage as the codebase grows.
>* Limited Flexibility: Difficult to adopt new technologies for specific parts.

## Real-World Applications of Monolithic architecture Pattern in Java
>* E-Commerce Platforms
>* Content Management Systems (CMS)
>* Banking and Financial Systems
>* Enterprise Resource Planning (ERP) Systems
>* Retail Point of Sale (POS) Systems

## References
>* [GeeksforGeeks](https://www.geeksforgeeks.org/monolithic-architecture-system-design/)
>* [Wikipedia](https://en.wikipedia.org/wiki/Monolithic_application)
>* [vFunction](https://vfunction.com/blog/what-is-monolithic-application/#:~:text=A%20traditional%20e%2Dcommerce%20platform,inseparable%20components%20of%20the%20system.) Blog post
>* [Microservices.io](https://microservices.io/patterns/monolithic.html)
>* [IBM](https://www.ibm.com/think/topics/monolithic-architecture)
>#### References used to create the code
>* [Mockito](https://site.mockito.org/) -Testing
>* [Junit](https://junit.org/junit5/docs/current/user-guide/) -Testing
>* [Springboot](https://docs.spring.io/spring-boot/index.html) -Web Application Initiation (implemented but not utilized in this example)
>* [Sprint Data Jpa](https://docs.spring.io/spring-data/jpa/reference/index.html) -Database connection
>* [Lombok](https://projectlombok.org/) -Simplifying Classes
>* [Log4j](https://logging.apache.org/log4j/2.x/index.html) -Capturing Logs
>* [H2 Databse](https://www.h2database.com/html/tutorial.html) -Efficient, Simple, Dynamic Databse
123 changes: 123 additions & 0 deletions monolithic-architecture/etc/Monolithic-Ecommerce.urm.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
@startuml
package com.iluwatar.monolithic.model {
class Orders {
- id : Long
- product : Products
- quantity : Integer
- totalPrice : Double
- user : User
+ Orders()
+ Orders(id : Long, user : User, product : Products, quantity : Integer, totalPrice : Double)
# canEqual(other : Object) : boolean
+ equals(o : Object) : boolean
+ getId() : Long
+ getProduct() : Products
+ getQuantity() : Integer
+ getTotalPrice() : Double
+ getUser() : User
+ hashCode() : int
+ setId(id : Long)
+ setProduct(product : Products)
+ setQuantity(quantity : Integer)
+ setTotalPrice(totalPrice : Double)
+ setUser(user : User)
+ toString() : String
}
class Products {
- description : String
- id : Long
- name : String
- price : Double
- stock : Integer
+ Products()
+ Products(id : Long, name : String, description : String, price : Double, stock : Integer)
# canEqual(other : Object) : boolean
+ equals(o : Object) : boolean
+ getDescription() : String
+ getId() : Long
+ getName() : String
+ getPrice() : Double
+ getStock() : Integer
+ hashCode() : int
+ setDescription(description : String)
+ setId(id : Long)
+ setName(name : String)
+ setPrice(price : Double)
+ setStock(stock : Integer)
+ toString() : String
}
class User {
- email : String
- id : Long
- name : String
- password : String
+ User()
+ User(id : Long, name : String, email : String, password : String)
# canEqual(other : Object) : boolean
+ equals(o : Object) : boolean
+ getEmail() : String
+ getId() : Long
+ getName() : String
+ getPassword() : String
+ hashCode() : int
+ setEmail(email : String)
+ setId(id : Long)
+ setName(name : String)
+ setPassword(password : String)
+ toString() : String
}
}
package com.iluwatar.monolithic.repository {
interface OrderRepo {
}
interface ProductRepo {
}
interface UserRepo {
+ findByEmail(String) : User {abstract}
}
}
package com.iluwatar.monolithic.controller {
class OrderCon {
- orderRepository : OrderRepo
- productRepository : ProductRepo
- userRepository : UserRepo
+ OrderCon(orderRepository : OrderRepo, userRepository : UserRepo, productRepository : ProductRepo)
+ placeOrder(userId : Long, productId : Long, quantity : Integer) : Orders
}
class ProductCon {
- productRepository : ProductRepo
+ ProductCon(productRepository : ProductRepo)
+ addProduct(product : Products) : Products
+ getAllProducts() : List<Products>
}
class UserCon {
- userRepository : UserRepo
+ UserCon(userRepository : UserRepo)
+ registerUser(user : User) : User
}
}
package com.iluwatar.monolithic {
class EcommerceApp {
- log : Logger {static}
- orderService : OrderCon
- productService : ProductCon
- userService : UserCon
+ EcommerceApp(userService : UserCon, productService : ProductCon, orderService : OrderCon)
# addProduct(scanner : Scanner)
+ main(args : String[]) {static}
# placeOrder(scanner : Scanner)
# registerUser(scanner : Scanner)
+ run(args : String[])
}
}
UserCon --> "-userRepository" UserRepo
Orders --> "-user" User
OrderCon --> "-productRepository" ProductRepo
OrderCon --> "-userRepository" UserRepo
OrderCon --> "-orderRepository" OrderRepo
EcommerceApp --> "-userService" UserCon
EcommerceApp --> "-productService" ProductCon
ProductCon --> "-productRepository" ProductRepo
Orders --> "-product" Products
EcommerceApp --> "-orderService" OrderCon
@enduml
Loading
Loading