Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

typediagram

CLI for typeDiagram. Render the typeDiagram DSL to SVG, or convert between the DSL and TypeScript, Python, Rust, Go, C#, F#, Dart, PHP, and Protobuf.

Live demo: typediagram.dev

Install

npm install -g typediagram

Usage

# DSL → SVG (default)
typediagram schema.td > diagram.svg

# Source language → SVG
typediagram --from typescript types.ts > diagram.svg

# DSL → source language
typediagram --to rust schema.td > types.rs

# One schema → every configured language, regenerated on save
typediagram --config typediagram.json --watch

# Read from stdin
cat schema.td | typediagram > diagram.svg

Options

Flag Values Default
--config FILE JSON source/output manifest
--watch watch the configured .td source config
--from <lang> typescript, python, rust, go, csharp, fsharp, dart, protobuf, php
--to <lang> typescript, python, rust, go, csharp, fsharp, dart, protobuf, php
--emit <fmt> svg, td, td+svg (for --from) svg
--theme light, dark light
--font-size N font size in px
-h, --help show help

If no file is given, stdin is read. Output goes to stdout; errors go to stderr.

Config paths are relative to the config file:

{
  "source": "schemas/user.td",
  "watch": true,
  "outputs": {
    "typescript": "frontend/src/generated/user.ts",
    "rust": "backend/src/generated/user.rs"
  }
}

Watch mode retains generated files when an edit is invalid and regenerates all selected languages after the source becomes valid again.

Example

cat > user.td <<'EOF'
typeDiagram

type User {
  id:    UUID
  name:  String
  email: Option<Email>
}

union Option<T> {
  Some { value: T }
  None
}

alias Email = String
EOF

typediagram user.td > user.svg

Related packages

  • typediagram-core — core library (parser, layout, SVG renderer)
  • TypeDiagram VS Code extension — syntax highlighting + live preview (search "TypeDiagram" by nimblesite on the Marketplace)

Links

MIT © Nimblesite