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.
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.
| Check | Done by | What it finds |
|---|---|---|
| Syntax | PlantUML, Mermaid | Does the text parse? Finds a missing bracket or an unknown keyword. Applies only to diagrams kept as text. |
| UML rules | A modelling tool with a metamodel | Is 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 quality | The same tool, softer rules | Is 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 code | ArchUnit and similar tests | Is 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.

| Finding | Severity | What to do |
|---|---|---|
| Inheritance runs in a circle | Error | Invoice 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" | Warning | Two 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 name | Warning | It exports as an empty string, and nobody can refer to it in a review. Name it or remove it. |
| Class names are not consistent | Note | Most 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 connected | Note | Address 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?
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-syntaxis 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 returnsfalsewhen called withsuppressErrors: 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.
- While drawing: legal connectors and model rules, in the editor. Fix errors at once. Decide on each warning before the diagram is shared.
- On commit: the syntax check for every diagram stored as text.
- 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.
- 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
- 01Name the check you mean: syntax, UML rules, model quality or agreement with the code.
- 02A syntax check is not a model check. Do not let a green build stand for a review.
- 03Rules found five of seven mistakes here. The other two needed knowledge of the system.
- 04Enforce one component diagram against the code rather than many class diagrams.
- 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
- 01UML vs C4 vs ArchiMate
- 02Scoping a model
- 03Naming conventions
- 04Document an existing system
- 05Validate UML automatically
- 06Keeping a model current
Related reading
Structure diagrams
Modelling practice
Modelling practice
Modelling practice
Modelling practice
Modelling practice