https://github.com/mwesox/xrpc
Type-safe, cross-platform RPC framework with fantastic developer experience
https://github.com/mwesox/xrpc
code-generation cross-platform openapi-alternative rpc type-safe typescript zod
Last synced: 25 days ago
JSON representation
Type-safe, cross-platform RPC framework with fantastic developer experience
- Host: GitHub
- URL: https://github.com/mwesox/xrpc
- Owner: mwesox
- License: mit
- Created: 2026-01-22T23:46:24.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2026-03-09T09:45:38.000Z (4 months ago)
- Last Synced: 2026-03-12T05:43:31.690Z (3 months ago)
- Topics: code-generation, cross-platform, openapi-alternative, rpc, type-safe, typescript, zod
- Language: TypeScript
- Size: 1.65 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# xRPC
**Define once. Generate everywhere. Type-safe across every boundary.**
[](https://opensource.org/licenses/MIT)
[](https://mwesox.github.io/xrpc/)
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
```bash
npm install -g @xrpckit/cli
```
Define your API with the xRPC DSL:
```typescript
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:
```typescript
export const router = createRouter({
ping: query({ input: z.object({}), output: z.object({ ok: z.boolean() }) }),
});
```
Generate code for your targets:
```bash
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:
```bash
bun add -d @xrpckit/ts-plugin
```
Enable it in your `tsconfig.json`:
```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](https://mwesox.github.io/xrpc/) for detailed guides.
Run docs locally:
```bash
bun install
bun run docs:dev
```
Build/preview docs exactly like CI:
```bash
bun run docs:build
bun run docs:preview
```
**Hands-on tutorial:** See the [x-rpc TODO App](./examples/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//vX.Y.Z` format
## Contributing
Contributions welcome. See [Contributing Guide](./CONTRIBUTING.md) and [Code of Conduct](./CODE_OF_CONDUCT.md).
## Security
Report vulnerabilities via our [Security Policy](./SECURITY.md).
## License
MIT
---
*Type safety shouldn't stop at language boundaries.*