# vault-developer/event-loop-explorer architecture

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

- Interactive diagram: https://gitdiagram.com/vault-developer/event-loop-explorer
- Repository: https://github.com/vault-developer/event-loop-explorer

## Overview

##### Main Components

a) User Interface Layer:
- Configurator Section (Code Editor & Controls)
- Visualization Components:
- Event Loop Wheel
- Call Stack
- Web API Queue
- Tasks Queue
- MicroTasks Queue
- RequestAnimationFrame Queue
- Console Output

b) Core Logic Layer:
- AST Parser & Traversal System
- Event Loop Simulator
- State Management
- Theme Provider

**┌─ UI Layer ──────────────────────────────────────────┐**

- ┌─ Configurator ─┐    ┌─ Visualization Area ─┐    │
- Code Editor  │    │  ┌─ Event Loop ─┐    │    │
- Controls     │    │  │    Wheel     │    │    │
- ┘    │  └──────────────┘    │    │
- ┌─ Queues ──────┐    │    │
- Call Stack  │    │    │
- Web API     │    │    │
- Tasks       │    │    │
- MicroTasks  │    │    │
- ┘    │    │
- ┘     │
- ┘
- ↑
**┌─ Core Logic Layer ──────┴────────────────────────┐**

- ┌─ AST System ─┐    ┌─ Simulation Engine ─┐    │
- Parser     │    │ - Event Loop Logic  │    │
- Traverser  │    │ - Timer System      │    │
- Serializer │    │ - State Calculator  │    │
- ┘    └───────────────────────┘   │

- ┌─ State Management ─┐    ┌─ Theme System ─┐   │
- (Store)       │    │ - Dark/Light   │   │
- ┘    └───────────────┘    │
- ┘

##### Important Elements to Highlight

a) Data Flow:
- How code input flows through the AST parser
- How the simulation engine processes the parsed code
- Demonstrate state updates affecting the visualization
- Event loop simulation cycle

b) Key Interactions:
- Code Editor → AST Parser → Simulation Engine
- Simulation Engine → State Management → UI Updates
- User Controls → Simulation Engine
- Theme Toggle → Theme System → UI Updates

##### Technical Stack Indicators

- React + TypeScript
- Emotion for styling
- Acorn for AST parsing
- Vite for building
- Jest for testing

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph UI["User Interface Layer"]
        direction TB
        subgraph Config["Configurator Section"]
            direction TB
            Editor["Code Editor"]
            Controls["Controls"]
        end

        subgraph Viz["Visualization Components"]
            direction TB
            Wheel["Event Loop Wheel"]
            
            subgraph Queues["Queue Components"]
                direction TB
                CallStack["Call Stack"]
                WebAPI["Web API Queue"]
                Tasks["Tasks Queue"]
                Micro["MicroTasks Queue"]
                RAF["RequestAnimationFrame Queue"]
            end
            
            Console["Console Output"]
        end
    end

    subgraph Core["Core Logic Layer"]
        direction TB
        subgraph AST["AST System"]
            Parser["Parser"]
            Traverser["Traverser"]
            Serializer["Serializer"]
        end

        subgraph Engine["Simulation Engine"]
            EventLoop["Event Loop Logic"]
            Timer["Timer System"]
            StateCalc["State Calculator"]
        end

        Store["State Management"]
        Theme["Theme System"]
    end

    %% Relationships
    Editor --> Parser
    Controls --> EventLoop
    Parser --> EventLoop
    EventLoop --> Store
    Store --> Wheel
    Store --> Queues
    Store --> Console
    Theme --> UI
    StateCalc --> Store

    %% Click Events
    click Config "https://github.com/vault-developer/event-loop-explorer/tree/master/src/pages/home/sections/Configurator/"
    click Editor "https://github.com/vault-developer/event-loop-explorer/tree/master/src/pages/home/sections/Configurator/Editor/"
    click Controls "https://github.com/vault-developer/event-loop-explorer/tree/master/src/pages/home/sections/Configurator/Controls/"
    click Wheel "https://github.com/vault-developer/event-loop-explorer/tree/master/src/pages/home/sections/EventLoop/Wheel/"
    click CallStack "https://github.com/vault-developer/event-loop-explorer/tree/master/src/pages/home/sections/Callstack/"
    click WebAPI "https://github.com/vault-developer/event-loop-explorer/tree/master/src/pages/home/sections/WebApiQueue/"
    click Tasks "https://github.com/vault-developer/event-loop-explorer/tree/master/src/pages/home/sections/TasksQueue/"
    click Micro "https://github.com/vault-developer/event-loop-explorer/tree/master/src/pages/home/sections/MicroTasksQueue/"
    click RAF "https://github.com/vault-developer/event-loop-explorer/tree/master/src/pages/home/sections/RequestAnimationFrameQueue/"
    click Console "https://github.com/vault-developer/event-loop-explorer/tree/master/src/pages/home/sections/Console/"
    click AST "https://github.com/vault-developer/event-loop-explorer/tree/master/src/utils/ast/"
    click EventLoop "https://github.com/vault-developer/event-loop-explorer/blob/master/src/utils/simulate.ts"
    click Store "https://github.com/vault-developer/event-loop-explorer/blob/master/src/store/store.ts"
    click Theme "https://github.com/vault-developer/event-loop-explorer/tree/master/src/theme/"
    click StateCalc "https://github.com/vault-developer/event-loop-explorer/tree/master/src/utils/calculator/"

    %% Styling
    classDef ui fill:#e1f5fe,stroke:#01579b
    classDef core fill:#e8f5e9,stroke:#1b5e20
    classDef state fill:#f3e5f5,stroke:#4a148c
    classDef queue fill:#fff3e0,stroke:#e65100

    class UI,Config,Editor,Controls,Viz,Wheel,Console ui
    class Core,AST,Parser,Traverser,Serializer,Engine,EventLoop,Timer,StateCalc core
    class Store,Theme state
    class Queues,CallStack,WebAPI,Tasks,Micro,RAF queue
```
