Architecture

RPC and protobuf contracts

A remote procedure call (RPC) lets a client invoke a named operation on another service. gRPC commonly uses Protocol Buffers to define messages and service methods; the schema is an agreement about data, not permission to access it. A unary GetBook operation accepts one request and returns one response. A .proto file defines numbered fields and their types, and tooling generates or dynamically loads client and server bindings. Field numbers identify binary fields; JavaScript property names alone do not describe the wire encoding. The server validates business constraints and authorizes the caller independently of decoding. A local object model below is deliberately not a Protobuf encoder. Do not assume a successfully decoded request is authorized or that a missing scalar is distinguishable from its default without explicit presence semantics. Sources: https://protobuf.dev/programming-guides/proto3/, https://grpc.io/docs/what-is-grpc/core-concepts/.

Formal Syntax & Structure

nodejs syntaxnodejs
Model a unary contract (conceptual contract; see example)

Working Example

Example Snippetnodejs
import assert from 'node:assert/strict';const books=new Map([['b1',{id:'b1',title:'River'}]]);function getBook(request){if(typeof request.id!=='string'||!request.id)throw Error('INVALID_ARGUMENT');return books.get(request.id)??null;}assert.throws(()=>getBook({id:''}),/INVALID_ARGUMENT/);console.log(getBook({id:'b1'}).title,getBook({id:'missing'}));
Node.js Reference