- Rust 87%
- Shell 6.4%
- HTML 3.7%
- JavaScript 2.4%
- Makefile 0.5%
The hero_osis HTTP server now uses /rpc/{context} as its single RPC
endpoint. Domain routing is handled via the JSON-RPC method name
(e.g. "identity.authenticate"), not the URL path.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
||
|---|---|---|
| docs | ||
| packages | ||
| scripts | ||
| .gitignore | ||
| build.sh | ||
| buildenv.sh | ||
| Cargo.lock | ||
| Cargo.toml | ||
| install.sh | ||
| Makefile | ||
| README.md | ||
| run.sh | ||
Hero RPC
Schema-driven code generation and RPC framework for building distributed services. Define your data model in .oschema files, and Hero RPC generates everything: Rust types, database persistence, JSON-RPC server, cross-platform client SDK, and workspace scaffolding.
Packages
| Crate | Description |
|---|---|
hero_rpc_osis |
Core framework: OSchema parsing, code generation, SmartID storage, JSON-RPC server, workspace scaffolding |
hero_rpc_derive |
Procedural macros: OsisObject, openrpc_client!, MCP client generation |
hero_rpc_client |
Cross-platform HTTP/WASM RPC client for generated services |
How It Works
1. Define your schema
Create .oschema files that describe your data model:
Difficulty = "easy" | "medium" | "hard"
# Recipe [rootobject]
Recipe = {
sid: str
@index
name: str
@index
description: str
difficulty: Difficulty
prep_time: u32
ingredients: [str]
created_at: otime
}
service RecipeService {
version: "1.0.0"
description: "Recipe management"
get_by_category(category: Category) -> [Recipe]
}
2. Scaffold a workspace
Generate a complete 5-crate workspace from your schemas:
cargo run -p hero_rpc_osis --bin osis_scaffold -- \
--name hero_recipes \
--schemas-dir schemas
This creates:
hero_recipes/
├── Cargo.toml # Workspace root
├── schemas/
│ └── recipes/recipes.oschema
├── crates/
│ ├── hero_recipes/ # Core types + DB persistence
│ │ ├── Cargo.toml
│ │ └── build.rs # Code generation on cargo build
│ ├── hero_recipes_openrpc/ # JSON-RPC server binary
│ │ ├── Cargo.toml
│ │ └── src/main.rs
│ ├── hero_recipes_client/ # Cross-platform client SDK
│ │ └── Cargo.toml
│ ├── hero_recipes_rhai/ # Rhai scripting bindings
│ │ ├── Cargo.toml
│ │ └── src/lib.rs
│ └── hero_recipes_http/ # HTTP proxy + admin panel
│ ├── Cargo.toml
│ └── src/main.rs
└── docs/schemas/
3. Build and run
cargo build -p hero_recipes # Generates types + handlers
cargo run -p hero_recipes_openrpc -- --seed-dir data/mock # Start server
The server exposes:
- Unix socket at
~/hero/var/sockets/{context}/hero_recipes.sock - JSON-RPC 2.0 API with CRUD operations per root object
- Full-text search on
@indexannotated fields
4. Use the client
Generated client code provides typed access:
use hero_recipes_client::RecipeClient;
let client = RecipeClient::new("http://localhost:8080", "root", "recipes")?;
let recipes = client.recipe_list().await?;
Package Details
hero_rpc_osis
The core framework. Handles:
- OSchema parsing — Reads
.oschemafiles and produces an AST - Code generation — Generates Rust types, server handlers, client SDKs, and Rhai bindings via
build.rs - SmartID (SID) — 4-6 character base-36 distributed identifiers for all objects
- Filesystem persistence — OTOML-format storage with directory-based organization
- JSON-RPC server — Axum-based server with CRUD + custom service methods (behind
rpcfeature) - Web inspector — Built-in data browser for development
- Workspace scaffolding —
osis_scaffoldCLI generates complete 5-crate workspaces
Key features:
rpc— Enables the Axum JSON-RPC server, Redis caching, and remote index clientrhai— Enables Rhai scripting bindings generation
hero_rpc_derive
Procedural macros:
-
#[derive(OsisObject)]— Generates theOsisObjecttrait for database persistence. Requiressid: SmartIdfield. Supports#[osis(type_name = "...")]and#[osis(index = "field1, field2")]. -
openrpc_client!— Generates typed RPC clients from OpenRPC specifications:openrpc_client!("specs/myservice.openrpc.json"); openrpc_client!(socket = "/tmp/myservice.sock"); openrpc_client!("spec.json", name = "CustomClient"); -
mcp_client_from_json!/mcp_client_from_file!— Generate typed MCP (Model Context Protocol) client structs from JSON specifications.
hero_rpc_client
Lightweight cross-platform RPC client:
- Native (desktop, iOS, Android) — Uses
reqwestfor HTTP transport - WASM (browser) — Uses
gloo-netfor fetch API - JSON-RPC 2.0 framing with authentication token support
- Generated domain clients compose
OsisClientfor typed API access
use hero_rpc_client::OsisClient;
// Native
let client = OsisClient::new("http://localhost:8080", "root", "recipes")?;
// With auth
let client = OsisClient::with_token("http://...", "root", "recipes", "my-token")?;
// JSON-RPC call
let result: Vec<String> = client.rpc_call("recipe.list", serde_json::json!({})).await?;
Architecture
.oschema files
│
▼
hero_rpc_osis (build.rs) ─── generates ──→ Rust types, server handlers,
│ client SDK, Rhai bindings
│
├── hero_rpc_derive (compile-time macros)
└── hero_rpc_client (runtime HTTP client)
Code generation flow:
build.rsin the core crate callsOschemaBuilder::generate()- OSchema files are parsed into an AST
- Rust types with
#[derive(OsisObject)]are generated for each root object - Server handlers (CRUD + custom methods) are generated for the
_openrpccrate - Client methods are generated for the
_clientcrate - OpenRPC specification JSON is emitted alongside
Runtime flow:
_openrpcserver starts, creates Unix socket per context- Registers domain handlers with the Axum JSON-RPC router
_httpproxy forwards HTTP requests to the Unix socket_clientSDK connects via HTTP and sends JSON-RPC 2.0 requests
Building
cargo check --workspace
cargo build --workspace
Requirements
- Rust 1.92.0+
- Edition 2024
Related Projects
- hero_lib — Core Rust libraries (otoml, derive, sid, infra)
- hero_osis — Reference OSIS service implementation
License
Apache-2.0