Skip to content

Instantly share code, notes, and snippets.

@craigarms
Created January 15, 2024 15:43
Show Gist options
  • Save craigarms/bab9d49cc15f536f366d155ab214848a to your computer and use it in GitHub Desktop.
Save craigarms/bab9d49cc15f536f366d155ab214848a to your computer and use it in GitHub Desktop.
ChatGPT Generated Sequence Diagram for Blog Article
from graphviz import Digraph
dot_content = '''
digraph {
splines=false
node [shape=box
fontname="Arial"
style="filled, rounded"
fillcolor="#e2e2f0"]
b_start [label="Bob"]
b_0 [label="" shape=point height=0] // it is a helper invisible node
b_1 [label="" shape=point height=0] // it is a helper invisible node
b_2 [label="" shape=point height=0] // it is a helper invisible node
b_3 [label="" shape=point height=0] // it is a helper invisible node
b_end [label="Bob"]
b_start -> b_0 -> b_1 -> b_2 -> b_3 -> b_end [style="dashed" arrowhead="none"]
a_start [label="Alice"]
a_0 [label="" shape=point height=0] // it is a helper invisible node
a_1 [label="" shape=point height=0] // it is a helper invisible node
a_2 [label="" shape=point height=0] // it is a helper invisible node
a_3 [label="" shape=point height=0] // it is a helper invisible node
a_end [label="Alice"]
a_start -> a_0 -> a_1 -> a_2 -> a_3 -> a_end [style="dashed" arrowhead="none"]
c_start [label="Charlie"]
c_0 [label="" shape=point height=0] // it is a helper invisible node
c_1 [label="" shape=point height=0] // it is a helper invisible node
c_2 [label="" shape=point height=0] // it is a helper invisible node
c_end [label="Charlie"]
c_start -> c_0 -> c_1 -> c_2 -> c_end [style="dashed" arrowhead="none"]
{rank=same;
b_0 -> a_0 [weight=0
arrowhead=vee fontname="Arial"
label=<<B>1 </B>Authentication Request>]}
{rank=same;
a_1 -> c_1 [weight=0
arrowhead=vee fontname="Arial"
label=<<B>1 </B>Authentication Validation>]}
{rank=same;
c_2 -> a_2 [weight=0
arrowhead=vee fontname="Arial"
label=<<B>1 </B>Authentication Valid>]}
{rank=same;
a_3 -> b_3 [weight=0
arrowhead=vee fontname="Arial"
label=<<B>2 </B>Authentication Response>]}
}
'''
# Create a Digraph from the DOT content
graph = Digraph(format='png')
graph.attr(dpi='300')
graph.attr(rankdir='LR')
graph.attr(size='8,5')
graph.node_attr.update(color='lightblue2', style='filled')
graph.attr('node', shape='box', fontname="Arial", style='filled, rounded', fillcolor='#e2e2f0')
graph.node('b_start', label='Bob')
graph.node('b_0', label='', shape='point', height='0')
graph.node('b_1', label='', shape='point', height='0')
graph.node('b_2', label='', shape='point', height='0')
graph.node('b_3', label='', shape='point', height='0')
graph.node('b_end', label='Bob')
graph.edge('b_start', 'b_0')
graph.edge('b_0', 'b_1')
graph.edge('b_1', 'b_2')
graph.edge('b_2', 'b_3')
graph.edge('b_3', 'b_end', style='dashed', arrowhead='none')
graph.node('a_start', label='Alice')
graph.node('a_0', label='', shape='point', height='0')
graph.node('a_1', label='', shape='point', height='0')
graph.node('a_2', label='', shape='point', height='0')
graph.node('a_3', label='', shape='point', height='0')
graph.node('a_end', label='Alice')
graph.edge('a_start', 'a_0')
graph.edge('a_0', 'a_1')
graph.edge('a_1', 'a_2')
graph.edge('a_2', 'a_3')
graph.edge('a_3', 'a_end', style='dashed', arrowhead='none')
graph.node('c_start', label='Charlie')
graph.node('c_0', label='', shape='point', height='0')
graph.node('c_1', label='', shape='point', height='0')
graph.node('c_2', label='', shape='point', height='0')
graph.node('c_end', label='Charlie')
graph.edge('c_start', 'c_0')
graph.edge('c_0', 'c_1')
graph.edge('c_1', 'c_2')
graph.edge('c_2', 'c_end', style='dashed', arrowhead='none')
graph.attr('node', shape='plaintext', fontname="Arial", style='filled, rounded', fillcolor='#e2e2f0')
graph.edge('b_0', 'a_0', weight='0', arrowhead='vee', fontname='Arial', label='<<B>1 </B>Authentication Request>')
graph.edge('a_1', 'c_1', weight='0', arrowhead='vee', fontname='Arial', label='<<B>1 </B>Authentication Validation>')
graph.edge('c_2', 'a_2', weight='0', arrowhead='vee', fontname='Arial', label='<<B>1 </B>Authentication Valid>')
graph.edge('a_3', 'b_3', weight='0', arrowhead='vee', fontname='Arial', label='<<B>2 </B>Authentication Response>')
# Save the graph as an image
graph.render('output_graph', format='png', cleanup=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment