Skip to content
/ xrpc Public

Type-safe, cross-platform RPC framework with fantastic developer experience

License

Notifications You must be signed in to change notification settings

mwesox/xrpc

xRPC

Define once. Generate everywhere. Type-safe across every boundary.

License: MIT Documentation

xRPC is a next-generation RPC framework that bridges the gap between type safety and cross-platform development. Write your API contracts in TypeScript with Zod schemas, and generate idiomatic, dependency-free code for any language.

No more hand-writing SDKs. No more API drift. No more runtime surprises.

Why xRPC?

Traditional API development forces a choice: type safety within a single language (tRPC) or cross-platform reach with verbose tooling (OpenAPI, gRPC). xRPC eliminates this tradeoff.

Capability tRPC gRPC OpenAPI xRPC
Type Safety Full Partial None Full
Schema Language TypeScript Protobuf YAML/JSON TypeScript + Zod
Cross-Platform No Yes Yes Yes
Generated Code Quality N/A Verbose Varies Idiomatic
Runtime Dependencies Heavy Heavy Varies Zero
Learning Curve Low High Medium Low

Get Started

npm install -g @xrpckit/cli

Define your API with the xRPC DSL:

import { z } from 'zod';
import { createRouter, group, query, mutation } from 'xrpckit';

const users = group("users", {
  get: query({
    input: z.object({ id: z.string().uuid() }),
    output: z.object({
      id: z.string().uuid(),
      name: z.string(),
      email: z.string().email(),
    }),
  }),
  create: mutation({
    input: z.object({
      name: z.string().min(1).max(100),
      email: z.string().email(),
    }),
    output: z.object({ id: z.string().uuid() }),
  }),
});

export const router = createRouter({ users });

For small APIs, flat endpoints are also supported:

export const router = createRouter({
  ping: query({ input: z.object({}), output: z.object({ ok: z.boolean() }) }),
});

Generate code for your targets:

xrpc generate --input src/api.ts --targets go-server,ts-client,swift-client

That's it. You now have type-safe clients and servers with full validation logic, zero runtime dependencies, and idiomatic code that feels native to each language.

TypeScript Go-to-Definition (Optional)

For TypeScript projects, you can enable contract-aware go-to-definition from generated api.group.method(...) calls.

Install the plugin:

bun add -d @xrpckit/ts-plugin

Enable it in your tsconfig.json:

{
  "compilerOptions": {
    "plugins": [
      { "name": "@xrpckit/ts-plugin" }
    ]
  }
}

This plugin is optional and only improves editor navigation. Generation/runtime behavior is unchanged.

Generated Code

xRPC generates production-ready code that follows each language's conventions:

Go — Structs, HTTP handlers, and validation using only the standard library TypeScript — Full type inference with Zod schemas Swift — Codable models with an async URLSession client Python — Pydantic models with FastAPI integration (coming soon) Rust — Serde structs with Axum handlers (coming soon)

All generated code includes:

  • Request/response types derived from your Zod schemas
  • Validation logic with detailed error messages
  • HTTP routing with proper status codes
  • JSON serialization/deserialization

Design Principles

Zero Dependencies — Generated code uses only standard libraries. No vendor lock-in.

Idiomatic Output — Code looks like it was written by a native developer, not a machine.

Schema as Source of Truth — Your Zod schemas define validation, types, and documentation in one place.

Compile-Time Safety — Catch errors before runtime, across language boundaries.

Use Cases

  • Polyglot Microservices — Type-safe contracts between services in different languages
  • SDK Generation — Ship idiomatic client libraries for your public API
  • Full-Stack Apps — Share types seamlessly between frontend and backend
  • Mobile + Web — Unified API contracts across iOS, Android, and web clients

Documentation

Check out the full documentation for detailed guides.

Run docs locally:

bun install
bun run docs:dev

Build/preview docs exactly like CI:

bun run docs:build
bun run docs:preview

Hands-on tutorial: See the x-rpc TODO App for a complete walkthrough building a fullstack app with a Go backend and React frontend from a single contract.

Releases

xRPC packages are released manually from main via GitHub Actions.

  • Workflow: .github/workflows/release-npm.yml
  • Versioning: manual Changesets (bunx changeset, then bun run release:version)
  • Tags: one per released package in npm/<pkg-slug>/vX.Y.Z format

Contributing

Contributions welcome. See Contributing Guide and Code of Conduct.

Security

Report vulnerabilities via our Security Policy.

License

MIT


Type safety shouldn't stop at language boundaries.