# smallnest/rsocket architecture

> Architecture diagram of the GitHub repository smallnest/rsocket, 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/smallnest/rsocket
- Repository: https://github.com/smallnest/rsocket

## Overview

##### Project Type & Purpose
- This is a Go-based library providing an rsocket protocol over RDMA. It offers a socket-level API that mirrors standard socket functions (with an "r" prefix) and is designed to be easily interchangeable with Go’s native net.Conn interface. The primary purpose is to improve performance by leveraging RDMA while maintaining a familiar interface for network programming. Additionally, several example applications (TCP/UDP clients and servers) are provided to demonstrate its usage.

##### File Structure
- Top-level project files include configuration files (go.mod, go.sum), documentation (README.md, LICENSE, .gitignore) and two key source code files (rsocket.go and tcp_conn.go) that form the core of the library.
- The examples directory is subdivided into various network communication demo projects: tcp_client, tcp_conn_client, tcp_conn_server, tcp_server, udp_client, udp_server. These illustrate how to integrate and use the library in both TCP and UDP contexts.

a. Core Library:
- "rsocket.go": Implements the core rsocket protocol logic over RDMA.
- "tcp_conn.go": Provides an encapsulation to allow the rsocket interface to be used wherever net.Conn is expected.
b. RDMA Interface:
- Underlying RDMA stack/resource, which is abstracted by the library to deliver high-performance communication.
c. Examples/Demonstration Applications:
- Separate example components for TCP and UDP clients/servers demonstrating different usage scenarios.
d. External Interfaces:
- The standard socket-level API, which applications interface with, mirroring the conventional socket calls but routed through the rsocket implementation.

##### Depicting Relationships and Interactions
- How the client/server applications call into the rsocket API.
- The rsocket library interacting with the RDMA layer.
- Bidirectional data flow between the application layer and the network/RDMA stack.
- The fact that tcp_conn.go enables seamless integration with existing code that uses net.Conn.

##### Architectural Patterns & Design Principles
- Abstraction layer: the rsocket API mirrors and extends standard socket calls.
- Separation of concerns: core protocol logic is separated from application-level examples.
- Interoperability: compatibility with net.Conn enables plug-and-play behavior with existing Go network code.
- Layering, where the application/business logic resides at the top, the rsocket library acts as a middleware, and the RDMA and underlying hardware/driver form the base.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Application Layer"
        subgraph "TCP Examples"
            TClient1["TCP Client (tcp_client.go)"]:::example
            TClient2["TCP Conn Client (tcp_conn_client.go)"]:::example
            TServer1["TCP Server (tcp_server.go)"]:::example
            TServer2["TCP Conn Server (tcp_conn_server.go)"]:::example
        end
        subgraph "UDP Examples"
            UClient["UDP Client (udp_client.go)"]:::example
            UServer["UDP Server (udp_server.go)"]:::example
        end
    end

    subgraph "Rsocket Library"
        R1["rsocket.go"]:::library
        R2["tcp_conn.go"]:::library
    end

    RDMA["RDMA Subsystem"]:::rdma

    TClient1 --> R1
    TClient2 --> R2
    TServer1 --> R1
    TServer2 --> R2
    UClient  --> R1
    UServer  --> R1

    R1 --> RDMA
    R2 --> RDMA

    click R1 "https://github.com/smallnest/rsocket/blob/master/rsocket.go"
    click R2 "https://github.com/smallnest/rsocket/blob/master/tcp_conn.go"
    click TClient1 "https://github.com/smallnest/rsocket/blob/master/examples/tcp_client/tcp_client.go"
    click TClient2 "https://github.com/smallnest/rsocket/blob/master/examples/tcp_conn_client/tcp_client.go"
    click TServer1 "https://github.com/smallnest/rsocket/blob/master/examples/tcp_server/tcp_server/tcp_server.go"
    click TServer2 "https://github.com/smallnest/rsocket/blob/master/examples/tcp_conn_server/tcp_server.go"
    click UClient "https://github.com/smallnest/rsocket/blob/master/examples/udp_client/udp_client.go"
    click UServer "https://github.com/smallnest/rsocket/blob/master/examples/udp_server/udp_server.go"

    classDef library fill:#FAD7A0,stroke:#333,stroke-width:2px;
    classDef example fill:#C2E7FF,stroke:#333,stroke-width:2px,stroke-dasharray: 5,5;
    classDef rdma fill:#C3FDB8,stroke:#333,stroke-width:2px;
```
