Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[plantuml] Draw C4 models with PlantUML #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions plantuml/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM alpine

ENV LANG en_US.UTF-8
ENV PLANTUML_DIRECTORY /plantuml
ENV PLANTUML_VERSION 1.2022.6

RUN apk add --no-cache openjdk8-jre graphviz ttf-droid ttf-droid-nonlatin

RUN mkdir ${PLANTUML_DIRECTORY}

WORKDIR ${PLANTUML_DIRECTORY}

ADD https://sourceforge.net/projects/plantuml/files/plantuml.${PLANTUML_VERSION}.jar/download /${PLANTUML_DIRECTORY}/plantuml.jar

CMD ["java", "-Djava.awt.headless=true", "-jar", "/plantuml/plantuml.jar", "-h"]
27 changes: 27 additions & 0 deletions plantuml/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
include ../make-default/Makefile
include ../make-help/Makefile

image=$(image_repo)/plantuml:latest

.PHONY: diagrams
diagrams: ## Build the final diagrams
docker run \
--rm \
-v $(shell pwd):/src \
-w /src \
-it $(image) \
/bin/sh /src/generate-diagrams.sh

.PHONY: image
image: ## Build the image
docker build . -t $(image)

.PHONY: shell
shell: ## Start interactive shell session inside the container
docker run \
--rm \
-v $(shell pwd):/src \
-w /plantuml \
--entrypoint /bin/sh \
-it $(image)

31 changes: 31 additions & 0 deletions plantuml/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# plantuml

Diagrams as code.

This repo contains some examples of [C4 Models](https://c4model.com/) using
[PlantUML](https://plantuml.com/).

## Build the image

```console
make image
```

## Write diagrams

Store new diagrams in the [diagrams](./diagrams/) directory.
Make sure the extension is `.puml`.
See some examples in the same directory.

## Draw diagrams

Once you have written all the stuff, convert the text to `png` and `svg`.

```console
make diagrams
```

The result is stored in the [output](./output/) directory.

Note: this is tested in a macOS with docker and colima.
It's likely to have file permission issues if you are running in a different environment.
36 changes: 36 additions & 0 deletions plantuml/diagrams/c4-basic-example.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@startuml c4-basic-example
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml

' https://github.com/awslabs/aws-icons-for-plantuml
!define AWSPuml https://raw.githubusercontent.com/awslabs/aws-icons-for-plantuml/v13.0/dist
!include AWSPuml/AWSCommon.puml
!include AWSPuml/ApplicationIntegration/SimpleQueueService.puml
!include AWSPuml/Database/ElastiCacheElastiCacheforRedis.puml
!include AWSPuml/Database/RDS.puml

' https://github.com/tupadr3/plantuml-icon-font-sprites
!define DEVICONS https://raw.githubusercontent.com/tupadr3/plantuml-icon-font-sprites/master/devicons
!define FONTAWESOME https://raw.githubusercontent.com/tupadr3/plantuml-icon-font-sprites/master/font-awesome-5
!include DEVICONS/go.puml
!include FONTAWESOME/users.puml
!include FONTAWESOME/react.puml

Person(user, "Customer", "People that need products", $sprite="users")
Container(spa, "SPA", "React", "The main interface that the customer interacts with", $sprite="react")
Container(api, "API", "Go", "Handles all business logic", $sprite="go")
ContainerDb(db, "Database", "Postgres", "Holds data", $sprite="RDS")
ContainerDb(cache, "Cache", "Redis", "Holds data", $sprite="ElastiCacheElastiCacheforRedis")
ContainerQueue(sqs, "Queue", "SQS", "Enqueue messages", $sprite="SimpleQueueService")
Container(worker, "Worker", "Go", "Consumes messages", $sprite="go")

Lay_D(api, worker)

Rel(user, spa, "Uses", "https")
Rel(spa, api, "Uses", "https")
Rel(api, db, "Reads/Writes data")
Rel_R(api, cache, "Caches data")
Rel_L(api, sqs, "Produces messages")
Rel_L(worker, sqs, "Consumes messages")
Rel_R(worker, db, "Writes data")

@enduml
8 changes: 8 additions & 0 deletions plantuml/generate-diagrams.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

for format in png svg; do
java -Djava.awt.headless=true -jar /plantuml/plantuml.jar \
-t${format} \
-I /src/diagrams/*.puml \
-o /src/output/
done
Binary file added plantuml/output/c4-basic-example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading