Skip to content

API Reference

Draph provides a REST API for programmatic diagram creation. Perfect for automation, CI/CD pipelines, and AI integrations.

Base URL: https://draph.sanath.dev

Create a diagram and get shareable URLs.

Request Body:

Either Mermaid code:

{
"mermaid": "flowchart TD\n A[Start] --> B[End]"
}

Or JSON nodes/connections:

{
"nodes": [...],
"connections": [...]
}

Response:

{
"url": "https://draph.sanath.dev/d/abc123",
"editUrl": "https://draph.sanath.dev/#eyJuIjpb..."
}
FieldDescription
urlShort shareable URL (redirects to editUrl)
editUrlDirect editor URL with encoded diagram data

Example:

Terminal window
curl -X POST https://draph.sanath.dev/api/diagram \
-H "Content-Type: application/json" \
-d '{
"nodes": [
{"id": "n1", "type": "rect", "label": "Start", "x": 100, "y": 100},
{"id": "n2", "type": "rect", "label": "End", "x": 100, "y": 200}
],
"connections": [
{"id": "c1", "from": "n1", "to": "n2"}
]
}'

Export a diagram as a PNG image.

Request Body:

{
"nodes": [...],
"connections": [...],
"width": 1200,
"height": 800,
"scale": 2
}

Or with Mermaid:

{
"mermaid": "flowchart TD\n A --> B",
"width": 1200,
"height": 800,
"scale": 2
}
ParameterTypeDefaultDescription
widthnumber1200Viewport width in pixels
heightnumber800Viewport height in pixels
scalenumber2Resolution multiplier

Response: Binary PNG image

Example:

Terminal window
curl -X POST https://draph.sanath.dev/api/diagram/image \
-H "Content-Type: application/json" \
-d '{"mermaid": "flowchart LR\n A --> B --> C"}' \
--output diagram.png

Load a diagram from a short URL. Redirects to the full editor URL.


Nodes are the shapes in your diagram.

{
"id": "n1",
"type": "rect",
"label": "My Node",
"x": 100,
"y": 100,
"width": 120,
"height": 44,
"color": "#7aa2f7",
"outlineColor": "#414868",
"fillStyle": "infill"
}
PropertyTypeDescription
idstringUnique identifier for this node
typestringShape type (see below)
xnumberX position in pixels
ynumberY position in pixels
PropertyTypeDefaultDescription
labelstring""Display text
widthnumbervariesWidth in pixels
heightnumbervariesHeight in pixels
colorhexvariesFill color. Omit for no fill
outlineColorhex#414868Border/stroke color
fillStylestringinfillFill pattern
TypeDescriptionDefault SizeMermaid
rectRectangle120 × 44A[Label]
pillRounded rectangle120 × 44A(Label)
diamondDecision/condition80 × 60A{Label}
circleTerminal/event80 × 80A((Label))
containerGroup box (dashed)280 × 180A[["Label"]]
textFree text100 × 24-
lineStandalone arrow100 × 0-
ValueDescription
outlineTransparent fill, border only
infillSolid color fill (default)
stripeDiagonal stripe pattern
gridDot grid pattern

Important: Do NOT use "transparent" as a color. Omit the color property instead.

Containers create visual group boxes with dashed borders.

{
"id": "g1",
"type": "container",
"label": "My Group",
"x": 50,
"y": 50,
"width": 300,
"height": 200,
"outlineColor": "#9ece6a"
}

Tips:

  • Define containers BEFORE the nodes they contain (render order)
  • Set outlineColor for visible border and label
  • Omit color property (containers don’t need fill)

For sequence diagrams, nodes can have lifelines:

PropertyTypeDescription
isParticipantbooleanMark as sequence participant
hasLifelinebooleanShow vertical dashed lifeline
isActorbooleanRender as stick figure

For UML class diagrams:

PropertyTypeDescription
isClassbooleanRender as UML class box
propertiesstring[]Class properties (e.g., ["+name: string"])
methodsstring[]Class methods (e.g., ["+getName()"])

Connections are the arrows/lines between nodes.

{
"id": "c1",
"from": "n1",
"to": "n2",
"label": "next",
"color": "#414868",
"lineStyle": "solid"
}
PropertyTypeDescription
idstringUnique identifier
fromstringSource node ID
tostringTarget node ID
PropertyTypeDefaultDescription
labelstring""Edge label text
colorhex#414868Line color
lineStylestringsolidsolid or dashed
fromSidestringautoSource edge: top, right, bottom, left
toSidestringautoTarget edge
fromIdxnumber1Connection point index on source side
toIdxnumber1Connection point index on target side

For sequence diagrams, connections become horizontal messages:

PropertyTypeDescription
isSequenceMessagebooleanRender as horizontal message
messageYnumberY position of the message line
indexnumberMessage order (vertical positioning)
arrowstringArrow style: ->>, -->>, -), --)

Tokyo Night Storm colors recommended:

NameHexUsage
Blue#7aa2f7Primary accent
Cyan#7dcfffSecondary accent
Green#9ece6aSuccess, start states
Red#f7768eError, danger
Yellow#e0af68Warning, decisions
Magenta#bb9af7Special, highlights
Orange#ff9e64Attention, output
Border#414868Default borders
Background#24283bCanvas background

{
"nodes": [
{"id": "start", "type": "pill", "label": "Start", "x": 200, "y": 50, "color": "#9ece6a"},
{"id": "process", "type": "rect", "label": "Process Data", "x": 170, "y": 130},
{"id": "decision", "type": "diamond", "label": "Valid?", "x": 180, "y": 220, "color": "#e0af68"},
{"id": "success", "type": "rect", "label": "Save", "x": 100, "y": 320},
{"id": "error", "type": "rect", "label": "Log Error", "x": 260, "y": 320, "color": "#f7768e"},
{"id": "end", "type": "pill", "label": "End", "x": 200, "y": 420}
],
"connections": [
{"id": "c1", "from": "start", "to": "process"},
{"id": "c2", "from": "process", "to": "decision"},
{"id": "c3", "from": "decision", "to": "success", "label": "Yes"},
{"id": "c4", "from": "decision", "to": "error", "label": "No"},
{"id": "c5", "from": "success", "to": "end"},
{"id": "c6", "from": "error", "to": "end"}
]
}
{
"nodes": [
{"id": "g1", "type": "container", "label": "Frontend", "x": 50, "y": 50, "width": 300, "height": 120, "outlineColor": "#9ece6a"},
{"id": "n1", "type": "rect", "label": "React App", "x": 70, "y": 90},
{"id": "n2", "type": "rect", "label": "Next.js", "x": 210, "y": 90},
{"id": "g2", "type": "container", "label": "Backend", "x": 50, "y": 200, "width": 300, "height": 120, "outlineColor": "#7aa2f7"},
{"id": "n3", "type": "rect", "label": "API Server", "x": 70, "y": 240},
{"id": "n4", "type": "pill", "label": "Auth", "x": 210, "y": 240},
{"id": "n5", "type": "circle", "label": "DB", "x": 400, "y": 240, "width": 60, "height": 60, "color": "#bb9af7"}
],
"connections": [
{"id": "c1", "from": "n1", "to": "n3"},
{"id": "c2", "from": "n2", "to": "n3"},
{"id": "c3", "from": "n3", "to": "n4"},
{"id": "c4", "from": "n4", "to": "n5"}
]
}
{
"nodes": [
{"id": "a", "type": "rect", "label": "Client", "x": 100, "y": 50, "isParticipant": true, "hasLifeline": true},
{"id": "b", "type": "rect", "label": "Server", "x": 300, "y": 50, "isParticipant": true, "hasLifeline": true},
{"id": "c", "type": "rect", "label": "Database", "x": 500, "y": 50, "isParticipant": true, "hasLifeline": true}
],
"connections": [
{"id": "m1", "from": "a", "to": "b", "label": "POST /login", "isSequenceMessage": true, "messageY": 150, "index": 0, "arrow": "->>"},
{"id": "m2", "from": "b", "to": "c", "label": "SELECT user", "isSequenceMessage": true, "messageY": 200, "index": 1, "arrow": "->>"},
{"id": "m3", "from": "c", "to": "b", "label": "user data", "isSequenceMessage": true, "messageY": 250, "index": 2, "arrow": "-->>"},
{"id": "m4", "from": "b", "to": "a", "label": "200 OK + token", "isSequenceMessage": true, "messageY": 300, "index": 3, "arrow": "-->>"}
]
}

The API returns standard HTTP status codes:

CodeDescription
200Success
400Bad request (invalid JSON or missing required fields)
429Rate limit exceeded
500Server error

Error response format:

{
"error": "Description of what went wrong"
}

API requests are rate limited to 30 requests per minute per IP using a sliding window.

When exceeded, you’ll receive a 429 response:

{
"error": "Rate limit exceeded. Please try again later.",
"retryAfter": 21
}

Response headers:

HeaderDescription
X-RateLimit-LimitMaximum requests per window
X-RateLimit-RemainingRequests remaining in current window
X-RateLimit-ResetUnix timestamp when the limit resets
Retry-AfterSeconds to wait before retrying