Example 4

In this example, servers are grouped in a cluster (SubGraph).

The SubGraph (part of PSGraph module) feature groups the three servers into a dashed rounded rectangle labeled "3 Tier Concept," visually encapsulating the Web, Application, and Database servers along with their connections.

PowerShell: param block
[CmdletBinding()]
param (
    [System.IO.FileInfo] $Path = '~\Desktop\',
    [array] $Format = @('png'),
    [bool] $DraftMode = $false
)

Starting with PowerShell v3, modules are auto-imported when needed. Importing the module here ensures clarity and avoids ambiguity.

PowerShell
Import-Module Diagrammer.Core -Force -Verbose:$false

Since the diagram output is a file, specify the output folder path using $OutputFolderPath.

PowerShell
$OutputFolderPath = Resolve-Path $Path

The $MainGraphLabel variable sets the main title of the diagram.

PowerShell
$MainGraphLabel = '3tier Web Application Diagram'

This section introduces the Subgraph feature, which allows grouping nodes together. In this example, all servers are grouped within a cluster named "3tier".

A SubGraph groups objects in a container, like a graph within a graph. SubGraph attributes allow you to set background color, label, border color, style, etc.

https://psgraph.readthedocs.io/en/latest/Command-SubGraph/

Example4.ps1 - SubGraph cmdlet
$example4 = & {
    SubGraph 3tier -Attributes @{Label = '3 Tier Concept'; fontsize = 18; penwidth = 1.5; labelloc = 't'; style = "dashed,rounded"; color = "gray" } {

        Node -Name Web01 -Attributes @{shape = 'rectangle'; fillColor = 'Green'; fontsize = 14 }
        Node -Name App01 -Attributes @{shape = 'rectangle'; fillColor = 'Blue'; fontsize = 14 }
        Node -Name DB01 -Attributes @{shape = 'rectangle'; fillColor = 'Red'; fontsize = 14 }

        Edge -From Web01 -To App01 @{label = 'gRPC'; color = 'black'; fontsize = 12; fontcolor = 'black'; minlen = 3 }
        Edge -From App01 -To DB01 @{label = 'SQL'; color = 'black'; fontsize = 12; fontcolor = 'black'; minlen = 3 }
    }
}

Finally, call the New-Diagrammer cmdlet with the specified parameters.

PowerShell
New-Diagrammer -InputObject $example4 -OutputFolderPath $OutputFolderPath -Format $Format -MainDiagramLabel $MainGraphLabel -Filename Example4 -LogoName "Main_Logo"  -DraftMode:$DraftMode

When you run the script, it generates a PNG file named Example4.png in the specified output folder.

Resulting diagram:

Example

Comments