# cyruspyre/flexon architecture

> Architecture diagram of the GitHub repository cyruspyre/flexon, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cyruspyre/flexon
- Repository: https://github.com/cyruspyre/flexon

## Overview

1. **What this repo is**
   - `flexon` is a single Rust library crate with two companion crates: `benchmark` for performance measurement and `fuzz` for parser robustness testing.
   - The core architecture is centered on fast JSON ingestion, optional JSONC-style comments, optional span tracking, lazy value representation, and serde interoperability.

2. **Top-level data flow**
   - Input enters through `Parser` from either in-memory text or a streaming reader.
   - The parser validates and tokenizes JSON, then produces either a concrete `Value`, a lazy value tree, or a serde-deserialized Rust type.
   - The reverse path goes through serde serialization modules to emit JSON text.

3. **Input/source boundary**
   - `src/source` isolates how bytes are obtained and prepared for parsing.
   - The main source forms are a reader-backed source and a null-padded in-memory source, which support safe fast scanning and in-situ parsing optimizations.
   - This boundary is important because some APIs operate on borrowed buffers, while others stream from `Read`.

4. **Parsing core**
   - `src/parser` is the structural JSON engine.
   - It contains normal parsing plus specialized paths for skipping, skipping to a target location, and unchecked parsing variants.
   - The checked vs. unchecked split is a major architectural boundary: checked APIs validate as they go, while unchecked paths trade safety checks for speed, especially in partial-parse scenarios.

5. **Partial extraction / path-based access**
   - The crate supports parsing only a subtree of a document, not necessarily the whole JSON payload.
   - This is surfaced through path-oriented APIs such as “get from” and lazy access by pointer-like queries.
   - Architecturally, this means the parser can stop early once the requested substructure is found, rather than materializing the full document.

6. **Value model**
   - `src/value` defines the JSON value layer and is split into borrowed, owned, and lazy representations.
   - Borrowed values avoid allocations where possible; owned values own string/storage data; lazy values validate while deferring materialization.
   - Arrays, objects, numbers, strings, and a builder are separated into dedicated modules, showing that the value layer is not a monolith but a family of storage strategies.

7. **Serde integration**
   - `src/serde` is the bridge to standard Rust serialization/deserialization.
   - It contains dedicated deserialize and serialize adapters, plus span/value/unchecked support around those flows.
   - This is the main interop surface for typed Rust structs and enums, and it is distinct from the crate’s native untyped `Value` APIs.

8. **Configuration and feature gating**
   - `src/config`, `src/comment`, and `src/span` define optional behavior that changes the parser’s contract.
   - Comments and trailing commas are compile-time or runtime configuration choices depending on the feature set; span tracking adds source-location metadata to parsed output.
   - The README makes clear that these features are intentionally optional so the fast path stays lean for strict JSON use cases.

9. **SIMD and numeric parsing**
   - `src/simd` and `src/fast_float` are the performance-heavy subsystems.
   - SIMD is used for broad scanning/tokenization acceleration, while `fast_float` handles high-performance number parsing across decimal/binary representations.
   - The architecture treats numeric conversion as a distinct optimized stage rather than folding it into generic parsing logic.

10. **Error, pointer, and span metadata**
   - `src/error`, `src/pointer`, and `src/span` provide the supporting metadata and diagnostics layer.
   - These modules allow the parser and higher-level APIs to report structured failures, locate values in the input, and express JSON-pointer-style navigation.
   - This is what makes the checked APIs and comment/span features usable in real applications.

11. **Auxiliary crates**
   - `benchmark` contains representative JSON fixtures and benchmark targets for struct deserialization, value deserialization, field extraction, lazy access, and serialization.
   - `fuzz` contains multiple parser fuzz targets, including checked and unchecked parse paths, which is a strong signal that parser correctness and safety boundaries are a first-class concern.

12. **How to draw the architecture**
   - A good diagram would show `input source -> parser -> {value tree | serde deserializer | lazy tree}` with optional branches for comments/spans and checked/unchecked validation.
   - Add a parallel optimized path for SIMD/fast-float underneath parsing.
   - Show `serde` as an adapter boundary to user structs, and `benchmark`/`fuzz` as external verification/measurement crates around the core library.

Main entry points: [`src/parser/mod.rs`](https://github.com/cyruspyre/flexon/blob/main/src/parser/mod.rs) (Parser), [`src/lib.rs`](https://github.com/cyruspyre/flexon/blob/main/src/lib.rs) (flexon), [`src/serde/mod.rs`](https://github.com/cyruspyre/flexon/blob/main/src/serde/mod.rs) (Serde bridge), [`src/value/mod.rs`](https://github.com/cyruspyre/flexon/blob/main/src/value/mod.rs) (Value)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core crate"]
  node_lib["flexon<br/>crate root<br/>[lib.rs]"]
  node_source["Source<br/>input boundary<br/>[mod.rs]"]
  node_source_reader["Reader src<br/>stream source<br/>[reader.rs]"]
  node_source_null["Padded src<br/>buffer source<br/>[null_padded.rs]"]
  node_parser["Parser<br/>json engine<br/>[mod.rs]"]
  node_parser_skip["Skip path<br/>partial parse<br/>[skip.rs]"]
  node_parser_skip_to["Get from<br/>path parse<br/>[skip_to.rs]"]
  node_parser_unchecked["Unchecked parse<br/>fast path<br/>[unchecked.rs]"]
  node_value["Value<br/>json model<br/>[mod.rs]"]
  node_value_borrowed["Borrowed<br/>value storage<br/>[mod.rs]"]
  node_value_owned["Owned<br/>value storage<br/>[mod.rs]"]
  node_value_lazy["Lazy<br/>deferred value<br/>[mod.rs]"]
  node_serde["Serde bridge<br/>interop layer<br/>[mod.rs]"]
  node_serde_de["Deserialize<br/>serde adapter<br/>[de.rs]"]
  node_serde_ser["Serialize<br/>serde adapter<br/>[ser.rs]"]
  node_serde_value["Serde value<br/>[value.rs]"]
  node_simd["SIMD<br/>scan accel<br/>[simd.rs]"]
  node_fast_float["Fast float<br/>number parser<br/>[mod.rs]"]
end

subgraph group_opt["Optional features"]
  node_config["Config<br/>feature control<br/>[config.rs]"]
  node_comment["Comments<br/>jsonc option<br/>[comment.rs]"]
  node_span["Spans<br/>metadata<br/>[span.rs]"]
  node_error["Errors<br/>diagnostics<br/>[error.rs]"]
  node_pointer["Pointer<br/>navigation<br/>[pointer.rs]"]
end

subgraph group_tools["Aux crates"]
  node_benchmark["Benchmark<br/>aux crate<br/>[lib.rs]"]
  node_fuzz["Fuzz<br/>aux crate<br/>[lib.rs]"]
end

node_lib -->|"uses"| node_source
node_lib -->|"exposes"| node_parser
node_lib -->|"exposes"| node_value
node_lib -->|"bridges"| node_serde
node_lib -->|"configures"| node_config
node_lib -->|"reports"| node_error
node_lib -->|"navigates"| node_pointer
node_lib -->|"annotates"| node_span
node_lib -->|"accelerates"| node_simd
node_lib -->|"parses numbers"| node_fast_float
node_source -->|"stream"| node_source_reader
node_source -->|"buffer"| node_source_null
node_source -->|"feeds"| node_parser
node_parser -->|"contains"| node_parser_skip
node_parser -->|"contains"| node_parser_skip_to
node_parser -->|"contains"| node_parser_unchecked
node_parser -->|"produces"| node_value
node_parser -->|"deserializes"| node_serde_de
node_parser -->|"optionally allows"| node_comment
node_parser -->|"optionally tracks"| node_span
node_value -->|"variants"| node_value_borrowed
node_value -->|"variants"| node_value_owned
node_value -->|"variants"| node_value_lazy
node_serde -->|"adapts"| node_serde_de
node_serde -->|"adapts"| node_serde_ser
node_serde -->|"supports"| node_serde_value
node_serde -->|"propagates"| node_span
node_serde -->|"can use"| node_parser_unchecked
node_fast_float -->|"supports"| node_parser
node_simd -->|"supports"| node_parser
node_benchmark -->|"measures"| node_serde_de
node_benchmark -->|"measures"| node_value
node_benchmark -->|"measures"| node_serde_ser
node_fuzz -->|"tests"| node_parser
node_fuzz -->|"tests"| node_parser_unchecked

click node_lib "https://github.com/cyruspyre/flexon/blob/main/src/lib.rs"
click node_source "https://github.com/cyruspyre/flexon/blob/main/src/source/mod.rs"
click node_source_reader "https://github.com/cyruspyre/flexon/blob/main/src/source/reader.rs"
click node_source_null "https://github.com/cyruspyre/flexon/blob/main/src/source/null_padded.rs"
click node_parser "https://github.com/cyruspyre/flexon/blob/main/src/parser/mod.rs"
click node_parser_skip "https://github.com/cyruspyre/flexon/blob/main/src/parser/skip.rs"
click node_parser_skip_to "https://github.com/cyruspyre/flexon/blob/main/src/parser/skip_to.rs"
click node_parser_unchecked "https://github.com/cyruspyre/flexon/blob/main/src/parser/unchecked.rs"
click node_value "https://github.com/cyruspyre/flexon/blob/main/src/value/mod.rs"
click node_value_borrowed "https://github.com/cyruspyre/flexon/blob/main/src/value/borrowed/mod.rs"
click node_value_owned "https://github.com/cyruspyre/flexon/blob/main/src/value/owned/mod.rs"
click node_value_lazy "https://github.com/cyruspyre/flexon/blob/main/src/value/lazy/mod.rs"
click node_serde "https://github.com/cyruspyre/flexon/blob/main/src/serde/mod.rs"
click node_serde_de "https://github.com/cyruspyre/flexon/blob/main/src/serde/de.rs"
click node_serde_ser "https://github.com/cyruspyre/flexon/blob/main/src/serde/ser.rs"
click node_serde_value "https://github.com/cyruspyre/flexon/blob/main/src/serde/value.rs"
click node_config "https://github.com/cyruspyre/flexon/blob/main/src/config.rs"
click node_comment "https://github.com/cyruspyre/flexon/blob/main/src/comment.rs"
click node_span "https://github.com/cyruspyre/flexon/blob/main/src/span.rs"
click node_error "https://github.com/cyruspyre/flexon/blob/main/src/error.rs"
click node_pointer "https://github.com/cyruspyre/flexon/blob/main/src/pointer.rs"
click node_simd "https://github.com/cyruspyre/flexon/blob/main/src/simd.rs"
click node_fast_float "https://github.com/cyruspyre/flexon/blob/main/src/fast_float/mod.rs"
click node_benchmark "https://github.com/cyruspyre/flexon/blob/main/benchmark/src/lib.rs"
click node_fuzz "https://github.com/cyruspyre/flexon/blob/main/fuzz/src/lib.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_lib,node_source,node_source_reader,node_source_null,node_parser,node_parser_skip,node_parser_skip_to,node_parser_unchecked,node_value,node_value_borrowed,node_value_owned,node_value_lazy,node_serde,node_serde_de,node_serde_ser,node_serde_value,node_simd,node_fast_float toneBlue
class node_config,node_comment,node_span,node_error,node_pointer toneAmber
class node_benchmark,node_fuzz toneMint
```

## Components

### Core crate

Main JSON parsing, value, and serde integration layers.

- [flexon](https://github.com/cyruspyre/flexon/blob/main/src/lib.rs): crate root · Top-level library entry and public API surface. · `src/lib.rs`
- [Source](https://github.com/cyruspyre/flexon/blob/main/src/source/mod.rs): input boundary · Abstracts in-memory and streaming input preparation. · `src/source/mod.rs`
- [Reader src](https://github.com/cyruspyre/flexon/blob/main/src/source/reader.rs): stream source · Reader-backed input for streaming parsing. · `src/source/reader.rs`
- [Padded src](https://github.com/cyruspyre/flexon/blob/main/src/source/null_padded.rs): buffer source · Null-padded in-memory source for fast scanning and in-situ parsing. · `src/source/null_padded.rs`
- [Parser](https://github.com/cyruspyre/flexon/blob/main/src/parser/mod.rs): json engine · Structural JSON parsing, skipping, partial extraction, and unchecked variants. · `src/parser/mod.rs`
- [Skip path](https://github.com/cyruspyre/flexon/blob/main/src/parser/skip.rs): partial parse · Early-exit traversal for skipping values and locating subtrees. · `src/parser/skip.rs`
- [Get from](https://github.com/cyruspyre/flexon/blob/main/src/parser/skip_to.rs): path parse · Targeted parsing that can stop once a requested subtree is found. · `src/parser/skip_to.rs`
- [Unchecked parse](https://github.com/cyruspyre/flexon/blob/main/src/parser/unchecked.rs): fast path · Parsing variants that trade validation for speed. · `src/parser/unchecked.rs`
- [Value](https://github.com/cyruspyre/flexon/blob/main/src/value/mod.rs): json model · Native JSON value layer spanning borrowed, owned, and lazy representations. · `src/value/mod.rs`
- [Borrowed](https://github.com/cyruspyre/flexon/blob/main/src/value/borrowed/mod.rs): value storage · Borrowed JSON values that avoid allocations when possible. · `src/value/borrowed/mod.rs`
- [Owned](https://github.com/cyruspyre/flexon/blob/main/src/value/owned/mod.rs): value storage · Owned JSON values with self-contained string and buffer storage. · `src/value/owned/mod.rs`
- [Lazy](https://github.com/cyruspyre/flexon/blob/main/src/value/lazy/mod.rs): deferred value · Lazy value representation that validates before materializing fully. · `src/value/lazy/mod.rs`
- [Serde bridge](https://github.com/cyruspyre/flexon/blob/main/src/serde/mod.rs): interop layer · Adapters between flexon values and Rust serde types. · `src/serde/mod.rs`
- [Deserialize](https://github.com/cyruspyre/flexon/blob/main/src/serde/de.rs): serde adapter · Typed deserialization from JSON into Rust data structures. · `src/serde/de.rs`
- [Serialize](https://github.com/cyruspyre/flexon/blob/main/src/serde/ser.rs): serde adapter · Serialization from Rust values back to JSON text. · `src/serde/ser.rs`
- [Serde value](https://github.com/cyruspyre/flexon/blob/main/src/serde/value.rs): serde value bridge · Integration glue for serde and flexon value representations. · `src/serde/value.rs`
- [SIMD](https://github.com/cyruspyre/flexon/blob/main/src/simd.rs): scan accel · Vectorized scanning and tokenization acceleration. · `src/simd.rs`
- [Fast float](https://github.com/cyruspyre/flexon/blob/main/src/fast_float/mod.rs): number parser · High-performance numeric conversion for decimal and binary forms. · `src/fast_float/mod.rs`

### Optional features

Configuration, comments, spans, pointer navigation, and diagnostics.

- [Config](https://github.com/cyruspyre/flexon/blob/main/src/config.rs): feature control · Parse-time configuration and feature-gated behavior. · `src/config.rs`
- [Comments](https://github.com/cyruspyre/flexon/blob/main/src/comment.rs): jsonc option · Optional comment and trailing-comma support. · `src/comment.rs`
- [Spans](https://github.com/cyruspyre/flexon/blob/main/src/span.rs): metadata · Source-location tracking for parsed output and diagnostics. · `src/span.rs`
- [Errors](https://github.com/cyruspyre/flexon/blob/main/src/error.rs): diagnostics · Structured parse and conversion failures. · `src/error.rs`
- [Pointer](https://github.com/cyruspyre/flexon/blob/main/src/pointer.rs): navigation · JSON-pointer-style path addressing and lookup. · `src/pointer.rs`

### Aux crates

Benchmarking and fuzzing companions around the core library.

- [Benchmark](https://github.com/cyruspyre/flexon/blob/main/benchmark/src/lib.rs): aux crate · Performance measurement crate with representative JSON workloads. · `benchmark/src/lib.rs`
- [Fuzz](https://github.com/cyruspyre/flexon/blob/main/fuzz/src/lib.rs): aux crate · Parser robustness and safety-testing crate. · `fuzz/src/lib.rs`

## Connections

- flexon → Source: uses · Public APIs begin with input sources.
- flexon → Parser: exposes · Parser is the central JSON ingestion engine.
- flexon → Value: exposes · Untyped JSON values are a core output form.
- flexon → Serde bridge: bridges · Serde integration is a primary interop surface.
- flexon → Config: configures · Feature-gated behavior shapes parsing contracts.
- flexon → Errors: reports · Structured errors are part of the public API.
- flexon → Pointer: navigates · Pointer-style lookups support partial access.
- flexon → Spans: annotates · Span metadata can be carried through parsing and serde flows.
- flexon → SIMD: accelerates · SIMD underpins fast scanning paths.
- flexon → Fast float: parses numbers · Dedicated numeric conversion is a performance-sensitive stage.
- Source → Reader src: stream · Reader-backed inputs support streaming parsing.
- Source → Padded src: buffer · Null-padded memory inputs support fast in-situ parsing.
- Source → Parser: feeds · Prepared input is handed to the parser.
- Parser → Skip path: contains · Skipping and partial traversal are parser subpaths.
- Parser → Get from: contains · Path-based early exit is a dedicated parser mode.
- Parser → Unchecked parse: contains · Unchecked variants form the speed-oriented boundary.
- Parser → Value: produces · Parsing can materialize JSON values.
- Parser → Deserialize: deserializes · Parser output can flow directly into typed Rust data.
- Parser → Comments: optionally allows · Comment/trailing-comma handling changes the accepted syntax.
- Parser → Spans: optionally tracks · Span tracking can be attached during parsing.
- Value → Borrowed: variants · Borrowed storage is one value strategy.
- Value → Owned: variants · Owned storage is another value strategy.
- Value → Lazy: variants · Lazy representation defers full materialization.
- Serde bridge → Deserialize: adapts · Deserialize adapters connect JSON to Rust types.
- Serde bridge → Serialize: adapts · Serialize adapters emit JSON text from Rust data.
- Serde bridge → Serde value: supports · Value-specific serde glue sits alongside typed adapters.
- Serde bridge → Spans: propagates · Span-aware serde flows preserve source metadata.
- Serde bridge → Unchecked parse: can use · Serde interop includes unchecked fast paths.
- Fast float → Parser: supports · Numeric conversion is an optimized parsing stage.
- SIMD → Parser: supports · SIMD accelerates scanning and token recognition.
- Benchmark → Deserialize: measures · Benchmarks cover typed deserialization.
- Benchmark → Value: measures · Benchmarks cover value parsing and extraction.
- Benchmark → Serialize: measures · Benchmarks cover serialization.
- Fuzz → Parser: tests · Fuzz targets exercise checked parsing paths.
- Fuzz → Unchecked parse: tests · Fuzz targets also cover unchecked parsing paths.
