|
| 1 | +# Cookie Jar - AI Agent Integration Guide |
| 2 | + |
| 3 | +> **Comprehensive guidelines for AI coding agents working on the Cookie Jar protocol** |
| 4 | +
|
| 5 | +## 📋 Quick Reference |
| 6 | + |
| 7 | +- **Root Rules**: [`.cursor/rules.md`](.cursor/rules.md) - Monorepo workflow & Guild standards |
| 8 | +- **Frontend Rules**: [`client/.cursor/rules.md`](client/.cursor/rules.md) - Next.js + React + Web3 patterns |
| 9 | +- **Contract Rules**: [`contracts/.cursor/rules.md`](contracts/.cursor/rules.md) - Solidity + Foundry standards |
| 10 | +- **E2E Rules**: [`e2e/.cursor/rules.md`](e2e/.cursor/rules.md) - Playwright testing patterns |
| 11 | + |
| 12 | +## 🎯 Project Context |
| 13 | + |
| 14 | +**Cookie Jar Protocol**: Decentralized funding pools with smart access control supporting allowlist, NFT, POAP, Unlock Protocol, Hypercerts, and Hats Protocol gating plus configurable withdrawal rules. |
| 15 | + |
| 16 | +**Architecture**: Monorepo with client (Next.js), contracts (Foundry), and e2e (Playwright) packages. |
| 17 | + |
| 18 | +## 🚀 Development Environment Setup |
| 19 | + |
| 20 | +```bash |
| 21 | +# Zero-configuration setup |
| 22 | +git clone https://github.com/greenpill-dev-guild/cookie-jar.git |
| 23 | +cd cookie-jar |
| 24 | +npm install # Auto-installs pnpm + Foundry + dependencies |
| 25 | +npm run dev # Starts Anvil + deploys contracts + launches frontend |
| 26 | +``` |
| 27 | + |
| 28 | +**Auto-included**: Local blockchain, pre-seeded demo jars, hot reload, type generation. |
| 29 | + |
| 30 | +## 🏗️ Architecture Overview |
| 31 | + |
| 32 | +### Core Components |
| 33 | +1. **CookieJarFactory**: Protocol access control + jar deployments |
| 34 | +2. **CookieJar**: Individual jar logic + withdrawal controls |
| 35 | +3. **CookieJarRegistry**: Metadata storage + jar lookup |
| 36 | +4. **Frontend**: Next.js PWA with Web3 integrations |
| 37 | +5. **E2E Tests**: Comprehensive Playwright test suite |
| 38 | + |
| 39 | +### Tech Stack |
| 40 | +- **Frontend**: Next.js 15 + React 18 + TypeScript + Tailwind + viem/wagmi |
| 41 | +- **Contracts**: Foundry + Solidity ^0.8.0 + OpenZeppelin |
| 42 | +- **Testing**: Vitest + React Testing Library + Playwright + Foundry |
| 43 | +- **Protocols**: POAP + Unlock + Hypercerts + Hats + Alchemy NFT API |
| 44 | + |
| 45 | +## 🎨 AI Agent Workflow |
| 46 | + |
| 47 | +### 1. Understanding Context |
| 48 | +Before making changes: |
| 49 | +- Review the specific `.cursor/rules.md` file for the area you're working in |
| 50 | +- Check existing patterns in similar components/contracts |
| 51 | +- Understand the user flow impact of your changes |
| 52 | + |
| 53 | +### 2. Development Approach |
| 54 | +```bash |
| 55 | +# Always start development environment first |
| 56 | +pnpm dev # This is critical - starts blockchain + contracts + frontend |
| 57 | + |
| 58 | +# Run relevant tests frequently |
| 59 | +pnpm test # All packages |
| 60 | +pnpm test:coverage # Ensure 90%+ coverage maintained |
| 61 | +pnpm test:e2e # Full user flow validation |
| 62 | +``` |
| 63 | + |
| 64 | +### 3. Code Quality Checklist |
| 65 | +- [ ] **TypeScript strict mode** - No `any` types, explicit interfaces |
| 66 | +- [ ] **Tests written** - Unit tests + integration tests as needed |
| 67 | +- [ ] **Documentation updated** - NatSpec for contracts, JSDoc for complex functions |
| 68 | +- [ ] **Accessibility verified** - WCAG 2.1 AA compliance for UI changes |
| 69 | +- [ ] **Security reviewed** - Especially for smart contract modifications |
| 70 | +- [ ] **Performance considered** - Bundle size impact, gas optimization |
| 71 | + |
| 72 | +### 4. Web3-Specific Considerations |
| 73 | +- **Always use viem/wagmi** (never ethers.js) |
| 74 | +- **Default to testnets** unless explicitly confirmed for mainnet |
| 75 | +- **Include gas estimation** and error handling for all transactions |
| 76 | +- **Validate chain IDs** before any blockchain interactions |
| 77 | +- **Use official protocol SDKs** (POAP, Unlock, etc.) not custom implementations |
| 78 | + |
| 79 | +## 📚 Domain-Specific Guidance |
| 80 | + |
| 81 | +### Frontend Development (`client/`) |
| 82 | +- Follow [client rules](client/.cursor/rules.md) for Next.js patterns |
| 83 | +- Use shadcn/ui components for complex UI elements |
| 84 | +- Implement proper loading/error states for all async operations |
| 85 | +- Ensure mobile-first responsive design |
| 86 | + |
| 87 | +### Smart Contract Development (`contracts/`) |
| 88 | +- Follow [contract rules](contracts/.cursor/rules.md) for Solidity patterns |
| 89 | +- Use OpenZeppelin libraries for standard functionality |
| 90 | +- Include comprehensive NatSpec documentation |
| 91 | +- Implement proper access controls and security measures |
| 92 | + |
| 93 | +### Testing (`__tests__/`, `e2e/`) |
| 94 | +- Follow [e2e rules](e2e/.cursor/rules.md) for testing patterns |
| 95 | +- Write user-centric test flows, not component-specific tests |
| 96 | +- Ensure accessibility compliance in e2e tests |
| 97 | +- Maintain high test coverage across all packages |
| 98 | + |
| 99 | +## 🔒 Security & Best Practices |
| 100 | + |
| 101 | +### Smart Contract Security |
| 102 | +- **Reentrancy protection**: Use OpenZeppelin's ReentrancyGuard |
| 103 | +- **Access control**: Implement role-based permissions properly |
| 104 | +- **Input validation**: Validate all parameters with custom errors |
| 105 | +- **Gas optimization**: Consider gas costs in all implementations |
| 106 | + |
| 107 | +### Frontend Security |
| 108 | +- **Environment variables**: Never expose private keys or secrets |
| 109 | +- **Input sanitization**: Validate all user inputs |
| 110 | +- **Error handling**: Don't expose internal errors to users |
| 111 | +- **CSP headers**: Implement proper content security policies |
| 112 | + |
| 113 | +## 🎯 Common Patterns & Conventions |
| 114 | + |
| 115 | +### Naming Conventions |
| 116 | +- **Files**: kebab-case (`cookie-jar-factory.ts`) |
| 117 | +- **Components**: PascalCase (`CookieJarCard.tsx`) |
| 118 | +- **Functions**: camelCase (`getUserJars()`) |
| 119 | +- **Constants**: UPPER_SNAKE_CASE (`MAX_WITHDRAWAL_AMOUNT`) |
| 120 | +- **Contracts**: PascalCase (`CookieJarFactory.sol`) |
| 121 | + |
| 122 | +### Git & PR Workflow |
| 123 | +- **Conventional commits**: `feat:`, `fix:`, `chore:`, `docs:` |
| 124 | +- **Small focused PRs**: One feature/fix per PR |
| 125 | +- **Comprehensive descriptions**: Explain what, why, and how |
| 126 | +- **Link issues**: Always reference related GitHub issues |
| 127 | + |
| 128 | +## 🚨 Critical Reminders |
| 129 | + |
| 130 | +### Before Any Deployment |
| 131 | +- [ ] All tests passing (`pnpm test`) |
| 132 | +- [ ] No TypeScript errors (`pnpm type-check`) |
| 133 | +- [ ] Linting passes (`pnpm lint`) |
| 134 | +- [ ] Coverage maintained (`pnpm test:coverage`) |
| 135 | +- [ ] E2E tests validate user flows (`pnpm test:e2e`) |
| 136 | + |
| 137 | +### Web3 Deployment Checklist |
| 138 | +- [ ] Contracts verified on block explorer |
| 139 | +- [ ] Gas estimation reasonable for target users |
| 140 | +- [ ] Access controls properly configured |
| 141 | +- [ ] Emergency pause functionality tested (if applicable) |
| 142 | + |
| 143 | +### Frontend Deployment Checklist |
| 144 | +- [ ] Core Web Vitals meet targets |
| 145 | +- [ ] Accessibility compliance verified |
| 146 | +- [ ] Mobile responsiveness tested |
| 147 | +- [ ] Error boundaries handle edge cases |
| 148 | + |
| 149 | +## 📞 Getting Help & Resources |
| 150 | + |
| 151 | +- **Codebase Questions**: Search existing code patterns before creating new ones |
| 152 | +- **Protocol Integration**: Refer to official SDK documentation |
| 153 | +- **Testing Issues**: Check existing test files for similar patterns |
| 154 | +- **Performance Problems**: Use Next.js bundle analyzer and Foundry gas reports |
| 155 | + |
| 156 | +## 🔄 Continuous Improvement |
| 157 | + |
| 158 | +As you work on Cookie Jar: |
| 159 | +- **Learn from patterns**: Study existing successful implementations |
| 160 | +- **Share improvements**: Document new patterns that work well |
| 161 | +- **Ask when uncertain**: Better to clarify than assume |
| 162 | +- **Test thoroughly**: User experience is paramount |
| 163 | + |
| 164 | +--- |
| 165 | + |
| 166 | +*This guide evolves with the project. When you discover better patterns or practices, update the relevant rule files to help future development.* |
0 commit comments