MCPcopy Index your code
hub / github.com/dev-formata-io/stof

github.com/dev-formata-io/stof @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
1,615 symbols 6,291 edges 156 files 1,148 documented · 71%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Stof

<em><b>Stof</b> is a <b>Data Runtime</b> built on top of Rust & WebAssembly. Designed to <b>combine data and logic</b> together in a portable & lightweight context that runs anywhere, <b>sandboxed</b>.</em>

Stof: JSON to Stof

Install

npm i @formata/stof     # TypeScript / JavaScript
cargo add stof          # Rust
pip install stof        # Python

Full setup for every language, the complete standard library, and worked end-to-end examples: stof.dev

Quickstart

Every JSON document you have is already a Stof document. Start with the data you have, add logic where you need it, and export back to JSON - or YAML, or TOML - any time.

import { stofAsync } from '@formata/stof';

const doc = await stofAsync`
{
    "name": "Stof"
    "hello": ():str => \`Hello, \${self.name}!\`
}`;

console.log(await doc.call('hello')); // Hello, Stof!
import { StofDoc } from '@formata/stof';

const doc = await StofDoc.parse({
    first: 'John',
    last: 'Doe',
    domain: 'example.com'
});

doc.parse(`
fn fill(domain: str = 'example.com') {
    self.domain = domain;
    self.email = \`\${self.first.lower()}.\${self.last.lower()}@\${self.domain}\`;
}`);

await doc.call('fill', 'stof.dev');
console.log(doc.record());

/*
{
    first: 'John',
    last: 'Doe',
    domain: 'stof.dev',
    email: 'john.doe@stof.dev',
}
*/

What Stof Is

Stof is a data runtime — not a data format, not a programming language, not a database.

The same way a JavaScript runtime executes JavaScript, a data runtime executes data. A Stof document doesn't just describe something; it validates itself, transforms itself, and acts, wherever the runtime lands.

Concretely: valid JSON is already valid Stof. You're not migrating to a new format — you're handing your existing data a place to keep the logic that used to live somewhere else.

Why it's different

  • Data and logic belong together. Splitting them across a data file and a separate codebase creates schema drift, versioning hell, and is a limitation for modern distributed systems. Stof documents carry both, as one unit.
  • Portable means portable. The same document runs native, in WebAssembly, or embedded in another host, with the same behavior every time. If it doesn't run everywhere, it isn't portable — it's just convenient sometimes.
  • Sandboxed by default. A document can only see and manipulate itself unless you explicitly hand it more. Logic that arrives over the wire has to be safe to run without a review cycle first.
  • Documents should be able to grow. A running document parsing new fields, new types, even new functions into itself isn't an edge case — it's the model working as intended. Data that can only be replaced, never extended, is still just a snapshot.
  • Interop with all data formats. A superset of JSON that is compatible with every other data format, even ones that don't exist yet — binary, images, PDFs, DOCX, YAML, TOML, JSON, etc.

Where This Came From

Stof comes out of a decade spent building parametric and geometry formats for CAD and graphics systems. That's where the core architectural insights come from: represent everything as a flat graph of nodes and data components (ECS + DAG), connected by pointers rather than nested copies, and moving or transforming part of the document stops being expensive. Everything — fields, functions, PDFs, images, binaries — become data components on a graph of nodes. Allow function components to manipulate the graph, and you have Stof.

Stof started as a solo project while trying to send wasm over the wire, and it's been running in production since — including as the policy engine underneath Limitr, where every plan, credit limit, and validation rule is a live Stof document.

Learn More

  • stof.dev — install docs, the full standard library, and examples
  • Discord — talk to the team and community
  • GitHub Issues — bugs and feature requests

License

Apache 2.0. See LICENSE for details.

Extension points exported contracts — how you extend this code

Format (Interface)
Format. [20 implementers]
src/model/formats/format.rs
Instruction (Interface)
Instruction trait for an operation within the runtime. [37 implementers]
src/runtime/instruction.rs
InitOutput (Interface)
(no doc)
web/pkg/stof.d.ts
StofData (Interface)
(no doc) [12 implementers]
src/model/mod.rs
InsDynAny (Interface)
Blanket manual upcast to dyn Any for instructions. [1 implementers]
src/runtime/instruction.rs
ImageFormat (Interface)
(no doc) [7 implementers]
src/model/formats/image/mod.rs
InsClone (Interface)
Blanket Clone implementation for any struct that implements Clone + Instruction [1 implementers]
src/runtime/instruction.rs
AsDynAny (Interface)
Blanket manual upcast to dyn Any for data. [1 implementers]
src/model/mod.rs

Core symbols most depended-on inside this repo

push
called by 1284
src/runtime/table.rs
clone
called by 1217
src/model/mod.rs
pop
called by 720
src/runtime/table.rs
clone
called by 370
src/runtime/value.rs
insert_libfunc
called by 356
src/model/graph.rs
len
called by 263
src/model/sid.rs
to_string
called by 242
src/runtime/units.rs
parse
called by 237
src/py/mod.rs

Shape

Method 783
Function 701
Class 88
Enum 33
Interface 9
Route 1

Languages

Rust94%
TypeScript5%
Python1%

Modules by API surface

src/model/graph.rs91 symbols
src/runtime/value.rs72 symbols
src/runtime/num.rs66 symbols
web/pkg/stof.js48 symbols
src/model/libraries/num/ops.rs42 symbols
src/runtime/variable.rs40 symbols
src/model/formats/image/image.rs38 symbols
src/model/libraries/obj/ops.rs36 symbols
src/model/node.rs33 symbols
src/runtime/units.rs32 symbols
src/parser/expr/math.rs31 symbols
src/model/sid.rs30 symbols

For agents

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

⬇ download graph artifact

Ask about this repo answers extend the page