@aws-prototyping-sdk/cdk-graph-plugin-diagram
Project description
Diagram Plugin - Cdk Graph
@aws-prototyping-sdk/cdk-graph-plugin-diagram
This plugin generates diagrams utilizing the cdk-graph framework.
More comprehensive documentation to come as this package stabilizes.
Disclaimer: This is the first cdk graph plugin, it is highly experimental, 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.stage
config option to override this for each graph or in defaults.
Quick Start
// bin/app.ts
// Must wrap cdk app with async IIFE function to enable async cdk-graph report
(async () => {
const app = new App();
// ... add stacks, etc
const graph = new CdkGraph(app, {
plugins: [new CdkGraphDiagramPlugin()],
});
app.synth();
// async cdk-graph reporting hook
await graph.report();
})();
// => cdk.out/diagram.dot
// => cdk.out/diagram.svg
// => cdk.out/diagram.png
This plugin currently only supports
async report()
generation following the above example. Make sure to wrap the cdk app with async IIFE.
Supported Formats
Format | Status | Extends | Provider |
---|---|---|---|
DOT | - | Graphviz | |
SVG | DOT | Graphviz | |
PNG | SVG | Graphviz |
Diagram Providers
Provider | Status | Formats |
---|---|---|
Graphviz | DOT, SVG, PNG | |
Drawio | TBD: very early stage design and development |
Configuration
See IPluginConfig interface for details, and look in unit tests for 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 Option
Changing the defaults
option will modify default options for all diagrams, including the default diagram.
See IDiagramConfigBase interface for
plugin.defaults
options.
new CdkGraphDiagramPlugin({
defaults: {
theme: "dark",
filterPlan: {
preset: FilterPreset.NONE,
},
},
});
// => results in a single diagram that is "verbose" and "dark", since no resources are filtered
Diagrams Option
By modifying the diagrams
option of the plugin you have full control over the rendering of diagrams, and can render multiple diagrams.
See IDiagramConfig interface for diagram config options.
new CdkGraphDiagramPlugin({
diagrams: [
{
name: "diagram-1",
title: "Diagram 1 (dark + compact)",
theme: "dark",
// the default `filterPlan: { preset: FilterPreset.COMPACT }` will still apply
},
{
name: "diagram-2",
title: "Diagram 2 (dark + verbose)",
theme: "dark",
filterPlan: {
preset: FilterPreset.NONE,
},
},
{
name: "diagram-3",
title: "Diagram 3 (no defaults)",
ignoreDefaults: true, // default options will not be applied (theme, filterPlan, etc)
},
],
});
Example Diagram Configs (expand below)
The below examples define individual diagram configs in the diagrams
options of the plugin as described above.
new CdkGraphDiagramPlugin({
diagrams: [
// ... insert diagram config(s) here - see below for examples
],
});
Presets
Preset: compact
{
name: "compact",
title: "Compact Diagram",
filterPlan: {
preset: FilterPreset.COMPACT,
},
},
Preset: verbose
{
name: "verbose",
title: "Verbose Diagram",
format: DiagramFormat.PNG,
ignoreDefaults: true,
},
Focus
Focus: 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,
},
Filters
Filter: 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(),
],
},
},
Themes
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 Steps
- Battle test in the wild and get community feedback
- Improve image coverage and non-image node rendering
- Add drawio support
- Add common filter patterns and helpers
- Enable generating diagrams outside of synthesis process (maybe CLI)
- Implement interactive diagram, with potential for dynamic filtering and config generation
- Support using interactive diagram as config generator for other plugins (or as separate plugin that depends on this)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aws_prototyping_sdk.cdk_graph_plugin_diagram-0.19.68.tar.gz
.
File metadata
- Download URL: aws_prototyping_sdk.cdk_graph_plugin_diagram-0.19.68.tar.gz
- Upload date:
- Size: 85.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d13ea40e74eca87988ec1d64e65c431da30e8a6a4cf8db93d4a81cb8d9cd0682 |
|
MD5 | 9dc0741e9e3fbe50684e4fc74249ba5c |
|
BLAKE2b-256 | 46dba2250ae01f6578c93c81bc97928515cde85450962d194168d90371abb63e |
File details
Details for the file aws_prototyping_sdk.cdk_graph_plugin_diagram-0.19.68-py3-none-any.whl
.
File metadata
- Download URL: aws_prototyping_sdk.cdk_graph_plugin_diagram-0.19.68-py3-none-any.whl
- Upload date:
- Size: 85.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b271fcf40fc6de712ef6fda94a3fe58feb1fcc1abc087d883d30e2ab911b348f |
|
MD5 | f7798379a53edddc8a7fc9add9149763 |
|
BLAKE2b-256 | 30a13ddd721a3e8a2100dc18daadd98c4f04c4e2979c8a63706fd3056f629d7d |