# jack-works/async-call-rpc architecture

> Architecture diagram of the GitHub repository jack-works/async-call-rpc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jack-works/async-call-rpc
- Repository: https://github.com/jack-works/async-call-rpc

## Overview

##### Main Components

a. Core RPC Layer:
- JSON RPC Protocol Handler
- Request/Response Manager
- Error Handler
- Batch & Notification Manager

b. Communication Layer:
- CallbackBasedChannel Interface
- EventBasedChannel Interface
- Built-in Channel Implementations (WebSocket, BroadcastChannel, Worker)

c. Encoding/Serialization Layer:
- An "Encoder Framework" showing:
- IsomorphicEncoder Interface
- IsomorphicEncoderFull Interface
- Default JSON Encoder
- Custom Encoder Support

d. Generator Support:
- An "AsyncGenerator Handler" component showing:
- Iterator Protocol Implementation
- Internal RPC Methods
- Generator State Management

##### Component Relationships

**Client Application → AsyncCall Core → Channel Layer → Network/IPC**
**Network/IPC → Channel Layer → AsyncCall Core → Server Implementation**

##### Detailed Elements

Specific technical details:
**Core Features:**
- JSON RPC 2.0 Protocol
- Request/Response Handling
- Error Mapping
- Batch Processing
- Notifications
- Type Safety (TypeScript)

**Channel Types:**
- WebSocket (Node/Web/Deno)
- BroadcastChannel
- Worker
- Custom Channel Support

**Encoding Options:**
- JSON
- Custom Encoders
- Serialization Controls

##### Implementation Notes

Annotations for:
- Zero dependencies
- ES2018+ Support
- Cross-platform compatibility
- TypeScript integration
- Custom error handling
- Memory leak warning for generators

##### Data Flow Markers

Specific data transformations:
**Raw Data → Encoder → Channel → Network → Channel → Decoder → Typed Data**

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Core["Core RPC Layer"]
        AC[AsyncCall Core]:::core
        BP[Batch Processing]:::core
        NH[Notification Handler]:::core
        JRPC[JSON RPC Protocol]:::core
        EH[Error Handler]:::core
    end

    subgraph Comm["Communication Layer"]
        direction TB
        CA[Channel Abstraction]:::comm
        subgraph Channels
            direction TB
            WSC[WebSocket Client]:::comm
            WSS[WebSocket Server]:::comm
            WC[Worker Channel]:::comm
            BC[BroadcastChannel]:::comm
        end
    end

    subgraph Encoding["Encoding/Serialization Layer"]
        direction TB
        EF[Encoder Framework]:::encoding
        SC[Serialization Core]:::encoding
        subgraph Encoders
            direction TB
            BE["BSON Encoder"]:::encoding
            ME["MessagePack Encoder"]:::encoding
        end
    end

    subgraph Gen["Generator Support"]
        GI[Generator Implementation]:::generator
    end

    subgraph Utils["Utility Components"]
        direction TB
        IDG[ID Generation]:::util
        OH[Options Handler]:::util
        CON[Constants]:::util
    end

    %% Relationships
    AC --> BP
    AC --> NH
    AC --> JRPC
    AC --> EH
    AC --> CA
    CA --> Channels
    AC --> EF
    EF --> SC
    EF --> Encoders
    AC --> GI

    %% Click Events
    click AC "https://github.com/jack-works/async-call-rpc/blob/main/src/Async-Call.ts"
    click BP "https://github.com/jack-works/async-call-rpc/blob/main/src/core/batch.ts"
    click NH "https://github.com/jack-works/async-call-rpc/blob/main/src/core/notify.ts"
    click JRPC "https://github.com/jack-works/async-call-rpc/blob/main/src/utils/jsonrpc.ts"
    click EH "https://github.com/jack-works/async-call-rpc/blob/main/src/utils/error.ts"
    click WSC "https://github.com/jack-works/async-call-rpc/blob/main/utils-src/web/websocket.client.ts"
    click WSS "https://github.com/jack-works/async-call-rpc/blob/main/utils-src/node/websocket.server.ts"
    click WC "https://github.com/jack-works/async-call-rpc/blob/main/utils-src/web/worker.ts"
    click BC "https://github.com/jack-works/async-call-rpc/blob/main/utils-src/web/broadcast.channel.ts"
    click EF "https://github.com/jack-works/async-call-rpc/blob/main/src/utils/encoder.ts"
    click SC "https://github.com/jack-works/async-call-rpc/blob/main/src/utils/serialization.ts"
    click BE "https://github.com/jack-works/async-call-rpc/blob/main/utils-src/web/bson.ts"
    click ME "https://github.com/jack-works/async-call-rpc/blob/main/utils-src/web/msgpack.ts"
    click GI "https://github.com/jack-works/async-call-rpc/blob/main/src/Async-Call-Generator.ts"
    click IDG "https://github.com/jack-works/async-call-rpc/blob/main/src/utils/generateRandomID.ts"
    click OH "https://github.com/jack-works/async-call-rpc/blob/main/src/utils/normalizeOptions.ts"
    click CON "https://github.com/jack-works/async-call-rpc/blob/main/src/utils/constants.ts"

    %% Styling
    classDef core fill:#2374ab,stroke:#2374ab,color:#fff
    classDef comm fill:#57a773,stroke:#57a773,color:#fff
    classDef encoding fill:#ff8c42,stroke:#ff8c42,color:#fff
    classDef generator fill:#9b5de5,stroke:#9b5de5,color:#fff
    classDef util fill:#666666,stroke:#666666,color:#fff

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Communication Components]:::comm
        L3[Encoding Components]:::encoding
        L4[Generator Components]:::generator
        L5[Utility Components]:::util
    end
```
