How gadget-inc/js-clients works
Main Components
• Monorepo Structure and Tooling:
– The repository is managed as a monorepo using tools like PNPM (see pnpm-lock.yaml and pnpm-workspace.yaml) to manage multiple packages. This central management is key for handling versioning, dependency resolution, and cross-package integrations.
– There are shared scripts, configurations (eslintrc, prettier, flake.nix, tsconfig files), and CI/CD pipelines (GitHub workflows and actions) that apply across the repository.
• Core Packages:
– API Client Core: Under packages/api-client-core, this library contains the heart of the client functionality. It provides helper functions, types, and exchange logic that are used across different generated clients. It also sets up the operations (building and running queries, mutations, live queries) and handles internal model management.
– React Bindings: Under packages/react, this package contains the React-specific integrations for Gadget. It exposes components such as GadgetProvider, auto forms, auto tables, authentication components, hooks (useAction, useFetch, useFindOne, etc.) and a wide range of auto-generated modules for integration with React.
– Shopify Integration Libraries:
▪ React Shopify App Bridge: Located in packages/react-shopify-app-bridge, it provides React components tailored to Shopify’s App Bridge. It integrates Gadget’s backend functionality with Shopify’s ecosystem.
▪ Shopify Extensions: Located in packages/shopify-extensions, it contains utilities for working with Shopify UI extensions (both React and plain JavaScript).
– Additional Packages:
– There are example projects (e.g., packages/blog-example) demonstrating usage.
– Other utility or testing packages, such as the test-bundles used to verify output or a tiny GraphQL query compiler (packages/tiny-graphql-query-compiler).
Relationships and Interactions
• The React package exposes UI components and hooks; these components may further consume the core functions as well as interfaces from both the API Client Core and potentially from Shopify Extensions if integration with Shopify is needed.
• The monorepo also includes CI/CD pipelines (workflows under .github/workflows and actions) that govern automated testing and releases. These should be represented as supporting infrastructure that interconnects with all packages.
Architectural Patterns and Design Principles
• Modularity: The design leverages distinct modules (packages) for each concern: core functionality, framework-specific bindings, and external integrations.
• Dependency Injection: React bindings and Shopify components rely on a common core, which minimizes redundant code and encourages reusability.
• Separation of Concerns: Different directories, such as src, spec, tests, and configuration files, help delineate business logic from testing, configuration, and usage examples.
• Extensibility: Given the multiple “auto” components and hooks in the React package, the project is designed to be extensible for different application needs and integration scenarios.