How andogq/qubit works
Project type and purpose
• This is an open-source monorepo containing a Rust library (qubit), a Rust procedural-macro crate (qubit-macros), a TypeScript client package (@qubit-rs/client), a Svelte integration example/package, and multiple end-to-end example applications.
• Its purpose is to provide seamless, type-safe JSONRPC 2.0-based RPC between Rust servers and TypeScript clients, generating TS bindings from Rust code and offering both HTTP and WebSocket transports.
File structure
• Top-level:
• Cargo workspace (Cargo.toml, crates/, src/) for the Rust library and macros.
• packages/ (client, svelte) for the TypeScript client and Svelte integration.
• examples/ demonstrating authentication, chaos test, chat-room React app, counter, hello-world.
• config and CI/CD (.github, pnpm-workspace.yaml, scripts).
• Rust crates:
• crates/qubit-macros: procedural macros for analysing handler attributes, codegen of TypeScript types.
• src/: core library—handler definitions, router builder, JSONRPC service adapter, TS-binding code.
• TS packages:
• packages/client: build_client, transport layers (http, ws), JSONRPC framing, handler/query/mutation/subscription wrappers.
• packages/svelte: opinionated UI template integrating the generated client in a SvelteKit app.
README for additional insights
• Core flow: define Rust functions with #[handler(query/mutation/subscription)], compose into a Router, call router.write_bindings_to_dir(), embed router in an Axum/Hyper server via jsonrpsee, then import generated TS bindings in TypeScript and call build_client<Bindings>(transport).
• Leverages serde for data serialization, ts-rs for type generation, jsonrpsee for RPC transport, and common Rust async ecosystem (tokio, axum).
Detail
• Every major crate, package, and example integration.
• Nested-router pattern inside the Rust server and subscription flow over WS.
• Annotations: e.g., “serde serialises payloads to JSON”, “ts-rs generates .d.ts”.