# reduxjs/redux-toolkit architecture

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

- Interactive diagram: https://gitdiagram.com/reduxjs/redux-toolkit
- Repository: https://github.com/reduxjs/redux-toolkit

## Overview

##### Project type and purpose
- This is an open-source, multi-package monorepo whose primary deliverable is “Redux Toolkit” (a set of utilities for Redux) plus related tools (RTK Query, codemods, code generators, base‐query adapters), documentation, example apps, and a website.

##### File structure
- Top-level directories:
- packages/ ─ houses all npm packages (toolkit core, query, query/react, codemods, codegen-openapi, graphql-request base query)
- docs/ ─ MDX-based API and tutorial content
- website/ ─ Docusaurus site configuration and theme to render docs
- examples/ ─ dozens of sample applications (React, CRA, Vite, Next.js, React-Native, etc.) consuming the toolkit
- CI configs ( .github/workflows/*.yml ) + netlify.toml for docs hosting
- Key config/build files: Yarn v4 workspaces (.yarnrc.yml), TypeScript configs (tsconfig.json), tsup/vite/Docusaurus configs

##### Derive architecture from the README (packages/toolkit/README.md)
- The core “toolkit” package exports APIs like configureStore, createSlice, createAsyncThunk, entity adapters, middleware enhancers (immutability, serializability, listener), plus the RTK Query core and React hooks subpackages.
- Other packages extend or integrate with the core (codemods for migrations, code generators for OpenAPI, GraphQL base query adapters).

##### Main components
a. Monorepo Root (GitHub)
b. Yarn v4 Workspaces linking all internal packages
c. Package Modules (each an npm artifact):
– toolkit/core
– @reduxjs/toolkit/query (core)
– @reduxjs/toolkit/query/react (React hooks)
– rtk-codemods (CLI)
– rtk-query-codegen-openapi (CLI & codegen)
– rtk-query-graphql-request-base-query (adapter)
d. Documentation Layer
– docs/ MDX files → consumed by website/ (Docusaurus) → static site
e. Example Applications
– examples/* projects import from the above packages (local workspaces)
f. CI/CD & Build Pipelines
– GitHub Actions workflows: tests, size checks, codegen, publish
– TypeScript compilers, tsup, vite, Docusaurus builds
g. External Services
– npm registry (publish & dependency fetch)
– Netlify (or similar) for docs site hosting

##### Relationships and interactions
- Developers push to GitHub → triggers GitHub Actions → Lint/Test each package → compile & bundle (tsup/vite)
- On release: version bump → packages published to npm registry
- Examples either consume local workspace packages (during development) or consume published npm versions (in CI/playwright tests)
- docs/ content feeds into website/ (Docusaurus) build → deployed via Netlify using netlify.toml
- Internal packages inter-depend: toolkit/core → query/core → query/react; codemods reference AST of toolkit API; codegen-openapi reads OpenAPI specs → outputs TS code that example apps use

##### Architectural patterns & design principles
- Monorepo with Yarn workspaces for atomic versioning & local linking
- Layered module architecture: core → query core → query React integration
- Plugin/Enhancer pattern for middleware (immutability, serializability, listener)
- CLI tool pattern for codemods & code generators
- Static site generation (SSG) for documentation (Docusaurus)

##### Elements
- workspace linking (monorepo → packages)
- build flows (GitHub Actions → compile/test → npm publish)
- content flows (docs → Docusaurus build → Netlify)
- dependency flows (examples → toolkit packages)

##### Detail level
- Six major package modules under “packages/”
- Two-stage query layering (core vs. React)
- CLI tools (codemods, codegen) as separate entities that consume package APIs
- Example app cluster consuming both local and published versions

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Monorepo Root and Workspace Config
    subgraph "Monorepo Root" 
        MR_Yarn[".yarnrc.yml"]:::cicd
        MR_Pkg["package.json"]:::cicd
    end
    MR_Yarn --> MR_Pkg
    MR_Pkg --> WG["Yarn Workspaces"]:::cicd

    %% Packages Layer
    subgraph "Library Packages" 
        direction TB
        TK_DIR["@reduxjs/toolkit (packages/toolkit)"]:::lib
        TK_SRC["src/"]:::lib
        TK_PKG["package.json"]:::lib

        QCORE_DIR["@reduxjs/toolkit/query (packages/toolkit/query)"]:::lib
        QCORE_PKG["package.json"]:::lib

        QREACT_DIR["@reduxjs/toolkit/query/react (packages/toolkit/query/react)"]:::lib
        QREACT_PKG["package.json"]:::lib

        LEGACY_DIR["@reduxjs/toolkit/react (packages/toolkit/react)"]:::lib
        LEGACY_PKG["package.json"]:::lib

        COD_DIR["rtk-codemods (packages/rtk-codemods)"]:::lib
        COD_CLI["bin/cli.mjs"]:::lib
        COD_TRANS["transforms/"]:::lib

        CG_DIR["rtk-query-codegen-openapi"]:::lib
        CG_CLI["src/bin/cli.ts"]:::lib
        CG_CORE["src/codegen.ts"]:::lib

        GQL_DIR["rtk-query-graphql-request-base-query"]:::lib
        GQL_SRC["src/index.ts"]:::lib
    end
    WG --> TK_DIR
    WG --> QCORE_DIR
    WG --> QREACT_DIR
    WG --> LEGACY_DIR
    WG --> COD_DIR
    WG --> CG_DIR
    WG --> GQL_DIR

    TK_DIR --> TK_SRC
    TK_DIR --> TK_PKG
    QCORE_DIR --> QCORE_PKG
    QREACT_DIR --> QREACT_PKG
    LEGACY_DIR --> LEGACY_PKG
    COD_DIR --> COD_CLI
    COD_DIR --> COD_TRANS
    CG_DIR --> CG_CLI
    CG_DIR --> CG_CORE
    GQL_DIR --> GQL_SRC

    %% Dependency Flows
    TK_DIR --> QCORE_DIR
    QCORE_DIR --> QREACT_DIR
    TK_DIR --> LEGACY_DIR
    COD_DIR --> TK_DIR
    CG_DIR --> TK_DIR
    GQL_DIR --> TK_DIR

    %% Documentation Layer
    subgraph "Documentation & Website" 
        direction TB
        DOCS_DIR["docs/"]:::docs
        DOCS_API["docs/api/"]:::docs
        DOCS_Q["docs/rtk-query/"]:::docs

        WEB_DIR["website/"]:::docs
        WEB_CFG["website/docusaurus.config.ts"]:::docs
        WEB_SRC["website/src/"]:::docs
        WEB_STATIC["website/static/"]:::docs
        NETLIFY_CFG["netlify.toml"]:::docs
    end
    DOCS_DIR --> DOCS_API
    DOCS_DIR --> DOCS_Q
    DOCS_DIR --> WEB_DIR
    WEB_DIR --> WEB_CFG
    WEB_DIR --> WEB_SRC
    WEB_DIR --> WEB_STATIC
    WEB_DIR --> NETLIFY_CFG

    %% Examples Layer
    Examples["examples/"]:::examples

    WG --> Examples

    %% CI/CD & Build Pipelines
    subgraph "CI/CD & Build" 
        direction TB
        GH_TEST[".github/workflows/tests.yml"]:::cicd
        GH_SIZE[".github/workflows/size.yml"]:::cicd
        GH_CODEGEN[".github/workflows/test-codegen.yml"]:::cicd
        GH_PUBLISH[".github/workflows/publish.yml"]:::cicd
    end
    MR_Pkg --> GH_TEST
    MR_Pkg --> GH_SIZE
    MR_Pkg --> GH_CODEGEN
    MR_Pkg --> GH_PUBLISH

    GH_TEST -->|build/test| TK_DIR
    GH_PUBLISH -->|publish| ExternalNPM["npm registry"]:::external

    %% Flows: Examples consumption
    Examples -->|local link| TK_DIR
    Examples -->|local link| QCORE_DIR
    Examples -->|local link| QREACT_DIR

    %% Docs flow to Netlify
    WEB_DIR -->|deploy| ExternalNetlify["Netlify"]:::external

    %% CI builds site
    GH_PUBLISH -->|trigger site build| ExternalNetlify

    %% Click Events
    click MR_Yarn "https://github.com/reduxjs/redux-toolkit/blob/master/.yarnrc.yml"
    click MR_Pkg "https://github.com/reduxjs/redux-toolkit/blob/master/package.json"
    click TK_DIR "https://github.com/reduxjs/redux-toolkit/tree/master/packages/toolkit/"
    click TK_SRC "https://github.com/reduxjs/redux-toolkit/tree/master/packages/toolkit/src/"
    click TK_PKG "https://github.com/reduxjs/redux-toolkit/blob/master/packages/toolkit/package.json"
    click QCORE_DIR "https://github.com/reduxjs/redux-toolkit/tree/master/packages/toolkit/query/"
    click QCORE_PKG "https://github.com/reduxjs/redux-toolkit/blob/master/packages/toolkit/query/package.json"
    click QREACT_DIR "https://github.com/reduxjs/redux-toolkit/tree/master/packages/toolkit/query/react/"
    click QREACT_PKG "https://github.com/reduxjs/redux-toolkit/blob/master/packages/toolkit/query/react/package.json"
    click LEGACY_DIR "https://github.com/reduxjs/redux-toolkit/tree/master/packages/toolkit/react/"
    click LEGACY_PKG "https://github.com/reduxjs/redux-toolkit/blob/master/packages/toolkit/react/package.json"
    click COD_DIR "https://github.com/reduxjs/redux-toolkit/tree/master/packages/rtk-codemods/"
    click COD_CLI "https://github.com/reduxjs/redux-toolkit/blob/master/packages/rtk-codemods/bin/cli.mjs"
    click COD_TRANS "https://github.com/reduxjs/redux-toolkit/tree/master/packages/rtk-codemods/transforms/"
    click CG_DIR "https://github.com/reduxjs/redux-toolkit/tree/master/packages/rtk-query-codegen-openapi/"
    click CG_CLI "https://github.com/reduxjs/redux-toolkit/blob/master/packages/rtk-query-codegen-openapi/src/bin/cli.ts"
    click CG_CORE "https://github.com/reduxjs/redux-toolkit/blob/master/packages/rtk-query-codegen-openapi/src/codegen.ts"
    click GQL_DIR "https://github.com/reduxjs/redux-toolkit/tree/master/packages/rtk-query-graphql-request-base-query/"
    click GQL_SRC "https://github.com/reduxjs/redux-toolkit/blob/master/packages/rtk-query-graphql-request-base-query/src/index.ts"
    click DOCS_DIR "https://github.com/reduxjs/redux-toolkit/tree/master/docs/"
    click DOCS_API "https://github.com/reduxjs/redux-toolkit/tree/master/docs/api/"
    click DOCS_Q "https://github.com/reduxjs/redux-toolkit/tree/master/docs/rtk-query/"
    click WEB_DIR "https://github.com/reduxjs/redux-toolkit/tree/master/website/"
    click WEB_CFG "https://github.com/reduxjs/redux-toolkit/blob/master/website/docusaurus.config.ts"
    click WEB_SRC "https://github.com/reduxjs/redux-toolkit/tree/master/website/src/"
    click WEB_STATIC "https://github.com/reduxjs/redux-toolkit/tree/master/website/static/"
    click NETLIFY_CFG "https://github.com/reduxjs/redux-toolkit/blob/master/netlify.toml"
    click GH_TEST "https://github.com/reduxjs/redux-toolkit/blob/master/.github/workflows/tests.yml"
    click GH_SIZE "https://github.com/reduxjs/redux-toolkit/blob/master/.github/workflows/size.yml"
    click GH_CODEGEN "https://github.com/reduxjs/redux-toolkit/blob/master/.github/workflows/test-codegen.yml"
    click GH_PUBLISH "https://github.com/reduxjs/redux-toolkit/blob/master/.github/workflows/publish.yml"

    %% Styles
    classDef lib fill:#cce5ff,stroke:#888,stroke-width:1px
    classDef docs fill:#d4edda,stroke:#888,stroke-width:1px
    classDef examples fill:#ffe5b4,stroke:#888,stroke-width:1px
    classDef cicd fill:#e2d5f5,stroke:#888,stroke-width:1px
    classDef external fill:#e0e0e0,stroke:#888,stroke-width:1px
```
