# juanjodiaz/json2csv architecture

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

- Interactive diagram: https://gitdiagram.com/juanjodiaz/json2csv
- Repository: https://github.com/juanjodiaz/json2csv

## Overview

##### Main Components
- Core Parsing Engine:
– The “Plainjs” package provides the synchronous parser and stream parser in pure JavaScript. This is effectively the base engine used by other packages.
- Wrappers/Interfaces for Different Environments:
– The “Node” package uses the core engine to build a Node.js Transform Stream and an asynchronous parser API.
– The “WHATWG” package wraps around the core streaming parser to leverage the WHATWG Transform Stream, aimed at browser (web streams) usage.
– The “CLI” package exposes these functionalities as a command line utility.
- Support Libraries:
– The “Transforms” package includes built-in data transformation functions (like flatten and unwind) to preprocess the JSON before conversion.
– The “Formatters” package provides a set of custom CSV cell formatting functions (e.g., for numbers, strings, objects, special excel formatting, etc.).
- Additional Tools:
– Support packages such as “test-helpers” and “test-performance” help with testing, benchmarking, and validation, though they are auxiliary and do not contribute directly to the runtime architecture.

##### Technical Stack & Design Patterns
- Modularity: The project is split into multiple packages each responsible for a specific part of the JSON-to-CSV conversion process.
- Use labels to clearly differentiate synchronous and asynchronous processes:
- Shared architectural patterns:
– Dependency Inversion is evident since the core library is abstracted from its environment-specific wrappers.
– The strategy of using pluggable “Transforms” and “Formatters” represents both modular design and separation of concerns.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A("JSON Input"):::io
    subgraph "Core Processing Pipeline"
        B("Core Parsing Engine: @json2csv/plainjs (Sync & Stream Parser)"):::core
        C("Transforms: @json2csv/transforms (Data Transformation Functions)"):::aux
        D("Formatters: @json2csv/formatters (CSV Cell Formatting Functions)"):::aux
        E("CSV Output"):::io
        B -->|"toTransform"| C
        C -->|"toFormat"| D
        D -->|"produces"| E
    end
    A -->|"feeds"| B
    F("Node Wrapper: @json2csv/node (Node Transform & Async Parser)"):::wrapper
    G("WHATWG Wrapper: @json2csv/whatwg (WHATWG Transform Stream & Streaming Parser)"):::wrapper
    H("CLI Utility: @json2csv/cli (Command Line Interface)"):::wrapper
    B -->|"wrapped-by"| F
    B -->|"wrapped-by"| G
    B -->|"exposed-to"| H

    %% Click Events for Core Parsing Engine
    click B "https://github.com/juanjodiaz/json2csv/tree/main/packages/plainjs"
    click B "https://github.com/juanjodiaz/json2csv/tree/main/dist/cdn/plainjs"

    %% Click Events for Node Wrapper
    click F "https://github.com/juanjodiaz/json2csv/tree/main/packages/node"

    %% Click Events for WHATWG Wrapper
    click G "https://github.com/juanjodiaz/json2csv/tree/main/packages/whatwg"
    click G "https://github.com/juanjodiaz/json2csv/tree/main/dist/cdn/whatwg"

    %% Click Events for CLI Utility
    click H "https://github.com/juanjodiaz/json2csv/tree/main/packages/cli"

    %% Click Events for Transforms
    click C "https://github.com/juanjodiaz/json2csv/tree/main/packages/transforms"
    click C "https://github.com/juanjodiaz/json2csv/tree/main/dist/cdn/transforms"

    %% Click Events for Formatters
    click D "https://github.com/juanjodiaz/json2csv/tree/main/packages/formatters"
    click D "https://github.com/juanjodiaz/json2csv/tree/main/dist/cdn/formatters"

    %% Styles
    classDef core fill:#ffa07a,stroke:#d9534f,stroke-width:2px;
    classDef wrapper fill:#add8e6,stroke:#0275d8,stroke-width:2px;
    classDef aux fill:#dff0d8,stroke:#3c763d,stroke-width:2px;
    classDef io fill:#fcf8e3,stroke:#8a6d3b,stroke-width:2px;
```
