# xnacly/libjson architecture

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

- Interactive diagram: https://gitdiagram.com/xnacly/libjson
- Repository: https://github.com/xnacly/libjson

## Overview

- Input (JSON String/Reader) → Lexer → Parser → Object Model → User Code

##### Key Features to Highlight (Use callouts)
- Query caching system
- Generic type system
- Zero-copy optimizations
- Standards compliance

- JSON Input
- ↓
- Lexical Analysis (Tokenization)
- ↓
- Syntactic Analysis (Parsing)
- ↓
- Object Construction
- ↓
- Query Interface

##### A separate section showing the query system
- Query String → Query Compiler → Cached Query → Object Traversal

- Buffer reuse paths
- Token streaming
- Memory pooling

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        JSON[JSON Input]
    end

    subgraph "Core Processing Pipeline"
        Lexer[Lexer]:::core
        Parser[Parser]:::core
        ObjectSystem[Object System]:::core
        TypeSystem[Type System]:::core
    end

    subgraph "Public Interfaces"
        API[Public API]:::interface
        CLI[Command Line Interface]:::interface
    end

    subgraph "Testing & Benchmarking"
        TestSuite[Test Suite]:::testing
        BenchSystem[Benchmarking System]:::testing
        TestGen[Test Generator]:::testing
    end

    subgraph "Performance Optimizations"
        BufferReuse[Buffer Reuse]:::optimization
        ZeroCopy[Zero-Copy String Handling]:::optimization
        QueryCache[Query Caching]:::optimization
    end

    %% Main Flow
    JSON --> Lexer
    Lexer --> Parser
    Parser --> ObjectSystem
    ObjectSystem --> API
    TypeSystem --> ObjectSystem

    %% Interface Connections
    API --> CLI
    ObjectSystem --> CLI

    %% Testing Connections
    TestSuite --> Lexer
    TestSuite --> Parser
    TestSuite --> ObjectSystem
    BenchSystem --> API
    TestGen --> TestSuite

    %% Optimization Connections
    BufferReuse -.-> Lexer
    ZeroCopy -.-> ObjectSystem
    QueryCache -.-> Parser

    %% Click Events
    click Lexer "https://github.com/xNaCly/libjson/blob/master/lexer.go"
    click Parser "https://github.com/xNaCly/libjson/blob/master/parser.go"
    click ObjectSystem "https://github.com/xNaCly/libjson/blob/master/object.go"
    click TypeSystem "https://github.com/xNaCly/libjson/blob/master/types.go"
    click API "https://github.com/xNaCly/libjson/blob/master/json.go"
    click CLI "https://github.com/xNaCly/libjson/blob/master/cmd/lj.go"
    click BenchSystem "https://github.com/xNaCly/libjson/blob/master/test/bench.sh"
    click TestGen "https://github.com/xNaCly/libjson/blob/master/test/gen.py"
    click TestSuite "https://github.com/xNaCly/libjson/blob/master/lexer_test.go"

    classDef core fill:#2374ab,stroke:#2374ab,color:white
    classDef interface fill:#47ab23,stroke:#47ab23,color:white
    classDef testing fill:#ab4723,stroke:#ab4723,color:white
    classDef optimization fill:#c4a000,stroke:#c4a000,color:white

    %% Legend
    subgraph Legend
        CoreComp[Core Components]:::core
        InterfaceComp[Public Interfaces]:::interface
        TestComp[Testing Components]:::testing
        OptComp[Optimizations]:::optimization
    end
```
