Using LLMs to Automatically Generate System Functional Module Diagrams and Architecture Diagrams

    This article presents a reusable workflow for using large language models to generate system functional module diagrams and architecture diagrams from design documents. It covers route selection, adding image understanding to text-only models, extracting visual style from reference diagrams, planning document analysis, generating architecture diagrams, validating output, and practices for reducing repeated attempts. The goal is to combine model-generated drafts with human review and script-based checks so teams can produce consistent, editable diagrams with less manual drawing.

    1. Background

    System design documents usually contain a large number of functional points. Manually organizing them into module diagrams is time-consuming and prone to omissions and inconsistent naming. Architecture diagrams must also express layering, deployment units, and dependency direction, which makes them even more expensive to draw. Large language models can understand documents and generate structured descriptions, so many teams have started trying to let models produce diagrams directly.

    In practice, three types of problems are common. First, the model’s understanding of the document is unstable: the same document may produce noticeably different results across multiple generations, and repeated retries are often needed before a usable version appears. Second, visual style is hard to describe clearly. Using text alone to specify “blue, rounded corners, left-right layout” often fails to reproduce the team’s existing diagram style. Third, when too much content is generated at once, module relationships and details are prone to errors.

    To address these issues, this article provides a reusable workflow: first extract the visual style, then analyze the document and create a plan, and finally generate and validate the output step by step.

    2. Choosing a Technical Route

    There are usually three routes for generating diagrams.

    1. Manual drawing: highest accuracy, but highly repetitive, and documents must be manually synchronized after changes.
    2. Templated generation: output graphics through a diagram description language or scripts. Results are controllable and suitable for scenarios with clear rules, but style adjustments depend on code changes.
    3. Direct generation by large models: greatest flexibility, with the ability to understand natural language documents and reference images, but weaker result stability.

    When comparing routes, four dimensions can be used: correctness, modifiability, style consistency, and cost. Overall, a more reliable approach is a hybrid route: let the large model understand the document and output a structured intermediate representation, and then let a rendering step generate the final graphic. The intermediate representation is easy for humans to review and convenient for later modification.

    3. Adding Image Understanding to Text-Only Models

    Many text-only large models do not support image input. If reference images or old diagrams need to be understood by the model, visual understanding capability must be connected. A common approach is to register a vision understanding service through an extension mechanism. It converts images into text descriptions and then passes them to the text model for processing.

    An example configuration is shown below. Specific fields should follow the documentation of the tool being used:

    1. {
    2. "extension": "vision-understanding",
    3. "mode": "VISION",
    4. "apiKey": "${VISION_API_KEY}"
    5. }

    Two points require attention. First, keys should be injected through environment variables and should not be written into configuration files or code repositories. Second, after configuration is complete, verify that the extension has loaded successfully. Ask the model to describe a test image and confirm that the returned content matches the image.

    The shortcut for pasting screenshots depends on the operating system. In actual use, follow the convention of the platform being used.

    4. Extracting the Visual Style from Reference Diagrams

    Reference diagrams are key to ensuring style consistency. Rather than asking the model to “draw according to this image,” it is better to first ask it to output an explicit style specification, which is then confirmed by a human before use. A style specification generally includes the following:

    • Layout: top-down layered layout or left-to-right column layout
    • Color palette: primary color, secondary color, background color, and text color
    • Shapes: proportion of rectangles and rounded rectangles, border thickness
    • Fonts and font sizes: hierarchy of titles, module names, and explanatory text
    • Spacing: white space between modules and between layers

    An example format is shown below:

    1. layout: top-down
    2. palette:
    3. primary: "#2F5597"
    4. background: "#FFFFFF"
    5. text: "#1F1F1F"
    6. shape:
    7. corner_radius: small
    8. border: 1px solid
    9. spacing:
    10. module_gap: medium

    After the specification is confirmed, all subsequent generation tasks reference the same specification to avoid style drift across generations. If the team already has old diagrams, they can also be used as reference samples, and the model can summarize their common features.

    5. Analyzing the Document and Creating an Execution Plan

    Directly asking the model to “draw a functional module diagram” often skips key analysis steps. A more reliable approach is to use planning mode: first ask the model to read the document and output a plan, and execute only after human confirmation.

    A typical plan can be divided into the following steps:

    1. Parse the document and extract functional points, roles, data objects, and flows.
    2. Merge functional points into modules and establish a hierarchy of first-level and second-level modules.
    3. Mark calls, dependencies, or data flow relationships between modules.
    4. Generate the graphic according to the reference style specification.
    5. Perform a self-check against the document and output a list of differences.

    The output of the first step can use a structured format for easier validation later:

    1. {
    2. "modules": [
    3. {
    4. "name": "User Management",
    5. "children": ["Registration", "Login", "Permission Assignment"]
    6. },
    7. {
    8. "name": "Order Management",
    9. "children": ["Order Placement", "Payment Status Sync", "Refund Processing"]
    10. }
    11. ],
    12. "relations": [
    13. {"from": "Order Management", "to": "User Management", "type": "dependency"}
    14. ]
    15. }

    Human review at this step checks whether the module division is reasonable and can effectively reduce later rework. Module granularity can be judged by the principle that “one module corresponds to a group of independently deliverable features.” If the granularity is too coarse, information is insufficient; if it is too fine, the diagram becomes difficult to read.

    6. Key Points for Generating Architecture Diagrams

    Functional module diagrams and architecture diagrams have different concerns. A functional module diagram answers “what functions does the system have, and how are they categorized?” An architecture diagram answers “what parts make up the system, how do the parts communicate, and where are they deployed?” Therefore, generating an architecture diagram requires the following additional information:

    • Layering conventions, such as access layer, service layer, and data layer
    • Deployment environment, such as container platforms, virtual machine clusters, or managed services
    • External dependencies, such as object storage, message queues, logging services, and monitoring and alerting
    • Communication methods, such as synchronous calls, asynchronous messages, or scheduled tasks

    When this information is missing, the model may invent components, making the diagram look complete while failing to match the actual system. It is recommended to clarify in the prompt which components belong to the existing system and which should be marked as pending confirmation.

    7. Validating Results

    Generated results need systematic validation rather than appearance-only review. Common checks include:

    1. Coverage: whether every functional point in the document appears in the diagram.
    2. Consistency: whether the same concept uses the same name across different diagrams.
    3. Relationship closure: whether both endpoints of every connection are nodes that exist in the diagram.
    4. Style conformance: whether colors, fonts, and layout comply with the specification.

    Coverage and consistency can be checked with script assistance, for example:

    1. def check_coverage(doc_features, diagram_modules):
    2. """Return feature points present in the document but missing from the diagram."""
    3. return sorted(set(doc_features) - set(diagram_modules))
    4. missing = check_coverage(
    5. ["Registration", "Login", "Refund Processing"],
    6. ["Registration", "Login"]
    7. )
    8. print(missing) # ['Refund Processing']

    Scripts can only detect structural issues. Semantic accuracy still requires human judgment.

    8. Practices for Reducing Repeated Attempts

    Based on practical experience, the following practices can significantly reduce rework.

    • Split requirements: generate only one diagram at a time, and handle functional diagrams and architecture diagrams separately.
    • Fix the output structure: require the model to output an intermediate representation first, then generate the graphic.
    • Provide examples: attaching a reference diagram that conforms to the specification is more effective than text descriptions.
    • Confirm step by step: after each stage, perform a human check so problems are found as early as possible.
    • Keep versions: save the previous result before each modification for comparison and rollback.

    It should be noted that generation quality is affected by document quality, model capability, and prompt design. The more complete and clearly structured the document is, the more stable the generated result will be. Large models are suitable for producing drafts, but final diagrams should still be reviewed and published by engineers.

    9. Conclusion

    Using large models to generate system functional module diagrams and architecture diagrams can delegate repetitive drawing work to the model while leaving judgment and review to humans. Three stages are key: constrain visual output with an explicit style specification, ensure content structure with a plan and intermediate representation, and validate results by combining scripts with human review. With this workflow, teams can obtain usable diagrams with fewer attempts and make later modifications traceable and reusable.