# infi-pc/locatorjs architecture

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

- Interactive diagram: https://gitdiagram.com/infi-pc/locatorjs
- Repository: https://github.com/infi-pc/locatorjs

## Overview

##### Main Components
- Browser Extension: Under apps/extension, this part includes multiple pages (Background, Content script, Popup UI, etc.), configuration files (manifest.v2.json, manifest.v3.json), and tooling (Webpack, Babel, ESLint, Tailwind). It is the entry point into the system from the user’s browser.
- Demo/Example Applications: There are several apps built with different technologies (e.g., apps/next-react-server-components, various apps/vite-* projects, and apps/web). These serve both as integrations and test beds for LocatorJS in different environments.
- Testing Infrastructure: The apps/playwright folder indicates end-to-end testing setups using Playwright. This component simulates user interactions and ensures the extension and libraries work as expected.
- Core and Supporting Libraries: The packages directory includes several modules:
- packages/runtime: Contains the core runtime logic, adapters for different frameworks (React, Svelte, Vue), components (UI elements for outlines, banner, tooltips, etc.), and helper functions.
- packages/babel-jsx: Provides Babel integrations for JSX transformations.
- packages/locatorjs: Likely holds integration logic (though it might be embedded in other modules) for actually locating components.
- Other packages such as packages/react-devtools-hook, packages/dev-config, packages/shared, and packages/ui contribute to configuration, shared logic, and UI widget components.
- Development and Workspace Configuration: Tools like turbo.json, lerna.json, pnpm-workspace.yaml, and various .vscode, .github configurations indicate CI/CD pipelines, workspace management, and contribution guidelines.

##### Relationships and Interactions
- The Browser Extension communicates with the webpage via injected content/hook scripts – for example, the “Hook” files and runtime adapters.
- The extension’s Popup and Background pages interact with the core LocatorJS libraries from packages/runtime and others. This is facilitated by scripted data flows (use of Webpack, Babel configurations, etc.).
- The demo applications (Vite, Next.js, etc.) serve as examples and testing grounds; they integrate LocatorJS as a library. Their UI components, when inspected, invoke LocatorJS’s runtime which then communicates back to the extension.
- Testing with Playwright orchestrates scenarios across these apps and the extension to simulate user actions.
- The “babel-jsx” package likely transforms or compiles JSX code during build time, working together with “react-devtools-hook” and “runtime” adapters to capture UI component information.

##### Important Architectural Patterns and Design Principles
- Modular / Repository Pattern: The monorepo is organized into discrete “apps” and “packages,” delineating consumer examples from core library functionality.
- Adapter Pattern: The runtime package’s adapters (for React, Svelte, Vue, etc.) abstract the specifics of each framework, allowing LocatorJS to remain framework-agnostic.
- Separation of Concerns: There’s a clear split between front-end/demo applications, the browser extension (UI and background processes), and the underlying libraries which handle business logic and component inspection.
- Testing & Development Workflow: With dedicated directories for Playwright tests and CI/CD workflows (under .github/workflows), the project emphasizes automated testing and continuous integration.

##### Relevant Technologies, Frameworks, and Tools
- Frameworks/Libraries: React, SolidJS, Preact, Svelte, Vue.
- Build Tools: Webpack (for the extension), Vite (for various sample projects), Babel (with specific JSX transformations).
- Testing: Playwright for end-to-end tests.
- Linting and Formatting: ESLint, Prettier, and other configuration presets housed in packages/dev-config.
- CI/CD: GitHub Actions workflows provided under .github/workflows.
- Package Management: pnpm, lerna, and turbo (turbo.json).

##### Elements
- Annotations: Include notes about technologies or protocols used (for example, “Webpack build-time bundling” for the extension, “Vite bundler” for demos).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser Extension Section
    BE["Browser Extension"]:::extension
    Popup["Popup UI"]:::extensionDetail
    Background["Background Script"]:::extensionDetail
    Content["Content Script/Hook"]:::extensionDetail
    BE -->|"init"| Popup
    BE -->|"init"| Background
    BE -->|"init"| Content
    Popup -->|"calls"| Runtime
    Background -->|"calls"| Runtime
    Content -->|"calls"| Runtime

    %% Demo/Example Applications Section
    subgraph "Demo Applications"
        Next["Next React Server Components"]:::demo
        VitePreact["Vite Preact Project"]:::demo
        ViteReactClean["Vite React Clean Project"]:::demo
        ViteReact["Vite React Project"]:::demo
        ViteSolid["Vite Solid Project"]:::demo
        ViteSvelteClean["Vite Svelte Clean Project"]:::demo
        ViteSvelte["Vite Svelte Project"]:::demo
        ViteVue["Vite Vue Project"]:::demo
        Web["Web Demo"]:::demo
    end

    %% Core and Supporting Libraries Section
    subgraph "Core and Supporting Libraries"
        Runtime["Runtime Core & Adapters"]:::core
        BabelJSX["Babel JSX Transformations"]:::core
        Locator["LocatorJS Integration"]:::core
        DevTools["React DevTools Hook Integration"]:::core
        DevConfig["Development and Linting Configurations"]:::core
        Shared["Shared Logic & Helpers"]:::core
        UI["UI Components (Widget Elements)"]:::core
    end

    %% Testing Infrastructure Section
    Test["Playwright Tests"]:::test

    %% Relationships between Demo Applications and Core Integration
    Next -->|"imports"| Locator
    VitePreact -->|"imports"| Locator
    ViteReactClean -->|"imports"| Locator
    ViteReact -->|"imports"| Locator
    ViteSolid -->|"imports"| Locator
    ViteSvelteClean -->|"imports"| Locator
    ViteSvelte -->|"imports"| Locator
    ViteVue -->|"imports"| Locator
    Web -->|"imports"| Locator

    %% Relationships within Core Libraries
    Runtime -->|"integrates"| Locator
    BabelJSX -->|"transforms"| Runtime
    DevTools -->|"hooks"| Runtime
    Shared -->|"supports"| Runtime
    UI -->|"providesUI"| Runtime

    %% Testing Relationships
    Test -->|"tests"| BE
    Test -->|"tests"| Next
    Test -->|"tests"| VitePreact
    Test -->|"tests"| ViteReactClean
    Test -->|"tests"| ViteReact
    Test -->|"tests"| ViteSolid
    Test -->|"tests"| ViteSvelteClean
    Test -->|"tests"| ViteSvelte
    Test -->|"tests"| ViteVue
    Test -->|"tests"| Web
    Test -->|"verifies"| Runtime

    %% Click Events for Component Mappings
    click BE "https://github.com/infi-pc/locatorjs/tree/master/apps/extension"
    click Next "https://github.com/infi-pc/locatorjs/tree/master/apps/next-react-server-components"
    click VitePreact "https://github.com/infi-pc/locatorjs/tree/master/apps/vite-preact-project"
    click ViteReactClean "https://github.com/infi-pc/locatorjs/tree/master/apps/vite-react-clean-project"
    click ViteReact "https://github.com/infi-pc/locatorjs/tree/master/apps/vite-react-project"
    click ViteSolid "https://github.com/infi-pc/locatorjs/tree/master/apps/vite-solid-project"
    click ViteSvelteClean "https://github.com/infi-pc/locatorjs/tree/master/apps/vite-svelte-clean-project"
    click ViteSvelte "https://github.com/infi-pc/locatorjs/tree/master/apps/vite-svelte-project"
    click ViteVue "https://github.com/infi-pc/locatorjs/tree/master/apps/vite-vue-project"
    click Web "https://github.com/infi-pc/locatorjs/tree/master/apps/web"
    click Test "https://github.com/infi-pc/locatorjs/tree/master/apps/playwright"
    click Runtime "https://github.com/infi-pc/locatorjs/tree/master/packages/runtime"
    click BabelJSX "https://github.com/infi-pc/locatorjs/tree/master/packages/babel-jsx"
    click Locator "https://github.com/infi-pc/locatorjs/tree/master/packages/locatorjs"
    click DevTools "https://github.com/infi-pc/locatorjs/tree/master/packages/react-devtools-hook"
    click DevConfig "https://github.com/infi-pc/locatorjs/tree/master/packages/dev-config"
    click Shared "https://github.com/infi-pc/locatorjs/tree/master/packages/shared"
    click UI "https://github.com/infi-pc/locatorjs/tree/master/packages/ui"

    %% Styles
    classDef extension fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef extensionDetail fill:#ffebee,stroke:#b71c1c,stroke-width:1px;
    classDef demo fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef core fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef test fill:#fff3cd,stroke:#856404,stroke-width:2px;
```
