MCPcopy Index your code
hub / github.com/ahonn/orpc-rs

github.com/ahonn/orpc-rs @v1.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.1.0 ↗ · + Follow
692 symbols 1,685 edges 61 files 156 documented · 23%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

orpc-rs

Rust implementation of oRPC — type-safe RPC with first-class Tauri support.

Build fully type-safe APIs in Rust with auto-generated TypeScript types, compatible with the official @orpc/client and @orpc/tanstack-query ecosystem.

Features

  • Type-safe procedures — Builder API with compile-time middleware composition
  • Wire-compatible — Matches @orpc/client RPC protocol (request/response, SSE subscriptions)
  • Rust client — Typed RPC client with #[orpc_service] proc-macro (define once → server + client)
  • File uploads — Multipart ORPCFile support, wire-compatible with @orpc/client
  • TypeScript generation — Auto-generate Client<> types via specta, works directly with @orpc/client
  • Tauri IPC — Zero-HTTP transport for desktop apps, with Channel-based subscriptions
  • Axum integration — RPC + OpenAPI endpoints with SSE keep-alive
  • TanStack QueryuseQuery / useMutation via @orpc/tanstack-query out of the box

Architecture

                        ┌─────────────────────────────────────────────────┐
                        │                   TypeScript                    │
                        │                                                 │
                        │  bindings.ts ──▶ @orpc/client ──▶ @orpc/tanstack-query
                        │       ▲              ▲                          │
                        │       │         TauriLink / RPCLink             │
                        └───────┼──────────────┼──────────────────────────┘
                                │              │
  ┌─────────────────────────────┼──────────────┼──────────┐
  │                Rust         │              │          │
  │                             │              │          │
  │  orpc-specta ───────────────┘              │          │
  │       ▲                                    │          │
  │       │                              ┌─────┴─────┐   │
  │    orpc (builder + router)           │ orpc-axum  │   │
  │    orpc-macros (#[orpc_service])     │ orpc-tauri │   │
  │       │                              └─────┬─────┘   │
  │       ▼                                    │         │
  │  orpc-procedure (type-erased engine)       │         │
  │       │                                    │         │
  │       └──────────── orpc-server ───────────┘         │
  │                                                       │
  │  orpc-client (Rust RPC client) ◀── orpc-macros        │
  └───────────────────────────────────────────────────────┘

Crates

Crate Description
orpc-procedure Type-erased execution engine
orpc Type-safe builder API, router, middleware
orpc-macros #[orpc_service] proc-macro (server + client from trait)
orpc-client Rust HTTP client with SSE subscriptions
orpc-server Wire protocol (RPC, SSE, OpenAPI)
orpc-axum Axum HTTP integration
orpc-specta TypeScript type generation
tauri-plugin-orpc Tauri v2 IPC plugin

Packages

Package Description
@orpc-rs/tauri TauriLink for @orpc/client

Quick Start

Define once — Server + Client

use orpc::*;

#[derive(Serialize, Deserialize)]
struct Planet { id: u32, name: String }

#[derive(Serialize, Deserialize)]
struct FindInput { name: String }

// Define the service trait — single source of truth
#[orpc_service(context = AppCtx)]
pub trait PlanetApi {
    async fn list(&self, ctx: AppCtx) -> Result<Vec<Planet>, ORPCError>;
    async fn find(&self, ctx: AppCtx, input: FindInput) -> Result<Planet, ORPCError>;
}

// Server: implement the trait
struct MyApi;
impl PlanetApi for MyApi {
    async fn list(&self, ctx: AppCtx) -> Result<Vec<Planet>, ORPCError> { /* ... */ }
    async fn find(&self, ctx: AppCtx, input: FindInput) -> Result<Planet, ORPCError> { /* ... */ }
}

// Build router from trait impl (auto-generated function)
let router = planet_api_router(MyApi);
let app = orpc_axum::into_router(router, |_parts| AppCtx { /* ... */ });

Rust Client — Typed, auto-generated

// PlanetApiClient is auto-generated by #[orpc_service]
let client = PlanetApiClient::new("http://localhost:3000/rpc");
let planet = client.find(&FindInput { name: "Earth".into() }).await?;

TypeScript Client — Full type safety

import { createORPCClient } from "@orpc/client"
import { RPCLink } from "@orpc/client/fetch"

const client = createORPCClient(new RPCLink({ url: "/rpc" }))

// Wire-compatible with Rust server
const planet = await client.planet.find({ name: "Earth" })

Builder API (alternative)

For more control (middleware, contracts, specta schemas):

let router = router! {
    "planet" => {
        "list" => os::<AppCtx>()
            .output(specta::<Vec<Planet>>())
            .handler(list_planets),
    },
};

// Auto-generate TypeScript types
orpc_specta::export_ts(&router, "../src/bindings.ts")?;

Examples

Example Description
axum-react Web app — Axum server + React client with RPC, OpenAPI, and SSE
tauri-app Desktop app — Tauri IPC + TanStack Query, zero HTTP

License

MIT

Extension points exported contracts — how you extend this code

ErasedSchema (Interface)
Type-erased schema interface for procedure input/output. This is the type-erased counterpart of the typed `Schema` trai [3 …
crates/orpc-procedure/src/schema.rs
MiddlewareChain (Interface)
Internal trait for compile-time middleware composition. Each layer transforms `TBaseCtx → TCurrentCtx` by chaining with [2 …
crates/orpc/src/middleware.rs
Link (Interface)
Transport abstraction for oRPC client calls. Mirrors the TypeScript `Link` interface from `@orpc/client`. Implementors [1 …
crates/orpc-client/src/link.rs
TauriLinkOptions (Interface)
(no doc)
packages/tauri/src/index.ts
Planet (Interface)
(no doc)
examples/axum-react/client/src/rpc.ts
Schema (Interface)
Unified Schema abstraction, counterpart to oRPC's Standard Schema. Provides validation and JSON Schema generation for p [2 …
crates/orpc/src/schema.rs
PlanetApi (Interface)
(no doc) [1 implementers]
crates/orpc-client/tests/service_macro.rs
SubscriptionEvent (Interface)
(no doc)
packages/tauri/src/index.ts

Core symbols most depended-on inside this repo

next
called by 52
crates/orpc/src/middleware.rs
exec
called by 32
crates/orpc-procedure/src/procedure.rs
insert
called by 25
crates/orpc-procedure/src/state.rs
into_erased
called by 24
crates/orpc/src/procedure.rs
is_empty
called by 24
crates/orpc/src/router.rs
to_value
called by 21
crates/orpc-procedure/src/output.rs
procedure
called by 21
crates/orpc/src/router.rs
encode_rpc_error
called by 19
crates/orpc-server/src/rpc.rs

Shape

Function 407
Method 149
Class 109
Interface 15
Enum 12

Languages

Rust95%
TypeScript5%

Modules by API surface

crates/orpc-server/src/rpc.rs43 symbols
crates/orpc-axum/tests/integration.rs39 symbols
crates/orpc-server/src/openapi.rs38 symbols
crates/orpc/src/error.rs26 symbols
crates/orpc-procedure/src/state.rs23 symbols
crates/orpc/src/middleware.rs22 symbols
crates/orpc/src/builder.rs22 symbols
crates/orpc-server/src/meta.rs22 symbols
crates/orpc-procedure/src/route.rs21 symbols
crates/orpc-axum/src/lib.rs20 symbols
crates/orpc/src/router.rs19 symbols
crates/orpc/src/contract.rs19 symbols

For agents

$ claude mcp add orpc-rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact