# plusnew/webcomponent architecture

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

## Overview

##### Main System Components

a) JSX Runtime Layer
- `jsx-runtime.ts` component
- It to the Babel transform plugin (`babel-plugin-transform-jsx.mjs`)

b) Reconciliation Layer (Core)
- This in the center as it's the heart of the system
- Array Reconciler
- Component Reconciler
- Fragment Reconciler
- Host Reconciler
- Text Reconciler
- Internal connections between reconciler components

c) Component Layer
- This to the right
- Portal system (`PortalEntrance.tsx`)
- Connection to the reconciler

##### Data Flow and Interactions

- JSX/TSX code → Babel Transform → JSX Runtime
- JSX Runtime → Reconciler
- Reconciler → WebComponent Output
- Portal Component → DOM manipulation

##### Architectural Patterns to Highlight

- Reconciliation pattern (similar to React's virtual DOM)
- Component composition
- Event handling system
- Error boundaries

##### Implementation Details

- TypeScript integration
- WebComponent standard compliance
- Browser compatibility
- Build/Development tools

##### Key Relationships

- How JSX gets transformed into WebComponents
- How the reconciler manages component lifecycle
- How portals interact with the main component tree
- Error boundary propagation

##### Technical Stack Indicators

- TypeScript
- WebComponents API
- Babel
- Testing Framework

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph JSX_Layer
        JSX_Runtime["JSX Runtime"]:::runtime
        Babel["Babel Transform Plugin"]:::transform
        JSX_Runtime --> Babel
    end

    subgraph Reconciliation_Core
        direction TB
        Main_Reconciler["Main Reconciler"]:::reconciler
        Array_Rec["Array Reconciler"]:::reconciler
        Comp_Rec["Component Reconciler"]:::reconciler
        Frag_Rec["Fragment Reconciler"]:::reconciler
        Host_Rec["Host Reconciler"]:::reconciler
        Text_Rec["Text Reconciler"]:::reconciler
        Util_Rec["Reconciler Utilities"]:::reconciler

        Main_Reconciler --> Array_Rec
        Main_Reconciler --> Comp_Rec
        Main_Reconciler --> Frag_Rec
        Main_Reconciler --> Host_Rec
        Main_Reconciler --> Text_Rec
        Main_Reconciler --> Util_Rec
    end

    subgraph Component_Layer
        Portal["Portal System"]:::component
    end

    subgraph Core_System
        Main_Entry["Main Entry"]:::core
        Types["Type Definitions"]:::core
        Utils["Utility Functions"]:::core
    end

    subgraph Test_Suite
        Error_Test["Error Boundaries Test"]:::test
        Event_Test["Event Handling Test"]:::test
        Portal_Test["Portal Testing"]:::test
        Fragment_Test["Fragment Testing"]:::test
        Host_Test["Host Testing"]:::test
        Context_Test["Context Testing"]:::test
        Base_Test["Base Functionality Test"]:::test
    end

    JSX_Layer --> Main_Entry
    Main_Entry --> Reconciliation_Core
    Reconciliation_Core --> Portal
    Portal --> DOM[("DOM")]:::external

    %% Component Mappings
    click JSX_Runtime "https://github.com/plusnew/webcomponent/blob/main/src/jsx-runtime.ts"
    click Babel "https://github.com/plusnew/webcomponent/blob/main/src/babel-plugin-transform-jsx.mjs"
    click Main_Reconciler "https://github.com/plusnew/webcomponent/blob/main/src/reconciler/index.ts"
    click Array_Rec "https://github.com/plusnew/webcomponent/blob/main/src/reconciler/array.ts"
    click Comp_Rec "https://github.com/plusnew/webcomponent/blob/main/src/reconciler/component.ts"
    click Frag_Rec "https://github.com/plusnew/webcomponent/blob/main/src/reconciler/fragment.ts"
    click Host_Rec "https://github.com/plusnew/webcomponent/blob/main/src/reconciler/host.ts"
    click Text_Rec "https://github.com/plusnew/webcomponent/blob/main/src/reconciler/text.ts"
    click Util_Rec "https://github.com/plusnew/webcomponent/blob/main/src/reconciler/util.ts"
    click Portal "https://github.com/plusnew/webcomponent/blob/main/src/components/PortalEntrance.tsx"
    click Main_Entry "https://github.com/plusnew/webcomponent/blob/main/src/index.ts"
    click Types "https://github.com/plusnew/webcomponent/blob/main/src/types.ts"
    click Utils "https://github.com/plusnew/webcomponent/blob/main/src/utils.ts"
    click Error_Test "https://github.com/plusnew/webcomponent/blob/main/test/error.test.tsx"
    click Event_Test "https://github.com/plusnew/webcomponent/blob/main/test/events.test.tsx"
    click Portal_Test "https://github.com/plusnew/webcomponent/blob/main/test/portal.test.tsx"
    click Fragment_Test "https://github.com/plusnew/webcomponent/blob/main/test/fragment.test.tsx"
    click Host_Test "https://github.com/plusnew/webcomponent/blob/main/test/host.test.tsx"
    click Context_Test "https://github.com/plusnew/webcomponent/blob/main/test/context.test.tsx"
    click Base_Test "https://github.com/plusnew/webcomponent/blob/main/test/base.test.tsx"

    classDef runtime fill:#4a90e2,stroke:#2e5b99,color:white
    classDef transform fill:#f39c12,stroke:#b37100,color:white
    classDef reconciler fill:#2ecc71,stroke:#27ae60,color:white
    classDef component fill:#9b59b6,stroke:#8e44ad,color:white
    classDef core fill:#e74c3c,stroke:#c0392b,color:white
    classDef test fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef external fill:#bdc3c7,stroke:#95a5a6,color:white
```
