Skip to content

feat: add architecture diagram skill#103

Open
mayakost wants to merge 26 commits intomainfrom
feat/diagram-skill
Open

feat: add architecture diagram skill#103
mayakost wants to merge 26 commits intomainfrom
feat/diagram-skill

Conversation

@mayakost
Copy link
Copy Markdown
Contributor

Summary

  • Adds a new aws-architecture-diagram skill to the deploy-on-aws plugin that generates validated AWS architecture diagrams as draw.io XML using official AWS4 icon libraries
  • Includes PostToolUse hook for automatic draw.io validation on Edit/Write, Python post-processing scripts (icon color fixes, nesting fixes, step badge rendering), and extensive reference material (style guide, XML templates, 6 annotated example diagrams)
  • Bumps deploy-on-aws plugin version from 1.1.0 to 1.2.0 and updates marketplace/plugin manifests with new keywords and description

Test plan

  • Install the plugin locally with claude --plugin-dir ./plugins/deploy-on-aws and trigger the skill by asking to generate an AWS architecture diagram
  • Verify the generated .drawio file opens correctly in draw.io desktop and renders with proper AWS4 icons, step badges, and category containers
  • Confirm the PostToolUse validation hook fires when writing/editing .drawio files and catches malformed XML
  • Run mise run lint:manifests to validate updated marketplace.json and plugin.json
  • Run mise run lint:cross-refs to validate cross-references between manifests
  • Test both modes: codebase analysis ("analyze my infrastructure") and interactive brainstorm ("design a serverless API")

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

mayakost and others added 3 commits March 20, 2026 19:59
…arkdown lint

Replace xml.etree.ElementTree with defusedxml.ElementTree in all Python
scripts to address Bandit B314/B405 and Semgrep XXE findings. Add nosec
suppression to subprocess import in drawio_url.py (browser URL opener only).
Fix 106 markdownlint errors (MD022/MD031/MD032 blank lines, MD001 heading
levels) across 7 reference files and SKILL.md. Trim SKILL.md from 515 to
495 lines to satisfy the 500-line SKILL001 limit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mayakost mayakost requested review from a team as code owners March 23, 2026 16:18
@mayakost mayakost changed the title Add architecture diagram skill feat: add architecture diagram skill Mar 23, 2026
mayakost and others added 7 commits March 23, 2026 12:43
Move detailed XML generation rules and layout guidelines from SKILL.md
(494 lines) into references/xml-generation-rules.md and
references/layout-guidelines.md. SKILL.md is now 219 lines, well under
the 300-line warning threshold enforced by SKILL001.
Run dprint fmt on 7 files (JSON and Markdown) that were not
conforming to the project's formatting rules.
…sues

- Replace defusedxml with stdlib xml.etree.ElementTree in all 5 Python
  scripts and validate-drawio.sh (XML is self-generated, no XXE risk)
- Remove pip3 auto-install from PostToolUse hook
- Remove unused import sys in fix_step_badges.py
- Remove unused style variable in post_process_drawio.py fix_legend_size
- Add explanatory comment to except block in post_process_drawio.py
…ples

Delete 5 files (-2039 lines):
- example-diagrams.md (803 lines): outdated XML examples conflicting with .drawio refs
- aws-diagram-guidelines.md (536 lines): internal wiki copy, all rules in style-guide.md
- xml-structure.md (209 lines): merged unique parts into group-styles.md + layout-guidelines.md
- xml-generation-rules.md (186 lines): trimmed and renamed to xml-rules.md (89 lines)
- aws4-shapes.md (231 lines): split into aws4-shapes-services.md (69) + aws4-shapes-resources.md (100)

All reference files now under 100-line DESIGN_GUIDELINES limit.
All shape names preserved in the split files (zero shape deletions).
All cross-references updated to point to new file names.
- Remove eager "Study" paragraph that loaded ~135k tokens upfront
- Move reference loading into Step 3 where references are actually needed
- Add example selection table: agent picks 1-2 most relevant .drawio
  examples per diagram type (reduces ~95k to ~10-18k tokens)
- Update cross-references to renamed files (xml-rules.md,
  aws4-shapes-services.md)
- SKILL.md: 226 lines (under 300 limit)
…s for dark mode

- Remove background="#FFFFFF" from mxGraphModel XML template in SKILL.md
- Change rule from "ALWAYS set background=#FFFFFF" to "NEVER set background"
- Change edge label rule from labelBackgroundColor=#ffffff to
  labelBackgroundColor=none in layout-guidelines.md and xml-rules.md
- Both white backgrounds break dark mode adaptive contrast
- New references/general-icons.md: maps 40+ non-AWS technologies
  (PostgreSQL, Docker, Kubernetes, CoreML, HuggingFace, GitHub, etc.)
  to draw.io shapes with category-appropriate tint colors
- Mode A codebase analysis now detects non-AWS tech when no AWS
  infrastructure files are found (Dockerfiles, DB configs, ML frameworks)
- Mixed architectures supported: AWS icons for AWS services, general
  icons for non-AWS, same layout rules for both
- Step 3 loads general-icons.md only when non-AWS services are present
@scoropeza
Copy link
Copy Markdown
Contributor

scoropeza commented Mar 24, 2026

PR Review Findings

I reviewed this PR and found 8 issues + 1 additional dark mode bug. All have been addressed in 5 new commits on this branch.

Findings Addressed

# Finding Fix
1 example-diagrams.md teaches outdated style (803 lines) Deleted — 7 .drawio files are authoritative
2 SKILL.md eager-loads ~135k tokens Restructured for progressive disclosure — refs load in Step 3
3 All 7 examples loaded (~95k tokens) Added example selection table — agent picks 1-2 per type
4 4 reference files exceed 100-line limit Consolidated: deleted 5 files (-2039 lines), split/trimmed rest
5 pip3 install defusedxml on every hook Switched to stdlib xml.etree.ElementTree (self-generated XML, no XXE risk)
6 Hook matches all Edit/Write Documented in post-processing.md (correct behavior, <10ms exit for non-.drawio)
7 Code quality (unused imports, variables) Fixed in fix_step_badges.py and post_process_drawio.py
8 No dependency declaration Moot — defusedxml removed entirely

Additional Fix

  • Dark mode: Removed background="#FFFFFF" from mxGraphModel template and labelBackgroundColor=#ffffff from edge labels — both broke dark mode adaptive contrast

New Feature

  • Non-AWS architecture support: Added general-icons.md reference mapping 40+ non-AWS technologies (PostgreSQL, Docker, CoreML, HuggingFace, etc.) to draw.io shapes with category tinting. The skill now handles pure non-AWS, mixed, and pure AWS architectures.

Commits

  1. d92c414 fix: remove defusedxml dependency, fix code quality
  2. 68caa21 refactor: consolidate references, delete outdated examples
  3. 1d1a401 refactor: restructure SKILL.md for progressive disclosure
  4. 35fc174 fix: remove white backgrounds for dark mode
  5. 41ae138 feat: support non-AWS architecture diagrams

Keep all new plugins from main (amazon-location-service, aws-amplify,
aws-serverless, databases-on-aws, migration-to-aws) and apply our
diagram skill additions to deploy-on-aws (description, keywords, tags,
version bump to 1.2.0).
Copy link
Copy Markdown

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semgrep OSS found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

- Restore defusedxml.ElementTree imports (CI scanners require it)
- Replace silent pip3 auto-install with informative error message
  when defusedxml is missing — no more modifying user's environment
- Add scripts/requirements.txt declaring defusedxml>=0.7.1
- Create plugin README.md per DESIGN_GUIDELINES (prerequisites,
  skills, MCP servers, installation, examples)
- Document defusedxml dependency in post-processing.md
- Fix 20 markdownlint errors (MD022, MD029, MD031, MD032, MD060)
- Apply dprint formatting to table separators
@scoropeza
Copy link
Copy Markdown
Contributor

Update: PR Review Fixes + Dependency Documentation

All 8 review findings have been addressed, along with additional improvements discovered during testing.

Review Findings Fixed

# Finding Resolution
1 example-diagrams.md outdated (803 lines) Deleted — 7 .drawio files are the authoritative examples
2 SKILL.md eager-loads ~135k tokens Restructured for progressive disclosure — references load in Step 3, not upfront
3 All 7 examples loaded per generation (~95k tokens) Added example selection table — agent picks 1-2 per diagram type (~10-18k tokens)
4 4 reference files exceed 100-line limit Consolidated: deleted 5 files (-2039 lines), split/trimmed remainder. All refs now ≤100 lines
5 pip3 install defusedxml on every hook invocation Replaced with check + informative error message (see below)
6 Hook matches all Edit/Write operations Documented in post-processing.md — exits <10ms for non-.drawio files
7 Code quality (unused imports/variables) Fixed in fix_step_badges.py and post_process_drawio.py
8 No dependency declaration Added scripts/requirements.txt with defusedxml>=0.7.1

defusedxml Dependency Handling

The CI pipeline (bandit B314 / semgrep) requires defusedxml over stdlib xml.etree.ElementTree for XML parsing. While defusedxml provides no practical security benefit here (all XML is self-generated by the agent, with no untrusted input), we've kept it for CI compliance.

What changed: The hook no longer silently runs pip3 install to modify the user's Python environment. Instead, it checks for defusedxml and shows an actionable install prompt if missing:

python3 -c "import defusedxml" 2>/dev/null || {
  echo '{"systemMessage": "Missing required dependency: defusedxml. Install it with: pip3 install defusedxml>=0.7.1"}'
  exit 0
}

The dependency is documented in three places:

  • README.md Prerequisites section
  • references/post-processing.md pipeline documentation
  • scripts/requirements.txt explicit declaration

Additional Improvements

  • Dark mode fix: Removed background="#FFFFFF" from mxGraphModel template and labelBackgroundColor=#ffffff from edge labels — both broke dark mode adaptive contrast
  • Non-AWS architecture support: Added references/general-icons.md mapping 40+ non-AWS technologies to draw.io shapes with category tinting (PostgreSQL, Docker, CoreML, HuggingFace, etc.)
  • Plugin README.md: Created per DESIGN_GUIDELINES requirements (overview, skills, MCP servers, prerequisites, installation, examples)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new aws-architecture-diagram skill to the deploy-on-aws plugin, plus a validation/post-processing pipeline, to generate AWS reference-style architecture diagrams as draw.io XML using AWS4 icon libraries.

Changes:

  • Introduces the aws-architecture-diagram skill with extensive style/template/reference materials and example diagrams.
  • Adds a PostToolUse hook and Python tooling to post-process and validate .drawio outputs (nesting fixes, icon color fixes, badge overlap fixes, legend sizing, preview URL generation).
  • Updates plugin README + marketplace/plugin manifests and bumps deploy-on-aws version to 1.2.0.

Reviewed changes

Copilot reviewed 34 out of 34 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
plugins/deploy-on-aws/skills/aws-architecture-diagram/SKILL.md New skill definition and end-to-end workflow for diagram generation + validation/export.
plugins/deploy-on-aws/skills/aws-architecture-diagram/references/xml-templates-structure.md Core XML scaffolding templates (title, users, containers, legend, badges).
plugins/deploy-on-aws/skills/aws-architecture-diagram/references/xml-templates-examples.md XML snippet examples for edges, waypoints, groups, annotations.
plugins/deploy-on-aws/skills/aws-architecture-diagram/references/xml-rules.md Structural rules/constraints for generating valid draw.io XML.
plugins/deploy-on-aws/skills/aws-architecture-diagram/references/style-guide.md Canonical styling rules (fonts, colors, dark mode, legend/badges).
plugins/deploy-on-aws/skills/aws-architecture-diagram/references/post-processing.md Documents the automatic fixer/validator pipeline run by the hook.
plugins/deploy-on-aws/skills/aws-architecture-diagram/references/layout-guidelines.md Layout/spacing/routing guidance to match AWS reference diagrams.
plugins/deploy-on-aws/skills/aws-architecture-diagram/references/group-styles.md Copy/paste style strings for AWS boundary groups and edge styles.
plugins/deploy-on-aws/skills/aws-architecture-diagram/references/general-icons.md Mapping guidance for non-AWS technologies to generic AWS4 shapes.
plugins/deploy-on-aws/skills/aws-architecture-diagram/references/example-sketch.drawio Example sketch-mode diagram demonstrating “hand-drawn” styling.
plugins/deploy-on-aws/skills/aws-architecture-diagram/references/example-multi-region-active-active.drawio Example multi-region reference architecture diagram.
plugins/deploy-on-aws/skills/aws-architecture-diagram/references/example-agentcore.drawio Example AgentCore diagram + auxiliary-services patterns.
plugins/deploy-on-aws/skills/aws-architecture-diagram/references/diagram-templates-basic.md Ready-to-use “basic” architecture layout patterns.
plugins/deploy-on-aws/skills/aws-architecture-diagram/references/diagram-templates-advanced.md Advanced patterns (multi-region/hybrid) + sizing guidance.
plugins/deploy-on-aws/skills/aws-architecture-diagram/references/cli-export.md Draw.io desktop CLI export reference (png/svg/pdf).
plugins/deploy-on-aws/skills/aws-architecture-diagram/references/aws4-shapes-services.md Registry-style list of allowable AWS4 service icon shape names.
plugins/deploy-on-aws/skills/aws-architecture-diagram/references/aws4-shapes-resources.md Registry-style list of allowable AWS4 sub-resource/misc shape names.
plugins/deploy-on-aws/scripts/validate-drawio.sh PostToolUse hook entrypoint: runs post-processing + validation + preview URL.
plugins/deploy-on-aws/scripts/requirements.txt Python dependency pin for the validation pipeline.
plugins/deploy-on-aws/scripts/lib/validate_drawio.py XML validator (structure, IDs, edges, AWS4 shapes) + “compliance” warnings.
plugins/deploy-on-aws/scripts/lib/post_process_drawio.py Unified post-processing runner chaining all fixers.
plugins/deploy-on-aws/scripts/lib/fix_step_badges.py Iterative badge overlap resolver for on-diagram step badges.
plugins/deploy-on-aws/scripts/lib/fix_nesting.py Fixes Region nesting (container=1 → container=0) + re-parenting/offsetting.
plugins/deploy-on-aws/scripts/lib/fix_icon_colors.py Corrects icon fill colors + container tint/strokes + renames broken shapes.
plugins/deploy-on-aws/scripts/lib/drawio_url.py Generates app.diagrams.net preview URLs by compressing/encoding XML.
plugins/deploy-on-aws/README.md Plugin-level docs updated to include the new diagram skill + prerequisites.
plugins/deploy-on-aws/hooks/hooks.json Registers PostToolUse hook to run the draw.io validator on Edit/Write.
plugins/deploy-on-aws/.claude-plugin/plugin.json Updates plugin description/keywords and bumps version to 1.2.0.
.claude-plugin/marketplace.json Updates marketplace metadata (keywords/tags/version/description).

2. Read `references/style-guide.md` for colors, fonts, and dark mode
3. Read `references/xml-templates-structure.md` for XML code blocks
4. Read `references/layout-guidelines.md` for spacing and edge routing
5. Select 1-2 example `.drawio` files from the table below and study them for edge routing and layout patterns
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The skill instructions are internally contradictory: Step 3 tells the agent to read/study example .drawio files, but the “Important Rules” section later says “Do NOT read existing .drawio files as reference”. This will lead to inconsistent agent behavior depending on which instruction it follows. Please reconcile (either allow reading the curated examples under references/, or remove the earlier instruction to study .drawio examples).

Suggested change
5. Select 1-2 example `.drawio` files from the table below and study them for edge routing and layout patterns
5. Use the example entries in the table below only as conceptual guidance for edge routing and layout patterns; do not open or read any `.drawio` files as reference.

Copilot uses AI. Check for mistakes.
Comment on lines +94 to +98
```xml
<mxCell id="legend-line-styles-group" style="group;fontFamily=Helvetica;fillColor=light-dark(#F5F5F5,#29393B);strokeColor=#666666;" value="" vertex="1" parent="legend-panel">
<mxGeometry height="133" width="456" as="geometry" />
</mxCell>
```
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the “Line Styles Box” template, the legend-line-styles-group cell uses parent="legend-panel", but there’s no legend-panel defined in the surrounding templates (the legend container is legend-outer/legend-container). This makes the snippet unusable as-is and will likely result in broken XML when copied. Please update the parent to a defined legend container ID consistent with the other templates/examples.

Copilot uses AI. Check for mistakes.
theagenticguy and others added 2 commits April 1, 2026 13:13
…d post-processor bugs

- Reject hardcoded background attribute on mxGraphModel (breaks dark mode)
- Reject bare <mxGraphModel> without <mxfile> wrapper per skill contract
- Lower font size threshold from 11px to 10px to match skill's font hierarchy
- Remove stale fontColor=#232F3E warning (redundant with style guide)
- Fix legend-panel parent ID typo in xml-templates-structure.md
- Fix .upper() bug in badge skip condition (dead code)
- Replace blunt "Do NOT read .drawio" rule with Reference Priority section
- Remove duplicate developer_tools entry in aws4-shapes.json that shadowed xray
@scoropeza
Copy link
Copy Markdown
Contributor

Code review

Found 8 issues across our review and Copilot's findings. Pushed fixes in commit 7742c33.

Fixes applied (7742c33):

  1. Validator enforced white background but SKILL.md forbids it — Inverted the check: now errors when ANY background attribute is set on mxGraphModel (breaks dark mode adaptive contrast). Also broadened SKILL.md rule from "NEVER set #FFFFFF" to "NEVER set a background attribute."

  2. legend-panel parent ID doesn't exist in XML template — Fixed parent="legend-panel"parent="legend-container" in xml-templates-structure.md:95. The template now produces valid XML.

  3. Badge skip condition was dead code (.upper() bug)"fillColor=#007CBD" in style.upper() never matched because .upper() converts fillColor to FILLCOLOR. Removed .upper() so the condition works as intended.

  4. Validator accepted bare <mxGraphModel> despite skill requiring <mxfile> wrapper — Now emits an error for bare format, enforcing the skill's output contract.

  5. Font size validator threshold conflicted with SKILL.md — Lowered from < 11 to < 10 to match the skill's font hierarchy (service labels = 10px). Updated warning message.

  6. Removed stale fontColor=#232F3E warning — The style guide handles color guidance via light-dark() conventions. This check was too narrow and created noise on valid diagrams.

  7. SKILL.md .drawio reference contradiction — Replaced "Do NOT read existing .drawio files" (which contradicted Step 3's "study example .drawio files") with a Reference Priority section that clarifies: skill references are authoritative, user's project files only on explicit request.

Also fixed: example-microservices.drawio and example-saas-backend.drawio were failing validation because aws4-shapes.json had a duplicate developer_tools key — the second (empty) entry shadowed the first (which included xray and 17 other shapes). Removed the duplicate so the validator now recognizes all Developer Tools shapes.

Noted but not changed:

  1. Hook matches all Edit/Write operations — Claude Code hooks don't support file-path matching in the matcher field. Filtering to .drawio files happens inside validate-drawio.sh via early-exit. Overhead per non-.drawio write is minimal. Acceptable for now.

  2. aws4-shapes-resources.md at ~101 lines — Intentionally kept as a single file. It's a flat lookup registry of valid shape names — splitting would reduce usability without improving progressive disclosure.

Copilot finding F3 (background color) note: Copilot claimed "SKILL.md says never set background #FFFFFF" — at the time of Copilot's review, SKILL.md actually said "ALWAYS set background #FFFFFF." Both the SKILL.md and the validator were stale. We've now aligned both: no hardcoded background attribute allowed.

Generated with Claude Code

Copy link
Copy Markdown

@MichaelWalker-git MichaelWalker-git left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

…on, and resource exhaustion

- Replace JSON escaping fallback with safe static message (CWE-838)
- Use importlib.util for sibling imports instead of sys.path manipulation (CWE-426)
- Fix defusedxml ET.indent() bug by using stdlib for write-time formatting
- Replace bare except with specific exception types in hook JSON parser (CWE-396)
- Add 2MB file size guard to URL generator before reading into memory (CWE-400)
…() import

The xml.etree.ElementTree import is only used for indent() (write-time
formatting), not XML parsing. All parsing uses defusedxml. Add inline
suppression for Bandit B405 and Semgrep XXE rules to match the existing
pattern in drawio_url.py.
…) import

The specific rule ID nosemgrep didn't match because Semgrep uses a
composite rule ID. Bare # nosemgrep suppresses all rules on the line.
The justification is in the comment: only used for indent(), not parsing.
scoropeza and others added 4 commits April 6, 2026 12:09
Drop the indent() call and StdET import that triggered Bandit B405 and
Semgrep XXE rules. XML indentation is cosmetic — draw.io and agents
handle non-indented XML fine. Added a comment noting that a custom
indent helper can be added later if human-readable XML is needed.
Prevent prompt injection via crafted draw.io cell attributes that flow
through the PostToolUse hook into agent systemMessage context. Adds
_sanitize_attr() which strips control characters, collapses whitespace,
restricts to safe characters, and truncates at 80 chars. Applied to all
user-controlled attribute values in error/warning messages.
theagenticguy
theagenticguy previously approved these changes Apr 6, 2026
Copy link
Copy Markdown
Contributor

@theagenticguy theagenticguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Member

@scottschreckengaust scottschreckengaust left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

…s, and info leakage (#119)

Follow-on security hardening for the architecture diagram skill (PR#103):

- Add 2MB file size checks before XML parsing in validate_drawio.py and
  post_process_drawio.py (matching existing drawio_url.py guard)
- Add iterparse-based XML depth (50) and element count (50,000) pre-flight
  check to prevent C-stack overflow from deeply nested files
- Reject symlinks in post_process_drawio.py before write-back to prevent
  symlink-follow write attacks
- Wrap fixer pipelines in top-level try/except to prevent unhandled
  exception tracebacks from leaking file paths and source code into the
  hook systemMessage (stderr captured via 2>&1)
- Add timeout wrappers (10s/5s) around all Python subprocess calls in
  validate-drawio.sh to prevent runaway processes from blocking the hook

Co-authored-by: Scott Schreckengaust <345885+scottschreckengaust@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@scottschreckengaust scottschreckengaust dismissed stale reviews from theagenticguy, MichaelWalker-git, and themself via 575876c April 7, 2026 07:08
# Not a drawio file, exit silently (hook compatibility)
sys.exit(0)

path = Path(file_path)

Check failure

Code scanning / Semgrep OSS

Semgrep Finding: ai.ai-best-practices.hooks-path-traversal.hooks-path-traversal.hooks-path-traversal-python Error

Hook input flows into a file path without validation. Claude Code and Cursor hooks receive JSON input that may contain user-controlled paths. An attacker could craft input with path traversal sequences (e.g., '../../etc/passwd') to read, modify, or delete arbitrary files. Use os.path.realpath() or os.path.abspath() to resolve and validate paths before file operations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants