# devgroves/bigjsontool architecture

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

- Interactive diagram: https://gitdiagram.com/devgroves/bigjsontool
- Repository: https://github.com/devgroves/bigjsontool

## Overview

#### Purpose and Runtime

Next.js App Router application for viewing and querying multi-GB JSON without loading the complete document in the browser or Node heap. The main UI is client-driven and API routes are dynamic. Raw files and derived metadata/indexes live under the OS temp directory; Next runs the UI/API process.

Entry points: `app/page.tsx`, `app/layout.tsx`, `app/api/json-level/route.ts`, `app/api/json-query/route.ts`.

#### Import and File Registration Pipeline

Files receive UUID IDs and are persisted as raw `.bin` files plus metadata. Three ingestion paths support generated streaming JSON, multipart upload, and remote-URL import. URL imports stream to disk and expose index-build progress through SSE.

Core routes: `app/api/stream-json/route.ts`, `app/api/upload/route.ts`, `app/api/import-url/route.ts`, `app/api/import-index-stream/route.ts`.

Storage and remote-file abstractions: `app/lib/uploadStore.ts`, `app/lib/remoteFileStore.ts`.

#### Local Byte-Offset Indexing

The local fallback is a byte-oriented, streaming indexer. It records root keys and container spans through depth 3, enabling direct range reads and bounded subtree parsing rather than full-document deserialization. Index data is persisted alongside the raw file and rebuilt when necessary.

Core implementation: `app/lib/buildIndex.ts`, `app/lib/BuildIndexStream.ts`, `app/lib/splitConfig.ts`.

`/api/json-level` resolves a requested path via an exact indexed container, an indexed ancestor walk, root-key offset, or finally a streaming full-file parse.

#### Splitter / Manifest Boundary

For large remote imports, an optional `pyjson-splitter` service splits root-level values into chunk files. A Fastify service serves chunks and subpaths. The application registers and reads a manifest that maps root keys to chunks, array ranges, and types; this path is preferred over local indexing.

Integration boundary: `app/api/register-manifest/route.ts`, `app/lib/manifestFileStore.ts`, `app/lib/manifestJsonValue.ts`.

External services: `pyjson-splitter` on localhost:8000 and Fastify chunk serving on localhost:4000. Their unavailability causes fallback to the local offset index / stream parsing path.

#### Tree Data Resolution and Pagination

`GET /api/json-level` produces a depth-limited subtree for the tree pane. Manifest-backed arrays are sliced across chunk boundaries; objects merge disjoint chunk subsets; scalars load from one chunk. Local files use byte spans and stream parsing. Returned deep containers become truncation markers, and arrays are paged in small previews.

Server endpoint: `app/api/json-level/route.ts`.
Client renderer and expansion controller: `app/components/JsonTreeView.tsx`.
Manifest resolution: `app/lib/manifestJsonValue.ts`.

#### JSONPath Query Execution

`POST /api/json-query` resolves the root key first, then applies the remaining JSONPath expression against only relevant data. Manifest arrays support positional windows, filters, and projection/descent over fetched items; chunk range metadata allows reads crossing chunk boundaries without loading whole arrays. Objects may require all chunks for that root object; local fallback uses indexed spans or streaming parsing.

Primary paths: `app/api/json-query/route.ts`, `app/lib/manifestJsonValue.ts`, `app/lib/manifestFileStore.ts`.

#### Browser Viewer and Byte Windows

The split-pane UI separates raw text access from structured navigation. The text component virtualizes fixed-width rows and fetches byte windows on demand; it does not accumulate the file client-side. The JSON tree performs incremental subtree and query requests, splicing expanded results into its current view.

UI paths: `app/page.tsx`, `app/components/VirtualTextArea.tsx`, `app/components/JsonTreeView.tsx`, `app/components/JsonEditor.tsx`.

Supporting APIs: `app/api/file-chars/route.ts`, `app/api/stream-file/route.ts`.

Main entry points: [`app/lib/splitConfig.ts`](https://github.com/devgroves/bigjsontool/blob/main/app/lib/splitConfig.ts) (Local resolver), [`app/lib/manifestJsonValue.ts`](https://github.com/devgroves/bigjsontool/blob/main/app/lib/manifestJsonValue.ts) (Manifest value resolver), [`app/lib/uploadStore.ts`](https://github.com/devgroves/bigjsontool/blob/main/app/lib/uploadStore.ts) (Raw file store), [`app/page.tsx`](https://github.com/devgroves/bigjsontool/blob/main/app/page.tsx) (Viewer page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Browser Viewer"]
  node_page["Viewer page<br/>Next.js client entry<br/>[page.tsx]"]
  node_text["Virtual text area<br/>virtualized byte viewer"]
  node_tree["JSON tree view<br/>incremental tree renderer<br/>[JsonTreeView.tsx]"]
  node_editor["JSON editor<br/>viewer component<br/>[JsonEditor.tsx]"]
end

subgraph group_api["Next.js API"]
  node_file_chars["File character API<br/>GET byte-window route<br/>[route.ts]"]
  node_stream_file["File stream API<br/>streaming file route<br/>[route.ts]"]
  node_json_level["JSON level API<br/>GET subtree route<br/>[route.ts]"]
  node_json_query["JSON query API<br/>POST JSONPath route<br/>[route.ts]"]
  node_ingest["Ingestion routes<br/>[route.ts]"]
  node_manifest_register["Manifest registration API<br/>manifest route<br/>[route.ts]"]
end

subgraph group_local["Local File Path"]
  node_upload_store[("Raw file store<br/>temp-file registry<br/>[uploadStore.ts]")]
  node_offset_index[("Byte-offset index<br/>streaming local indexer<br/>[buildIndex.ts]")]
  node_index_stream["Index build stream<br/>streaming index pipeline"]
  node_local_fallback["Local resolver<br/>[splitConfig.ts]"]
end

subgraph group_split["Remote Split Path"]
  node_manifest_store[("Manifest store<br/>manifest registry")]
  node_manifest_resolver["Manifest value resolver<br/>chunk-aware resolver"]
  node_splitter{{"pyjson-splitter<br/>external splitter service"}}
  node_chunk_server{{"Fastify chunk server<br/>external chunk service"}}
end

node_page -->|"renders"| node_text
node_page -->|"renders"| node_tree
node_page -->|"renders"| node_editor
node_text -->|"fetches windows"| node_file_chars
node_text -->|"streams raw text"| node_stream_file
node_tree -->|"expands paths"| node_json_level
node_tree -->|"submits JSONPath"| node_json_query
node_ingest -->|"persists raw files"| node_upload_store
node_ingest -->|"builds index"| node_index_stream
node_index_stream -->|"writes spans"| node_offset_index
node_file_chars -->|"reads byte range"| node_upload_store
node_stream_file -->|"streams file"| node_upload_store
node_json_level -->|"prefers manifest"| node_manifest_resolver
node_json_query -->|"queries relevant chunks"| node_manifest_resolver
node_json_level -.->|"falls back"| node_local_fallback
node_json_query -.->|"falls back"| node_local_fallback
node_local_fallback -->|"uses spans"| node_offset_index
node_local_fallback -->|"range reads / parses"| node_upload_store
node_manifest_register -->|"stores manifest"| node_manifest_store
node_manifest_resolver -->|"reads ranges"| node_manifest_store
node_manifest_resolver -->|"fetches chunks"| node_chunk_server
node_ingest -.->|"optional remote split"| node_splitter
node_splitter -->|"produces served chunks"| node_chunk_server

click node_page "https://github.com/devgroves/bigjsontool/blob/main/app/page.tsx"
click node_text "https://github.com/devgroves/bigjsontool/blob/main/app/components/VirtualTextArea.tsx"
click node_tree "https://github.com/devgroves/bigjsontool/blob/main/app/components/JsonTreeView.tsx"
click node_editor "https://github.com/devgroves/bigjsontool/blob/main/app/components/JsonEditor.tsx"
click node_file_chars "https://github.com/devgroves/bigjsontool/blob/main/app/api/file-chars/route.ts"
click node_stream_file "https://github.com/devgroves/bigjsontool/blob/main/app/api/stream-file/route.ts"
click node_json_level "https://github.com/devgroves/bigjsontool/blob/main/app/api/json-level/route.ts"
click node_json_query "https://github.com/devgroves/bigjsontool/blob/main/app/api/json-query/route.ts"
click node_ingest "https://github.com/devgroves/bigjsontool/blob/main/app/api/import-url/route.ts"
click node_manifest_register "https://github.com/devgroves/bigjsontool/blob/main/app/api/register-manifest/route.ts"
click node_upload_store "https://github.com/devgroves/bigjsontool/blob/main/app/lib/uploadStore.ts"
click node_offset_index "https://github.com/devgroves/bigjsontool/blob/main/app/lib/buildIndex.ts"
click node_index_stream "https://github.com/devgroves/bigjsontool/blob/main/app/lib/BuildIndexStream.ts"
click node_local_fallback "https://github.com/devgroves/bigjsontool/blob/main/app/lib/splitConfig.ts"
click node_manifest_store "https://github.com/devgroves/bigjsontool/blob/main/app/lib/manifestFileStore.ts"
click node_manifest_resolver "https://github.com/devgroves/bigjsontool/blob/main/app/lib/manifestJsonValue.ts"

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_page,node_text,node_tree,node_editor toneBlue
class node_file_chars,node_stream_file,node_json_level,node_json_query,node_ingest,node_manifest_register toneAmber
class node_upload_store,node_offset_index,node_index_stream,node_local_fallback toneMint
class node_manifest_store,node_manifest_resolver,node_splitter,node_chunk_server toneRose
```

## Components

### Browser Viewer

- [Viewer page](https://github.com/devgroves/bigjsontool/blob/main/app/page.tsx): Next.js client entry · Coordinates raw-text and tree panes. · `app/page.tsx`
- [Virtual text area](https://github.com/devgroves/bigjsontool/blob/main/app/components/VirtualTextArea.tsx): virtualized byte viewer · Requests byte windows without retaining the full file. · `app/components/VirtualTextArea.tsx`
- [JSON tree view](https://github.com/devgroves/bigjsontool/blob/main/app/components/JsonTreeView.tsx): incremental tree renderer · Expands subtrees and applies query results in place. · `app/components/JsonTreeView.tsx`
- [JSON editor](https://github.com/devgroves/bigjsontool/blob/main/app/components/JsonEditor.tsx): viewer component · `app/components/JsonEditor.tsx`

### Next.js API

- [File character API](https://github.com/devgroves/bigjsontool/blob/main/app/api/file-chars/route.ts): GET byte-window route · `app/api/file-chars/route.ts`
- [File stream API](https://github.com/devgroves/bigjsontool/blob/main/app/api/stream-file/route.ts): streaming file route · `app/api/stream-file/route.ts`
- [JSON level API](https://github.com/devgroves/bigjsontool/blob/main/app/api/json-level/route.ts): GET subtree route · Returns depth-limited, paged tree data and truncation markers. · `app/api/json-level/route.ts`
- [JSON query API](https://github.com/devgroves/bigjsontool/blob/main/app/api/json-query/route.ts): POST JSONPath route · Resolves a root key before querying relevant data. · `app/api/json-query/route.ts`
- [Ingestion routes](https://github.com/devgroves/bigjsontool/blob/main/app/api/import-url/route.ts): stream, upload, and URL routes · Registers UUID-backed raw files; URL import reports indexing progress by SSE. · `app/api/import-url/route.ts`
- [Manifest registration API](https://github.com/devgroves/bigjsontool/blob/main/app/api/register-manifest/route.ts): manifest route · `app/api/register-manifest/route.ts`

### Local File Path

- [Raw file store](https://github.com/devgroves/bigjsontool/blob/main/app/lib/uploadStore.ts): temp-file registry · Persists UUID metadata and raw .bin files in OS temp storage. · `app/lib/uploadStore.ts`
- [Byte-offset index](https://github.com/devgroves/bigjsontool/blob/main/app/lib/buildIndex.ts): streaming local indexer · Stores root keys and depth-3 container spans beside raw files. · `app/lib/buildIndex.ts`
- [Index build stream](https://github.com/devgroves/bigjsontool/blob/main/app/lib/BuildIndexStream.ts): streaming index pipeline · `app/lib/BuildIndexStream.ts`
- [Local resolver](https://github.com/devgroves/bigjsontool/blob/main/app/lib/splitConfig.ts): indexed range / stream parser · Uses exact spans, ancestor spans, root offsets, then full-file streaming parse. · `app/lib/splitConfig.ts`

### Remote Split Path

- [Manifest store](https://github.com/devgroves/bigjsontool/blob/main/app/lib/manifestFileStore.ts): manifest registry · Maps root keys to chunk files, ranges, and value types. · `app/lib/manifestFileStore.ts`
- [Manifest value resolver](https://github.com/devgroves/bigjsontool/blob/main/app/lib/manifestJsonValue.ts): chunk-aware resolver · Slices arrays across chunks, merges object subsets, and loads scalars. · `app/lib/manifestJsonValue.ts`
- **pyjson-splitter**: external splitter service · Optionally splits remote root-level values into chunks.
- **Fastify chunk server**: external chunk service · Serves chunk files and subpaths.

## Connections

- Viewer page → Virtual text area: renders
- Viewer page → JSON tree view: renders
- Viewer page → JSON editor: renders
- Virtual text area → File character API: fetches windows
- Virtual text area → File stream API: streams raw text
- JSON tree view → JSON level API: expands paths
- JSON tree view → JSON query API: submits JSONPath
- Ingestion routes → Raw file store: persists raw files
- Ingestion routes → Index build stream: builds index
- Index build stream → Byte-offset index: writes spans
- File character API → Raw file store: reads byte range
- File stream API → Raw file store: streams file
- JSON level API → Manifest value resolver: prefers manifest
- JSON query API → Manifest value resolver: queries relevant chunks
- JSON level API → Local resolver: falls back
- JSON query API → Local resolver: falls back
- Local resolver → Byte-offset index: uses spans
- Local resolver → Raw file store: range reads / parses
- Manifest registration API → Manifest store: stores manifest
- Manifest value resolver → Manifest store: reads ranges
- Manifest value resolver → Fastify chunk server: fetches chunks
- Ingestion routes → pyjson-splitter: optional remote split
- pyjson-splitter → Fastify chunk server: produces served chunks
