|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Grill is a modern Solana development kit monorepo that provides React components and utilities for building Solana applications with automatic account batching and caching. It's built on top of gill-react and integrates with @solana/kit. |
| 8 | + |
| 9 | +## Technology Stack |
| 10 | + |
| 11 | +- **Package Manager**: Bun (v1.2.19) |
| 12 | +- **Build System**: Turbo for monorepo orchestration |
| 13 | +- **Framework**: React 19 with TypeScript |
| 14 | +- **Solana**: @solana/kit, gill, gill-react |
| 15 | +- **State Management**: @tanstack/react-query for caching |
| 16 | +- **Routing**: @tanstack/react-router (in example-dapp) |
| 17 | +- **Styling**: Tailwind CSS v4 with shadcn/ui components |
| 18 | +- **Code Quality**: Biome for formatting, ESLint for linting |
| 19 | +- **Testing**: Vitest |
| 20 | + |
| 21 | +## Essential Commands |
| 22 | + |
| 23 | +```bash |
| 24 | +# Development |
| 25 | +bun install # Install all dependencies |
| 26 | +bun run build # Build all packages |
| 27 | +bun run build:watch # Watch mode for all packages |
| 28 | +bun run build:watch:packages # Watch mode for packages only |
| 29 | + |
| 30 | +# Code Quality |
| 31 | +bun run lint # Run biome check + eslint |
| 32 | +bun run lint:fix # Fix linting issues |
| 33 | +biome check --write # Format with biome |
| 34 | + |
| 35 | +# Testing |
| 36 | +bun run test # Run all tests |
| 37 | +bun test # Run tests directly |
| 38 | + |
| 39 | +# Package Publishing |
| 40 | +bun run changeset # Create changeset for version bumps |
| 41 | +bun run ci:publish # Publish packages to npm |
| 42 | + |
| 43 | +# Example App Development |
| 44 | +cd apps/example-dapp |
| 45 | +bun run dev # Start Vite dev server |
| 46 | +bun run build # Build the app |
| 47 | +``` |
| 48 | + |
| 49 | +## Architecture |
| 50 | + |
| 51 | +### Monorepo Structure |
| 52 | + |
| 53 | +The project uses Bun workspaces with packages in two directories: |
| 54 | +- `packages/*` - Core library packages |
| 55 | +- `apps/*` - Example applications |
| 56 | + |
| 57 | +### Core Packages |
| 58 | + |
| 59 | +1. **@macalinao/grill** - Main package providing React context and hooks |
| 60 | + - `GrillProvider`: Creates DataLoader for batching account requests |
| 61 | + - `WalletProvider`: Kit wallet integration context |
| 62 | + - `useAccount`: Hook for fetching account data with batching |
| 63 | + - `useKitWallet`: Access wallet signer and RPC |
| 64 | + |
| 65 | +2. **@macalinao/solana-batch-accounts-loader** - DataLoader implementation for batching Solana account fetches |
| 66 | + |
| 67 | +3. **@macalinao/wallet-adapter-compat** - Compatibility layer between @solana/wallet-adapter and @solana/kit |
| 68 | + |
| 69 | +4. **dataloader-es** - ES module compatible DataLoader implementation |
| 70 | + |
| 71 | +### Provider Hierarchy |
| 72 | + |
| 73 | +When using Grill, providers must be set up in this order: |
| 74 | +```tsx |
| 75 | +QueryClientProvider |
| 76 | + → SolanaProvider (gill-react) |
| 77 | + → ConnectionProvider (@solana/wallet-adapter-react) |
| 78 | + → WalletProvider (@solana/wallet-adapter-react) |
| 79 | + → WalletModalProvider |
| 80 | + → GrillProvider |
| 81 | +``` |
| 82 | + |
| 83 | +### Account Batching Architecture |
| 84 | + |
| 85 | +The core innovation is automatic batching of concurrent account requests: |
| 86 | +- Multiple `useAccount` calls in different components are automatically batched |
| 87 | +- Uses DataLoader pattern to coalesce requests within a tick |
| 88 | +- Single RPC call instead of multiple, improving performance |
| 89 | +- Integrated with React Query for caching |
| 90 | + |
| 91 | +### Kit Wallet Integration |
| 92 | + |
| 93 | +Provides two contexts: |
| 94 | +1. Account batching context (GrillProvider) |
| 95 | +2. Wallet context for TransactionSendingSigner (WalletProvider from grill) |
| 96 | + |
| 97 | +## Code Style Guidelines |
| 98 | + |
| 99 | +### TypeScript |
| 100 | +- Use specific types, avoid `any` |
| 101 | +- Prefer interfaces over type aliases for objects |
| 102 | +- Use `import type` for type-only imports (enforced by Biome) |
| 103 | +- Arrays use shorthand syntax: `string[]` not `Array<string>` |
| 104 | +- **Use double quotes for strings** (not single quotes) |
| 105 | +- Follow default Prettier settings |
| 106 | + |
| 107 | +### React Components |
| 108 | +- Small, focused components |
| 109 | +- Use function components with hooks |
| 110 | +- Props interfaces should be explicitly defined |
| 111 | +- File structure: `components/category/component-name/index.tsx` |
| 112 | + |
| 113 | +### Biome/ESLint Configuration |
| 114 | +- No floating promises (must be handled) |
| 115 | +- Use const assertions where applicable |
| 116 | +- No non-null assertions are allowed |
| 117 | +- Simplified logic expressions required |
| 118 | +- No double equals (use === instead) |
| 119 | +- Imports are auto-organized on save |
| 120 | + |
| 121 | +## Example App (example-dapp) |
| 122 | + |
| 123 | +The example-dapp demonstrates: |
| 124 | +- TanStack Router for routing |
| 125 | +- shadcn/ui component integration |
| 126 | +- Wallet connection with Solana wallet adapter |
| 127 | +- Layout system with navigation and sidebar |
| 128 | +- Dark mode support |
| 129 | + |
| 130 | +Routes: |
| 131 | +- `/` - Home page |
| 132 | +- `/dashboard` - Simple dashboard |
| 133 | +- `/examples/*` - Examples section with sidebar navigation |
| 134 | + |
| 135 | +## Turborepo Configuration |
| 136 | + |
| 137 | +Tasks are defined in turbo.json: |
| 138 | +- `build`: Depends on upstream builds, outputs to `./dist/**` |
| 139 | +- `lint`: Depends on upstream builds |
| 140 | +- `test`: Depends on build, no caching |
| 141 | +- Tasks run in topological order respecting dependencies |
| 142 | + |
| 143 | +## Working with Providers |
| 144 | + |
| 145 | +When creating new features that need account data: |
| 146 | +1. Ensure component is wrapped in GrillProvider |
| 147 | +2. Use `useAccount` hook for fetching account data |
| 148 | +3. Account requests are automatically batched |
| 149 | +4. React Query handles caching and refetching |
| 150 | + |
| 151 | +## Vendor Documentation |
| 152 | + |
| 153 | +The repository includes vendor documentation at `/docs/vendor/`: |
| 154 | +- `gill.md` - Complete documentation for the gill library (Solana client library) |
| 155 | + - Includes transaction builders, token operations, and program clients |
| 156 | + - Used as the foundation for Solana operations in Grill |
| 157 | + |
| 158 | +## CI/CD |
| 159 | + |
| 160 | +GitHub Actions workflow runs on push/PR to master: |
| 161 | +- Installs dependencies with frozen lockfile |
| 162 | +- Builds all packages |
| 163 | +- Runs linting (biome + eslint) |
| 164 | +- Runs tests |
| 165 | +- Checks TypeScript compilation |
| 166 | + |
| 167 | +## Publishing Workflow |
| 168 | + |
| 169 | +1. Create changeset: `bun run changeset` |
| 170 | +2. Version packages: `bun run ci:version` |
| 171 | +3. Publish to npm: `bun run ci:publish` |
| 172 | +4. Changesets handle version bumping and changelog generation |
0 commit comments