Logo

dev-resources.site

for different kinds of informations.

Create Nice-looking Schema Diagrams in PlantUML

Published at
1/22/2023
Categories
database
plantuml
Author
sualeh
Categories
2 categories in total
database
open
plantuml
open
Author
6 person written this
sualeh
open
Create Nice-looking Schema Diagrams in PlantUML

PlantUML is a descriptive language to generate a number of types of software diagrams, such as sequence, class, deployment and state diagrams, and many others. PlantUML does not generate very good-looking schema diagrams out of the box, but it supports themes and preprocessed macros. If you use themes and macros, you can not only use a simplified syntax, but also generate beautiful diagrams.

Here is an example of a PlantUML schema diagram, and we will build up the code to generate it.

Schema diagram

To start, describe your schemas, tables and columns using this syntax as an example.

$schema("PUBLISHER_SALES", "id_7f7f6c20") {

  $table("SALES", "id_751e68cc") {
    $column("POSTALCODE"): VARCHAR NOT NULL
    $column("COUNTRY"): VARCHAR NOT NULL
    $fk("BOOKID"): INTEGER
    $fk("COUPON_ID"): INTEGER
    $column("PERIODENDDATE"): DATE
    $column("TOTALAMOUNT"): DOUBLE
  }

}
Enter fullscreen mode Exit fullscreen mode

You can pick any id, as long as it is unique across the diagram. This will allow you to have tables with the same name in different schemas.

Then, using those ids, you can define foreign key relationships like this:

id_208b5502.id_f521e766::ID  ||--o{ id_208b5502.id_ead84c5d::AUTHORID : FK_AUTHOR
Enter fullscreen mode Exit fullscreen mode

The secret sauce to this meta-language is in the file header, and it looks like this:

!theme plain
hide empty methods

!procedure $schema($name, $slug)
package "$name" as $slug <<Rectangle>>
!endprocedure

!procedure $table($name, $slug)
entity "<b>$name</b>" as $slug << (T, Orange) table >>
!endprocedure

!procedure $view($name, $slug)
entity "<b>$name</b>" as $slug << (V, Aquamarine) view >>
!endprocedure

!procedure $pk($name)
<color:#GoldenRod><&key></color> <b>$name</b>
!endprocedure

!procedure $fk($name)
<color:#Silver><&key></color> $name
!endprocedure

!procedure $column($name)
{field} <color:#White><&media-record></color> $name
!endprocedure
Enter fullscreen mode Exit fullscreen mode

Here is an example file with everything put together. You can visualize diagram this online using PlantText editor, and then create your own.

Take a look at SchemaCrawler, which extends functionality by connecting to your database server and generating a PlantUML schema diagram from it using this technique.

plantuml Article's
28 articles in total
Favicon
Run devcontainers as a non-root user
Favicon
PlantUML to compute diagrams!
Favicon
PlantUMLApp 3.0 - Let's play with AI Multi-Modality
Favicon
Create UML Class Diagrams for Java projects with IntelliJ IDEA and PlantUML
Favicon
Teoria | Documentando arquitetura de software com C4 Model + Plant UML
Favicon
Por que representar a arquitetura de uma aplicação em diagramas?
Favicon
Building a TypeScript-Compatible Webpack Loader: A PlantUML Mind Map Example
Favicon
PlantUML4iPad 2.0
Favicon
Documentation as Code for Cloud - PlantUML
Favicon
PlantUML and Jira: Combining Forces to Simplify Gantt Chart Creation
Favicon
PlantUML meets OpenAI on iPad
Favicon
Draw.io + PlantUML - Como tornar mais fácil o processo de documentação
Favicon
Create Nice-looking Schema Diagrams in PlantUML
Favicon
Keep your diagrams updated with continuous delivery
Favicon
Generate class diagrams with a Kotlin DSL for PlantUML
Favicon
Automatic C4 diagrams for a distributed microservice ecosystem with GitHub Actions
Favicon
PlantUML tips and tricks
Favicon
"Diagram as code"
Favicon
Software architecture documentation - Made easy with arc42 and C4
Favicon
Introduce the new PlantUML IntelliJ Plugin, which has high functionality editor!
Favicon
PlantUML y C4
Favicon
Text based diagramming
Favicon
Software architecture diagrams - which tool should we use?
Favicon
Modelling software architecture with PlantUML
Favicon
How to draw ER diagram with code using plantuml
Favicon
rewrite plantuml with golang or rust
Favicon
Bash/Zsh function to export SVG diagrams using PlantUML
Favicon
Handy Bash/Zsh function to generate PlantUML diagrams

Featured ones: