|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Package Management & Scripts |
| 6 | + |
| 7 | +This project uses **pnpm** for package management. Common commands: |
| 8 | + |
| 9 | +```bash |
| 10 | +# Development |
| 11 | +pnpm dev # Start development server |
| 12 | +pnpm build # Build for production |
| 13 | +pnpm preview # Preview production build |
| 14 | + |
| 15 | +# Code Quality |
| 16 | +pnpm lint # Lint with Biome |
| 17 | +pnpm lint:fix # Fix linting issues |
| 18 | +pnpm format # Check formatting |
| 19 | +pnpm format:fix # Fix formatting |
| 20 | +pnpm check # Run all checks |
| 21 | +pnpm check:fix # Fix all issues |
| 22 | +``` |
| 23 | + |
| 24 | +**Important**: Always use `pnpm` commands. The project uses Biome (not ESLint/Prettier) for linting and formatting. |
| 25 | + |
| 26 | +## Application Architecture |
| 27 | + |
| 28 | +**Nuwa Client** is a React 19 + TypeScript + Vite application for AI chat with CAP (Conversational AI Programs) creation capabilities, Web3 wallet integration, and decentralized identity. |
| 29 | + |
| 30 | +### Core Technology Stack |
| 31 | + |
| 32 | +- **Frontend**: React 19, TypeScript, Vite, React Router v7 |
| 33 | +- **Styling**: Tailwind CSS + Radix UI components |
| 34 | +- **State**: Zustand with persistence middleware |
| 35 | +- **Storage**: Dexie (IndexedDB) for structured data |
| 36 | +- **AI**: AI SDK (@ai-sdk/react), OpenRouter, LiteLLM providers |
| 37 | +- **Web3**: Reown AppKit, Wagmi, Viem |
| 38 | +- **Identity**: @nuwa-ai/identity-kit (decentralized identity) |
| 39 | +- **Code Quality**: Biome for linting/formatting |
| 40 | + |
| 41 | +### Feature-Based Architecture |
| 42 | + |
| 43 | +The codebase uses a feature-based structure under `src/features/`: |
| 44 | + |
| 45 | +- **`auth/`** - Authentication and authorization |
| 46 | +- **`chat/`** - Core chat functionality with AI models |
| 47 | +- **`cap-studio/`** - CAP creation/editing interface (like an IDE) |
| 48 | +- **`cap-store/`** - CAP marketplace and discovery |
| 49 | +- **`settings/`** - User preferences and configuration |
| 50 | +- **`sidebar/`** - Navigation and chat history |
| 51 | +- **`wallet/`** - Web3 wallet integration and payments |
| 52 | + |
| 53 | +Each feature follows this structure: |
| 54 | +``` |
| 55 | +feature/ |
| 56 | +├── components/ # React components |
| 57 | +├── hooks/ # Custom React hooks |
| 58 | +├── stores.ts # Zustand state stores |
| 59 | +├── services.ts # Business logic |
| 60 | +├── types.ts # TypeScript definitions |
| 61 | +└── utils.ts # Utility functions |
| 62 | +``` |
| 63 | + |
| 64 | +### Key Architectural Concepts |
| 65 | + |
| 66 | +**CAPs (Conversational AI Programs)**: User-configurable AI assistants with custom prompts, models, and MCP (Model Context Protocol) tool integrations. Users can create, edit, and share CAPs. |
| 67 | + |
| 68 | +**MCP Integration**: The app connects to MCP servers to provide tools and capabilities to AI models. Managed by `GlobalMCPManager` singleton. |
| 69 | + |
| 70 | +**Decentralized Identity**: All user data is scoped to their DID (Decentralized Identifier) for privacy and portability. |
| 71 | + |
| 72 | +**Multi-Layer Storage**: |
| 73 | +- Zustand stores (in-memory state) |
| 74 | +- localStorage (user preferences) |
| 75 | +- IndexedDB via Dexie (structured data: chats, CAPs, settings) |
| 76 | + |
| 77 | +### Core Services |
| 78 | + |
| 79 | +**Global Services** (in `src/shared/services/`): |
| 80 | +- **`global-mcp-manager.ts`** - Manages MCP server connections and tool registration |
| 81 | +- **`identity-kit.ts`** - Decentralized identity management |
| 82 | +- **`mcp-client.ts`** - Model Context Protocol client |
| 83 | +- **`authorized-fetch.ts`** - Authenticated HTTP requests |
| 84 | + |
| 85 | +**Key Data Entities**: |
| 86 | +- **ChatSession** - Chat conversations with message history |
| 87 | +- **Cap** - AI assistant configuration (prompt, model, MCP servers) |
| 88 | +- **Settings** - User preferences and app configuration |
| 89 | + |
| 90 | +### UI Components |
| 91 | + |
| 92 | +**Shared Components** (in `src/shared/components/ui/`): |
| 93 | +- Based on Radix UI primitives with Tailwind styling |
| 94 | +- Do not modify files in `ui/` folder - they are generated components |
| 95 | +- For custom components, create in feature-specific `components/` folders |
| 96 | + |
| 97 | +### Development Patterns |
| 98 | + |
| 99 | +**State Management**: |
| 100 | +- Use Zustand stores with persistence middleware |
| 101 | +- Store files typically export both store and selectors |
| 102 | +- User data automatically scoped by DID |
| 103 | + |
| 104 | +**Data Fetching**: |
| 105 | +- Use SWR for server state management |
| 106 | +- Custom hooks in feature `hooks/` folders |
| 107 | +- Services handle business logic and API calls |
| 108 | + |
| 109 | +**Routing**: |
| 110 | +- React Router v7 with nested layouts |
| 111 | +- Route components in `src/pages/` |
| 112 | +- Layout components in `src/layout/` |
| 113 | + |
| 114 | +**Styling**: |
| 115 | +- Tailwind CSS with custom design system |
| 116 | +- Radix UI for accessible primitives |
| 117 | +- Theme support via next-themes |
| 118 | + |
| 119 | +### Important Files |
| 120 | + |
| 121 | +- **`src/main.tsx`** - Application entry point |
| 122 | +- **`src/router.tsx`** - Route configuration |
| 123 | +- **`src/layout/main-layout.tsx`** - Main application layout |
| 124 | +- **`biome.json`** - Biome configuration for linting/formatting |
| 125 | +- **`tailwind.config.ts`** - Tailwind CSS configuration |
| 126 | + |
| 127 | +### Development Notes |
| 128 | + |
| 129 | +- The app supports both light and dark themes |
| 130 | +- All user interfaces are internationalized (i18n support) |
| 131 | +- Web3 functionality uses Reown AppKit for wallet connections |
| 132 | +- AI model switching is supported via the model selector |
| 133 | +- MCP servers can be dynamically added/removed per CAP |
0 commit comments