How reduxjs/redux-toolkit works
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