pmndrs/zustand architecture
Zustand is a modular monolith state management library for React, implemented in TypeScript. It features a core state engine responsible for store creation, state mutation, and listener management, which is extended by middleware modules providing persistence, Redux compatibility, devtools integration, and immutability support. React bindings expose hooks for consuming store state, supporting both basic and advanced usage patterns. The architecture is layered and modular, emphasizing extensibility, type safety, and developer experience. The system includes comprehensive testing, example applications, configuration management, and documentation, making Zustand a flexible and reliable choice for React state management.
Architecture: modular monolith. Built with TypeScript, JavaScript, React, Vite, ESLint, Prettier, Rollup, Vitest, Immer, Redux DevTools, Three.js, prism-react-renderer.
- Core State Engine: Implements the core state container logic, including store creation, state mutation, and listener management. This is the foundation of Zustand's state management capabilities.
- Type Definitions: TypeScript type definitions and interfaces for the core API, middleware, and store creators, ensuring type safety across the codebase.
- Middleware: Provides middleware functions that extend store capabilities, such as persistence, Redux compatibility, devtools integration, immutability (Immer), and SSR safety.
- Public API: Implements the main public API entry point, re-exporting core and middleware features for external consumption.
- React Bindings: Provides React-specific hooks and utilities for binding Zustand stores to React components, including the main useStore hook and store creation helpers.
- Advanced React Bindings: Implements alternative store creation and usage patterns, such as equality function support for selectors, for advanced React integration.
- Testing: Comprehensive test suite covering core, middleware, and React bindings, ensuring correctness and regression prevention.
- Examples: Example React applications demonstrating Zustand usage, including advanced 3D scenes and basic starter templates.
- Configuration: Project configuration for building, linting, formatting, and managing dependencies, including Vite, ESLint, TypeScript, and Rollup.
- Documentation: Documentation, guides, and markdown files for user and contributor reference.