This is the Coinbase Design System (CDS) - a cross-platform React component library. Primary language: Typescript Package manager: yarn Task runner & monorepo tooling: Nx Runtime: NodeJS (see .nvmrc for version)
- NEVER make commits without being instructed to do so directly
- IMPORTANT: After you are done writing code, ALWAYS perform these tasks:
- run the unit for the specific file(s) you modified
- run typecheck on the specific package(s) you modified
- run the formatter
- For complex tasks, ask clarifying questions to the user before executing
- ALWAYS look for relevant skills and rules you can apply before beginning your work
yarn install- Install dependenciesyarn release- Automates versioning of packages unaffected by changes to keep version numbers in syncyarn clean- Removes all build artifacts, deletes .nx folder and resets the Nx daemonyarn nx reset- Reset Nx daemon cache
ALWAYS run Nx commands using the formats demonstrated by the commands below.
yarn nx show projects- Show all projects in the workspace (project names differ from package names)yarn nx affected --target=test- Run tests only for affected projectsyarn nx run <project>:test- Run tests for a specific projectyarn nx run <project>:test --testNamePattern=<pattern>- Run tests matching patternyarn nx format:write- Formats all files in the workspace with Prettieryarn nx run <project>:lint- Lint a specific projectyarn nx run <project>:typecheck- Check for type errors in a specific projectyarn nx run-many --target=<target1>,<target2>- Run targets for all projectsyarn nx run-many --target=<target1>,<target2> --projects=<project1>,<project2>- Run targets for specific projects
- Platform-specific implementations: Separate implementations for web (React) and mobile (React Native)
- Shared functionality: Common business logic in
packages/commonused across other packages - Theme system: CDS design tokens are themable and applied via CSS variables (web) and styles (react-native) through a ThemeProvider
- Design tokens: Design tokens (e.g. "bgPrimary", "fgMuted") can be used as values for special CDS component "style props" (e.g. "background")
- Component structure: Each component has its own folder with the component, tests, stories, and Figma bindings
- Testing: Tests are written in Typescript and run with Jest.
packages/web/- React web components (@coinbase/cds-web)packages/mobile/- React Native mobile components (@coinbase/cds-mobile)packages/common/- Shared functionality and types (@coinbase/cds-common)packages/icons/- Icon definitions and data (@coinbase/cds-icons)packages/illustrations/- Illustration assets (@coinbase/illustrations)packages/web-visualization/- Web visualization components built with D3 (@coinbase/cds-web-visualization)packages/mobile-visualization/- Mobile visualization components built with D3 and react-native-skia (@coinbase/cds-mobile-visualization)apps/docs/- Public documentation website (Docusaurus)apps/storybook/- Component development and testing environment for cds-webapps/mobile-app/- Sample React Native app for testing components from cds-mobile
- We prefer quality over quantity for unit tests: focus on high-quality tests that provide outsized value before writing exhaustive test cases for coverage.
- Prefer constants over magic numbers: replace hard-coded values with descriptively named constants in camelCase
- Use meaningful names: variables and functions should reveal their purpose
- Code is self-documenting: code shouldn't need comments unless it is unusually complex in which case add brief comments where appropriate
- NEVER use exports marked as deprecated in the codebase when writing code or a plan.
- Always memoize CDS components with
memoHOC - Use
useMemofor expensive computations or for computed/conditional styles - Use
useCallbackfor event handlers passed as props to other components - Use
useEffectonly for side effects (e.g API calls, subscriptions, browser API calls, etc.) - Consult React's docs if you feel you need a useEffect for something else (https://react.dev/learn/you-might-not-need-an-effect)