Package: aws-prototyping-sdk.cdk-graph-plugin-diagram
Diagram Plugin - Cdk Graph@aws-prototyping-sdk/cdk-graph-plugin-diagramThis plugin generates diagrams utilizing thecdk-graphframework.More comprehensive documentation to come as this package stabilizes.Disclaimer:This is the firstcdk graphplugin, it is highlyexperimental, and subject to major refactors as we gain feedback from the community.BREAKING CHANGES(pre-release)<= v0.14.8: Only the last stage of a multi stage app will be rendered by default, which is commonly the production stage. Use thetheme.rendering.stageconfig option to override this for each graph or in defaults.Quick Start//bin/app.ts//MustwrapcdkappwithasyncIIFEfunctiontoenableasynccdk-graphreport(async()=>{constapp=newApp();//...addstacks,etcconstgraph=newCdkGraph(app,{plugins:[newCdkGraphDiagramPlugin()],});app.synth();//asynccdk-graphreportinghookawaitgraph.report();})();//=>cdk.out/diagram.dot//=>cdk.out/diagram.svg//=>cdk.out/diagram.pngThis plugin currently only supportsasync report()generation following the above example.Make sure to wrap the cdk app withasync IIFE.Supported FormatsFormatStatusExtendsProviderDOT-GraphvizSVGDOTGraphvizPNGSVGGraphvizDiagram ProvidersProviderStatusFormatsGraphvizDOT,SVG,PNGDrawioTBD: very early stage design and developmentConfigurationSeeIPluginConfiginterface for details, and look inunit testsfor additional examples.By default the diagram plugin will generate a single "compact" preset diagram.
It is capable of creating multiple diagrams each with different configurations, as well as defining the defaults to use.Defaults OptionChanging thedefaultsoption will modify default options for all diagrams, including the default diagram.SeeIDiagramConfigBaseinterface forplugin.defaultsoptions.newCdkGraphDiagramPlugin({defaults:{theme:"dark",filterPlan:{preset:FilterPreset.NONE,},},});//=>resultsinasinglediagramthatis"verbose"and"dark",sincenoresourcesarefilteredDiagrams OptionBy modifying thediagramsoption of the plugin you have full control over the rendering of diagrams, and can rendermultiplediagrams.SeeIDiagramConfiginterface for diagram config options.newCdkGraphDiagramPlugin({diagrams:[{name:"diagram-1",title:"Diagram 1 (dark + compact)",theme:"dark",//thedefault`filterPlan:{preset:FilterPreset.COMPACT}`willstillapply},{name:"diagram-2",title:"Diagram 2 (dark + verbose)",theme:"dark",filterPlan:{preset:FilterPreset.NONE,},},{name:"diagram-3",title:"Diagram 3 (no defaults)",ignoreDefaults:true,//defaultoptionswillnotbeapplied(theme,filterPlan,etc)},],});Example Diagram Configs (expand below)The below examples define individual diagram configs in thediagramsoptions of the plugin as described above.newCdkGraphDiagramPlugin({diagrams:[//...insertdiagramconfig(s)here-seebelowforexamples],});PresetsPreset: compact{name:"compact",title:"Compact Diagram",filterPlan:{preset:FilterPreset.COMPACT,},},Preset: verbose{name:"verbose",title:"Verbose Diagram",format:DiagramFormat.PNG,ignoreDefaults:true,},FocusFocus: hoist{name:"focus",title:"Focus Lambda Diagram (non-extraneous)",filterPlan:{focus:(store)=>store.getNode(getConstructUUID(app.stack.lambda)),preset:FilterPreset.NON_EXTRANEOUS,},ignoreDefaults:true,},Focus: no hoist{name:"focus-nohoist",title:"Focus WebServer Diagram (noHoist, verbose)",filterPlan:{focus:{node:(store)=>store.getNode(getConstructUUID(app.stack.webServer)),noHoist:true,},},ignoreDefaults:true,},FiltersFilter: Include specific cfn resource types{name:"includeCfnType",title:"Include CfnType Diagram (filter)",filterPlan:{filters:[Filters.includeCfnType([aws_arch.CfnSpec.ServiceResourceDictionary.EC2.Instance,/AWS::Lambda::Function.*/,"AWS::IAM::Role",]),Filters.compact(),],},},Filter: Exclude specific cfn resource types{name:"excludeCfnType",title:"Exclude CfnType Diagram (filter)",filterPlan:{filters:[Filters.excludeCfnType([/AWS::EC2::VPC.*/,aws_arch.CfnSpec.ServiceResourceDictionary.IAM.Role,]),Filters.compact(),],},},Filter: Include specific graph node types{name:"includeNodeType",title:"Include NodeType Diagram (filter)",filterPlan:{filters:[Filters.includeNodeType([NodeTypeEnum.STACK,NodeTypeEnum.RESOURCE,]),Filters.compact(),],},},Filter: Include specific graph node types{name:"includeNodeType",title:"Include NodeType Diagram (filter)",filterPlan:{filters:[Filters.includeNodeType([NodeTypeEnum.STACK,NodeTypeEnum.RESOURCE,]),Filters.compact(),],},},Filter: Exclude specific graph node types{name:"excludeNodeType",title:"Exclude NodeType Diagram (filter)",filterPlan:{filters:[Filters.excludeNodeType([NodeTypeEnum.NESTED_STACK,NodeTypeEnum.CFN_RESOURCE,NodeTypeEnum.OUTPUT,NodeTypeEnum.PARAMETER,]),Filters.compact(),],},},ThemesTheme: Dark{name:"Dark",title:"Dark Theme Diagram",theme:theme,},Theme: Dark - render service icons{name:"dark-services",title:"Dark Theme Custom Diagram",theme:{theme:theme,rendering:{resourceIconMin:GraphThemeRenderingIconTarget.SERVICE,resourceIconMax:GraphThemeRenderingIconTarget.CATEGORY,cfnResourceIconMin:GraphThemeRenderingIconTarget.DATA,cfnResourceIconMax:GraphThemeRenderingIconTarget.RESOURCE,},},},Theme: Dark - verbose{name:"dark-verbose",title:"Dark Theme Verbose Diagram",ignoreDefaults:true,theme:theme,},---Next StepsBattle test in the wild and get community feedbackImprove image coverage and non-image node renderingAdd drawio supportAdd common filter patterns and helpersEnable generating diagrams outside of synthesis process (maybe CLI)Implement interactive diagram, with potential for dynamic filtering and config generationSupport using interactive diagram as config generator for other plugins (or as separate plugin that depends on this)Inspired bycdk-diaandcfn-diawith ❤️