# johnyzhub/jee-cdi2 architecture

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

- Interactive diagram: https://gitdiagram.com/johnyzhub/jee-cdi2
- Repository: https://github.com/johnyzhub/jee-cdi2

## Overview

##### Project Type & Purpose
- The README clearly states “JEE 7 CDI 2.x Practice Project.” This project serves as a demonstration of Java EE’s Contexts and Dependency Injection (CDI) features.
- The file tree reveals three main modules:
– BookStore: Contains core business logic, entities, producers, decorators, interceptors, events, qualifying annotations, and services.
– BookStoreTracker: Likely a simpler module focusing on tracking, possibly demonstrating plain POJO usage and time tracking.
– RestWithProduce: A web module exposing REST functionality (with a standard webapp directory, web.xml, and JSP) that uses CDI to produce REST responses.

##### Analyzing the File Structure
- Each module follows a Maven standard layout (pom.xml, src/main/java, and src/main/resources).
- In the BookStore module, you observe further subdivisions:
- Entities (e.g., Author, Book, BookPrice, Category, StoreDetails)
- Services (e.g., BookService)
- Producers (e.g., DynamicProducer, InjectionProducer)
- Decorators (e.g., EbookPriceDecorator, PaperBackPriceDecorator)
- Interceptors (logging and constructor interceptors)
- CDI qualifiers and extension classes, which indicate advanced usage of CDI features.
- Event handlers (both synchronous and asynchronous)
- The RestWithProduce module shows a similar package structure but is tailored for building a REST web application with its own producers, selectors and entity definitions (e.g., FictionBook, SuspenseBook) that are exposed via REST endpoints.
- The BookStoreTracker module includes plain POJOs (such as a TimeTracker), probably to illustrate lightweight component design and tracking functionality.

a. Main Components:
- BookStore Module:
- BookService as the business service layer
- Entity layer including Book, Author, etc.
- Producer components (DynamicProducer, InjectionProducer) that instantiate beans dynamically based on qualifiers.
- Decorator components (EbookPriceDecorator, PaperBackPriceDecorator) to modify behavior.
- Interceptor stack (LoggingInterceptor, MethodInterceptor, ConstructorInterceptor) for cross-cutting concerns.
- Event handling components (SyncEventHandler and AsyncEventHandler)
- Qualifiers and extensions (PropertyLoaderExtension and associated qualifier classes)

- RestWithProduce Module:
- REST Controller/Resource: BookService under the “rest” package.
- Supporting components: Entities (Book, FictionBook, SuspenseBook), ProducerFactory, and BookSelector.
- Web layer including JSP view and web.xml for configuration.

- BookStoreTracker Module:
- A simple tracker component (TimeTracker) and any POJO-based logic.

- Supporting Infrastructure:
- The CDI container acting as the underlying dependency injection framework.
- External configuration files (beans.xml, WEB-INF/web.xml) that govern component discovery and configuration.

b. Relationships & Interactions:
- How the CDI container injects producers into services.
- Interaction between BookService and underlying entities.
- How decorators and interceptors wrap or modify calls to the service or method invocations.
- Event flow between source components and the synchronous/asynchronous handlers.
- REST module interactions: the REST controller routes calls to business services and in turn interacts with producers/selectors.
- The plain POJO-based tracker consuming time events or being updated by certain processes.

c. Key Architectural Patterns & Design Principles:
- Dependency Injection via CDI: Illustrate the container responsible for injecting beans produced by factories and producers.
- Decorator Pattern: Show decorator classes modifying behavior of price computation.
- Interceptor Pattern: Represent interceptors intercepting method calls for logging or security.
- Event-driven Architecture: Represent asynchronous and synchronous events being fired and handled.

d. Relevant Technologies, Frameworks & Libraries:
- Java EE environment (with JEE 7 specifics)
- CDI 2.x for dependency injection and bean management.
- The use of standard configuration files (beans.xml under META-INF) that control CDI behavior.
- For the web module, include REST (JAX-RS likely), and JSP/servlet container elements for the web aspect.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Supporting Infrastructure
    CDI_Container["CDI Container"]:::cdi

    %% BookStore Module
    subgraph "BookStore Module"
        BS_Entity["Entity Layer (Book, Author, etc.)"]:::entity
        BS_BS["BookService (Business Logic)"]:::service
        BS_DynamicProducer["DynamicProducer (Bean Producer)"]:::producer
        BS_InjectionProducer["InjectionProducer (Bean Producer)"]:::producer
        BS_EbookDecorator["EbookPriceDecorator (Decorator)"]:::decorator
        BS_PaperDecorator["PaperBackPriceDecorator (Decorator)"]:::decorator
        BS_LoggingInterceptor["LoggingInterceptor (Interceptor)"]:::interceptor
        BS_MethodInterceptor["MethodInterceptor (Interceptor)"]:::interceptor
        BS_ConstructorInterceptor["ConstructorInterceptor (Interceptor)"]:::interceptor
        BS_SyncEvent["SyncEventHandler (Event Handler)"]:::event
        BS_AsyncEvent["AsyncEventHandler (Event Handler)"]:::event
        BS_Qualifiers["Qualifiers"]:::qualifier
        BS_Extension["PropertyLoaderExtension (CDI Extension)"]:::extension
    end

    %% RestWithProduce Module
    subgraph "RestWithProduce Module"
        RWP_RESTBookService["BookService (REST Controller)"]:::controller
        RWP_Entity["Entity Layer (Book, FictionBook, SuspenseBook)"]:::entity
        RWP_ProducerFactory["ProducerFactory"]:::producer
        RWP_BookSelector["BookSelector"]:::selector
        RWP_webxml["web.xml (Configuration)"]:::config
        RWP_JSP["JSP View"]:::config
    end

    %% BookStoreTracker Module
    subgraph "BookStoreTracker Module"
        BST_TimeTracker["TimeTracker"]:::tracker
    end

    %% Connections within BookStore Module
    CDI_Container -->|"manages"| BS_BS
    CDI_Container -->|"manages"| BS_DynamicProducer
    CDI_Container -->|"manages"| BS_InjectionProducer

    BS_DynamicProducer -->|"injects"| BS_BS
    BS_InjectionProducer -->|"injects"| BS_BS

    BS_BS -->|"uses"| BS_Entity
    BS_BS -->|"firesEvent"| BS_SyncEvent
    BS_BS -->|"firesEvent"| BS_AsyncEvent

    BS_BS -->|"decoratedBy"| BS_EbookDecorator
    BS_BS -->|"decoratedBy"| BS_PaperDecorator

    BS_BS -->|"interceptedBy"| BS_LoggingInterceptor
    BS_BS -->|"interceptedBy"| BS_MethodInterceptor
    BS_BS -->|"interceptedBy"| BS_ConstructorInterceptor

    BS_Qualifiers -->|"appliesTo"| BS_DynamicProducer
    BS_Extension -->|"configures"| BS_DynamicProducer

    %% Connections within RestWithProduce Module
    CDI_Container -->|"manages"| RWP_RESTBookService
    RWP_RESTBookService -->|"calls"| BS_BS
    RWP_RESTBookService -->|"uses"| RWP_ProducerFactory
    RWP_RESTBookService -->|"selects"| RWP_BookSelector
    RWP_RESTBookService -->|"uses"| RWP_Entity

    RWP_webxml -->|"configures"| RWP_RESTBookService
    RWP_JSP -->|"providesView"| RWP_RESTBookService

    %% Connections within BookStoreTracker Module
    CDI_Container -->|"manages"| BST_TimeTracker

    %% Click Events for BookStore Module
    click BS_BS "https://github.com/johnyzhub/jee-cdi2/blob/master/BookStore/src/main/java/org/myjee/cdi/practice/BookStore/service/BookService.java"
    click BS_Entity "https://github.com/johnyzhub/jee-cdi2/tree/master/BookStore/src/main/java/org/myjee/cdi/practice/BookStore/entity"
    click BS_DynamicProducer "https://github.com/johnyzhub/jee-cdi2/blob/master/BookStore/src/main/java/org/myjee/cdi/practice/BookStore/Producers/DynamicProducer.java"
    click BS_InjectionProducer "https://github.com/johnyzhub/jee-cdi2/blob/master/BookStore/src/main/java/org/myjee/cdi/practice/BookStore/Producers/InjectionProducer.java"
    click BS_EbookDecorator "https://github.com/johnyzhub/jee-cdi2/blob/master/BookStore/src/main/java/org/myjee/cdi/practice/BookStore/decorator/EbookPriceDecorator.java"
    click BS_PaperDecorator "https://github.com/johnyzhub/jee-cdi2/blob/master/BookStore/src/main/java/org/myjee/cdi/practice/BookStore/decorator/PaperBackPriceDecorator.java"
    click BS_LoggingInterceptor "https://github.com/johnyzhub/jee-cdi2/blob/master/BookStore/src/main/java/org/myjee/cdi/practice/BookStore/interceptor/LoggingInterceptor.java"
    click BS_MethodInterceptor "https://github.com/johnyzhub/jee-cdi2/blob/master/BookStore/src/main/java/org/myjee/cdi/practice/BookStore/interceptor/MethodInterceptor.java"
    click BS_ConstructorInterceptor "https://github.com/johnyzhub/jee-cdi2/blob/master/BookStore/src/main/java/org/myjee/cdi/practice/BookStore/interceptor/ConstructorInterceptor.java"
    click BS_SyncEvent "https://github.com/johnyzhub/jee-cdi2/blob/master/BookStore/src/main/java/org/myjee/cdi/practice/BookStore/event/SyncEventHandler.java"
    click BS_AsyncEvent "https://github.com/johnyzhub/jee-cdi2/blob/master/BookStore/src/main/java/org/myjee/cdi/practice/BookStore/event/AsyncEventHandler.java"
    click BS_Qualifiers "https://github.com/johnyzhub/jee-cdi2/tree/master/BookStore/src/main/java/org/myjee/cdi/practice/BookStore/qualifier"
    click BS_Extension "https://github.com/johnyzhub/jee-cdi2/blob/master/BookStore/src/main/java/org/myjee/cdi/practice/BookStore/extension/PropertyLoaderExtension.java"

    %% Click Events for RestWithProduce Module
    click RWP_RESTBookService "https://github.com/johnyzhub/jee-cdi2/blob/master/RestWithProduce/src/main/java/org/myjee/cdi/practice/rest/BookService.java"
    click RWP_Entity "https://github.com/johnyzhub/jee-cdi2/tree/master/RestWithProduce/src/main/java/org/myjee/cdi/practice/rest/entity"
    click RWP_ProducerFactory "https://github.com/johnyzhub/jee-cdi2/blob/master/RestWithProduce/src/main/java/org/myjee/cdi/practice/rest/producer/ProducerFactory.java"
    click RWP_BookSelector "https://github.com/johnyzhub/jee-cdi2/blob/master/RestWithProduce/src/main/java/org/myjee/cdi/practice/rest/selector/BookSelector.java"
    click RWP_webxml "https://github.com/johnyzhub/jee-cdi2/blob/master/RestWithProduce/src/main/webapp/WEB-INF/web.xml"
    click RWP_JSP "https://github.com/johnyzhub/jee-cdi2/blob/master/RestWithProduce/src/main/webapp/index.jsp"

    %% Click Event for BookStoreTracker Module
    click BST_TimeTracker "https://github.com/johnyzhub/jee-cdi2/blob/master/BookStoreTracker/src/main/java/org/myjee/cdi/practice/plainpojo/time/TimeTracker.java"

    %% Style Definitions
    classDef cdi fill:#BFD8B8,stroke:#0B3B0B,stroke-width:2px;
    classDef service fill:#66ccff,stroke:#003399,stroke-width:2px;
    classDef entity fill:#ffcc00,stroke:#cc9900,stroke-width:2px;
    classDef producer fill:#e0bbff,stroke:#8a2be2,stroke-width:2px;
    classDef decorator fill:#f9d5bb,stroke:#d2691e,stroke-width:2px;
    classDef interceptor fill:#ff9999,stroke:#cc0000,stroke-width:2px;
    classDef event fill:#d9d9f3,stroke:#6666ff,stroke-width:2px;
    classDef qualifier fill:#d5f4e6,stroke:#008080,stroke-width:2px;
    classDef extension fill:#f0e68c,stroke:#b8860b,stroke-width:2px;
    classDef controller fill:#add8e6,stroke:#00008b,stroke-width:2px;
    classDef selector fill:#ffdead,stroke:#cd853f,stroke-width:2px;
    classDef config fill:#f4cccc,stroke:#cc0000,stroke-width:2px;
    classDef tracker fill:#c0d6e4,stroke:#4682b4,stroke-width:2px;
```
