# awslabs/diagram-as-code architecture

> Architecture diagram of the GitHub repository awslabs/diagram-as-code, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/awslabs/diagram-as-code
- Repository: https://github.com/awslabs/diagram-as-code

## Overview

##### Main Components Identification

The system can be broken down into these key components:

a) Command Layer (cmd/awsdac)
- Entry point for CLI operations
- Handles user input and flags

b) Core Processing Components (internal/)
- Definition processor (internal/definition)
- Type system (internal/types)
- Cache management (internal/cache)
- Control logic (internal/ctl)
- Font handling (internal/font)

c) Resource Definitions (definitions/)
- Static resources

d) Input/Output Processing
- YAML input processing
- Image generation output
- CloudFormation template processing (beta feature)

**┌─────────────────────────────────────────────────────────┐**
- User Interface                       │
- (CLI Interface)                       │
- ┬─────────────────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Input Processing                       │
- ┌───────────────┐  ┌──────────────┐  ┌──────────┐   │
- YAML Parser  │  │ CFN Template │  │ DAC File │   │
- ┘  └──────────────┘  └──────────┘   │
- ┬─────────────────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Core Processing                       │
- ┌──────────┐ ┌──────────┐ ┌─────────┐ ┌──────────┐   │
- Definition│ │  Types   │ │  Cache  │ │  Control │   │
- ┘ └──────────┘ └─────────┘ └──────────┘   │
- ┬─────────────────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Resource Processing                     │
- ┌───────────────┐  ┌──────────────┐                 │
- ┘  └──────────────┘                 │
- ┬─────────────────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Image Generation                       │
- (PNG Output)                          │
- ┘

##### Important Implementation Details

- Support for multiple input formats (YAML, CloudFormation)
- Separation between definition processing and rendering
- Caching mechanism for performance optimization
- Platform-specific font handling (Windows/Linux/MacOS)
- Beta features with appropriate notation

##### Key Relationships to Emphasize

- The flow from input YAML/CFN to final PNG output
- The relationship between type system and link handling
- The control layer's orchestration of all components

##### Additional Notes

- Version information and platform support indicators
- Beta status of certain features

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph CLI["Command Layer"]
        CMD["CLI Interface"]
    end

    subgraph Input["Input Processing Layer"]
        YAML["YAML Parser"]
        CFN["CloudFormation Template"]
        DAC["DAC File"]
    end

    subgraph Core["Core Processing Layer"]
        DEF["Definition Processor"]
        TYP["Type System"]
        CAC["Cache"]
        CTL["Control Logic"]
        FONT["Font Handler"]
    end

    subgraph Resource["Resource Processing Layer"]
        AWSICON["AWS Icons"]
        LINKS["Link Definitions"]
    end

    subgraph Types["Type System Components"]
        RES["Resource Types"]
        LNK["Link Handler"]
        subgraph Layout["Layout Management"]
            HS["Horizontal Stack"]
            VS["Vertical Stack"]
        end
    end

    subgraph Output["Output Layer"]
        IMG["PNG Generation"]
    end

    CMD --> YAML
    CMD --> CFN
    CMD --> DAC
    YAML --> CTL
    CFN --> CTL
    DAC --> CTL
    CTL --> DEF
    CTL --> TYP
    CTL --> CAC
    CTL --> FONT
    DEF --> AWSICON
    TYP --> LINKS
    TYP --> RES
    TYP --> LNK
    LNK --> HS
    LNK --> VS
    DEF --> IMG
    TYP --> IMG

    %% Click events for component mapping
    click CMD "https://github.com/awslabs/diagram-as-code/blob/main/cmd/awsdac/main.go"
    click YAML "https://github.com/awslabs/diagram-as-code/blob/main/internal/ctl/dacfile.go"
    click CFN "https://github.com/awslabs/diagram-as-code/blob/main/internal/ctl/cfntemplate.go"
    click DAC "https://github.com/awslabs/diagram-as-code/blob/main/internal/ctl/create.go"
    click DEF "https://github.com/awslabs/diagram-as-code/tree/main/internal/definition"
    click TYP "https://github.com/awslabs/diagram-as-code/tree/main/internal/types"
    click CAC "https://github.com/awslabs/diagram-as-code/blob/main/internal/cache/cache.go"
    click CTL "https://github.com/awslabs/diagram-as-code/tree/main/internal/ctl"
    click FONT "https://github.com/awslabs/diagram-as-code/tree/main/internal/font"
    click AWSICON "https://github.com/awslabs/diagram-as-code/blob/main/definitions/definition-for-aws-icons-light.yaml"
    click LINKS "https://github.com/awslabs/diagram-as-code/tree/main/doc/static"
    click RES "https://github.com/awslabs/diagram-as-code/blob/main/internal/types/resource.go"
    click LNK "https://github.com/awslabs/diagram-as-code/blob/main/internal/types/link.go"
    click HS "https://github.com/awslabs/diagram-as-code/blob/main/internal/types/horizontal_stack.go"
    click VS "https://github.com/awslabs/diagram-as-code/blob/main/internal/types/vertical_stack.go"

    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef cli fill:#b3e0ff,stroke:#333,stroke-width:2px
    classDef input fill:#90EE90,stroke:#333,stroke-width:2px
    classDef core fill:#FFB366,stroke:#333,stroke-width:2px
    classDef resource fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef output fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef types fill:#FFE4B5,stroke:#333,stroke-width:2px

    class CMD,CLI cli
    class YAML,CFN,DAC,Input input
    class DEF,TYP,CAC,CTL,FONT,Core core
    class AWSICON,LINKS,Resource resource
    class IMG,Output output
    class RES,LNK,Layout,HS,VS,Types types
```
