This aids in verbal communication and helps novice sequence diagram readers understand the sequence you're trying to communicate.Īdding numbers is as simple as adding the autonumber line to the beginning of your sequenceDiagram in Mermaid. It can be helpful to include sequence numbers in your diagram. The placement of notes does matter and trying a few different approaches when using notes may be necessary to get the effect you're looking for. Note over C, S: Subsequent requests include JWT Note over DB: Password is not stored in database Notes allow you to show the reader helpful text and can be placed over a single system or over two different systems using the note syntax: sequenceDiagram Often you'll want to annotate your diagrams with notes. S->C: 200 OK & JWT Notes and Sequence Numbers If you wanted to indicate that a system is actually an actor (typically something involving a human user), you can use the word actor instead of participant and the diagram will update. Here C, S, and DB are all aliases used in the actual message lines while their full names still show up in the generated diagram. This also gives us an opportunity to tweak the order of the systems shown, if we wanted to swap the order of the Database and Server, for example: sequenceDiagram Aliases and Actorsīecause typing Client and Server can get tedious, Mermaid.js gives us a way of creating aliases for our systems by declaring them at the top of the sequenceDiagram block. Here by adding the Database node and illustrating the message was sent from the server to the database, our diagram automatically expands.Īlso note that systems appear in the order in which they're first mentioned, with the first system on the left and the last being at the right. Now that we've seen a simple message between two systems, let's show the database's role in fulfilling the request: sequenceDiagram The -> arrow (note the two dashes instead of one) indicates a dotted line return value This will not appear in the examples in this article Note: for asynchronous messages you would indicate them with -). The value after the : describes the contents of the message. The -> arrow indicates that the message is intended to be synchronous. Next, we declare a message from a Client to the Server. Here we start by specifying that the Mermaid diagram we want to use is a sequence diagram. sequenceDiagramĬlient->Server: Login (Username, Password) Let's start with a simple sequence diagram representing a message from the client to the server and the server's response back. If you're curious about this, however, I do have an article and video on understanding JWT authentication. However, the focus of the article's text will be on the diagrams themselves, not the process of JWT authentication. Over the course of this article, we'll create and expand a sequence diagram to explain JSON Web Token (JWT) authentication. If you're curious about sequence diagrams in general, a good starting point might be Visual Paradigm's Guide to Sequence Diagrams. This can help explain complex logic and interactions with a technical diagram and identify areas of confusion or misunderstanding. Sequence diagrams represent systems and individuals as vertical columns and messages between these parts as horizontal lines that move across the various lanes to show how data flows between different pieces of the system. What are Sequence Diagrams?įor those of you who haven't been exposed, sequence diagrams describe a series of messages in a sequence between different objects. Mermaid.js is available in a variety of tools, but I most frequently use it in GitHub markdown files and in Polyglot Notebooks. It also means that the diagram source is easily version-controlled and anyone on your team can modify it without special tooling or licenses. This means your time is focused on actually writing the interaction logic instead of generating a visual. With Mermaid.js you can write a few lines of text and use its JavaScript library to generate a professional sequence diagram like the one below: Mermaid.js is the solution I needed 20 years ago. I distinctly remember working on sequence diagrams in my undergraduate computer science education and having so many issues trying to get the various boxes and arrows to look standard, rearrange shapes as I needed to expand the diagram, and generally focusing on anything but the logic the diagrams intended to create. Previously I've shown how Mermaid.js allows you to create entity relationship diagrams and class diagrams, but in this article we'll cover a far more complex diagram: the sequence diagram. I've been really enjoying seeing how Mermaid.js lets you generate technical diagrams from simple markdown.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |