This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is an official Cloudflare product - a React+Vite frontend with Cloudflare Workers backend that features a Durable Object-based AI agent capable of building webapps phase-wise from user prompts.
Important Context:
- Core functionality: AI-powered webapp generation via Durable Objects
- Authentication system and database schemas are currently under development (existing code is AI-generated and needs review/rewrite)
- Full Cloudflare stack: Workers, D1, Durable Objects, R2 (planned)
- All tests in the project are AI-generated and need replacement
npm run dev # Start Vite dev server with hot reload
npm run build # Build production frontend
npm run lint # Run ESLint
npm run preview # Preview production buildnpm run local # Run Worker locally with Wrangler
npm run cf-typegen # Generate TypeScript types for CF bindings
npm run deploy # Deploy to Cloudflare Workers + secretsnpm run db:setup # Initial database setup
npm run db:generate # Generate migrations (local)
npm run db:migrate:local # Apply migrations locally
npm run db:migrate:remote # Apply migrations to production
npm run db:studio # Open Drizzle Studio for local DBnpm run test # Run Jest tests (current tests need replacement)The heart of the system is the CodeGeneratorAgent Durable Object that implements sophisticated code generation:
- Blueprint Phase: Analyzes user requirements and creates project blueprint
- Incremental Generation: Generates code phase-by-phase with specific files per phase
- SCOF Protocol: Structured Code Output Format for streaming generated code
- Review Cycles: Multiple automated review passes including:
- Static analysis (linting, type checking)
- Runtime validation via Runner Service
- AI-powered error detection and fixes
- Diff Support: Efficient file updates using unified diff format
- Durable Object:
worker/agents/codegen/phasewiseGenerator.ts- Stateful code generation - State Management:
worker/agents/codegen/state.ts- Generation state tracking - WebSocket Protocol: Real-time streaming of generation progress
- Runner Service: External service for code execution and validation
- Initial Request: POST
/api/agent - WebSocket Connection:
/api/agent/:agentId/wsfor real-time updates - Message Types: Typed protocol for file updates, errors, phase transitions
Current implementation in worker/auth/ and worker/api/controllers/authController.ts:
- OAuth providers (Google, GitHub) - needs production hardening
- JWT session management - requires security review
- Database schema for users/sessions - needs optimization
- Currently using Drizzle ORM with D1
- Schema in
worker/database/schema.ts- under active development - Migration system needs refinement
- All current tests are AI-generated placeholders
- Need proper unit tests for core generation logic
- Integration tests for Durable Objects
- E2E tests for generation workflow
- Modify agent logic in
worker/agents/codegen/phasewiseGenerator.ts - Update state types in
worker/agents/codegen/state.ts - Add new message types for WebSocket protocol
- Update frontend handler in
src/routes/chat/hooks/use-chat.ts
- Durable Objects: Used for stateful, long-running operations
- D1 Database: SQLite-based, use batch operations for performance
- Environment Bindings: Access via
envparameter (AI, DB, CodeGenObject) - Service Bindings: Runner service accessed via
env.RUNNER_SERVICE
Required in .dev.vars for local development:
JWT_SECRET- For session management (under development)ANTHROPIC_API_KEY,OPENAI_API_KEY,GOOGLE_AI_STUDIO_API_KEY- AI providersRUNNER_SERVICE_API_KEY- For code execution service- OAuth credentials (being redesigned)
- Focus on core AI generation functionality when making changes
- Prioritize Cloudflare-native solutions (D1, Durable Objects, R2)
- Always strictly follow DRY principles
- Keep code quality high and maintainability in mind
- Always research and understand the codebase before making changes
- Never use 'any' type. If you see 'any', Find the proper appropriate type in the project and then replace it. If nothing is found, then write a type for it.
- Never use dynamic imports. If you see dynamic imports, Correct it!
- Implement everything the 'right' and 'correct' way instead of 'fast' and 'quick'.
- Don't add comments for explaining your changes to me. Comments should be professional, to the point and should be there to explain the code, not your changes
- Don't start writing new 'corrected' versions of files instead of working on fixing the existing ones
- Monitor Durable Object logs:
npm run local - Check WebSocket messages in browser DevTools
- Verify Runner Service connectivity
- Review generation state in
CodeGeneratorAgent
- Class:
worker/agents/codegen/phasewiseGenerator.ts - Binding:
env.CodeGenObject - ID Generation: Based on session/user context
- State Persistence: Automatic via Cloudflare
- Executes generated code in isolated environment
- Provides runtime error feedback
- Returns preview URLs for generated apps
- Configuration in
wrangler.jsonc