# nettybun/acorn-macros architecture

> Architecture diagram of the GitHub repository nettybun/acorn-macros, 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/nettybun/acorn-macros
- Repository: https://github.com/nettybun/acorn-macros

## Overview

##### Main Components

a) Input Processing Layer
- Source JS/TS Files
- ESBuild Bundle
- Macro Import Detection

b) Core Processing Engine
- Acorn Parser
- AST Walker
- Macro Registry
- Macro Evaluation Pipeline

c) Macro Implementation Layer
- Individual Macro Packages
- Macro Configuration
- Output Handlers

##### Component Relationships

**┌─ Build Process ──────────────────────────────────────────┐**

- ┌─ Input ─────┐    ┌─ Processing ───┐    ┌─ Output ──┐ │
- Source Files│    │  Acorn Parser  │    │ Processed │ │
- ESBuild     │ -> │  AST Walker    │ -> │   JS      │ │
- Bundle      │    │  Macro Engine  │    │ CSS/etc.  │ │
- ┘    └───────────────┘    └──────────┘ │
- ↑                            │

- ┌─ Macro Registry ───────────────────────────────┐   │
- ┌─────────┐ ┌────────┐ ┌─────────┐ ┌───────┐  │   │
- style.   │ │ms.     │ │preval.  │ │Other   │  │   │
- acorn    │ │acorn   │ │acorn    │ │Macros  │  │   │
- ┘ └────────┘ └─────────┘ └───────┘  │   │
- ┘   │
- ┘

##### Key Elements to Highlight

- Input/Source files (Blue)
- Processing Engine (Green)
- Macro Implementations (Orange)
- Output Files (Purple)

b) Flow Indicators:

##### Important Details

- Single-pass nature of the AST walk
- Macro evaluation order for nested macros
- Source code replacement mechanism
- Hooks (Pre/Post) integration points

##### Implementation Details

A separate section showing:
- Macro interface definition
- Hook points (Pre/Post)
- Range calculation mechanism
- Code replacement strategy

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Build["Build Process"]
        direction TB
        
        subgraph Input["Input Processing Layer"]
            direction TB
            SourceFiles["Source JS/TS Files"]
            ESBuild["ESBuild Bundle"]
            MacroDetect["Macro Import Detection"]
            
            SourceFiles --> ESBuild
            ESBuild --> MacroDetect
        end

        subgraph Core["Core Processing Engine"]
            direction TB
            Parser["Acorn Parser"]
            Walker["AST Walker"]
            Engine["Macro Evaluation Pipeline"]
            
            Parser --> Walker
            Walker --> Engine
        end

        subgraph Registry["Macro Registry"]
            direction TB
            StyleMacro["Style Macro"]
            MSMacro["MS Macro"]
            PrevalMacro["Preval Macro"]
            CommonTags["Common Tags Macro"]
        end

        subgraph Output["Output Layer"]
            direction TB
            ProcessedJS["Processed JS"]
            ProcessedCSS["CSS Output"]
            OtherOutput["Other Outputs"]
        end

        Input --> Core
        Core --> Output
        Registry --> Core
    end

    %% Click events for component mapping
    click Core "https://github.com/nettybun/acorn-macros/blob/work//packages/acorn-macros/index.ts"
    click StyleMacro "https://github.com/nettybun/acorn-macros/tree/work//packages/style.acorn/"
    click MSMacro "https://github.com/nettybun/acorn-macros/tree/work//packages/ms.acorn/"
    click PrevalMacro "https://github.com/nettybun/acorn-macros/tree/work//packages/preval.acorn/"
    click CommonTags "https://github.com/nettybun/acorn-macros/tree/work//packages/common-tags.acorn/"
    click ESBuild "https://github.com/nettybun/acorn-macros/blob/work//test/all/out/esbuild.ts"
    click Build "https://github.com/nettybun/acorn-macros/blob/work//build.js"

    %% Styling
    classDef input fill:#a8d1ff,stroke:#333,stroke-width:2px
    classDef core fill:#90EE90,stroke:#333,stroke-width:2px
    classDef registry fill:#FFB347,stroke:#333,stroke-width:2px
    classDef output fill:#DDA0DD,stroke:#333,stroke-width:2px

    class SourceFiles,ESBuild,MacroDetect input
    class Parser,Walker,Engine core
    class StyleMacro,MSMacro,PrevalMacro,CommonTags registry
    class ProcessedJS,ProcessedCSS,OtherOutput output

    %% Legend
    subgraph Legend
        direction TB
        L1["Input Components"]:::input
        L2["Core Components"]:::core
        L3["Macro Components"]:::registry
        L4["Output Components"]:::output
    end
```
