# facebook/hyperion architecture

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

- Interactive diagram: https://gitdiagram.com/facebook/hyperion
- Repository: https://github.com/facebook/hyperion

## Overview

##### Project type and purpose
- This is a TypeScript‐based monorepo of modular NPM packages (“hyperion-*”) for virtualizing and observing JavaScript/browser behavior.
- It provides core interceptors, DOM virtualization, event logging, context (“flowlet”) propagation, React integration, utility functions, plugins, a visualizer UI, sample app, docs, and CI/build configuration.

##### File structure
- Top-level: CI/ config (.github/workflows, jest.config.js, babel.config.js, rollup.config.js), monorepo root package.json, tsconfig.json, top-level src/test (likely a simple demo or legacy).
- packages/: each subfolder is a self-contained package with its own src, test, tsconfig.json, babel/jest configs, and package.json.
- Key groups:
- Core interceptor engine (packages/hyperion-core)
- DOM virtualization (packages/hyperion-dom)
- Autologging framework (packages/hyperion-autologging + plugin + visualizer)
- Pub-sub channel (packages/hyperion-channel)
- Flowlet context (packages/hyperion-flowlet)
- React integrations (packages/hyperion-react, hyperion-hook, hyperion-react-testapp)
- Misc utilities (async-counter, timed-trigger, test-and-set, globals, util)
- Devtools, docs site.
- The monorepo uses Rollup/Babel for bundling, Jest for tests, VSCode settings, ESLint.

##### README insights
- Goal: “automatically add more observability and control to the behavior of JavaScript objects and classes” by intercepting browser APIs.

##### Main components & interactions
a. Core Interceptors
- packages/hyperion-core: function, method, property interceptors.
- packages/hyperion-dom: DOM API virtualization via intercepting prototypes.
b. Event Logging & Pub-Sub
- packages/hyperion-autologging: publishes DOM/user/network events, state mutations, flowlet transitions.
- packages/hyperion-channel: central Pub/Sub bus for event distribution.
- packages/hyperion-util & hyperion-globals: shared utilities (IDs, timestamps, persistent data).
- packages/hyperion-autologging-plugin-eventhash: plugin to hash events on channel.
c. Context Management
- packages/hyperion-flowlet: tracks logical execution contexts (“flowlets”).
- hyperion-hook & hyperion-react: React hook and integration for flowlets and logging in React components.
d. Visualization & Devtools
- packages/hyperion-autologging-visualizer: React/Cytoscape UI to render event graphs.
- packages/hyperion-devtools: CLI or in-browser tooling sample.
- packages/hyperion-react-testapp: sample React app demonstrating integration.
e. Documentation & CI
- packages/hyperion-docs: Docusaurus site.
- .github/workflows, rollup.config.js: build, test, deploy pipelines.

##### Architectural patterns & design principles
- Plugin/Modular architecture: each feature as its own NPM package.
- Interceptor pattern: injecting behavior into existing APIs.
- Pub/Sub event bus: decouples producers (autologging) from consumers (visualizer, plugins).
- Context propagation: flowlets maintain context across async boundaries.
- Consumer sample: React test app demonstrates end-to-end usage.
- Monorepo management: centralized build/test configs at root, per-package overrides.

##### Essential elements
- Clear, unique labels for each package or logical component.
- Callouts for design patterns (Interceptor, Pub/Sub, Plugin).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External APIs Layer
    subgraph "External APIs"
        direction TB
        Browser["Browser Environment<br/>Window, DOM, XHR/fetch, User Events"]:::external
    end

    %% Interceptor Layer
    subgraph "Interceptor Layer"
        direction TB
        Core["hyperion-core"]:::interceptor
        DOM["hyperion-dom"]:::interceptor
    end

    %% Event & Context Layer
    subgraph "Event & Context Layer"
        direction TB
        Autologging["hyperion-autologging"]:::event
        Flowlet["hyperion-flowlet"]:::event
        Channel["hyperion-channel"]:::event
        Util["hyperion-util"]:::event
        Globals["hyperion-globals"]:::event
    end

    %% Plugins & Extensions
    subgraph "Plugins & Extensions"
        direction TB
        EventHash["hyperion-autologging-plugin-eventhash"]:::plugin
    end

    %% Consumers & UI
    subgraph "Consumers & UI"
        direction TB
        Visualizer["hyperion-autologging-visualizer"]:::consumer
        Devtools["hyperion-devtools"]:::consumer
        Hook["hyperion-hook"]:::consumer
        ReactInt["hyperion-react"]:::consumer
        TestApp["hyperion-react-testapp"]:::consumer
    end

    %% Documentation & CI
    subgraph "Docs & CI"
        direction TB
        Docs["hyperion-docs"]:::docs
        CI[".github/workflows/main.yml"]:::docs
        BuildConfig["rollup.config.js<br/>babel.config.js<br/>jest.config.js"]:::docs
        RootPkg["package.json<br/>tsconfig.json"]:::docs
    end

    %% Data Flow
    Browser -->|"intercept calls"| Core
    Browser -->|"intercept DOM API"| DOM
    Core -->|"emit events"| Autologging
    DOM -->|"emit DOM events"| Autologging
    Autologging -->|"publish events"| Channel
    Flowlet -->|"provide context"| Autologging
    Autologging -->|"uses utils"| Util
    Autologging -->|"uses globals"| Globals
    Channel -->|"distribute events"| EventHash
    Channel -->|"distribute events"| Visualizer
    Channel -->|"distribute events"| Devtools
    Channel -->|"distribute events"| Hook
    Hook -->|"integrate with React"| ReactInt
    ReactInt -->|"demo app uses"| TestApp

    %% Dotted dependencies
    Docs -.-> Core
    Docs -.-> DOM
    Docs -.-> Autologging
    Docs -.-> Channel
    Docs -.-> Flowlet
    Docs -.-> Util
    Docs -.-> Globals
    Docs -.-> EventHash
    Docs -.-> Visualizer
    Docs -.-> Devtools
    Docs -.-> Hook
    Docs -.-> ReactInt
    Docs -.-> TestApp
    CI -.-> Core
    CI -.-> DOM
    CI -.-> Autologging
    CI -.-> Channel
    CI -.-> Flowlet
    CI -.-> Util
    CI -.-> Globals
    CI -.-> EventHash
    CI -.-> Visualizer
    CI -.-> Devtools
    CI -.-> Hook
    CI -.-> ReactInt
    CI -.-> TestApp
    BuildConfig -.-> Core
    BuildConfig -.-> DOM
    BuildConfig -.-> Autologging
    BuildConfig -.-> Channel
    BuildConfig -.-> Flowlet
    BuildConfig -.-> Util
    BuildConfig -.-> Globals
    BuildConfig -.-> EventHash
    BuildConfig -.-> Visualizer
    BuildConfig -.-> Devtools
    BuildConfig -.-> Hook
    BuildConfig -.-> ReactInt
    BuildConfig -.-> TestApp
    RootPkg -.-> Core
    RootPkg -.-> DOM
    RootPkg -.-> Autologging
    RootPkg -.-> Channel
    RootPkg -.-> Flowlet
    RootPkg -.-> Util
    RootPkg -.-> Globals
    RootPkg -.-> EventHash
    RootPkg -.-> Visualizer
    RootPkg -.-> Devtools
    RootPkg -.-> Hook
    RootPkg -.-> ReactInt
    RootPkg -.-> TestApp

    %% Click Events
    click Core "https://github.com/facebook/hyperion/tree/main/packages/hyperion-core"
    click DOM "https://github.com/facebook/hyperion/tree/main/packages/hyperion-dom"
    click Autologging "https://github.com/facebook/hyperion/tree/main/packages/hyperion-autologging"
    click Channel "https://github.com/facebook/hyperion/tree/main/packages/hyperion-channel"
    click Util "https://github.com/facebook/hyperion/tree/main/packages/hyperion-util"
    click Globals "https://github.com/facebook/hyperion/tree/main/packages/hyperion-globals"
    click EventHash "https://github.com/facebook/hyperion/tree/main/packages/hyperion-autologging-plugin-eventhash"
    click Flowlet "https://github.com/facebook/hyperion/tree/main/packages/hyperion-flowlet"
    click Hook "https://github.com/facebook/hyperion/tree/main/packages/hyperion-hook"
    click ReactInt "https://github.com/facebook/hyperion/tree/main/packages/hyperion-react"
    click Visualizer "https://github.com/facebook/hyperion/tree/main/packages/hyperion-autologging-visualizer"
    click Devtools "https://github.com/facebook/hyperion/tree/main/packages/hyperion-devtools"
    click TestApp "https://github.com/facebook/hyperion/tree/main/packages/hyperion-react-testapp"
    click Docs "https://github.com/facebook/hyperion/tree/main/packages/hyperion-docs"
    click CI "https://github.com/facebook/hyperion/blob/main/.github/workflows/main.yml"
    click BuildConfig "https://github.com/facebook/hyperion/blob/main/rollup.config.js"
    click RootPkg "https://github.com/facebook/hyperion/blob/main/package.json"

    %% Styles
    classDef external fill:#D6EAF8,stroke:#1B4F72,color:#1B2631;
    classDef interceptor fill:#FDEDEC,stroke:#922B21,color:#641E16;
    classDef event fill:#EAFAF1,stroke:#1E8449,color:#145A32;
    classDef plugin fill:#FEF9E7,stroke:#B7950B,color:#7D6608;
    classDef consumer fill:#E8DAEF,stroke:#6C3483,color:#4A235A;
    classDef docs fill:#F2F3F4,stroke:#566573,color:#1C2833;
```
