PracticeModelling practice

How to validate UML diagrams automatically

A tool can check four different things about a UML diagram: the syntax, the rules of the language, the quality of the model, and whether the code still matches it. No single tool does all four. This guide runs a broken class diagram through one of them, shows what was found, and shows two mistakes that nothing found.

8 min readModelling practice5 of 6

The short answer

  • "Valid" means four separate things: the text parses, the UML is legal, the model is tidy, and the code agrees with it. Ask a tool which of them it checks.
  • A syntax check reads the text and not the model. Two classes that inherit from each other are two well-formed lines.
  • Rules can find a cycle, a duplicate, a nameless box or an orphan. They cannot find an arrow that points the wrong way between two classes that may legally depend on each other.
  • Only a check against the code, such as an ArchUnit test, can tell you that a diagram has stopped being true.

Open full size

UML class diagram of an order service with mistakes in it. Order is composed of order_line, which depends on Invoice. Invoice and Document are each a generalization of the other. Order is associated with one class named Customer and Invoice with a second class named Customer. order_line is associated with Product, and Document with a class that has no name. Address is connected to nothing. CardGateway realizes the PaymentGateway interface.
The diagram this guide checks. The highlighted classes take part in the five findings. Two more mistakes are on this canvas, and no rule reports them.

01Four checks that share one name#

"Validate the diagram" can mean four things. They need different inputs and different tools, and a tool that does one of them well may not attempt the others.

CheckDone byWhat it finds
SyntaxPlantUML, MermaidDoes the text parse? Finds a missing bracket or an unknown keyword. Applies only to diagrams kept as text.
UML rulesA modelling tool with a metamodelIs this legal UML? Finds classes that inherit from each other in a circle, or an interface realization that does not end at an interface.
Model qualityThe same tool, softer rulesIs the model tidy? Finds two elements with one name, a box with no name, an orphan, mixed naming. UML forbids two classes with one name in one namespace. The other three are legal UML, and still a problem.
Agreement with codeArchUnit and similar testsIs it still true? Finds a dependency in the code that the diagram does not allow.

The rules in the second row come from UML 2.5.1 (OMG, December 2017), the version this site follows.

02A real run on a broken diagram#

The diagram at the top has eleven classifiers and was drawn in Archyno on 29 November 2026 with mistakes put in on purpose. The editor checks a view while you draw it. The check is a fixed set of rules that runs in the browser; it makes no AI call, so the same model always gives the same list.

Open full size:The Archyno editor with the order service class diagram on the left and five findings on the right: inheritance runs in a circle, two elements named Customer, an element has no name, class names are not consistent, and one element is not connected to anything.
The Issues tab for this diagram: one error, two warnings and two notes. Select the image to see it at full size.
FindingSeverityWhat to do
Inheritance runs in a circleErrorInvoice is a kind of Document, which is a kind of Invoice. UML forbids it, and Java or C# would refuse to compile it. Delete one of the two generalizations.
2 elements named "Customer"WarningTwo separate elements, not one element drawn twice. A rename now has to happen in two places. Keep one and connect both lines to it.
An element has no nameWarningIt exports as an empty string, and nobody can refer to it in a review. Name it or remove it.
Class names are not consistentNoteMost names are PascalCase and order_line is not. The rule reads the convention from the diagram instead of imposing one; see UML naming conventions.
One element is not connectedNoteAddress has no line to anything. That is normal halfway through drawing and suspicious at the end.

Illegal connectors are missing from the list for a good reason: the editor does not let you draw them. In Archyno a realization can only end at an interface, and the class diagram rules decide which ends a composition may have.

03The two mistakes no rule found#

The report has five findings and the diagram has seven mistakes. These two are legal UML, so there is nothing for a rule to object to.

The dependency points the wrong way. The diagram says order_line depends on Invoice. In the system it describes, the invoice is built from the order lines, and the order lines know nothing about invoices. Either direction is legal between two classes, so only somebody who knows the system, or a tool that reads the code, can tell which one is true.

Two elements form an island. PaymentGateway and CardGateway are connected to each other and to nothing else. The orphan rule looks for an element with no connector at all, so a pair passes. The missing line is the important one: who calls the gateway?

Open full size

The corrected UML class diagram of the order service. Order is composed of one or more OrderLine and is associated with Customer, which is associated with Address. Each OrderLine is associated with one Product. Invoice depends on OrderLine, is associated with Customer and is a kind of Document, which is associated with Attachment. Order depends on the PaymentGateway interface, which CardGateway realizes.
After the review. The five findings are gone, the dependency is turned round, and Order depends on PaymentGateway. The same rules report nothing on this diagram.

04Checking diagrams kept as text#

If diagrams live in the repository as PlantUML or Mermaid, the cheapest check is the parser. These are the documented entry points, read on 29 November 2026:

  • PlantUML: plantuml --check-syntax is described as "Check diagram syntax without generating images". The command-line page lists exit code 0 for success and above 0 for an error, and marks this command line as beta.
  • Mermaid: await mermaid.parse(text) "validates graph definitions without rendering a graph". It throws on invalid text, or returns false when called with suppressErrors: true. See Mermaid usage.

Both answer the first row of the table only. Neither page promises to apply UML's own rules. Two classes that inherit from each other are two well-formed lines of text, so a syntax check is the wrong place to look for that error. If you write diagrams this way, the Mermaid guide shows what the format can carry, and Archyno and PlantUML compares text with a model.

05Checking a diagram against the code#

The fourth check is what most people mean by software architecture validation. The diagram becomes a rule, and a test fails when the code breaks it. In Java, ArchUnit reads a PlantUML component diagram directly:

classes().should(adhereToPlantUmlDiagram(diagram, consideringAllDependencies()))

The user guide (version 1.5.1, read on 29 November 2026) sets two limits: "Diagrams supported have to be component diagrams and associate classes to components via stereotypes." A stereotype on each component holds a package pattern, and that is how the test knows which classes belong to which box. A class diagram cannot be used this way.

That limit is useful advice. A component diagram with six boxes changes a few times a year and is worth enforcing. A class diagram changes with every commit, and the code is already its most exact form. Our example would be caught one level up: draw orders and billing as components, allow billing to use orders, and the wrong arrow becomes a failing test.

06Put the checks in order#

Run the cheap checks first, and give each one a place where it cannot be skipped.

  1. While drawing: legal connectors and model rules, in the editor. Fix errors at once. Decide on each warning before the diagram is shared.
  2. On commit: the syntax check for every diagram stored as text.
  3. In the test suite: one architecture test for the component diagram you care most about. One that always runs is better than ten that are switched off.
  4. In review: the questions no rule can answer. Keep a finding that you accept written down next to the diagram, so nobody spends time on it twice.

Be clear about what your tool covers. Archyno checks UML, ArchiMate and BPMN rules in the editor. It has no command that runs the UML view rules in a build pipeline today. For a system that already exists, start from the code instead: how to document an existing system shows a repository scan and what it missed. To draw one yourself, open a class diagram in the editor without an account, or read what Archyno does.

In one line each

  1. 01Name the check you mean: syntax, UML rules, model quality or agreement with the code.
  2. 02A syntax check is not a model check. Do not let a green build stand for a review.
  3. 03Rules found five of seven mistakes here. The other two needed knowledge of the system.
  4. 04Enforce one component diagram against the code rather than many class diagrams.
  5. 05Write down the warnings you accept, next to the diagram.

07Common questions#

Can a tool check whether a UML diagram is correct?

It can check whether the diagram is legal UML and whether the model has common faults such as inheritance cycles or duplicate names. It cannot check whether the diagram describes your system, unless it also reads the code. Treat a clean report as "no known fault", not as "correct".

Does PlantUML validate UML?

PlantUML checks that its own text parses. Its documentation describes the --check-syntax option as checking diagram syntax without generating images, with exit code 0 for success and above 0 for an error. It does not promise to apply the UML metamodel, so add another check for that.

How do I check UML diagrams in a CI pipeline?

For diagrams kept as text, run the parser and fail the build on a non-zero exit code or a thrown error. For Java code, add an ArchUnit test that compares the packages with a PlantUML component diagram. Rules about UML itself usually run inside the modelling tool rather than in the pipeline.

What is the difference between validating and verifying a model?

Verifying asks whether the model follows its rules: legal connectors, no cycles, every element named. Validating asks whether it is the right model for the real system. Tools are good at the first. The second needs the code or a person who knows the system.

In this series

Related reading

← All articles