# sanity-io/react-rx architecture

> Architecture diagram of the GitHub repository sanity-io/react-rx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sanity-io/react-rx
- Repository: https://github.com/sanity-io/react-rx

## Overview

##### Project type and purpose
- This is a monorepo hosting an open-source TypeScript library (“react-rx”) that provides React hooks and reactive components on top of RxJS, plus a Next.js–based documentation/demo website.
- The core deliverable is an npm package (“react-rx”) for React+RxJS integration; the “website” directory holds docs, examples, and the marketing site.

##### File structure
- Top-level:
– .github/workflows: CI & release pipelines (ci.yml, prettier, react-compiler)
– package.json, pnpm-workspace.yaml: monorepo workspace config
– src/: core library source, tests, build configs (tsconfig.*, vitest)
- “website/”:
– Next.js application (pages/, components/, examples/, utils/, public/)
– Uses its own tsconfig, package.json, theming (theme.config.jsx)
- Config & tooling:
– ESLint (eslint.config.mjs), Prettier (.prettierrc, .prettierignore)
– Release config (releaserc.json), CHANGELOG, LICENSE

##### README for additional insights
- Describes two API styles: “reactiveComponent” and hook utilities (useObservable, useObservableEvent).
- Points to docs/guide, examples, API reference on the website.
- CI & Release via GitHub Actions and semantic-release to npm.

a. Main components
- Core Library Package (src/)
- Test Suite (vitest tests under src/__tests__)
- Documentation Site (website/)
- CI/CD Pipeline (GitHub Actions & Renovate)
- External Services:
– npm registry (publishing)
– GitHub (code host, workflows)
b. Relationships and interactions
- Developers push to GitHub → CI workflows run tests, build, lint, then semantic-release publishes to npm.
- Core Library builds artefact → consumed by Documentation Site directly via workspace link during dev or via npm install in production.
- Website shows examples that import and demonstrate the Core Library APIs.
- Renovate bot auto-opens dependency update PRs.
c. Architectural patterns and design principles
- Monorepo with pnpm workspaces (single source of truth, shared configs).
- Library built in TS, tested with Vitest, linted/formatted centrally.
- Website as a static-site generator (Next.js MDX for guides/examples).
- Strict separation of concerns: “src” for business logic, “website” for docs/UI.
d. Key technologies and frameworks
- React + RxJS (core interop)
- TypeScript (tsconfig.base/build)
- Next.js + MDX (docs site)
- Vitest (unit tests)
- ESLint, Prettier (code quality)
- GitHub Actions (CI, CD)
- Semantic-release (automated versioning)
- Renovate (dependency management)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Monorepo Root
    subgraph "Monorepo Root"
        ROOT_PKG["package.json"] 
        WORKSPACE["pnpm-workspace.yaml"]
    end

    %% Tooling & Configs
    subgraph "Tooling / Configs"
        TS_BASE["tsconfig.base.json"]
        TS_BUILD["tsconfig.build.json"]
        TS_PROJECT["tsconfig.json"]
        VITEST_CFG["vitest.config.ts"]
        VITEST_WS["vitest.workspace.ts"]
        ESLINT["eslint.config.mjs"]
        PRETTIER_RC[".prettierrc"]
        PRETTIER_IGNORE[".prettierignore"]
        RELEASE_CFG[".releaserc.json"]
        CHANGELOG["CHANGELOG.md"]
        LICENSE["LICENSE"]
    end

    %% Core Library
    subgraph "Core Library Package (src)" 
        SRC["src/"]:::core
        ENTRY["index.ts"]:::core
        HOOK1["useObservable.ts"]:::core
        HOOK2["useObservableEvent.ts"]:::core
        TESTS["__tests__/"]:::core
    end

    %% Documentation Site
    subgraph "Documentation & Demo Site (website)" 
        WEB_ROOT["website/"]:::site
        WEB_PKG["package.json"]:::site
        NEXT_CFG["next.config.ts"]:::site
        GLOBALS["globals.d.ts / next-env.d.ts"]:::site
        PAGES["src/pages/"]:::site
        COMPONENTS["src/components/"]:::site
        EXAMPLES["src/examples/"]:::site
        UTIL["src/utils/readFile.ts"]:::site
        THEME["theme.config.jsx"]:::site
        WEB_TS["tsconfig.json"]:::site
        PUBLIC["public/"]:::site
    end

    %% CI/CD Pipeline
    subgraph "CI / CD Pipeline" 
        CI[".github/workflows/ci.yml"]:::ci
        PRETTIER_CI[".github/workflows/prettier.yml"]:::ci
        COMPILER_CI[".github/workflows/react-compiler.yml"]:::ci
        RENOVATE[".github/renovate.json"]:::ci
    end

    %% External Services
    subgraph "External Services"
        GITHUB[(GitHub)]:::external
        NPM[(npm Registry)]:::external
    end

    %% Relationships
    GITHUB -->|push code triggers| CI
    RENOVATE -->|opens PRs| GITHUB
    CI -->|build/test/lint| SRC
    CI -->|publish| NPM
    SRC -->|exports APIs| ENTRY
    ENTRY -->|provides| HOOK1
    ENTRY -->|provides| HOOK2
    SRC -->|tested by| TESTS
    ENTRY -->|consumed by| EXAMPLES
    NPM -->|installed by| WEB_ROOT
    WEB_ROOT -->|imports| ENTRY

    ROOT_PKG --> TOOLING_CFG[&nbsp;] 
    WORKSPACE --> TOOLING_CFG 

    classDef core fill:#cce5ff,stroke:#004085,color:#004085;
    classDef ci fill:#d4edda,stroke:#155724,color:#155724;
    classDef site fill:#fff3cd,stroke:#856404,color:#856404;
    classDef external stroke-dasharray: 5 5,fill:#f8f9fa,stroke:#6c757d,color:#6c757d;

    %% Click Events
    click SRC "https://github.com/sanity-io/react-rx/tree/current/src/"
    click ENTRY "https://github.com/sanity-io/react-rx/blob/current/src/index.ts"
    click HOOK1 "https://github.com/sanity-io/react-rx/blob/current/src/useObservable.ts"
    click HOOK2 "https://github.com/sanity-io/react-rx/blob/current/src/useObservableEvent.ts"
    click TESTS "https://github.com/sanity-io/react-rx/tree/current/src/__tests__/"
    click WORKSPACE "https://github.com/sanity-io/react-rx/blob/current/pnpm-workspace.yaml"
    click ROOT_PKG "https://github.com/sanity-io/react-rx/blob/current/package.json"
    click TS_BASE "https://github.com/sanity-io/react-rx/blob/current/tsconfig.base.json"
    click TS_BUILD "https://github.com/sanity-io/react-rx/blob/current/tsconfig.build.json"
    click TS_PROJECT "https://github.com/sanity-io/react-rx/blob/current/tsconfig.json"
    click VITEST_CFG "https://github.com/sanity-io/react-rx/blob/current/vitest.config.ts"
    click VITEST_WS "https://github.com/sanity-io/react-rx/blob/current/vitest.workspace.ts"
    click ESLINT "https://github.com/sanity-io/react-rx/blob/current/eslint.config.mjs"
    click PRETTIER_RC "https://github.com/sanity-io/react-rx/blob/current/.prettierrc"
    click PRETTIER_IGNORE "https://github.com/sanity-io/react-rx/blob/current/.prettierignore"
    click RELEASE_CFG "https://github.com/sanity-io/react-rx/blob/current/.releaserc.json"
    click CHANGELOG "https://github.com/sanity-io/react-rx/blob/current/CHANGELOG.md"
    click LICENSE "https://github.com/sanity-io/react-rx/tree/current/LICENSE"
    click CI "https://github.com/sanity-io/react-rx/blob/current/.github/workflows/ci.yml"
    click PRETTIER_CI "https://github.com/sanity-io/react-rx/blob/current/.github/workflows/prettier.yml"
    click COMPILER_CI "https://github.com/sanity-io/react-rx/blob/current/.github/workflows/react-compiler.yml"
    click RENOVATE "https://github.com/sanity-io/react-rx/blob/current/.github/renovate.json"
    click WEB_ROOT "https://github.com/sanity-io/react-rx/tree/current/website/"
    click WEB_PKG "https://github.com/sanity-io/react-rx/blob/current/website/package.json"
    click NEXT_CFG "https://github.com/sanity-io/react-rx/blob/current/website/next.config.ts"
    click GLOBALS "https://github.com/sanity-io/react-rx/blob/current/website/globals.d.ts"
    click PAGES "https://github.com/sanity-io/react-rx/tree/current/website/src/pages/"
    click COMPONENTS "https://github.com/sanity-io/react-rx/tree/current/website/src/components/"
    click EXAMPLES "https://github.com/sanity-io/react-rx/tree/current/website/src/examples/"
    click UTIL "https://github.com/sanity-io/react-rx/blob/current/website/src/utils/readFile.ts"
    click THEME "https://github.com/sanity-io/react-rx/blob/current/website/theme.config.jsx"
    click WEB_TS "https://github.com/sanity-io/react-rx/blob/current/website/tsconfig.json"
    click PUBLIC "https://github.com/sanity-io/react-rx/tree/current/website/public/"

    class TOOLING_CFG,TS_BASE,TS_BUILD,TS_PROJECT,VITEST_CFG,VITEST_WS,ESLINT,PRETTIER_RC,PRETTIER_IGNORE,RELEASE_CFG,CHANGELOG,LICENSE core
```
