# asyncapi/generator architecture

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

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

## Overview

##### Project Type and Purpose
- The project is a monorepo managed by Turborepo that packages together various tools related to the AsyncAPI Generator. Its primary purpose is to take an AsyncAPI specification file as input and generate different types of code or documentation using templates.
- The main tool (“apps/generator”) provides a CLI interface to process AsyncAPI files. It relies on a modular design using reusable libraries such as “apps/hooks” (for lifecycle hook functions) and “apps/nunjucks-filters” (for applying Nunjucks-specific filters, although with a noted deprecation in favor of the React renderer engine).

##### File Structure and Main Components
- The top-level structure identifies several directories:
- apps/generator: Contains the core generator CLI, its library files (including parsers, renderers for nunjucks and react, template configuration validators, etc.), tests, and documentation.
- apps/hooks: Provides reusable hook functions that extend or modify the generation process.
- apps/nunjucks-filters: Supplies custom filters for processing templates.
- packages: Contains additional packages like components, helpers, and templates (including various client templates for JavaScript, Python, etc.) that expand the generator functionality.
- Several config files, CI/CD workflow definitions (in “.github/workflows”), and build scripts are present to structure the project’s infrastructure and continuous integration.

##### Key Architectural Relationships and Patterns
- The architecture centers on a core CLI tool (the Generator) that orchestrates the code generation process. It reads an AsyncAPI file, processes it using logic embedded in parser and renderer modules, and then applies customizable hooks and filters during template generation.
- Modular design: The hooks and nunjucks-filters are designed as independent libraries that are “plugged in” to the generator. This separation of concerns facilitates easier extension and maintenance.
- Monorepo management via Turborepo ensures that shared code, tests, and configuration are centralized.
- Template-driven Generation: Beyond core logic, the “packages/templates” directory shows that static and dynamic client templates exist, indicating separation between core generator logic and the actual template assets.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["AsyncAPI Specification Input"]:::input

    subgraph "Core Generation Process"
        G["Generator CLI"]:::core
        P["Parser Module"]:::subcore
        Rn["Renderer Module (Nunjucks)"]:::subcore
        Rr["Renderer Module (React)"]:::subcore
        T["Template Config Validator"]:::subcore
        W["Watcher Module"]:::subcore
        L["Logger Module"]:::subcore
    end

    subgraph "Extension Libraries"
        H["Hooks Library"]:::lib
        NF["Nunjucks-Filters Library"]:::lib
    end

    subgraph "Templates & Packages"
        TP["Template Packages"]:::template
        AC["Components"]:::package
        AH["Helpers"]:::package
    end

    subgraph "CI/CD & Build Pipelines"
        CI["GitHub Workflows"]:::infra
        TB["Turborepo Config (turbo.json)"]:::infra
    end

    A -->|"processed_by"| G
    G -->|"calls_parser"| P
    G -->|"calls_rendererNunjucks"| Rn
    G -->|"calls_rendererReact"| Rr
    G -->|"validates"| T
    G -->|"watches_files"| W
    G -->|"logs_activity"| L
    G -->|"invokes_hooks"| H
    G -->|"applies_filters"| NF
    G -->|"uses_templates"| TP
    TP -->|"includes"| AC
    TP -->|"includes"| AH
    CI -->|"triggers_build"| G
    TB -->|"manages_repo"| G

    style A fill:#ffe6f0,stroke:#cc3366,stroke-width:2px
    style G fill:#cce5ff,stroke:#3366cc,stroke-width:2px
    style P fill:#e6f7ff,stroke:#3399ff,stroke-width:1px
    style Rn fill:#e6f7ff,stroke:#3399ff,stroke-width:1px
    style Rr fill:#e6f7ff,stroke:#3399ff,stroke-width:1px
    style T fill:#e6f7ff,stroke:#3399ff,stroke-width:1px
    style W fill:#e6f7ff,stroke:#3399ff,stroke-width:1px
    style L fill:#e6f7ff,stroke:#3399ff,stroke-width:1px
    style H fill:#d5f5e3,stroke:#28b463,stroke-width:2px
    style NF fill:#d5f5e3,stroke:#28b463,stroke-width:2px
    style TP fill:#f9e79f,stroke:#f39c12,stroke-width:2px
    style AC fill:#fcf3cf,stroke:#f1c40f,stroke-width:1px
    style AH fill:#fcf3cf,stroke:#f1c40f,stroke-width:1px
    style CI fill:#fdebd0,stroke:#d35400,stroke-width:2px
    style TB fill:#fdebd0,stroke:#d35400,stroke-width:2px

    click G "https://github.com/asyncapi/generator/tree/master/apps/generator"
    click H "https://github.com/asyncapi/generator/tree/master/apps/hooks"
    click NF "https://github.com/asyncapi/generator/tree/master/apps/nunjucks-filters"
    click TP "https://github.com/asyncapi/generator/tree/master/packages/templates"
    click AC "https://github.com/asyncapi/generator/tree/master/packages/components"
    click AH "https://github.com/asyncapi/generator/tree/master/packages/helpers"
    click CI "https://github.com/asyncapi/generator/tree/master/.github/workflows"
    click TB "https://github.com/asyncapi/generator/blob/master/turbo.json"

classDef input fill:#ffe6f0,stroke:#cc3366,stroke-width:2px;
classDef core fill:#cce5ff,stroke:#3366cc,stroke-width:2px;
classDef subcore fill:#e6f7ff,stroke:#3399ff,stroke-width:1px;
classDef lib fill:#d5f5e3,stroke:#28b463,stroke-width:2px;
classDef template fill:#f9e79f,stroke:#f39c12,stroke-width:2px;
classDef package fill:#fcf3cf,stroke:#f1c40f,stroke-width:1px;
classDef infra fill:#fdebd0,stroke:#d35400,stroke-width:2px;
```
