# s1000f/jsonrpc-handler-kotlin architecture

> Architecture diagram of the GitHub repository s1000f/jsonrpc-handler-kotlin, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/s1000f/jsonrpc-handler-kotlin
- Repository: https://github.com/s1000f/jsonrpc-handler-kotlin

## Overview

##### Main Components

a. Core Components:
- JSON-RPC Dispatcher System
- Method Mapping System
- Request/Response Handler
- Data Transfer Objects (DTOs)
- Parser System

b. Integration Points:
- HTTP Server Integration (Ktor/Spring Boot examples)
- External JSON Parser (Jackson)

**┌─────────────────────────────────────────────────────┐**
- HTTP Server Layer                    │
- (Ktor/Spring Boot Integration)             │
- ┤

- JSON-RPC Handler Core                 │
- ┌─────────────┐    ┌──────────┐    ┌──────────┐   │
- Dispatcher │←───│ Context  │────→│ Parser   │   │
- ┘    │ Builder  │    │(Jackson) │   │
- ↕          └──────────┘    └──────────┘   │
- ┌─────────────┐                                   │
- Method    │                                   │
- Mapper    │                                   │
- ┘                                   │
- ↕                                          │
- ┌─────────────┐    ┌──────────┐                  │
- RPC      │────→│   DTO    │                  │
- Methods   │    │  Layer   │                  │
- ┘    └──────────┘                  │

- ┘

##### Component Details

a. Dispatcher System:
- AbstractDispatcher and JsonrpcHandler
- Connection to ContextBuilder
- Relationship with JsonParser interface

b. Method Mapping:
- MethodMapper and RouteMapper
- Connection to RpcMethod implementations
- AbstractHandlerMapper relationship

c. DTO Layer:
- Request/Response objects
- ErrorCode and PresetError relationships
- RpcContext and ContextHolder

##### Important Relationships to Highlight

- How external HTTP requests flow through the system
- Method resolution process
- Demonstrate error handling paths
- Parameter validation flow

##### Implementation Notes

- The library's role as a middleware component
- Protocol-agnostic nature (works with any transport)
- Extensibility through custom RpcMethod implementations
- Type-safe parameter handling
- Clear separation between protocol handling and business logic

##### Integration Examples

- Ktor integration example
- Spring Boot integration example
- Custom method implementation pattern

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph HTTP["HTTP Server Layer"]
        KT[Ktor]
        SB[Spring Boot]
    end

    subgraph Core["JSON-RPC Handler Core"]
        subgraph Dispatcher["Dispatcher System"]
            AD["Abstract Dispatcher"]:::core
            JH["JSON-RPC Handler"]:::core
        end

        subgraph Mapper["Method Mapping System"]
            MM["Method Mapper"]:::core
            RM["Route Mapper"]:::core
            AHM["Abstract Handler Mapper"]:::core
        end

        subgraph Parser["Parser System"]
            JP["JSON Parser Interface"]:::util
            JKP["Jackson Parser"]:::util
        end

        subgraph Context["Context Management"]
            CB["Context Builder"]:::util
            CH["Context Holder"]:::util
        end

        subgraph DTOs["Data Transfer Objects"]
            REQ["Request"]:::data
            RESP["Response"]:::data
            RC["RPC Context"]:::data
            EC["Error Code"]:::data
            PE["Preset Error"]:::data
        end

        subgraph Methods["RPC Methods"]
            RMI["RPC Method Interface"]:::core
            HRM["HTTP Route Method"]:::core
            SEM["Sample Echo Method"]:::core
        end
    end

    %% Relationships
    KT & SB --> AD
    AD --> JH
    JH <--> CB
    CB --> CH
    JH <--> JP
    JP --> JKP
    JH --> MM
    MM --> RM
    MM --> AHM
    RM & AHM --> RMI
    RMI --> HRM
    RMI --> SEM
    JH --> REQ & RESP
    CB --> RC
    RESP --> EC
    EC --> PE

    %% Styling
    classDef core fill:#2196F3,stroke:#1976D2,color:white
    classDef util fill:#FFC107,stroke:#FFA000,color:black
    classDef data fill:#FF9800,stroke:#F57C00,color:white
    classDef http fill:#4CAF50,stroke:#388E3C,color:white

    %% Click events
    click AD "https://github.com/S1000f/jsonrpc-handler-kotlin/blob/master/src/main/kotlin/jsonrpc/dispatcher/AbstractDispatcher.kt"
    click JH "https://github.com/S1000f/jsonrpc-handler-kotlin/blob/master/src/main/kotlin/jsonrpc/dispatcher/JsonrpcHandler.kt"
    click MM "https://github.com/S1000f/jsonrpc-handler-kotlin/blob/master/src/main/kotlin/jsonrpc/mapper/MethodMapper.kt"
    click RM "https://github.com/S1000f/jsonrpc-handler-kotlin/blob/master/src/main/kotlin/jsonrpc/mapper/RouteMapper.kt"
    click AHM "https://github.com/S1000f/jsonrpc-handler-kotlin/blob/master/src/main/kotlin/jsonrpc/mapper/AbstractHandlerMapper.kt"
    click REQ "https://github.com/S1000f/jsonrpc-handler-kotlin/blob/master/src/main/kotlin/jsonrpc/dto/Request.kt"
    click RESP "https://github.com/S1000f/jsonrpc-handler-kotlin/blob/master/src/main/kotlin/jsonrpc/dto/Response.kt"
    click RC "https://github.com/S1000f/jsonrpc-handler-kotlin/blob/master/src/main/kotlin/jsonrpc/dto/RpcContext.kt"
    click EC "https://github.com/S1000f/jsonrpc-handler-kotlin/blob/master/src/main/kotlin/jsonrpc/dto/ErrorCode.kt"
    click PE "https://github.com/S1000f/jsonrpc-handler-kotlin/blob/master/src/main/kotlin/jsonrpc/dto/PresetError.kt"
    click JP "https://github.com/S1000f/jsonrpc-handler-kotlin/blob/master/src/main/kotlin/jsonrpc/dispatcher/JsonParser.kt"
    click JKP "https://github.com/S1000f/jsonrpc-handler-kotlin/blob/master/src/main/kotlin/jsonrpc/dispatcher/JacksonParser.kt"
    click RMI "https://github.com/S1000f/jsonrpc-handler-kotlin/blob/master/src/main/kotlin/jsonrpc/method/RpcMethod.kt"
    click HRM "https://github.com/S1000f/jsonrpc-handler-kotlin/blob/master/src/main/kotlin/jsonrpc/method/HttpRouteMethod.kt"
    click SEM "https://github.com/S1000f/jsonrpc-handler-kotlin/blob/master/src/main/kotlin/jsonrpc/method/SampleEchoMethod.kt"
    click CB "https://github.com/S1000f/jsonrpc-handler-kotlin/blob/master/src/main/kotlin/jsonrpc/dispatcher/ContextBuilder.kt"
    click CH "https://github.com/S1000f/jsonrpc-handler-kotlin/blob/master/src/main/kotlin/jsonrpc/dto/ContextHolder.kt"
```
