Skip to content

Mermaid Diagrams Are My New Best Friend

Nov 30, 2026 7 min read #ai #programming

On a client’s Laravel project, I needed a little bit of guidance from them, so I asked them to build me a couple of workflow diagrams. I thought it’d be a good idea for these to be built in Mermaid, because not only could we see them visually, but AI could use them too. Turns out I got a lot more than I asked for.

What/Why Mermaid

Why did I pick Mermaid.js, and what’s the point?

Well, for a couple of reasons, really. It’s plain text in the repo, and both human and Claude or AI agents can read it. Another benefit is that GitLab and GitHub both render Mermaid in markdown, so even a stakeholder can read them in their browser with no tooling. There’s also mmdc, which is the Mermaid CLI, that parses them locally and allows the AI agent to determine if the Mermaid will be correctly rendered.

So since I knew there was a lot of automated tooling and we could see these and they were plain text, I thought it would be perfect for the stakeholder to also use this tool.

While the client was developing the workflows for me, I decided to use Claude to check on the existing workflows and document those as well. This way I would have that reference. So would Claude. And I could even show the stakeholder an example of the type of Mermaid documents that we would use.

Because Claude was authoring these and it actually uses them a lot, I decided to keep them inside of the Claude skills folder, not a docs folder. I told the stakeholders where to look, and that way I don’t have to keep two copies of them.

The First Round

So the first time I had Claude go through and build out these documents, they became really large and hard to follow. I tried to explain that I need to be able to understand these as a human, and with more than a couple of different branches and decisions, I’m going to get lost. I think there are conceptually workflows within workflows, and we could kind of segment these into multiple files.

So we split them into smaller diagrams and they reference each other. This is nice because I can open them up in the browser, still kind of follow along, but Claude can still jump between them because it has a reference to follow with the pointers.

Surprise - Your App Has Bugs

There are 2 different levels of bugs in the application. Some are pretty obvious, and then some are more logical bugs that you wouldn’t necessarily know are a bug because they’re not bugs with code. They’re more bugs with business process.

While Claude was diagramming stuff, it was having a commentary, as AI models do. It found maybe a bug or two and Claude was able to point out that, yes, it really appears to be a bug as it’s reading the software again. I was really appreciative of that, and I was not expecting to find that.

But it did also mention a couple of other things that, if you weren’t paying attention, you wouldn’t necessarily have noticed. And if you don’t understand your application or the bounds in which it should function, you wouldn’t necessarily know that it had found bugs or things that we could fix.

The two examples I’m referring to are some access controls that were missing and the workflow branches that ended up in 500 errors.

Access Control Bugs

The application was developed with multiple levels of authorization. “Bug” feels like a strong word, but it is actually accurate. What I found was that there were certain workflows or paths through the code that were more protected and authorized than others. So, in some situations, the user would be stopped immediately and could not do anything else if they did not have the proper permission. In other parts of the app, they could load the page, but then be stopped on every single action, which of course is a bug. They shouldn’t have been able to load it at all.

Through the diagramming process, Claude explained that there was a difference between these two authorization cases, as if it was factual and as if it was designed that way. Because I know my application, and I was paying attention to the output of the models, I knew that it was actually telling me about a bug, but it just didn’t know it was a bug. Because of course, it’s just reading the code.

So because of these Mermaid diagrams, I was able to tighten up a little bit more authorization inside of my application. That was a first win that I was not expecting.

500s

The second set of bugs was sort of a conceptual difference between what I wanted diagrammed and what was actually a bug. The diagrams ended up having workflow branches that ended in error 500s. As I looked into those further, though, I realized there were 2 different segments or 2 different reasons for this.

One was about catastrophic errors, like the database going down. These were things I did not want inside of my workflow, because those are exceptional cases that are going to be handled a different way. That’s not necessarily a workflow situation. I told Claude that I do not want those diagrammed.

But the other set of errors, 500s, were usually from situations where I had not done validation properly. So a user could pass in an accidental value, or a malicious user could pass in an incorrect value on purpose, and we’d find it would generate a 500, which is never the right outcome. It should have stopped that with validation and type checking.

So, I was generating even more work (“bug fixes”) from my diagramming process. But this is great because I was able to fix the bugs (that I didn’t even know about before).

End Notes

Honestly, I thought I was just going to be generating some Mermaid diagrams. In fact, I didn’t even know what value I’d get out of these. I knew that I’d look at them sometimes, but I wasn’t really expecting to study them. I had built up the application, so I didn’t need to be reminded about these workflows.

Or so I thought.

In a bit of a humbling experience, I realized that this Mermaid diagramming workflow process exposed a couple of misses inside of my application. So moving forward, I think I get two bits of value out of using Mermaid.

First, I can communicate with stakeholders what their application is doing in a nice visual way, and it’s still text I can write myself or have an AI agent build out from the code. So either direction, I can document the workflow first and build the code, or I can build the code and document the workflow.

Second, since this is sort of a structured review of the code, I can also find bugs as part of this documentation process. Claude may not necessarily identify them as bugs, but that’s my job as the programmer to pay attention to the workflow it’s describing from the code and determine if, in fact, we have missed some stuff.

What I think this means is that Mermaid is now a tool in my toolbox for all future projects.