MDX.org.ai
Structured Data

Structured Data

YAML-LD frontmatter, schemas, templates, and database storage for MDX documents

The Structured Data layer of MDX provides semantic frontmatter using YAML-LD (YAML + Linked Data), enabling type-safe schemas, validation, and database storage.

Core Concepts

Document

The fundamental unit - combines YAML-LD frontmatter with content body.

---
$type: BlogPost
$id: https://example.com/posts/hello
title: Hello World
author: https://example.com/authors/jane
---

See the Document overview.

Database

Schema-first database modeling with automatic bi-directional relationships.

const db = DB({
  Post: {
    title: 'string',
    author: 'Author.posts',  // Creates both directions
  },
})

See the Database overview.

Templates (Shapes)

Templates define the shape of your data - the TypeScript type or JSON Schema that structures your content:

type StoryBrand = {
  name: string
  hero: {
    persona: string
    occupation: string
  }
  problem: {
    external: string
    internal: string
  }
}
 
type Noun = {
  name: string
  plural: string
  properties: Array<{ name: string; type: string; required: boolean }>
  actions: Array<{ name: string; returns: string }>
}

Templates enable bi-directional conversion between objects and content formats:

import { toMarkdown, fromMarkdown } from '@mdxld/markdown'
import { toJSONLD, toJSONSchema } from '@mdxld/json'
 
// Object → Formats
const markdown = toMarkdown(storyBrand)
const jsonld = toJSONLD(storyBrand)
const schema = toJSONSchema(StoryBrandType)
 
// Markdown → Object
const data = fromMarkdown<StoryBrand>(editedMarkdown)

See Unstructured Content for markdown layouts and UI Components for JSX rendering.

Packages

mdxld

Parse, stringify, validate, and compile MDXLD documents.

npm install mdxld

See the mdxld overview.

mdxdb

Database adapters for storing MDX documents:

  • @mdxdb/fs - Filesystem (git-friendly)
  • @mdxdb/sqlite - SQLite with vector search
  • @mdxdb/do - Cloudflare Durable Objects (primary backend)
  • @mdxdb/vectorize - Cloudflare Vectorize vector search
  • @mdxdb/clickhouse - ClickHouse for analytics

See the mdxdb overview.

On this page