PlantUML diagrams evolve with git: renaming, migration, archival
Writing the
.pumlisn’t the end. Three months later: services get renamed, architectures refactored, components deprecated — the diagram has to evolve alongside git to avoid the awkward “docs say A, code has been calling it B for months” moment. This is the rename migration toolkit, archival strategy, and git log sync.
Two layers of renaming
Layer 1: filename rename — user-service.puml → identity-service.puml (service renamed to identity)
Layer 2: in-diagram reference rename — component "user-service" → component "identity-service", and every --> us becomes --> identity
Both must be in sync — rename the file but not the references inside, git diff won’t show it; rename references but not the file, git history breaks.
Tool 1: git mv combined with sed
1 | # 1. rename file |
git mv beats manual mv + add because git detects the rename — even if you modify content after renaming, git’s rename detection still catches it.
Tool 2: bash script for renaming with dry-run, error handling, grep verification
1 |
|
1 | chmod +x rename-component.sh |
Tool 3: PlantUML !define for indirect reference
Prevention is better than cure — start with !define to abstract the name:
1 | !define USER_SVC identity-service |
Renaming a service means changing the !define line once — but this convention only works if the team honors it, otherwise newcomers write identity-service directly, bypassing the define.
Tool 4: CI detection of “code vs diagram” drift
Architecture diagrams’ most common rot — code renamed a service, diagram didn’t.
1 | # tests/test_architecture_drift.py |
CI runs the test — code changes a service but diagram doesn’t → fail.
Architecture split: diagram evolution
Service split from monolith to microservices, the diagram follows.
Phase 1: monolith
1 | @startuml |
Phase 2: extract User service
1 | @startuml |
Old and new diagrams coexist — architecture-v1-monolith.puml (archived) + architecture.puml (current).
Phase 3: extract Order
1 | @startuml |
The evolution stays traceable in git — new hires can read git log to see architecture history.
Archive strategy
Old diagrams shouldn’t be deleted directly — put them in archive/ with date prefix:
1 | docs/ |
_config.yml configures skip_render to prevent archive rendering:
1 | skip_render: |
The archive directory doesn’t enter the CI flow, but git history has it.
Cross-version reference: use git history as diagram metadata
PlantUML doesn’t support in-diagram git references — but you can read git log via %load_json:
1 | # generate diagrams/git-history.json |
1 | @startuml |
Diagram shows recent commits to itself — who changed it, when, what.
Doc-code sync via git hooks
Client-side hook auto-syncs the diagram at commit time:
1 | # .git/hooks/pre-commit |
When committing service code, the architecture diagram auto-regenerates and joins the commit — developers don’t manually edit the diagram.
Year-spanning refactor: diagram migration
Scenario: massive service renames (e.g. user-service → identity-service plus 30 other services renamed in one go):
Steps:
- Freeze diagram edits — README says “service rename in progress, diagram updates paused”
- Batch change code + diagram — single PR does it all, don’t split into multiple
- CI verify — drift test must pass before merge
- Delete old + archive — after rename completes, old
user-service.pumlmoves toarchive/ - Update docs — README references new service names
Conversely — if the diagram is already stale (untouched for 3 months):
- Acknowledge staleness — README top adds ⚠️ “diagram may differ from code; code wins”
- File a redraw ticket — dedicated ticket to redraw
- Add drift test — prevent the next round of rot
Field foot-guns
- git rename detection doesn’t fire — you change >50% of file content, git treats it as delete + add, rename not shown. Rename + replace in same commit — only then rename detection works.
- PlantUML alias
usdoesn’t track user-service → identity rename — alias is syntactic sugar, renaming or not doesn’t affect rendering, but grep foruswill hitus-east-1and similar. Use grep with anchored regex:grep -E "(as|component) +us\b". - Cross-language references — Java service called
UserService, Gouser-service, PlantUML usesuser-service— standardize on kebab-case is the simplest convention. - CI test flakes — drift test requires service directories to strictly match the diagram, but sometimes the diagram intentionally has “future services” — mark with
// future:comment:Test skips components marked with1
// future: payment-service (not yet deployed)
future:comment.
Summary
| Scenario | Tool |
|---|---|
| Service rename | git mv + sed |
| Architecture split | archive old + new in phases |
| Prevent rot | CI drift test |
| Auto-sync | git pre-commit hook calling Python |
| Year-spanning refactor | single PR for everything, no intermediate state |
Core principle: diagram and code evolve together — either auto-generated (with drift test as safety net) or manually edited with CI reminder. No automation means the diagram doesn’t survive long-term.
- Title: PlantUML diagrams evolve with git: renaming, migration, archival
- Author: puml.online
- Created at : 2026-07-30 17:15:00
- Updated at : 2026-08-14 21:34:29
- Link: https://puml.online/blog/plantuml-versioning-renaming-en/
- License: This work is licensed under CC BY-NC-SA 4.0.