How paritytech/jsonrpsee works
Main Components
• Client Subsystems: The project includes different client implementations found under the “client” directory. There are several clients:
– HTTP Client (“client/http-client”)
– WebSocket Client (“client/ws-client”)
– WASM Client (“client/wasm-client”)
• Server Subsystem: The “server” directory contains the server implementation which leverages the core and supports middleware (for both HTTP and RPC) and custom transport handling (HTTP and WebSocket). Create a block labeled “Server” that shows these internal components:
– Middleware (with HTTP and RPC variants)
– Transport layers (HTTP transport, WS transport)
• Proc Macros: The “proc-macros” directory contains code generation tools that automate client/server code generation with annotations. Mark this as an “Extension” or “Code Generation” component that interacts with or generates code for both client and server modules.
• Examples/Tests/Benchmarks: Although not part of the production architecture, the “examples”, “tests”, “benches”, and “test-utils” directories highlight usage patterns and integration tests. Represent them as auxiliary components that validate or demonstrate how the main components interact.
Relationships and Data Flow
• The “Server” processes requests (hinting at the inclusion of middleware layers) and ultimately depends on the core error handling and response-building logic.
Architectural Patterns & Design Principles
• Modularization: Emphasize the separation between transport layers, core logic, middleware, and code generation – key for extensibility.
• Abstraction: A clear client abstraction is provided through transport modules, allowing custom transport implementations.
• Asynchronous Design: The entire architecture is built around async/await patterns, ensuring non-blocking IO for both the client and server.
• Extensibility via Middleware: The server supports custom middleware, which can intercept, log and modify JSON-RPC calls.
• Code Generation: Utilization of Rust proc macros to reduce boilerplate and enforce a defined RPC schema.
Technology and Tools
• Language: Rust is the main technology.
• Async: Leverages async/await in Rust.
• Middleware: Server side middleware layers indicate pluggability.
• WebAssembly: The wasm client is available for web integration.
• Testing/Benchmarking: There are dedicated folders for robust testing and benchmarks.
Elements
• Inline Annotations: Optionally include notes or callouts stating key characteristics such as “async/await”, “middleware layering”, or “transport abstraction”.