# smallnest/rpcx architecture

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

- Interactive diagram: https://gitdiagram.com/smallnest/rpcx
- Repository: https://github.com/smallnest/rpcx

## Overview

##### Main Components Identification
The system should be divided into these primary components:

a. Client Layer
- Core Client Components
- Client Plugins
- Discovery Mechanisms
- Load Balancing
- Circuit Breaker

b. Server Layer
- Core Server Components
- Server Plugins
- Service Registration
- Gateway Support

c. Protocol & Codec Layer
- Message Protocol
- Multiple Codec Support
- Compression

**[Client Applications] → [Client Layer] → [Transport Layer] → [Server Layer] → [Services]**

##### Connection Types
Supported transport protocols:
- TCP
- HTTP
- QUIC
- KCP
- RDMA

##### Cross-Cutting Concerns
- Error Handling
- Logging
- Metrics
- Context Management
- Authentication
- Service Discovery

##### Specific Details to Highlight

a. Client Features:
- Multiple client modes (Failover, Failfast, Failtry)
- Load balancing strategies
- Service discovery methods
- Circuit breaker implementation

b. Server Features:
- Plugin architecture
- Gateway support
- Service registration
- Stream handling

c. Protocol Features:
- Binary protocol support
- Multiple codec support
- Compression options
- Metadata handling

##### Integration Points

Integration with:
- Service registries (etcd, consul, zookeeper)
- Monitoring systems
- Gateway services
- Cross-language clients

##### Notes

Annotations for:
- Performance characteristics
- Scalability features
- High availability options
- Cross-platform support

This system design should effectively communicate rpcx's architecture as a high-performance, feature-rich RPC framework with extensive plugin support and multiple transport options.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        XC["XClient Interface"]:::client
        click XC "https://github.com/smallnest/rpcx/blob/master/client/xclient.go"
        CC["Core Client"]:::client
        click CC "https://github.com/smallnest/rpcx/blob/master/client/client.go"
        
        subgraph Discovery["Service Discovery"]
            DNS["DNS Discovery"]:::discovery
            click DNS "https://github.com/smallnest/rpcx/blob/master/client/dns_discovery.go"
            MDNS["mDNS Discovery"]:::discovery
            click MDNS "https://github.com/smallnest/rpcx/blob/master/client/mdns_discovery.go"
            P2P["Peer2Peer Discovery"]:::discovery
            click P2P "https://github.com/smallnest/rpcx/blob/master/client/peer2peer_discovery.go"
        end
        
        subgraph LB["Load Balancing"]
            SEL["Selector"]:::lb
            click SEL "https://github.com/smallnest/rpcx/blob/master/client/selector.go"
        end
        
        CB["Circuit Breaker"]:::client
        click CB "https://github.com/smallnest/rpcx/blob/master/client/circuit_breaker.go"
        
        subgraph CP["Client Plugins"]
            RRL["Redis Rate Limiting"]:::plugin
            click RRL "https://github.com/smallnest/rpcx/blob/master/clientplugin/req_rate_limiting_redis.go"
        end
    end
    
    subgraph Transport["Transport Layer"]
        TCP["TCP"]:::transport
        HTTP["HTTP"]:::transport
        QUIC["QUIC"]:::transport
        click QUIC "https://github.com/smallnest/rpcx/blob/master/client/connection_quic.go"
        KCP["KCP"]:::transport
        click KCP "https://github.com/smallnest/rpcx/blob/master/client/connection_kcp.go"
        RDMA["RDMA"]:::transport
        click RDMA "https://github.com/smallnest/rpcx/blob/master/client/connection_rdma.go"
    end
    
    subgraph Server["Server Layer"]
        SC["Server Core"]:::server
        click SC "https://github.com/smallnest/rpcx/blob/master/server/server.go"
        SVC["Service Handler"]:::server
        click SVC "https://github.com/smallnest/rpcx/blob/master/server/service.go"
        CTX["Context Manager"]:::server
        click CTX "https://github.com/smallnest/rpcx/blob/master/server/context.go"
        
        subgraph SP["Server Plugins"]
            MET["Metrics"]:::plugin
            click MET "https://github.com/smallnest/rpcx/blob/master/serverplugin/metrics.go"
            RL["Rate Limiting"]:::plugin
            click RL "https://github.com/smallnest/rpcx/blob/master/serverplugin/rate_limiting.go"
            BL["Blacklist"]:::plugin
            click BL "https://github.com/smallnest/rpcx/blob/master/serverplugin/blacklist.go"
            WL["Whitelist"]:::plugin
            click WL "https://github.com/smallnest/rpcx/blob/master/serverplugin/whitelist.go"
        end
        
        GW["Gateway"]:::server
        click GW "https://github.com/smallnest/rpcx/blob/master/server/gateway.go"
        FT["File Transfer"]:::server
        click FT "https://github.com/smallnest/rpcx/blob/master/server/file_transfer.go"
        STR["Stream Handler"]:::server
        click STR "https://github.com/smallnest/rpcx/blob/master/server/stream.go"
    end
    
    subgraph Protocol["Protocol & Codec Layer"]
        MP["Message Protocol"]:::protocol
        click MP "https://github.com/smallnest/rpcx/blob/master/protocol/message.go"
        COMP["Compression"]:::protocol
        click COMP "https://github.com/smallnest/rpcx/blob/master/protocol/compressor.go"
        COD["Codec Support"]:::protocol
        click COD "https://github.com/smallnest/rpcx/blob/master/codec/codec.go"
    end
    
    subgraph Utilities["Cross-Cutting Concerns"]
        LOG["Logging"]:::util
        click LOG "https://github.com/smallnest/rpcx/blob/master/log/logger.go"
        ERR["Error Handling"]:::util
        click ERR "https://github.com/smallnest/rpcx/blob/master/errors/error.go"
        REFL["Service Reflection"]:::util
        click REFL "https://github.com/smallnest/rpcx/blob/master/reflection/server_reflection.go"
        SCTX["Shared Context"]:::util
        click SCTX "https://github.com/smallnest/rpcx/blob/master/share/context.go"
        UTIL["Compression Utils"]:::util
        click UTIL "https://github.com/smallnest/rpcx/blob/master/util/compress.go"
    end
    
    %% Connections
    XC --> CC
    CC --> Discovery
    CC --> LB
    CC --> CB
    CC --> CP
    CC --> Transport
    Transport --> Server
    SC --> SP
    SC --> GW
    SC --> FT
    SC --> STR
    SC --> Protocol
    
    %% Styling
    classDef client fill:#2374ab
    classDef discovery fill:#2a9d8f
    classDef lb fill:#e9c46a
    classDef plugin fill:#f4a261
    classDef transport fill:#48cae4
    classDef server fill:#006d77
    classDef protocol fill:#4a4e69
    classDef util fill:#9a8c98

    %% Legend
    subgraph Legend
        L1["Client Components"]:::client
        L2["Discovery Services"]:::discovery
        L3["Load Balancing"]:::lb
        L4["Plugins"]:::plugin
        L5["Transport"]:::transport
        L6["Server Components"]:::server
        L7["Protocol Components"]:::protocol
        L8["Utilities"]:::util
    end
```
