|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Development Commands |
| 6 | + |
| 7 | +### Core Development |
| 8 | + |
| 9 | +- `pnpm dev` - Starts all development servers in parallel: |
| 10 | + - localhost:3002 (Next.js example) |
| 11 | + - localhost:5174 (Svelte example) |
| 12 | + - localhost:3001 (Keychain) |
| 13 | + - localhost:3003 (Profile) |
| 14 | +- `pnpm build` - Builds all packages and dependencies |
| 15 | +- `pnpm storybook` - Launches Storybook for component development |
| 16 | + |
| 17 | +### Testing |
| 18 | + |
| 19 | +- `pnpm test` - Runs keychain test suite |
| 20 | +- `pnpm test:ci` - Runs tests in CI mode |
| 21 | +- `pnpm test:storybook` - Runs Storybook visual regression tests |
| 22 | +- `pnpm e2e` - Runs end-to-end tests with Playwright |
| 23 | +- `pnpm e2e:ui` - Runs E2E tests with UI |
| 24 | + |
| 25 | +### Code Quality |
| 26 | + |
| 27 | +- `pnpm lint` - Runs linting and format checking |
| 28 | +- `pnpm format` - Runs formatting and lint fixes |
| 29 | + |
| 30 | +### Package Management |
| 31 | + |
| 32 | +- `pnpm i` - Install dependencies |
| 33 | +- `pnpm clean` - Clean all build artifacts and prune store |
| 34 | +- `corepack enable pnpm` - Enable pnpm via corepack |
| 35 | + |
| 36 | +## Architecture Overview |
| 37 | + |
| 38 | +### Project Structure |
| 39 | + |
| 40 | +This is a **monorepo** using **pnpm workspaces** and **Turbo** for build orchestration. The project implements a gaming-specific smart contract wallet ecosystem for StarkNet. |
| 41 | + |
| 42 | +### Core Packages (`/packages/`) |
| 43 | + |
| 44 | +**Primary Applications:** |
| 45 | + |
| 46 | +- **`controller/`** - Main SDK implementing StarkNet account interfaces. Implements account abstractions and communicates with embedded keychain iframe for secure operations. |
| 47 | +- **`keychain/`** - Sandboxed React app (<https://x.cartridge.gg/>) responsible for sensitive operations like transaction signing, user authentication, and key management. |
| 48 | +- **`profile/`** - React app (<https://profile.cartridge.gg/>) for displaying account state, balances, activities, and achievements. |
| 49 | +- **`connector/`** - Lightweight connector interface for easy integration with StarkNet React applications. |
| 50 | + |
| 51 | +**Supporting Packages:** |
| 52 | + |
| 53 | +- **`eslint/`** - Shared ESLint configuration |
| 54 | +- **`tsconfig/`** - Shared TypeScript configuration |
| 55 | +- **`torii-config/`** - Token metadata configuration |
| 56 | + |
| 57 | +### Integration Examples (`/examples/`) |
| 58 | + |
| 59 | +- **`next/`** - Next.js integration example with full transaction signing |
| 60 | +- **`svelte/`** - Svelte integration example |
| 61 | +- **`node/`** - Node.js server-side usage example |
| 62 | + |
| 63 | +### Technology Stack |
| 64 | + |
| 65 | +- **Frontend**: React, TypeScript, Next.js, Svelte, TailwindCSS, Vite |
| 66 | +- **Blockchain**: StarkNet, starknet.js |
| 67 | +- **Testing**: Jest, Playwright, Storybook |
| 68 | +- **Build**: Turbo, pnpm workspaces |
| 69 | +- **Authentication**: WebAuthn/Passkeys, Session Tokens |
| 70 | + |
| 71 | +### Security Architecture |
| 72 | + |
| 73 | +The project uses an **iframe-based security model** where: |
| 74 | + |
| 75 | +- Sensitive operations (key management, signing) occur in the sandboxed keychain iframe |
| 76 | +- Controller SDK communicates with keychain via secure postMessage |
| 77 | +- Session tokens enable seamless gaming UX while maintaining security |
| 78 | +- WebAuthn/Passkeys provide passwordless authentication |
| 79 | + |
| 80 | +### Development Workflow |
| 81 | + |
| 82 | +1. **Monorepo Dependencies**: `pnpm dev` automatically handles workspace dependencies |
| 83 | +2. **Visual Testing**: Storybook provides component isolation and visual regression testing |
| 84 | +3. **Account Import**: For local development, export accounts from production keychain using `window.cartridge.exportAccount()` and import with `window.cartridge.importAccount()` |
| 85 | + |
| 86 | +### Key Integration Points |
| 87 | + |
| 88 | +- **Multi-wallet Support**: Integrates with MetaMask, Solana wallets, etc. |
| 89 | +- **Session Management**: Gaming-optimized session tokens for reduced signing friction |
| 90 | +- **GraphQL Data Layer**: Account information and state management |
| 91 | +- **Stripe Integration**: Fiat payment processing |
| 92 | +- **Cross-platform**: Web, mobile WebView support |
| 93 | + |
| 94 | +### File Architecture Notes |
| 95 | + |
| 96 | +- **Storybook snapshots** in `__image_snapshots__/` for visual regression testing |
| 97 | +- **Example apps** demonstrate various integration patterns |
| 98 | + |
| 99 | +## Claude Code Workflow Guidelines |
| 100 | + |
| 101 | +### Code Quality Requirements |
| 102 | + |
| 103 | +- **Always run linting/formatting** before committing: `pnpm lint` and `pnpm format` |
| 104 | +- **TypeScript compliance** - All TypeScript errors must be resolved |
| 105 | +- **Test coverage** - Run relevant tests after making changes: `pnpm test` for unit tests, `pnpm test:storybook` for visual regression |
| 106 | + |
| 107 | +### Common Development Tasks |
| 108 | + |
| 109 | +**Working with Components:** |
| 110 | + |
| 111 | +- After modifying components, run `pnpm storybook` to verify visually |
| 112 | +- Update Storybook snapshots with `pnpm test:storybook:update` if needed |
| 113 | + |
| 114 | +**Adding New Features:** |
| 115 | + |
| 116 | +- Check existing patterns in `packages/controller/src/` for SDK features |
| 117 | +- For UI changes, update both keychain (`packages/keychain/`) and profile (`packages/profile/`) as needed |
| 118 | +- Test integration with examples in `examples/next/` or `examples/svelte/` |
| 119 | + |
| 120 | +**Debugging Integration Issues:** |
| 121 | + |
| 122 | +- Use browser dev tools with local keychain at <http://localhost:3001> |
| 123 | +- Account import/export via `window.cartridge.exportAccount()` and `window.cartridge.importAccount()` |
| 124 | +- Check iframe communication between controller and keychain |
| 125 | + |
| 126 | +**Monorepo Navigation:** |
| 127 | + |
| 128 | +- Use `pnpm --filter <package-name>` to run commands in specific packages |
| 129 | +- Common filters: `@cartridge/controller`, `@cartridge/keychain`, `@cartridge/profile`, `@cartridge/connector` |
| 130 | +- Dependencies are automatically linked via workspace protocol |
| 131 | + |
| 132 | +### Testing Strategy |
| 133 | + |
| 134 | +- **Unit tests** in individual packages (Jest) |
| 135 | +- **Visual regression** via Storybook snapshots |
| 136 | +- **E2E testing** with Playwright for full user flows |
| 137 | +- **Integration testing** via example applications |
| 138 | + |
| 139 | +### Key Files to Check When Making Changes |
| 140 | + |
| 141 | +- `packages/controller/src/index.ts` - Main SDK exports |
| 142 | +- `packages/keychain/src/components/` - UI components for wallet operations |
| 143 | +- `turbo.json` - Build dependencies and caching |
| 144 | +- `pnpm-workspace.yaml` - Package workspace configuration |
0 commit comments