# rich-harris/devalue architecture

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

## Overview

##### Main Components

a) Input/Output Processing Layer
- Entry points (uneval, stringify, parse, unflatten)
- Different types of inputs it can handle

b) Core Processing Components
- Base64 handling (from base64.js)
- Parsing engine (from parse.js)
- Stringification engine (from stringify.js)
- Uneval processor (from uneval.js)

c) Support Systems
- Type handling system
- Constants management
- Utility functions

- ┌─ API Layer ─────────────────────┐
- uneval() stringify() parse() ... │
- Processing Layer ──────────────┤
- Parser  Stringifier  Uneval     │
- Support Layer ────────────────┤
- Types  Utils  Constants        │
- ┘

##### Data Flow Representation

- Input data → Type checking → Processing → Output
- Circular reference handling paths
- Custom type processing routes

##### Special Features to Highlight

Create dedicated sections showing:
- XSS mitigation handling
- Circular reference detection
- Custom type processing
- Special value handling (undefined, Infinity, etc.)

##### Implementation Details

**┌─ Security Layer ─────────────────┐**
- XSS Prevention  Type Validation  │
- Core Processing ───────────────┤
- Serialization    Deserialization│
- Reference Tracking  Type Mapping│
- Type Handlers ────────────────┤
- Built-in Types   Custom Types  │
- ┘

##### Integration Points

How the library integrates with:
- JSON.stringify/parse alternatives
- Custom type systems
- Error handling mechanisms

Remember to include version information and any relevant notes about browser/environment compatibility in a separate metadata section.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph API
        A1["uneval()"]
        A2["stringify()"]
        A3["parse()"]
        A4["unflatten()"]
    end

    subgraph Security
        S1["XSS Prevention"]
        S2["Type Validation"]
    end

    subgraph Core_Processing
        C1["Parser Engine"]:::core
        C2["Stringification Engine"]:::core
        C3["Uneval Processor"]:::core
        C4["Base64 Handler"]:::core
    end

    subgraph Type_Handlers
        T1["Built-in Types"]
        T2["Custom Types"]
        T3["Type System"]:::types
    end

    subgraph Support_Systems
        U1["Constants"]:::support
        U2["Utility Functions"]:::support
    end

    subgraph Testing
        Test1["Test Suite"]:::test
        Test2["CI Pipeline"]:::ci
    end

    %% Connections
    A1 --> S2
    A2 --> S2
    A3 --> S1
    A4 --> S2

    S1 --> C1
    S2 --> |Validation| C2
    S2 --> |Validation| C3

    C1 --> T1
    C2 --> T1
    C3 --> T1
    C4 --> C1
    C4 --> C2

    T1 --> U1
    T2 --> U1
    T3 --> T1
    T3 --> T2

    U1 --> U2
    T1 --> Test1
    T2 --> Test1

    %% Styles
    classDef core fill:#2374ab
    classDef types fill:#57a773
    classDef support fill:#a8d0db
    classDef test fill:#f7d794
    classDef ci fill:#f19066

    %% Click events
    click A1,A2,A3,A4 "https://github.com/Rich-Harris/devalue/blob/main/index.js"
    click C1 "https://github.com/Rich-Harris/devalue/blob/main/src/parse.js"
    click C2 "https://github.com/Rich-Harris/devalue/blob/main/src/stringify.js"
    click C3 "https://github.com/Rich-Harris/devalue/blob/main/src/uneval.js"
    click C4 "https://github.com/Rich-Harris/devalue/blob/main/src/base64.js"
    click T3 "https://github.com/Rich-Harris/devalue/blob/main/src/types.d.ts"
    click U1 "https://github.com/Rich-Harris/devalue/blob/main/src/constants.js"
    click U2 "https://github.com/Rich-Harris/devalue/blob/main/src/utils.js"
    click Test1 "https://github.com/Rich-Harris/devalue/blob/main/test/test.js"
    click Test2 "https://github.com/Rich-Harris/devalue/blob/main/.github/workflows/ci.yml"
```
