SpruceKit
SpruceID
  • 🌲SpruceKit Introduction
    • Decentralized Identity Overview
    • Glossary
  • ⚡Quickstart
  • SpruceKit Mobile
    • SpruceKit Showcase App
      • Installation
      • Getting Started
      • Issue a Showcase Credential
      • Present a Showcase Credential
    • SpruceKit Mobile SDK
      • Introduction
      • Core Components
        • StorageManager
        • KeyManager
        • CredentialPack
        • Card
        • IsoMdlPresentation
        • mDocReader/IsomDLReader
        • Document Scanner
      • SpruceKit iOS SDK
        • Installation
        • Build a Wallet
          • Accept a W3C VC
          • Present a W3C VC
          • Present mDL in-person/offline
          • Present an mDL over the internet
        • Build a Verifier
          • Verify a W3C VC
          • Verify an mDL in-person/offline
          • Verify an mDL over the internet
      • SpruceKit Android SDK
        • Installation
        • Build a Wallet
          • Accept a W3C VC
          • Present a W3C VC
          • Present an mDL in-person/offline
          • Present an mDL over the internet
        • Build a Verifier
          • Verify a W3C VC
          • Verify an mDL in-person/offline
          • Verify an mDL over the internet
  • Verifiable Digital Credentials
    • ⚙️DIDKit
      • Installation
      • Core Concepts
      • DID Methods
      • Runtime Configuration
      • Specifications and Dependencies
      • Quickstart
      • DIDKit Packages
        • Command Line Interface
        • HTTP Server
        • Rust Crate
        • C Interface
        • Java and Android
        • Python
        • Javascript
      • DIDKit Examples
        • Core Functions (CLI)
        • Core Functions (HTTP)
        • did-web in minutes
        • Batch Generation & Verification
    • 🪪ISO mDL
      • Quickstart
      • Core Concepts
      • User Guide
  • Schema Definition Language
    • 🔗TreeLDR
      • TreeLDR Quickstart
        • First Schema
        • Compilation into JSON Schema
        • Compilation into JSON-LD Context
        • Writing a Layout
        • Simple Rust Integration
      • Types
        • Literal Types
      • Layouts
        • Primitive Layouts
        • Literal Layouts
        • Enumeration
        • Array Layout
        • References
      • Compiling
        • Schema Definition Formats
          • JSON Schema
          • JSON-LD Context
          • Resource Description Framework (RDF)
        • Programming Languages
          • Compiling to Rust
      • RDF Vocabulary
      • 💡TreeLDR Basics
        • Types and Layouts
        • Properties
        • Syntax
  • Witness for Credential Claims
    • 🔭Rebase
      • Core Library
      • Rust Client/Witness SDK
      • WASM Client SDK
      • Simple "Basic Post" Schema
      • DNS Witness Flow Schema
  • References
    • Contributing
    • Code of Conduct
Powered by GitBook
On this page

Was this helpful?

  1. Schema Definition Language

TreeLDR

PreviousUser GuideNextTreeLDR Quickstart

Last updated 7 months ago

Was this helpful?

This page contains documentation for TreeLDR v0.1.0. The library has since undergone significant updates and is now at version 0.2. We're actively working to update the documentation — thank you for your patience!

TreeLDR is a schema definition language that aims at describing both the structure and semantics of the defined schema in a comprehensible way. It lies at the intersection between (and its various schema definition ontologies such as ) and structure-oriented schema definition frameworks such as or .

To try out TreeLDR, check out our Quickstart guide:

  • A backend server, written in Rust, managing users, the publication and access to blog posts. We will consider a federation where multiple backend servers can also communicate between each other in a decentralized manner;

  • A database server, storing users and posts information;

  • A client application, written in TypeScript, connecting to the backend server, accessing and displaying posts to some user.

All those components know the concept of user and post but may have a different inner data representation for them. For instance:

  • The backend server represents users and posts in memory following the

  • The database server stores users and posts in a SQL table.

In addition, they must agree on a data representation to communicate with each other. For instance:

  • The backend server may communicate with the database using SQL queries;

  • Servers may communicate with each other using ;

  • Clients may communicate with a server using JSON, regulated by a .

This example shows how even a simple distributed application introduces a lot of redundancies in data schema definitions. Here each concept (user and post) require at least 5 different representations throughout the different components, and conversion procedures to go from one representation to the other.

TreeLDR can solve this issue by providing a single language to define common concepts (types) and shared data representations (layouts) that can then be exported into various other languages and schema definitions. For instance here is a simple TreeLDR schema definition for our blogging application:

use <http://www.w3.org/2001/XMLSchema#> as xs;

type User {
	name: xs:string,
	birthDate: xs:date
}

type BlogPost {
	title: required xs:string,
	content: required xs:string
}

The end goal of TreeLDR is to use this unique definition to generate every other schema definition in our distributed application. In our example this means:

  • Rust type definitions for User and BlogPost in the backend server,

  • the necessary SQL table definitions for the database server,

  • TypeScript type definitions for User and BlogPost in the client application,

  • a JSON-LD context defining User and BlogPost in the JSON-LD documents exchanged between the servers,

  • a JSON Schema constraining the JSON documents exchanged between the client and server.

Here is the Rust code generated from the definition above, that we won't have to write ourselves thanks to TreeLDR.

pub mod xs {
	pub type String = ::std::alloc::String;
	pub type Date = ::chrono::Date<::chrono::offset::Utc>;
}

struct User {
	name: Option<xs::String>,
	birth_date: Option<xs::Date>
}

struct BlogPost {
	title: xs::String,
	content: xs::String
}

Besides the schema itself, by understanding the semantics attached to the schema TreeLDR can automatically generate boiler plate code for common tasks such as serialization/deserialization, conversions between different representations, etc.

RDF
OWL
JSON Schema
IPLD
TreeLDR Quickstart
layout of their respective Rust type definition
JSON-LD
JSON Schema
🔗
Page cover image