GraphViz Reference

GraphViz graph description language. Directed and undirected graphs, clusters, ranking, edge styling, and layout engines.

Directed Graphs

Basic digraph with nodes and edges
digraph {
    rankdir=LR
    A -> B -> C
    A -> D -> C
}

rankdir=LR flows left to right. Default is TB (top to bottom).

Node attributes — shape, color, label
digraph {
    node [fontname="Helvetica" fontsize=11]
    server [label="Web Server" shape=box style=filled fillcolor="#89b4fa" fontcolor="#1e1e2e"]
    db [label="PostgreSQL" shape=cylinder style=filled fillcolor="#a6e3a1" fontcolor="#1e1e2e"]
    server -> db [label="SQL" color="#f5c2e7"]
}

Undirected Graphs

Undirected graph — uses graph and -- instead of digraph and
graph {
    A -- B
    B -- C
    A -- C
}

Node Shapes

Common shape reference
digraph {
    a [shape=box label="box"]
    b [shape=ellipse label="ellipse (default)"]
    c [shape=diamond label="diamond"]
    d [shape=circle label="circle"]
    e [shape=cylinder label="cylinder"]
    f [shape=hexagon label="hexagon"]
    g [shape=parallelogram label="parallelogram"]
    h [shape=record label="{record|with|fields}"]
}

Subgraphs (Clusters)

Cluster subgraphs for logical grouping
digraph {
    subgraph cluster_network {
        label="Network Layer"
        style=filled
        color="#313244"
        fontcolor="#cdd6f4"
        fw [label="Firewall"]
        lb [label="Load Balancer"]
        fw -> lb
    }
    subgraph cluster_app {
        label="Application Layer"
        style=filled
        color="#313244"
        fontcolor="#cdd6f4"
        api [label="API"]
        worker [label="Worker"]
    }
    lb -> api
    api -> worker
}

Cluster names must start with cluster_ to render as a box.

Ranking and Alignment

Force nodes to the same rank (horizontal alignment)
digraph {
    rankdir=TB
    {rank=same; A; B; C}
    start -> A
    start -> B
    start -> C
    A -> end
    B -> end
    C -> end
}

Edge Styling

Edge attributes — style, color, weight, arrowhead
digraph {
    A -> B [style=dashed color=red]
    A -> C [style=bold penwidth=2.0]
    A -> D [arrowhead=diamond label="inherits"]
    B -> D [style=dotted constraint=false]
}

constraint=false prevents the edge from affecting rank ordering.

CLI Commands

Render to SVG and PNG
dot -Tsvg graph.dot -o graph.svg
dot -Tpng graph.dot -o graph.png
Other layout engines
neato -Tsvg graph.dot -o graph.svg   # Spring model (undirected)
fdp -Tsvg graph.dot -o graph.svg     # Force-directed
circo -Tsvg graph.dot -o graph.svg   # Circular layout
twopi -Tsvg graph.dot -o graph.svg   # Radial layout
sfdp -Tsvg graph.dot -o graph.svg    # Large graph force-directed

Kroki Integration

GraphViz in AsciiDoc via Kroki
[graphviz,target=infra-graph,format=svg]
....
digraph {
    rankdir=LR
    client -> firewall -> server -> database
}
....

Record-Based Nodes

Struct-like records for data schemas
digraph {
    node [shape=record]
    user [label="{User|+id: int\l+name: string\l+email: string\l|+save()\l+delete()\l}"]
    session [label="{Session|+token: string\l+expires: datetime\l}"]
    user -> session [label="has_many"]
}

The \l left-aligns text within a record field.

See Also