Architecture diagram

From OpenKnots/okcode · View interactive version

Architecture diagram is an AI agent skill from the GitHub repository OpenKnots/okcode. Generate architecture diagrams for documentation using matplotlib.

How to use this skill

Skill file

Architecture Diagram Generator

When to use this skill

What this skill does

Generates publication-quality PNG architecture diagrams using Python + matplotlib. Diagrams use a consistent visual language: colored rounded boxes for components, styled arrows for data flow, dashed boundaries for service groups, and score badges for comparisons.

Implementation

Step 1: Identify the diagram type

Determine which diagram pattern fits the request:

| Pattern | When to use | Example |

| --------------------------- | ---------------------------------------- | ------------------------------- |

| High-level architecture | Full system overview with all components | high-level-architecture.png |

| Request/event flow | Show how data moves through a pipeline | server-request-flow.png |

| Package dependencies | Show import/dependency relationships | package-dependencies.png |

| Event flow | Show event sourcing or pub/sub patterns | orchestration-event-flow.png |

| Tech stack | Layered technology overview | tech-stack.png |

| Architecture comparison | Compare N alternatives with scores | telemetry-style comparison grid |

Step 2: Use or extend the generator script

The diagram generator lives at scripts/generate-architecture-diagrams.py. It provides reusable primitives:

from generate_architecture_diagrams import (
    draw_box,      # Rounded colored rectangle with label + sublabel
    draw_arrow,    # Styled arrow with optional label and curve
    draw_boundary, # Dashed service/group boundary
    draw_badge,    # Colored score circle
    new_fig,       # Create a new figure with standard theme
    save,          # Save to assets/diagrams/
    THEME,         # Consistent color palette
    Box, Arrow,    # Dataclasses for components
)

To add a new diagram, add a new generate_*() function to the script following the existing patterns, then call it from main().

To create a standalone diagram, write a new Python script that imports the primitives or copies the pattern.

Step 3: Generate the PNG

# Ensure matplotlib is available (use a venv if system Python is externally-managed)
python3 -m venv /tmp/diag-venv 2>/dev/null
/tmp/diag-venv/bin/pip install matplotlib 2>/dev/null
/tmp/diag-venv/bin/python scripts/generate-architecture-diagrams.py

Output lands in assets/diagrams/. Reference from markdown as:

![Alt text](assets/diagrams/diagram-name.png)

Step 4: Embed in README

Add diagram references to the relevant README.md using relative paths. Place diagrams immediately after the section heading they illustrate.

Visual language reference

Color palette (THEME dict)

| Role | Color | Hex | Use for |

| --------- | ---------- | --------- | -------------------------------- |

| Client | Blue | #4A90D9 | UI, browser, external clients |

| Server | Green | #2ECC71 | Server components, orchestration |

| Provider | Orange | #E67E22 | External provider processes |

| Contracts | Purple | #9B59B6 | Shared type/schema packages |

| Shared | Light blue | #3498DB | Shared runtime utilities |

| Storage | Amber | #F39C12 | Persistence, checkpoints |

| External | Gray | #95A5A6 | External/third-party processes |

| Desktop | Dark gray | #34495E | Desktop/Electron shell |

Arrow styles

| Style | Color | Meaning |

| ------------ | ------------- | ----------------------------- |

| Solid green | arrow_ws | WebSocket connection |

| Solid orange | arrow_stdio | JSON-RPC stdio pipe |

| Solid purple | arrow_event | Event stream / push |

| Dashed | any | Import / dependency reference |

Component primitives

Best practices

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.