How rbrahul/awesome-json-viewer works
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: