# vinsguru/spring-webflux-course architecture

> Architecture diagram of the GitHub repository vinsguru/spring-webflux-course, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vinsguru/spring-webflux-course
- Repository: https://github.com/vinsguru/spring-webflux-course

## Overview

Based on our review of the complete file tree and the README, the project is clearly a course repository for building reactive microservices with Spring WebFlux. It contains several modules and projects that serve as demos, playgrounds, and final implementations—as well as legacy examples—that showcase reactive versus traditional paradigms, use of R2DBC vs. JDBC, streaming with SSE, WebFilters, error handling, and more. There is even a “trade-platofrm” final project composed of multiple microservices (aggregator, customer, product, and user services) to illustrate a multi-service architecture using Spring WebFlux.

##### Main Components
- Frontend/Demo Layer: Although the primary focus is on service logic (and you may only have a static index.html as view), note the presence of static resources in several modules. This represents the client side for testing and demonstration (WebFlux playground modules and static web resources).
- API / Controller Layer: Each module (for example, sec01–sec09 in the “02-webflux-playground” and the controllers in the “03-final-project” services) represents the reactive API endpoints. Graphically, each controller or functional route should be noted.
- Service Layer: Almost every module adopts a service class (e.g., CustomerService, ProductService, TradeService) which encapsulates business logic.
- Data Access / Repository Layer: Several packages (e.g., repository packages in sec02, sec03, etc.) indicate the use of reactive repositories and data access concrete implementation to interact with databases (using R2DBC).
- Domain & DTO: Include domain entities and data transfer objects (DTOs) which show that each service is designed with layers that separate concerns.
- Exception Handling & Validation: The existence of advices, exception handlers, and validators in multiple modules shows that error handling and input validations are considered an integral part of the design.
- External Clients & Integration: For instance, in the aggregator service, there are client packages (e.g., CustomerServiceClient and StockServiceClient) that call external services. This highlights service-to-service communication across microservices.

##### Interactions and Relationships
- Among Microservices in the “trade-platofrm” Final Project: Emphasize that the aggregator service interacts with the customer and (possibly) stock services. Use connectors to indicate API calls or messaging between these microservices.
- External Systems: Illustrate any external calls (such as WebClient calls for streaming data, SSE endpoints) and indicate that reactive clients are used to consume external APIs and services.

##### Architectural Patterns and Technologies
- Reactive Programming: Clearly mark that the controllers are built on reactive principles (Flux and Mono) and that the data access uses reactive patterns (R2DBC drivers for connecting to relational databases).
- Functional Endpoints: Indicate that some modules (for example, sec06 in the playground) use a functional routing approach rather than the traditional @Controller-based method.
- Exception Handling and Validation: Identify components such as ApplicationExceptionHandler and RequestValidator as key modules ensuring robustness.
- Test Components: Although not runtime components, note that there are dedicated integration and unit test packages (using WebTestClient) verifying various aspects of reactive microservices.

- For microservices (trade platform), explicitly show:
- The external communication (client calls between aggregator and customer services)
- Shared configuration or common concerns if any
- The repository and database setup as part of each microservice.

## Diagram (Mermaid)

```mermaid
graph TD

  %% Webflux Playground Modules
  subgraph "Webflux Playground Modules"
    %% Frontend / Demo Layer
    subgraph "Frontend / Demo Layer"
      F1["Static Web Resource"]:::frontend
    end

    %% API / Controller Layer
    subgraph "API / Controller Layer"
      RC["Reactive WebController"]:::api
      TC["Traditional WebController"]:::api
      CC3["CustomerController (Sec03)"]:::api
      CC4["CustomerController (Sec04)"]:::api
      CC5["CustomerController (Sec05)"]:::api
      CRH["CustomerRequestHandler"]:::api
    end

    %% Service Layer
    subgraph "Service Layer"
      CS3["CustomerService (Sec03)"]:::service
      CS4["CustomerService (Sec04)"]:::service
      CS5["CustomerService (Sec05)"]:::service
      CS6["CustomerService (Sec06)"]:::service
    end

    %% Repository / Data Access Layer
    subgraph "Repository Layer"
      COR["CustomerOrderRepository"]:::repository
      CPR2["CustomerRepository (Sec02)"]:::repository
      PRR2["ProductRepository (Sec02)"]:::repository
      CPR3["CustomerRepository (Sec03)"]:::repository
      PRR8["ProductRepository (Sec08)"]:::repository
      PRR9["ProductRepository (Sec09)"]:::repository
    end

    %% Domain & DTO
    subgraph "Domain & DTO"
      PE["Product Entity"]:::domain
      CE["Customer Entity"]:::domain
      ODT["OrderDetails DTO"]:::domain
      CDT["CustomerDto"]:::domain
      PDT["ProductDto"]:::domain
    end

    %% Exception Handling & Validation
    subgraph "Exception Handling & Validation"
      AEH["ApplicationExceptionHandler"]:::exception
      RV["RequestValidator"]:::exception
    end

    %% Connections within Playground
    F1 -->|"triggers"| RC
    F1 -->|"triggers"| TC

    RC -->|"delegates"| CS3
    TC -->|"delegates"| CS3
    CC3 -->|"delegates"| CS3
    CC4 -->|"delegates"| CS4
    CC5 -->|"delegates"| CS5
    CRH -->|"delegates"| CS6

    CS3 -->|"accesses"| CPR3
    CS4 -->|"accesses"| CPR3
    CS5 -->|"accesses"| CPR3
    CS6 -->|"accesses"| CPR3

    %% Link Domain usage (illustrative)
    CPR3 ---|"maps to"| PE
    CPR3 ---|"maps to"| CE
    CS3 ---|"transfers"| CDT
    CS3 ---|"transfers"| ODT
    PRR8 ---|"maps to"| PDT

    %% Exception and Validation links
    RC ---|"handles"| AEH
    TC ---|"handles"| AEH
    CC3 ---|"validates"| RV
    CC4 ---|"validates"| RV
    CC5 ---|"validates"| RV
    CRH ---|"validates"| RV
  end

  %% Trade Platform Microservices: Aggregator Service
  subgraph "Trade Platform Microservices - Aggregator Service"
    %% API / Controller Layer for Aggregator
    APC["CustomerPortfolioController"]:::api
    SPSC["StockPriceStreamController"]:::api

    %% Service Layer for Aggregator
    CPS["CustomerPortfolioService"]:::service

    %% External Clients & Integration
    CSC["CustomerServiceClient"]:::external
    SSC["StockServiceClient"]:::external

    APC -->|"calls"| CPS
    SPSC -->|"calls"| CPS
    CPS -->|"integrates"| CSC
    CPS -->|"integrates"| SSC
  end

  %% Click Events for Frontend / Demo Layer
  click F1 "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/resources/static/index.html"

  %% Click Events for API / Controller Layer in Playground
  click RC "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec01/ReactiveWebController.java"
  click TC "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec01/TraditionalWebController.java"
  click CC3 "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec03/controller/CustomerController.java"
  click CC4 "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec04/controller/CustomerController.java"
  click CC5 "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec05/controller/CustomerController.java"
  click CRH "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec06/config/CustomerRequestHandler.java"

  %% Click Events for Service Layer in Playground
  click CS3 "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec03/service/CustomerService.java"
  click CS4 "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec04/service/CustomerService.java"
  click CS5 "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec05/service/CustomerService.java"
  click CS6 "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec06/service/CustomerService.java"

  %% Click Events for Repository Layer in Playground
  click COR "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec02/repository/CustomerOrderRepository.java"
  click CPR2 "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec02/repository/CustomerRepository.java"
  click PRR2 "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec02/repository/ProductRepository.java"
  click CPR3 "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec03/repository/CustomerRepository.java"
  click PRR8 "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec08/repository/ProductRepository.java"
  click PRR9 "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec09/repository/ProductRepository.java"

  %% Click Events for Domain & DTO
  click PE "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec01/Product.java"
  click CE "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec02/entity/Customer.java"
  click ODT "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec02/dto/OrderDetails.java"
  click CDT "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec03/dto/CustomerDto.java"
  click PDT "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec08/dto/ProductDto.java"

  %% Click Events for Exception Handling & Validation
  click AEH "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec04/advice/ApplicationExceptionHandler.java"
  click RV "https://github.com/vinsguru/spring-webflux-course/blob/master/02-webflux-playground/src/main/java/com/vinsguru/playground/sec04/validator/RequestValidator.java"

  %% Click Events for Trade Platform Microservices - Aggregator Service
  click APC "https://github.com/vinsguru/spring-webflux-course/blob/master/03-final-project/trade-platofrm/aggregator-service/src/main/java/com/vinsguru/aggregator/controller/CustomerPortfolioController.java"
  click SPSC "https://github.com/vinsguru/spring-webflux-course/blob/master/03-final-project/trade-platofrm/aggregator-service/src/main/java/com/vinsguru/aggregator/controller/StockPriceStreamController.java"
  click CPS "https://github.com/vinsguru/spring-webflux-course/blob/master/03-final-project/trade-platofrm/aggregator-service/src/main/java/com/vinsguru/aggregator/service/CustomerPortfolioService.java"
  click CSC "https://github.com/vinsguru/spring-webflux-course/blob/master/03-final-project/trade-platofrm/aggregator-service/src/main/java/com/vinsguru/aggregator/client/CustomerServiceClient.java"
  click SSC "https://github.com/vinsguru/spring-webflux-course/blob/master/03-final-project/trade-platofrm/aggregator-service/src/main/java/com/vinsguru/aggregator/client/StockServiceClient.java"

  %% Styles
  classDef frontend fill:#ffde9e,stroke:#d48f00,stroke-width:2px;
  classDef api fill:#c9e9ff,stroke:#5fa8d3,stroke-width:2px;
  classDef service fill:#d0f0c0,stroke:#6aa84f,stroke-width:2px;
  classDef repository fill:#f9f9a9,stroke:#e69138,stroke-width:2px;
  classDef domain fill:#ffe599,stroke:#bf9000,stroke-width:2px;
  classDef exception fill:#f4cccc,stroke:#cc0000,stroke-width:2px;
  classDef external fill:#d9d2e9,stroke:#8e7cc3,stroke-width:2px;
```
