Generating Architecture Diagrams with Reference-Image Style Transfer: A Practical Guide

    Learn how to use a vision-understanding MCP service with a text-only LLM in a CLI coding tool to generate architecture diagrams that match your team's existing style. This guide covers environment setup, MCP configuration, a plan-mode generation workflow, acceptance checklists, common failure cases, and compliance considerations for handling API keys and sensitive architecture information.

    1. Problem and Scope

    System module diagrams in engineering documentation are usually drawn by hand. When a system has many modules that change frequently, maintenance costs are high, and diagrams produced by different people tend to look inconsistent. A natural idea is to have an AI coding assistant read the functional module documentation and produce the module diagram directly.

    Before taking this approach, two prerequisites must be confirmed:

    1. Whether the large language model you use supports image input. Many text-only models do not, and require an external vision service.
    2. Whether your team has historical architecture diagrams to use as references. Without a reference image, the model decides the output style on its own.

    The scope of this article: a command-line AI coding tool that supports MCP extensions, with a text-only model as the main model, and vision capability provided by a separate vision-understanding MCP service. Commands and configurations below are written generically; refer to the official documentation of your tool and vision service for exact field names and commands.

    2. Environment Setup

    2.1 Prerequisites

    • Node.js 18 or later is installed, and the npx command is available.
    • A command-line AI coding tool that supports MCP is installed.
    • You have an API key for the vision-understanding service, and you have confirmed its quota and terms of use.

    2.2 MCP Configuration

    The following is an example configuration for a stdio-type MCP server. The package name and version are placeholders—this example will not run as-is. Obtain the real package name and version from the vision service’s official documentation, and install only from official sources.

    1. {
    2. "type": "stdio",
    3. "command": "npx",
    4. "args": ["-y", "<vision-mcp-package-name>@<version>"],
    5. "env": {
    6. "API_KEY": "<read from environment variable, see below>",
    7. "MODE": "VISION"
    8. }
    9. }

    MODE is set to VISION, which enables the image-understanding channel. Refer to the service documentation for the exact value.

    Key injection: Do not write real keys into configuration files, code repositories, screenshots, or logs. Set an environment variable in the terminal where you launch the tool:

    1. # macOS / Linux
    2. export VISION_API_KEY="your-key-here"
    1. # Windows PowerShell
    2. $env:VISION_API_KEY="your-key-here"

    If your tool supports variable expansion, write API_KEY as "${VISION_API_KEY}" in the configuration. If it does not, consult the tool’s documentation and use a secure injection method it supports, such as loading from a secrets management service.

    2.3 Verifying the Connection

    Run the command that lists MCP servers in your tool. For example, Claude Code uses claude mcp list; other tools have their own equivalent commands. Confirm that the service status shows as connected. If the status is abnormal, check the startup logs first, then verify the package name, version, network, and API key in that order.

    Once the status is normal, run one functional check: send a test image with known content—for example, a simple diagram with three boxes and two arrows—and ask the model to describe the text and node count in the image. If the description matches the image, the vision channel is working correctly.

    3. Generation Workflow

    3.1 Workflow Overview

    Stage Input Output Acceptance Criteria Failure Handling
    Prepare reference image 1–2 historical team architecture diagrams Reference image list Colors, node shapes, and connector styles match team conventions Switch to a reference image with a single consistent style
    Style extraction Reference image, plan mode Style element list (layout, colors, nodes, connectors) No missing elements; each item matches the reference image Ask the model to explain the basis for each item
    Content parsing Functional module documentation (Markdown) Module hierarchy and dependency list Module count, hierarchy, and dependency directions match the document Fix the document structure first, then re-parse
    Plan execution Style elements and module list Module diagram file Passes the acceptance checklist in Section 4 Identify the failing stage and rerun only that stage

    3.2 Providing the Reference Image

    Image input methods vary by tool. Common approaches include dragging an image into the input area, using a paste shortcut supported by the tool, or providing an image file path in the prompt. Refer to your tool’s documentation for shortcuts—do not assume a key combination works in every environment.

    3.3 Plan-Mode Prompt

    Plan mode makes the model produce its analysis and execution steps first, so you can confirm them before it generates anything. You can use the following prompt template:

    1. Do not generate any image yet. Complete the following steps and wait for my confirmation:
    2. 1. Analyze the reference image I provided. List the style elements item by item: layout type, primary and secondary colors (with hex values), node shape, corner radius, connector style, and legend position. Explain the basis for each judgment.
    3. 2. Read the "Functional Module Documentation" and list all modules, their hierarchy levels, and dependency directions.
    4. 3. Provide a generation plan: the operation in each step, the output file name, and the acceptance criteria you intend to use.

    The plan output can follow the format below. The sample data is for illustration only; actual content depends on your reference image and documentation:

    1. Plan:
    2. 1. Style elements: layered layout; primary color #2B579A, secondary color #F3F3F3; rounded-rectangle nodes; solid connectors with arrows; legend in the upper-right corner.
    3. 2. Module list: 2 modules in the gateway layer, 4 in the business layer, 2 in the data layer; dependencies flow top to bottom.
    4. 3. Output: architecture.svg; acceptance: 8 modules, 3 layers, dependency edges consistent with the document.

    Execute only after confirming the plan. If the style elements or module list in the plan do not match your expectations, revise the prompt before executing—this avoids rework after generation.

    4. Test Conditions and Acceptance Checklist

    4.1 Recording Test Conditions

    To make results reproducible, record the following for every test: tool name and version, model name, vision MCP package name and version, the version of the functional module documentation, and the reference image file name.

    4.2 Suggested Sample Design

    Prepare at least 5 documents of different sizes for testing, covering small (about 5 modules), medium (about 20 modules), and large (about 50 modules) cases. Use the same reference image for every document so results are comparable.

    4.3 Acceptance Checklist

    Check each of the following items:

    • Module count matches the document, with no omissions and no extra nodes
    • Hierarchy matches the document
    • Dependency directions are correct, with no reversed arrows
    • Colors are close to the reference image’s hex values, judged by human visual inspection
    • Node shapes and corner radii match the reference image
    • Text has no typos and is not truncated
    • Legend position matches the reference image

    The above is a suggested testing approach and does not represent universal results. No large-scale comparative experiments were conducted for this article. Generated output must be reviewed item by item by a human before it can enter formal documentation.

    5. Common Failure Cases and Troubleshooting

    1. Image not entering the context: The model’s replies show no awareness of the image content. Common causes: the vision MCP is not connected, or the tool does not support the current image input method. Send a test image first, then check the MCP connection status.
    2. Large style deviation: Colors are correct, but node shapes or connector styles do not match. Common cause: the reference image itself mixes multiple styles. Switch to a reference image with a single consistent style, or explicitly specify the elements in the plan.
    3. Missing modules: Deeply nested modules in the document do not appear in the result. Common cause: unclear document hierarchy. Convert nested lists into heading levels and re-parse.
    4. Reversed dependency directions: Arrows point the opposite way from the document. Describe dependencies explicitly in the document using the phrasing “A depends on B,” then regenerate.
    5. Service timeout or quota exhaustion: The vision service returns errors or responds very slowly. Check the network and quota; if necessary, reduce the number of images sent in a single request.
    6. Key leakage: A configuration containing a real key was committed to a code repository. Immediately revoke the key on the service side and generate a new one, clean the commit history before pushing again, and check whether anyone has already pulled the repository.

    6. Risks and Compliance

    • API keys must be injected only through environment variables or a secrets management service—never written into code, configuration templates, screenshots, or logs.
    • Reference images and functional module documentation may contain internal architecture information. Before using a third-party vision service, confirm its data processing terms. If necessary, desensitize sensitive information such as system names, service names, and addresses first.
    • Generation quality depends on model capability, document quality, and reference image quality. Output requires human review and cannot be used directly as a final deliverable.

    7. Conclusion

    With a vision-understanding MCP service, a text-only model can read reference images. Plan mode makes style elements and module lists visible, so problems can be corrected before execution. The acceptance checklist makes generated results verifiable item by item. It is recommended to first run the full workflow end to end with one small document, record the test conditions, and then gradually scale up to all of your team’s architecture documentation.