# lovasoa/jsonjoy-builder architecture

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

- Interactive diagram: https://gitdiagram.com/lovasoa/jsonjoy-builder
- Repository: https://github.com/lovasoa/jsonjoy-builder

## Overview

##### Project Type and Purpose
- This is a front-end-only, React-based visual JSON Schema editor.
- It runs entirely in the browser, with no custom backend service.
- Key features: visual schema editing, real-time JSON view, schema inference, JSON validation.

##### File Structure
- **src/components/** organizes React components:
- SchemaEditor (visual + JSON tabs)
- SchemaVisualEditor, JsonSchemaVisualizer
- Feature dialogs: SchemaInferencer, JsonValidator
- UI primitives: buttons, inputs, dialogs (ShadCN UI wrappers)
- **src/lib/** contains core logic: schema-inference, editor helpers, utilities.
- **src/hooks/** holds reusable React hooks (mobile-detection, theme, toast).
- **src/utils/** has JSON validator wrapper, example-schema generator.
- No backend folder—pure client app.
- Build/deploy: rsbuild.config.ts, package.json scripts, tailwind configs.
- Tests: lightweight Node.js test runner under test/ and javascript:test/.

##### README Insights
- Confirms React + TypeScript + Rsbuild + Monaco Editor + Ajv + Zod + ShadCN UI.
- Describes core components and feature capabilities.
- No external APIs—everything runs in-browser.

##### Main Components
a. User Interface Layer
- React Components (SchemaEditor, SchemaVisualEditor, JsonSchemaVisualizer, SchemaInferencer, JsonValidator)
- UI primitives (buttons, dialogs, sidebar)
- Monaco Editor embedded for JSON view
b. Business-Logic Layer (client-side libraries)
- Schema inference engine (src/lib/schema-inference.ts)
- JSON validation engine (Ajv wrapper in src/utils/jsonValidator.ts)
- In-memory schema state/store (React state + hooks)
c. Utility Layer
- Zod for parsing
- ShadCN UI components
- Tailwind CSS for styling
d. Build & Deployment
- Rsbuild (development server + bundler)
- package.json scripts
- Output: static assets in dist/ served over CDN or static host
e. Testing
- Node.js Test Runner executing tests in test/ and javascript:test/

##### Relationships and Data Flows
- User actions in the UI trigger React state updates.
- UI dispatches to schema-inference or validation modules.
- Business logic returns results (new schema AST or validation errors).
- React updates the visual or JSON panes.
- Monaco Editor reads/writes JSON through props.
- Build pipeline transforms source → bundle → deploy.
- Test runner imports src/lib and src/utils to verify logic.

##### Architectural Patterns & Principles
- SPA with unidirectional data flow (React).
- Component-based modularization.
- Clear separation:
- Presentation (UI components)
- Domain logic (schema inference/validation)
- Utilities & third-party libs
- Hooks for cross-cutting concerns (theme, mobile view, toasts).

##### Final Checklist
- Break the SPA into: UI Layer, Logic Layer, External Dependencies, Build/Deploy, Testing.
- Technologies (React, Ts, Ajv, Zod, Monaco, Rsbuild, Tailwind).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser/Client Container
    subgraph "Browser/Client"
        %% UI Layer
        subgraph "UI Layer"
            SchemaEditor["SchemaEditor Component"]:::ui
            SchemaVisualEditor["SchemaVisualEditor"]:::ui
            JsonSchemaEditor["JsonSchemaEditor (Monaco)"]:::ui
            JsonSchemaVisualizer["JsonSchemaVisualizer"]:::ui
            SchemaInferencer["SchemaInferencer Dialog"]:::ui
            JsonValidator["JsonValidator Dialog"]:::ui
            UIPrimitives["UI Primitives"]:::ui
        end
        %% Logic Layer
        subgraph "Logic Layer"
            SchemaInference["Schema Inference Engine"]:::logic
            EditorHelpers["Editor Helpers & State"]:::logic
            JsonValidation["JSON Validation Engine (Ajv)"]:::logic
            SchemaExample["Example Schema Generator"]:::logic
        end
        %% Utilities & Hooks
        subgraph "Utilities & Hooks"
            Zod["Zod"]:::ext
            Tailwind["Tailwind CSS"]:::ext
            ShadCN["ShadCN UI"]:::ext
            Lucide["Lucide Icons"]:::ext
            Hooks["React Hooks"]:::ext
        end
    end

    %% External Dependencies
    subgraph "External Dependencies"
        Monaco["Monaco Editor"]:::ext
        Ajv["Ajv"]:::ext
    end

    %% Build & Deploy
    subgraph "Build & Deploy"
        Rsbuild["Rsbuild"]:::build
        NpmScripts["package.json Scripts"]:::build
        TailwindConfig["Tailwind Configs"]:::build
        Dist["Static Assets (dist/)"]:::build
        CDN["CDN/Static Host"]:::build
    end

    %% Testing
    subgraph "Testing"
        TestRunner["Node.js Test Runner"]:::test
        JsonSchemaTests["jsonSchema.test.js"]:::test
        JsonValidatorTests["jsonValidator.test.js"]:::test
        SchemaInferenceTests["schemaInference.test.js"]:::test
        JSVarTests["javascript:test/schemaInference.test.js"]:::test
    end

    %% Data Flows
    User["User"]:::actor -->|"interacts with"| SchemaEditor
    SchemaEditor -->|"renders"| SchemaVisualEditor
    SchemaEditor -->|"renders"| JsonSchemaEditor
    SchemaEditor -->|"renders"| JsonSchemaVisualizer
    SchemaEditor -->|"opens"| SchemaInferencer
    SchemaEditor -->|"opens"| JsonValidator
    SchemaEditor -->|"uses"| UIPrimitives

    SchemaVisualEditor -->|"dispatches to"| SchemaInference
    JsonSchemaEditor -->|"dispatches to"| JsonValidation
    JsonSchemaVisualizer -->|"reads from"| EditorHelpers
    SchemaInferencer -->|"calls"| SchemaInference
    JsonValidator -->|"calls"| JsonValidation

    SchemaInference -->|"returns AST"| SchemaVisualEditor
    JsonValidation -->|"returns errors"| JsonSchemaVisualizer
    SchemaExample -->|"provides examples"| SchemaInference

    %% Dependencies
    SchemaInference -->|"uses"| Zod
    JsonValidation -->|"wraps"| Ajv
    UIPrimitives -->|"styled by"| Tailwind
    UIPrimitives -->|"icons from"| Lucide
    JsonSchemaEditor -->|"integrates"| Monaco
    Hooks -->|"used by"| SchemaEditor
    Hooks -->|"used by"| JsonSchemaEditor

    %% Build & Deploy Flow
    src["src Files"]:::source --> Rsbuild
    Rsbuild -->|"bundles"| Dist
    NpmScripts -->|"scripts run"| Rsbuild
    TailwindConfig -->|"configures"| Rsbuild
    Dist -->|"served by"| CDN

    %% Testing Flow
    TestRunner --> JsonSchemaTests
    TestRunner --> JsonValidatorTests
    TestRunner --> SchemaInferenceTests
    TestRunner --> JSVarTests
    TestRunner -->|"imports"| SchemaInference
    TestRunner -->|"imports"| JsonValidation

    %% Click Events
    click SchemaEditor "https://github.com/lovasoa/jsonjoy-builder/tree/main/src/components/SchemaEditor"
    click SchemaVisualEditor "https://github.com/lovasoa/jsonjoy-builder/blob/main/src/components/SchemaEditor/SchemaVisualEditor.tsx"
    click JsonSchemaEditor "https://github.com/lovasoa/jsonjoy-builder/blob/main/src/components/SchemaEditor/JsonSchemaEditor.tsx"
    click JsonSchemaVisualizer "https://github.com/lovasoa/jsonjoy-builder/blob/main/src/components/SchemaEditor/JsonSchemaVisualizer.tsx"
    click SchemaInferencer "https://github.com/lovasoa/jsonjoy-builder/blob/main/src/components/features/SchemaInferencer.tsx"
    click JsonValidator "https://github.com/lovasoa/jsonjoy-builder/blob/main/src/components/features/JsonValidator.tsx"
    click UIPrimitives "https://github.com/lovasoa/jsonjoy-builder/tree/main/src/components/ui"
    click SchemaInference "https://github.com/lovasoa/jsonjoy-builder/blob/main/src/lib/schema-inference.ts"
    click EditorHelpers "https://github.com/lovasoa/jsonjoy-builder/blob/main/src/lib/schemaEditor.ts"
    click JsonValidation "https://github.com/lovasoa/jsonjoy-builder/blob/main/src/utils/jsonValidator.ts"
    click SchemaExample "https://github.com/lovasoa/jsonjoy-builder/blob/main/src/utils/schemaExample.ts"
    click Hooks "https://github.com/lovasoa/jsonjoy-builder/tree/main/src/hooks"
    click Rsbuild "https://github.com/lovasoa/jsonjoy-builder/blob/main/rsbuild.config.ts"
    click NpmScripts "https://github.com/lovasoa/jsonjoy-builder/blob/main/package.json"
    click TailwindConfig "https://github.com/lovasoa/jsonjoy-builder/blob/main/tailwind.config.js"
    click TestRunner "https://github.com/lovasoa/jsonjoy-builder/tree/main/test"
    click JsonSchemaTests "https://github.com/lovasoa/jsonjoy-builder/blob/main/test/jsonSchema.test.js"
    click JsonValidatorTests "https://github.com/lovasoa/jsonjoy-builder/blob/main/test/jsonValidator.test.js"
    click SchemaInferenceTests "https://github.com/lovasoa/jsonjoy-builder/blob/main/test/schemaInference.test.js"
    click JSVarTests "https://github.com/lovasoa/jsonjoy-builder/blob/main/javascript:test/schemaInference.test.js"

    %% Styling
    classDef ui fill:#cfe2ff,stroke:#5b9bd5,stroke-width:2px
    classDef logic fill:#d9ead3,stroke:#6aa84f,stroke-width:2px
    classDef ext fill:#ffe599,stroke:#f1c232,stroke-width:2px
    classDef build fill:#d9d2e9,stroke:#8e7cc3,stroke-width:2px
    classDef test fill:#e7e6e6,stroke:#a6a6a6,stroke-width:2px
    classDef actor fill:#fff2cc,stroke:#bf9000,stroke-width:2px
    classDef source fill:#f4cccc,stroke:#c00000,stroke-width:2px
```
