# rbrahul/awesome-json-viewer architecture

> Architecture diagram of the GitHub repository rbrahul/awesome-json-viewer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rbrahul/awesome-json-viewer
- Repository: https://github.com/rbrahul/awesome-json-viewer

## Overview

##### Main Components
- Chrome Extension Shell:
- This includes the Manifest (chrome-extension/manifest.json and extension-resources/manifest.json) and HTML files (chrome-extension/index.html, options.html, extension-resources/index.html) that form the user-facing extension interfaces.
- Background and Content Scripts:
- Found in chrome-extension/js (background.js, contentScript.js) and src/scripts (background.js, contentScript.js). These scripts handle events from the browser (like context menu interactions and API JSON interception) and prepare data for rendering.
- Viewer/Editor UI:
- Built using ReactJS in the src/ folder (files such as src/App.jsx, src/ChartView.jsx, src/TreeView.jsx, src/components/Editor, etc.). This component handles displaying JSON in tree and chart views.
- Options/Settings Page:
- Located in both chrome-extension and src/options directories. This segment allows users to change settings, import custom CSS, change themes, and configure other viewer properties.
- Utility/Helper Modules:
- In src/utils (chart rendering logic with D3, common helper functions for JSON parsing, datetime, and file downloading).
- Additional Assets:
- Build/Configuration Layers:
- Vite configuration files (vite.config.js, vite.options-page.config.js) and other configuration files (jsconfig.json, postcss.config.js, eslint.config.js) for bundling, linting, and building the project.

##### Relationships and Data Flow
- The user interacts with one of two extension interfaces:
- The viewer interface (React web app) that presents the JSON in an interactive tree/chart.
- The options/settings page where the user can change themes and adjust settings.
- When visiting a webpage:
- The contentScript.js intercepts and detects JSON responses (along with additional logic for applications like NextJS or Twitter Cards).
- The background.js manages global events such as notifications, context menu interactions, and triggering the viewer UI.
- Data communication:
- The background and content scripts interact with the main React application to pass the JSON data.
- Within the React application, utilities and hooks (e.g., src/hooks/usePrevious.jsx) process the data and feed it to visual components.
- The build tools (Vite config files) ensure that both the options page and the main React app are bundled correctly for deployment under Manifest V3.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- The project is modular: UI components are grouped under src/components, while extension scripts are logically separated (chrome-extension, src/scripts).
- Component-Based Design:
- Use of Modern Build Tools:
- The Vite configuration along with style preprocessors (SCSS in several locations) and tooling (Prettier, ESLint) suggest a modern development pipeline.
- Extension Communication Model:

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User"]:::user
    Shell["Manifest & Extension Shell"]:::extension
    Content["Content Script"]:::scripts
    Background["Background Script"]:::scripts
    Viewer["Viewer UI (React App)"]:::react
    Options["Options / Settings Page"]:::react
    Utility["Utility Modules"]:::utility
    Assets["Assets & Themes"]:::assets
    Build["Build & Configuration"]:::build

    User -->|"activates"| Shell
    User -->|"opens"| Options
    Shell -->|"injects"| Content
    Content -->|"sends_JSON"| Background
    Background -->|"triggers"| Viewer
    Options -->|"configures"| Viewer
    Viewer -->|"processes_via"| Utility
    Viewer -->|"uses"| Assets
    Options -->|"uses"| Assets
    Build -->|"bundles"| Shell
    Build -->|"bundles"| Content
    Build -->|"bundles"| Background
    Build -->|"bundles"| Viewer
    Build -->|"bundles"| Options

    click Shell "https://github.com/rbrahul/awesome-json-viewer/blob/master/chrome-extension/manifest.json"
    click Background "https://github.com/rbrahul/awesome-json-viewer/blob/master/chrome-extension/js/background.js"
    click Content "https://github.com/rbrahul/awesome-json-viewer/blob/master/chrome-extension/js/contentScript.js"
    click Viewer "https://github.com/rbrahul/awesome-json-viewer/blob/master/src/App.jsx"
    click Options "https://github.com/rbrahul/awesome-json-viewer/blob/master/chrome-extension/options.html"
    click Utility "https://github.com/rbrahul/awesome-json-viewer/blob/master/src/utils/chart.ts"
    click Assets "https://github.com/rbrahul/awesome-json-viewer/blob/master/chrome-extension/css/codemirror.css"
    click Build "https://github.com/rbrahul/awesome-json-viewer/blob/master/vite.config.js"

    classDef user fill:#FFC107,stroke:#333,stroke-width:2px,color:#000
    classDef extension fill:#AED6F1,stroke:#1F618D,stroke-width:2px,color:#000
    classDef scripts fill:#A9DFBF,stroke:#1E8449,stroke-width:2px,color:#000
    classDef react fill:#F5B7B1,stroke:#922B21,stroke-width:2px,color:#000
    classDef utility fill:#FCF3CF,stroke:#B7950B,stroke-width:2px,color:#000
    classDef assets fill:#FADBD8,stroke:#943126,stroke-width:2px,color:#000
    classDef build fill:#D5DBDB,stroke:#566573,stroke-width:2px,color:#000
```
