Friday, 2 May 2025
Affinity-for-mermaid
A little aside from the [Mikrotik series](https://blog.themillhousegroup.com/search/label/mikrotik), but related.
As this blog series starts getting a little more involved I wanted to include some network diagrams. [Mermaid.js](https://mermaid.js.org/) has been [my choice for diagrams-as-markdown for ages now](https://blog.themillhousegroup.com/2023/10/markdown-and-mermaid-on-blogger-in-2023.html), and I noted that the new(ish) beta [architecture syntax](https://mermaid.js.org/syntax/architecture.html) would be a good fit.
Notably lacking however, was a nice suite of standard network diagram icons (routers, switches, firewalls, servers etc) to go with it.
A quick search led me to a Reddit question in [`r/networking`](https://www.reddit.com/r/networking/comments/108buv8/what_network_diagram_icons_is_everyone_using/?rdt=63267) where the [Affinity SVG set](https://github.com/ecceman/affinity) by [ecceman on GitHub]((https://github.com/ecceman) was [highly recommended](https://www.reddit.com/r/networking/comments/108buv8/comment/j3r8wxz/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button).
I liked the style, and the fact that the icons could be had "naked" as well as surrounded by circles or rounded squares (and in colour).
One [fork](https://github.com/themillhousegroup/affinity-for-mermaid) and some processing with [IconTools](https://iconify.design/docs/libraries/tools/import/directory.html) has led to a Mermaid.js-compatible icon library, ready to consume with just a couple of extra lines of mermaid configuration:
```
mermaid.registerIconPacks([{
name: 'affinity',
loader: () => fetch('https://themillhousegroup.github.io/affinity-for-mermaid/icons.json').then((res) => res.json()),
}]);
```
In addition to hosting the all-important JSON files, the GitHub pages also include icon list and [demo](https://themillhousegroup.github.io/affinity-for-mermaid/demo.html) pages so you can see what's available:
I have plans to expand this list to show the circular and square variants (and fix up some of the naming inconsistencies therein) - maybe even code up a live sandbox page too ...
But without any further ado, here's the mermaid architecture description for my home network ...
```
architecture-beta
service internet(affinity:cloud)
group home(affinity:house)[Home]
group study[Study] in home
service ispr(affcircle:c-firewall) [ISP Router] in study
group mik(affcircle:c-router)[RB2011] in study
service gbe(affcircle:c-switch-blue)[GbE] in mik
service hun(affcircle:c-switch-green)[100Mbps] in mik
service pi(affcircle:c-server-blue)[Pi] in study
service nas(affcircle:c-nas-blue)[NAS] in study
service nuc(affcircle:c-server-green)[NUC] in study
service studywifi(affcircle:c-wireless-green)[WiFi AP] in study
group closet[Closet] in home
group closetap(affcircle:c-switch) [ClosetAP] in closet
service closetswitch(affcircle:c-switch-blue)[Switch] in closetap
service closetwifi(affinity:wifi)[WiFi] in closetap
service tv(affcircle:c-client-blue)[TV] in home
service ps4(affcircle:c-server-blue)[PS4] in home
service cc(affcircle:c-client-blue)[ChromeCast] in home
internet:B -- T:ispr
ispr:L -[GbE]- R:gbe
ispr:R -[GbE study to closet backbone]- L:closetswitch
gbe:L -- R:hun
junction huns in study
hun:L -- R:huns
huns:L -[100Mbps]- R:nuc
huns:B -[100Mbps]- T:studywifi
junction gbes in study
gbe:B -- T:gbes
gbes:L -[GbE]- R:pi
gbes:R -[GbE]- L:nas
junction avgear in home
closetswitch:B -[GbE]- T:avgear
avgear:L -- R:tv
avgear:B -- T:ps4
avgear:R -- L:cc
```
... and the corresponding diagram:
```mermaid
architecture-beta
service internet(affinity:cloud)
group home(affinity:house)[Home]
group study[Study] in home
service ispr(affcircle:c-firewall) [ISP Router] in study
group mik(affcircle:c-router)[RB2011] in study
service gbe(affcircle:c-switch-blue)[GbE] in mik
service hun(affcircle:c-switch-green)[100Mbps] in mik
service pi(affcircle:c-server-blue)[Pi] in study
service nas(affcircle:c-nas-blue)[NAS] in study
service nuc(affcircle:c-server-green)[NUC] in study
service studywifi(affcircle:c-wireless-green)[WiFi AP] in study
group closet[Closet] in home
group closetap(affcircle:c-switch) [ClosetAP] in closet
service closetswitch(affcircle:c-switch-blue)[Switch] in closetap
service closetwifi(affinity:wifi)[WiFi] in closetap
service tv(affcircle:c-client-blue)[TV] in home
service ps4(affcircle:c-server-blue)[PS4] in home
service cc(affcircle:c-client-blue)[ChromeCast] in home
internet:B -- T:ispr
ispr:L -[GbE]- R:gbe
ispr:R -[GbE study to closet backbone]- L:closetswitch
gbe:L -- R:hun
junction huns in study
hun:L -- R:huns
huns:L -[100Mbps]- R:nuc
huns:B -[100Mbps]- T:studywifi
junction gbes in study
gbe:B -- T:gbes
gbes:L -[GbE]- R:pi
gbes:R -[GbE]- L:nas
junction avgear in home
closetswitch:B -[GbE]- T:avgear
avgear:L -- R:tv
avgear:B -- T:ps4
avgear:R -- L:cc
```
I won't lie, it took a fair bit of tweaking to get that to lay out properly (there's no way to hint or influence the layout at this stage unfortunately, so trial-and-error via the `T|R|B|L` specifier on edges, and the occasional superfluous [`junction`](https://mermaid.js.org/syntax/architecture.html#junctions) is the only option) - but I'm pretty happy with the result now.
Subscribe to:
Posts (Atom)