# sivaosorg/fj architecture

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

## Overview

##### Main Components

a) Core Processing Components:
- JSON Parser Engine
- Path Resolution System
- Query Processing System
- Transformer Pipeline
- Type System Handler

b) Supporting Components:
- Context Management
- Value Extraction System

**[Input Layer]**

- ▼
**[Parser Engine] ◄────────────► [Type System Handler]**

- ▼                              ▼
**[Path Resolution] ◄───────► [Context Management]**

- ▼                              ▼
**[Query Processor] ◄───────► [Value Extraction]**

- ▼
**[Transformer Pipeline]**

- ▼
**[Output Formatting]**

##### Component Details

a) Input Layer:
- Accepts both string and []byte JSON inputs
- Handles JSON Lines format
- Direct file reading capabilities

b) Parser Engine:
- Fast, zero-allocation JSON parsing
- Streaming capabilities
- Direct byte manipulation
- Error handling and validation

c) Path Resolution System:
- Dot notation parser
- Wildcard handling
- Array index resolution
- Query syntax parsing

d) Query Processing:
- Comparison operators (==, !=, <, <=, >, >=)
- Pattern matching (%, !%)
- Boolean evaluation (~true, ~false, ~null, ~*)
- Array filtering

e) Transformer Pipeline:
- Built-in transformers (@trim, @pretty, @minify, etc.)
- Custom transformer support
- Chaining capability
- Configuration options

f) Type System:
- JSON type handling (string, number, boolean, null)
- Type conversion utilities
- Array and object handling
- Custom type implementations

##### Flow Indicators

→ Primary data flow
⟷ Bi-directional communication
⤷ Optional path
● Connection point

##### Implementation Notes

- The modular design allowing for easy extension
- The clear separation between parsing, querying, and transformation
- The efficient handling of different input types
- The comprehensive type system
- The flexible transformation pipeline

##### Key Relationships

- Parser Engine ↔ Type System: Type inference and validation
- Path Resolution ↔ Query Processor: Query execution and filtering
- Context Management ↔ Value Extraction: Data access and manipulation
- Transformer Pipeline ↔ Output Formatting: Data transformation and presentation

This system design should be drawn with clear boundaries between components while showing their interactions, emphasizing the package's focus on performance and flexibility in JSON manipulation.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        I1[JSON String Input]:::input
        I2[JSON Bytes Input]:::input
        I3[JSON Lines Format]:::input
        I4[Direct File Input]:::input
    end

    subgraph Core
        PE["Parser Engine"]:::core
        click PE "https://github.com/sivaosorg/fj/blob/master/fj.go"
        TS["Type System Handler"]:::type
        click TS "https://github.com/sivaosorg/fj/blob/master/types.go"
        CM["Context Management"]:::support
        click CM "https://github.com/sivaosorg/fj/blob/master/h.go"
    end

    subgraph Processing
        PR["Path Resolution"]:::query
        QP["Query Processor"]:::query
        VE["Value Extraction"]:::support
    end

    subgraph Transform
        TP["Transformer Pipeline"]:::transform
        click TP "https://github.com/sivaosorg/fj/blob/master/transformers.go"
        OF["Output Formatting"]:::transform
    end

    subgraph Config
        CF["Constants & Config"]:::support
        click CF "https://github.com/sivaosorg/fj/blob/master/const.go"
    end

    %% Connections
    I1 --> PE
    I2 --> PE
    I3 --> PE
    I4 --> PE

    PE <--> TS
    PE --> PR
    PR <--> CM
    PR --> QP
    QP <--> VE
    QP --> TP
    TP --> OF

    CM <--> VE
    TS <--> CM

    %% Styles
    classDef input fill:#2196F3,stroke:#1565C0,color:white
    classDef core fill:#4CAF50,stroke:#2E7D32,color:white
    classDef query fill:#FFC107,stroke:#FFA000,color:black
    classDef transform fill:#FF9800,stroke:#F57C00,color:white
    classDef type fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef support fill:#9E9E9E,stroke:#616161,color:white

    %% Legend
    subgraph Legend
        L1[Input/Output]:::input
        L2[Core Processing]:::core
        L3[Query Components]:::query
        L4[Transformation]:::transform
        L5[Type System]:::type
        L6[Support Utilities]:::support
    end
```
