# azure/draft architecture

> Architecture diagram of the GitHub repository azure/draft, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/azure/draft
- Repository: https://github.com/azure/draft

## Overview

##### Main Components Identification

The system should be divided into these major components:

a) Core Command Processing
- Root command handler (cmd/root.go)
- Individual command handlers (create, validate, setup-gh, etc.)

b) Template Processing System
- Template management (pkg/handlers/template.go)
- Template writers (pkg/templatewriter/)
- Variable extractors (pkg/handlers/variableextractors/)

c) Language Detection & Support
- Linguist package (pkg/linguist/)
- Language-specific handlers

d) Kubernetes Integration
- Deployment handlers (pkg/handlers/)
- Safeguards system (pkg/safeguards/)
- Manifest processors

##### Component Relationships

**User Input -> Command Layer -> Processing Layer -> Output Generation**

##### Detailed Component Breakdown

a) Command Layer (Blue components):
- Create command
- Generate-workflow command
- Setup-gh command
- Validate command
- Info command
- Update command

b) Processing Layer (Green components):
- Template processor
- Language detector
- Configuration manager
- Safeguards validator

c) Integration Layer (Orange components):
- GitHub workflow generator
- Kubernetes manifest generator
- Docker file generator

d) Output Layer (Purple components):
- File writers
- CLI output
- Validation results

##### Data Flow Representation

- User input flow
- Template processing flow
- Configuration validation flow
- File generation flow

##### External Integration Points

Connections with:
- Kubernetes clusters
- GitHub Actions
- Azure services
- Docker build system

##### Key Design Elements

- Template system (pkg/handlers/template.go)
- Language detection (pkg/linguist/)
- Safeguards system (pkg/safeguards/)
- Configuration management (pkg/config/)

##### Implementation Details

Specialized components for:
- Different deployment types (Helm, Kustomize, plain manifests)
- Language-specific processors
- Validation rules
- GitHub workflow generation

##### Layer organization
- Top: User interface/CLI
- Middle: Core processing
- Bottom: Output generation
- Right side: External integrations

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph CLI["Command Layer"]
        direction TB
        UserInput[User Input]
        RootCmd[Root Command]
        CreateCmd[Create Command]
        GenWFCmd[Generate Workflow]
        SetupGHCmd[Setup GitHub]
        ValidateCmd[Validate Command]
        InfoCmd[Info Command]
        UpdateCmd[Update Command]
    end

    subgraph Processing["Processing Layer"]
        direction TB
        TempProc[Template Processor]
        LangDetect[Language Detector]
        ConfigMgr[Configuration Manager]
        SafeGuard[Safeguards Validator]
    end

    subgraph Integration["Integration Layer"]
        direction TB
        GHFlow[GitHub Workflow Generator]
        K8sGen[Kubernetes Manifest Generator]
        DockerGen[Docker File Generator]
    end

    subgraph Output["Output Layer"]
        direction TB
        FileWrite[File Writers]
        CLIOut[CLI Output]
        ValidRes[Validation Results]
    end

    subgraph External["External Services"]
        direction TB
        K8s[(Kubernetes)]
        GitHub[(GitHub Actions)]
        Azure[(Azure Services)]
        Docker[(Docker Build)]
    end

    %% Core Command Flow
    UserInput --> RootCmd
    RootCmd --> CreateCmd & GenWFCmd & SetupGHCmd & ValidateCmd & InfoCmd & UpdateCmd

    %% Processing Flow
    CreateCmd & GenWFCmd & SetupGHCmd & ValidateCmd --> TempProc
    CreateCmd --> LangDetect
    TempProc --> ConfigMgr
    ConfigMgr --> SafeGuard

    %% Integration Flow
    TempProc --> GHFlow & K8sGen & DockerGen
    
    %% Output Flow
    GHFlow & K8sGen & DockerGen --> FileWrite
    SafeGuard --> ValidRes
    ValidRes & FileWrite --> CLIOut

    %% External Connections
    K8sGen --> K8s
    GHFlow --> GitHub
    DockerGen --> Docker

    %% Click Events
    click RootCmd "https://github.com/azure/draft/blob/main/cmd/root.go"
    click CreateCmd "https://github.com/azure/draft/blob/main/cmd/create.go"
    click GenWFCmd "https://github.com/azure/draft/blob/main/cmd/generateworkflow.go"
    click SetupGHCmd "https://github.com/azure/draft/blob/main/cmd/setupgh.go"
    click ValidateCmd "https://github.com/azure/draft/blob/main/cmd/validate.go"
    click InfoCmd "https://github.com/azure/draft/blob/main/cmd/info.go"
    click UpdateCmd "https://github.com/azure/draft/blob/main/cmd/update.go"
    click TempProc "https://github.com/azure/draft/blob/main/pkg/handlers/template.go"
    click LangDetect "https://github.com/azure/draft/blob/main/pkg/linguist/linguist.go"
    click ConfigMgr "https://github.com/azure/draft/blob/main/pkg/config/draftconfig.go"
    click SafeGuard "https://github.com/azure/draft/tree/main/pkg/safeguards"
    click GHFlow "https://github.com/azure/draft/blob/main/pkg/cmdhelpers/github_workflow.go"
    click FileWrite "https://github.com/azure/draft/blob/main/pkg/templatewriter/templatewriter.go"

    %% Styling
    classDef cli fill:#2374ab
    classDef processing fill:#2a9d8f
    classDef integration fill:#e9c46a
    classDef output fill:#9c6fb6
    classDef external fill:#gray

    class UserInput,RootCmd,CreateCmd,GenWFCmd,SetupGHCmd,ValidateCmd,InfoCmd,UpdateCmd cli
    class TempProc,LangDetect,ConfigMgr,SafeGuard processing
    class GHFlow,K8sGen,DockerGen integration
    class FileWrite,CLIOut,ValidRes output
    class K8s,GitHub,Azure,Docker external
```
