# asyncapi/cli architecture

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

- Interactive diagram: https://gitdiagram.com/asyncapi/cli
- Repository: https://github.com/asyncapi/cli

## Overview

##### Main Components

a. Core Components:
- Command Handler (src/commands/*)
- Core Engine (src/core/*)
- Parser Module (src/core/parser.ts)
- Configuration Manager (src/commands/config/*)
- Error Handling System (src/core/errors/*)
- Models Layer (src/core/models/*)
- Utilities (src/core/utils/*)

b. External Integrations:
- AsyncAPI Specification Parser
- File System Interface
- Template Engine
- Studio Integration

**[User Input] → [CLI Entry Point (bin/)]**
- ↓
**[Command Handler Layer] → [Core Engine]**
- ↓                     ↓
**[Configuration Manager] ← [Parser Module]**
- ↓                     ↓
**[Models Layer] ← → [Error Handler]**
- ↓
**[External Services/Utilities]**

##### Specific Implementation Details

a. Command Structure:
**[CLI Entry] → [Command Router]**
- ↓
**[Command Handlers]**
- validate
- bundle
- convert
- diff
- format
- generate
- new
- start

b. Core Services:
**[Core Engine]**
- ↓
**[SpecificationFile] → [Parser] → [Validator]**
- ↓
**[Context Manager] → [Configuration Store]**

##### Additional Elements

A section for:
- File handling capabilities
- Template processing
- Studio integration
- Analytics collection (as shown in metrics_collection.md)

##### Notes

- Command pattern implementation ("verb + noun" and "namespace + noun + [verb]")
- Extensibility points for new commands
- Test infrastructure relationship
- Integration points with external tools

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph User
        UI[User Input]
    end

    subgraph CLI
        EP["CLI Entry Point"]:::entry
        CH["Command Handler"]:::command
        CF["Command Flags/Parameters"]:::command
    end

    subgraph Core
        CE["Core Engine"]:::core
        BC["Base Command Structure"]:::core
        PM["Parser Module"]:::core
        SF["Specification File Handler"]:::core
    end

    subgraph Configuration
        CM["Configuration Manager"]:::config
        CTX["Context Management"]:::config
    end

    subgraph Services
        ML["Models Layer"]:::service
        EH["Error Handling System"]:::error
        UT["Utilities"]:::util
        GU["Generator Utilities"]:::util
    end

    subgraph External
        TE["Template Engine"]:::external
        SI["Studio Integration"]:::external
        FS["File System Interface"]:::external
        AP["AsyncAPI Parser"]:::external
    end

    UI --> EP
    EP --> CH
    CH --> CF
    CH --> CE
    CE --> BC
    CE --> PM
    PM --> SF
    CE --> CM
    CM --> CTX
    CE --> ML
    ML --> EH
    ML --> UT
    UT --> GU
    CE --> TE
    CE --> SI
    CE --> FS
    PM --> AP

    %% Click events for component mapping
    click CH "https://github.com/asyncapi/cli/tree/master/src/commands/"
    click CE "https://github.com/asyncapi/cli/tree/master/src/core/"
    click PM "https://github.com/asyncapi/cli/blob/master/src/core/parser.ts"
    click CM "https://github.com/asyncapi/cli/tree/master/src/commands/config/"
    click EH "https://github.com/asyncapi/cli/tree/master/src/core/errors/"
    click ML "https://github.com/asyncapi/cli/tree/master/src/core/models/"
    click UT "https://github.com/asyncapi/cli/tree/master/src/core/utils/"
    click EP "https://github.com/asyncapi/cli/tree/master/bin/"
    click TE "https://github.com/asyncapi/cli/tree/master/assets/create-template/"
    click SI "https://github.com/asyncapi/cli/blob/master/src/commands/start/studio.ts"
    click CF "https://github.com/asyncapi/cli/tree/master/src/core/flags/"
    click CTX "https://github.com/asyncapi/cli/tree/master/src/commands/config/context/"
    click BC "https://github.com/asyncapi/cli/blob/master/src/core/base.ts"
    click SF "https://github.com/asyncapi/cli/blob/master/src/core/models/SpecificationFile.ts"
    click GU "https://github.com/asyncapi/cli/blob/master/src/core/utils/generator.ts"

    %% Styling
    classDef entry fill:#2196F3,stroke:#1565C0,color:white
    classDef command fill:#4CAF50,stroke:#2E7D32,color:white
    classDef core fill:#FFC107,stroke:#FFA000,color:black
    classDef config fill:#FF9800,stroke:#F57C00,color:white
    classDef service fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef error fill:#F44336,stroke:#D32F2F,color:white
    classDef util fill:#607D8B,stroke:#455A64,color:white
    classDef external fill:#795548,stroke:#5D4037,color:white

    %% Legend
    subgraph Legend
        L1["Entry Points"]:::entry
        L2["Command Components"]:::command
        L3["Core Components"]:::core
        L4["Configuration"]:::config
        L5["Services"]:::service
        L6["Error Handling"]:::error
        L7["Utilities"]:::util
        L8["External Services"]:::external
    end
```
