Skip to content

victorrentea/spring-modulith

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

225 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Modular Monolith Exercise

Uses Spring Modulith https://spring.io/projects/spring-modulith/

Module Overview

  • catalog: product details management & search
  • order: order workflow
  • inventory: stock and reservations
  • customer data
  • shipping

Spring Modulith Intro

A module can only reference by default the classes in the top-level package of other modules. A class in any subpackage (eg. impl) is considered implementation detail, and it should NOT be accessed from outside that module. Extra packages can be exposed via @NamedInterface

Modules cannot form dependency cycles.

index.adoc contains a diagram of the module interactions generated at each test run.

Exercises

Expand the hints if needed, and keep running ArchSpringModulithTest:

  1. In GetProductApi return the stock in the response.
  • catalog should not access any internal class of inventory module (run tests).
  • Enable and Pass GetProductE2ETest.
  • HintRetrieve the stock item number via a call to a new method in `InventoryInternalApi`
  1. Extract payment-related classes out of order module into a new payment module.
  • Fix the encapsulation violation and the dependency cycle introduced.
    • Hint to fix 'non-exposed..':Code having to do with the `order` internals should stay in `order`.
    • Hint to fix cycle:Solution#1Have a `PaymentCompletedEvent` thrown from payment back into order
    • Hint to fix cycle:Solution#2Introduce an interface in one of the modules implemented in the other (aka Dependency Inversion). Which module should hold the interface?
  • Encapsulate the new payment module: hide as many classes exposing as few classes to other modules
    • HintMove classes in a subpackage, like 'impl'
  1. SearchProductApi should only return products in stock

    • Test SearchProductsApiTest should pass.
    1. OptionSearch for matching products and join in-memory with all stock. Or vice-versa.
    2. OptionJOIN Stock via SQL/JPQL😐
    3. OptionReplicate stock item number at every change via events from `inventory`
    4. OptionPublish `OutOfStockEvent` and `BackInStockEvent` from `inventory`, updating a `Product.inStock` boolean;
    5. OptionJoin the Product with the StockView @Entity exposed by `inventory`
  2. Notifications

    • When payment is confirmed

    • Hint - code snippet
       public void onOrderStatusChanged(OrderStatusChangedEvent event) { String customerEmail = customerModule.getCustomer(event.customerId()).email(); if (event.status() == OrderStatus.PAYMENT_APPROVED) { sendPaymentConfirmedEmail(event, customerEmail); } if (event.status() == OrderStatus.SHIPPING_IN_PROGRESS) { sendOrderShippedEmail(event, customerEmail); } } 
  3. Move Reviews-related stuff out of catalog module

    • tests should pass

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages