If you've ever tried to explain your network setup to a teammate or document a system for future reference, you know how messy it can get. Whiteboard drawings disappear. Screenshots of Visio files get outdated fast. That's where PlantUML code for network topology diagrams comes in. You write your network layout as plain text, and PlantUML turns it into a clean visual diagram. No drag-and-drop. No proprietary file formats. Just code you can version-control, share, and edit in seconds.
This matters because network diagrams aren't optional. They help teams troubleshoot outages, plan upgrades, and onboard new engineers. When your diagram lives as code, it becomes part of your documentation workflow right next to your scripts, configs, and runbooks. For developers and network engineers who already work with different diagram code languages, PlantUML offers a familiar, text-based approach that fits naturally into that workflow.
What does PlantUML network topology code actually look like?
PlantUML uses a simple markup syntax to define nodes, connections, and groupings. For network diagrams, you work with the nwdiag or basic component diagram features. Here's a straightforward example:
@startuml
nwdiag {
network dmz {
address = "10.0.0.x"
webserver [address = "10.0.0.1"]
firewall [address = "10.0.0.2"]
}
network internal {
address = "192.168.1.x"
appserver [address = "192.168.1.1"]
dbserver [address = "192.168.1.2"]
firewall [address = "192.168.1.254"]
}
}
@enduml
This code produces a two-zone network diagram showing a DMZ and an internal network with labeled IP addresses. The syntax reads almost like a config file, which makes it approachable even if you've never used PlantUML before. If you're curious about the broader mechanics of how these diagram languages work, our overview of how diagram codes work in UML covers the foundations.
Why use PlantUML instead of a drag-and-drop diagram tool?
Traditional tools like Visio, draw.io, or Lucidchart work fine for one-off diagrams. But they create problems when your network changes frequently:
- Version control: PlantUML files are plain text. You can track changes in Git, see who modified what, and roll back mistakes easily. Binary diagram files don't give you that.
- Consistency: Code-based diagrams look the same every time you render them. No accidental font changes or misplaced boxes.
- Automation: You can generate PlantUML diagrams from scripts. If you pull device data from an inventory system, you can auto-generate a topology diagram from it.
- Collaboration: Any text editor works. Your teammate can edit the diagram without needing a specific software license.
This is one reason many teams working across multiple diagram code formats adopt PlantUML specifically for networking documentation.
How do you build a more detailed network diagram in PlantUML?
Real networks have firewalls, load balancers, switches, VLANs, and multiple subnets. PlantUML handles this with grouping, stereotyping, and directional arrows. Here's a more realistic example:
@startuml
skinparam componentStyle rectangle
cloud "Internet" as internet
package "DMZ - 10.0.0.0/24" {
[Load Balancer\n10.0.0.1] as lb
[Web Server 1\n10.0.0.10] as web1
[Web Server 2\n10.0.0.11] as web2
}
package "App Tier - 172.16.0.0/24" {
[App Server 1\n172.16.0.10] as app1
[App Server 2\n172.16.0.11] as app2
}
package "Database Tier - 192.168.1.0/24" {
[Primary DB\n192.168.1.10] as db1
[Replica DB\n192.168.1.11] as db2
}
database "Shared Storage\n192.168.1.100" as storage
internet --> lb
lb --> web1
lb --> web2
web1 --> app1
web2 --> app2
app1 --> db1
app2 --> db1
db1 --> db2
db1 --> storage
db2 --> storage
@enduml
This gives you a three-tier architecture with load balancing, database replication, and shared storage. Each node has an IP address label. The package keyword groups devices by subnet or zone, and arrows show traffic flow.
What are the most common mistakes people make?
After working with PlantUML network diagrams in team environments, a few patterns come up repeatedly:
- Overcomplicating the first draft. Start with your core topology servers, firewalls, and routers. Add VLANs, monitoring agents, and secondary connections later.
- Skipping IP addresses and labels. A diagram without addresses or hostnames is hard to use during troubleshooting. Always label your nodes with meaningful identifiers.
- Not using packages or groups. Flat diagrams with 20+ devices become unreadable. Group by subnet, zone, or function using
packageblocks. - Forgetting about rendering. PlantUML needs a Java runtime or an online server to render. Make sure your team knows how to generate the image from the code.
- Not storing the source file with your project. If you render the image but lose the
.pumlfile, you've defeated the purpose. Keep both in your repository.
Can you use PlantUML to diagram cloud and hybrid networks?
Yes. PlantUML doesn't care whether your servers are physical, virtual, or cloud-based. You can represent AWS VPCs, Azure VNets, or on-premises segments using the same package and component syntax. Many teams use PlantUML to map hybrid environments where traffic flows between cloud accounts and data centers.
For example, you can label a package as "AWS VPC - 10.2.0.0/16" and another as "On-Prem DC - 10.1.0.0/16", then draw a VPN connection between them. The notation stays the same. This flexibility is a big reason PlantUML shows up in network documentation alongside tools like Terraform and Ansible.
What tools do you need to get started?
You need very little to begin writing PlantUML network diagrams:
- A text editor. VS Code with the PlantUML extension is popular. Vim, Sublime, or even Notepad work fine too.
- Java Runtime Environment. PlantUML is a Java application. Most systems already have this, or you can install it quickly.
- PlantUML JAR file. Download the latest release from the official PlantUML site.
- Graphviz (optional). Some diagram types need Graphviz for layout. The
nwdiagnetwork diagram type requires it.
If you don't want to install anything locally, the PlantUML online server lets you paste code and see the result instantly in your browser.
How do you keep network diagrams accurate over time?
A diagram is only useful if it reflects reality. Here are practices that help:
- Store the
.pumlfile in the same repo as your infrastructure-as-code files. - Add a CI step that renders the diagram on every commit so the image stays current.
- Assign ownership one person or team should be responsible for updating the network diagram when infrastructure changes.
- Use comments in the PlantUML source to note the date, author, and reason for each major change.
- Review diagrams during change management or post-incident reviews to verify they match the actual network state.
Quick checklist for your first PlantUML network diagram
- ✅ Install PlantUML and Graphviz, or use the online server to render.
- ✅ Start with your main network zones (DMZ, internal, database, cloud).
- ✅ Label every node with hostname and IP address.
- ✅ Use
packageblocks to group devices by subnet or function. - ✅ Draw arrows to show traffic direction and primary data flows.
- ✅ Save the
.pumlsource file in your version control system. - ✅ Render and commit the output image alongside the source code.
- ✅ Set a reminder to review and update the diagram after each infrastructure change.
Start with a simple two-zone diagram, get the syntax under your fingers, and build from there. The real value shows up the first time a teammate finds your diagram during an incident and resolves the issue faster because the network layout was documented clearly in code.
Mermaid vs Plantuml Syntax: a Comprehensive Comparison Guide
How Uml Diagram Codes Work
Diagram Code Languages Every Software Developer Should Know
Code-Based Sequence Diagram Tools and Languages for Developers
Mermaid Diagram Scripting for Beginners: Easy Step-by-Step Tutorial
Diagram Types Reference Guide for Software Engineers