# kptfh/json-reactive architecture

> Architecture diagram of the GitHub repository kptfh/json-reactive, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kptfh/json-reactive
- Repository: https://github.com/kptfh/json-reactive

## Overview

##### Project type and purpose
- Project type: A multi-module Java library providing reactive JSON binding on top of Jackson’s non-blocking parser.
- Purpose: Offer core non-blocking JSON parsing plus two reactive adapters (Reactor and RxJava2) so consumers can stream POJOs reactively.

##### File structure
Top-level modules (in `pom.xml`):
– **json-nonblocking**
– **json-reactor**
– **json-rx2**
Each module is a standard Maven sub-project, containing source under `src/main/java` and tests under `src/test/java`.
– `json-nonblocking` implements core asynchronous parsing (classes under `com.fasterxml.jackson.core.async_` and `reactivejson` packages).
– `json-reactor` wraps the core parser into Project Reactor’s `Flux<T>`.
– `json-rx2` wraps the core parser into RxJava2’s `Flowable<T>`.
Shared dependencies: Jackson Core (`JsonFactory`, `NonBlockingJsonParser`), plus Reactor or RxJava2.

##### README for additional insights
- Modules description confirms the structure.
- Usage snippets show how users instantiate `ReactorObjectReader` or `Rx2ObjectReader` with `JsonFactory` and an `ObjectReader<T>` to produce a reactive stream of POJOs.

a. **Core Non-Blocking Parser Module** (`json-nonblocking`):
– Jackson’s `JsonFactory` → `NonBlockingJsonParser`
– `Tokenizer` and `NonBlockingObjectReader` that feed raw tokens into POJO binding
b. **Reactive Adapters**:
– **Reactor Adapter** (`json-reactor`): `ReactorObjectReader` → produces `Flux<T>`
– **Rx2 Adapter** (`json-rx2`): `Rx2ObjectReader` → produces `Flowable<T>`
c. **External Libraries**:
– Jackson Core (for `JsonFactory`, low-level parser)
– Project Reactor (for `Flux`)
– RxJava2 (for `Flowable`)
d. **Consumer Layer**: Your application code or any downstream service subscribing to the reactive streams.

##### Relationships and data flow
– Input: ByteBuffer stream of JSON data
– Core module parses bytes asynchronously → emits JSON tokens
– Tokenizer/NonBlockingObjectReader converts tokens to Java objects via Jackson’s `ObjectReader<T>`
– Reactive adapter wraps the reader output into a `Flux<T>` or `Flowable<T>`
– Consumer subscribes, processes or persists POJOs

##### Architectural patterns and design principles
– **Modular layering**: Core parsing is decoupled from reactive frameworks
– **Adapter pattern**: Reactor and Rx2 modules adapt the same core API to different reactive types
– **Dependency inversion**: Core defines abstractions (`NonBlockingObjectReader`), adapters depend on those, not vice versa
– **Separation of concerns**: Parsing, tokenization, binding, and streaming are distinct layers

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Input stream
    ByteBuffer["ByteBuffer[] stream"]:::external

    %% Core Non-Blocking Parser Module
    subgraph "json-nonblocking (core non-blocking parser)"
        direction TB
        JsonFactory["JsonFactory"]:::core
        NonBlockingJsonParser["NonBlockingJsonParser"]:::core
        Tokenizer["Tokenizer"]:::core
        NonBlockingObjectReader["NonBlockingObjectReader"]:::core
    end

    %% Reactor Adapter Module
    subgraph "json-reactor (Reactor Adapter)"
        direction TB
        ReactorObjectReader["ReactorObjectReader"]:::reactor
        Flux["Flux<T>"]:::reactor
    end

    %% RxJava2 Adapter Module
    subgraph "json-rx2 (RxJava2 Adapter)"
        direction TB
        Rx2ObjectReader["Rx2ObjectReader"]:::rx2
        Flowable["Flowable<T>"]:::rx2
    end

    %% Consumer Layer
    subgraph "Consumer Code"
        direction TB
        Consumer["Consumer subscribes POJOs"]:::consumer
    end

    %% External Libraries
    subgraph External
        direction TB
        JacksonCore["Jackson Core"]:::external
        ProjectReactor["Project Reactor"]:::external
        RxJava2["RxJava2"]:::external
    end

    %% Data Flow
    ByteBuffer -->|bytes| JsonFactory
    JsonFactory -->|creates parser| NonBlockingJsonParser
    NonBlockingJsonParser -->|tokens| Tokenizer
    Tokenizer -->|POJO tokens| NonBlockingObjectReader

    NonBlockingObjectReader -->|emit objects| ReactorObjectReader
    ReactorObjectReader -->|Flux<T>| Flux
    Flux -->|subscribe| Consumer

    NonBlockingObjectReader -->|emit objects| Rx2ObjectReader
    Rx2ObjectReader -->|Flowable<T>| Flowable
    Flowable -->|subscribe| Consumer

    %% External Dependencies
    JacksonCore -.-> JsonFactory
    JacksonCore -.-> NonBlockingJsonParser
    ProjectReactor -.-> ReactorObjectReader
    RxJava2 -.-> Rx2ObjectReader

    %% Click Events
    click JsonFactory "https://github.com/kptfh/json-reactive/blob/master/json-nonblocking/src/main/java/com/fasterxml/jackson/core/async_/JsonFactory.java"
    click NonBlockingJsonParser "https://github.com/kptfh/json-reactive/blob/master/json-nonblocking/src/main/java/com/fasterxml/jackson/core/async_/NonBlockingJsonParser.java"
    click Tokenizer "https://github.com/kptfh/json-reactive/blob/master/json-nonblocking/src/main/java/reactivejson/Tokenizer.java"
    click NonBlockingObjectReader "https://github.com/kptfh/json-reactive/blob/master/json-nonblocking/src/main/java/reactivejson/NonBlockingObjectReader.java"
    click ReactorObjectReader "https://github.com/kptfh/json-reactive/blob/master/json-reactor/src/main/java/reactivejson/ReactorObjectReader.java"
    click Rx2ObjectReader "https://github.com/kptfh/json-reactive/blob/master/json-rx2/src/main/java/reactivejson/Rx2ObjectReader.java"

    %% Styles
    classDef core fill:#e0f7fa,stroke:#006064,color:#004d40;
    classDef reactor fill:#e8f5e9,stroke:#2e7d32,color:#1b5e20;
    classDef rx2 fill:#fff3e0,stroke:#ef6c00,color:#e65100;
    classDef external fill:#eeeeee,stroke:#757575,color:#424242,stroke-dasharray: 5 5;
    classDef consumer fill:#f5f5f5,stroke:#9e9e9e,color:#616161,stroke-dasharray: 2 2;
```
