|
| 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 | +CodinIT.dev is an AI-powered full-stack development platform that runs in the browser or as an Electron desktop app. It provides an integrated development environment with live preview, WebContainer sandboxing, AI chat with 19+ LLM providers, and deployment capabilities. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +### Essential Commands |
| 12 | +```bash |
| 13 | +# Development |
| 14 | +pnpm run dev # Start development server with hot reload (requires Chrome Canary if using Chrome) |
| 15 | +pnpm run build # Build for production |
| 16 | +pnpm run start # Run built application locally with Wrangler Pages |
| 17 | +pnpm run preview # Build and start for production testing |
| 18 | + |
| 19 | +# Testing & Quality |
| 20 | +pnpm test # Run test suite with Vitest |
| 21 | +pnpm run test:watch # Run tests in watch mode |
| 22 | +pnpm run lint # Run ESLint |
| 23 | +pnpm run lint:fix # Run ESLint with auto-fix |
| 24 | +pnpm run typecheck # Run TypeScript type checking |
| 25 | +pnpm run typegen # Generate Wrangler types |
| 26 | + |
| 27 | +# Docker |
| 28 | +pnpm run dockerbuild # Build development Docker image |
| 29 | +docker compose --profile development up # Run with Docker Compose |
| 30 | +pnpm run dockerbuild:prod # Build production Docker image |
| 31 | + |
| 32 | +# Electron Desktop App |
| 33 | +pnpm electron:build:mac # Build for macOS |
| 34 | +pnpm electron:build:win # Build for Windows |
| 35 | +pnpm electron:build:linux # Build for Linux |
| 36 | +pnpm electron:build:dist # Build for all platforms |
| 37 | + |
| 38 | +# Deployment |
| 39 | +pnpm run deploy # Build and deploy to Cloudflare Pages |
| 40 | +``` |
| 41 | + |
| 42 | +### Important Notes |
| 43 | +- **CRITICAL**: Use `pnpm` exclusively as the package manager (packageManager: pnpm@10.0.0) |
| 44 | + - Never use npm or yarn - this can cause dependency conflicts |
| 45 | +- Node.js version requirement: >=20.15.1 |
| 46 | +- Chrome 129 has a known issue; use Chrome Canary for local development |
| 47 | +- For Ollama and LMStudio, use `127.0.0.1` instead of `localhost` to avoid IPv6 issues |
| 48 | + |
| 49 | +## Architecture Overview |
| 50 | + |
| 51 | +### Tech Stack |
| 52 | +- **Framework**: Remix v2 with Vite |
| 53 | +- **Runtime**: Cloudflare Pages (Cloudflare Workers runtime) |
| 54 | +- **Styling**: UnoCSS with SCSS support |
| 55 | +- **UI Components**: Radix UI primitives with custom components |
| 56 | +- **State Management**: Nanostores for reactive state |
| 57 | +- **Code Editor**: CodeMirror 6 with syntax highlighting via Shiki |
| 58 | +- **Terminal**: xterm.js for integrated terminal |
| 59 | +- **WebContainer**: @webcontainer/api for sandboxed Node.js runtime in browser |
| 60 | +- **Desktop**: Electron for native desktop application |
| 61 | + |
| 62 | +### Directory Structure |
| 63 | + |
| 64 | +``` |
| 65 | +app/ |
| 66 | +├── components/ # React components organized by feature |
| 67 | +│ ├── chat/ # AI chat interface components |
| 68 | +│ ├── workbench/ # Code editor and file management |
| 69 | +│ ├── editor/ # CodeMirror editor components |
| 70 | +│ ├── sidebar/ # Navigation and history |
| 71 | +│ ├── header/ # Top navigation bar |
| 72 | +│ ├── deploy/ # Deployment integrations |
| 73 | +│ ├── git/ # Git version control UI |
| 74 | +│ ├── @settings/ # Settings panels and configuration |
| 75 | +│ └── ui/ # Reusable UI primitives |
| 76 | +├── lib/ |
| 77 | +│ ├── .server/ # Server-side only code |
| 78 | +│ │ └── llm/ # LLM streaming and AI logic |
| 79 | +│ ├── stores/ # Nanostores state management |
| 80 | +│ ├── modules/ # Core business logic modules |
| 81 | +│ │ └── llm/ # LLM provider system (base-provider, registry, manager) |
| 82 | +│ ├── webcontainer/ # WebContainer integration |
| 83 | +│ ├── persistence/ # Local storage and data persistence |
| 84 | +│ ├── hooks/ # Custom React hooks |
| 85 | +│ ├── utils/ # Utility functions |
| 86 | +│ ├── runtime/ # Runtime environment handling |
| 87 | +│ └── services/ # External service integrations |
| 88 | +├── routes/ # Remix file-based routing |
| 89 | +│ ├── _index.tsx # Home page |
| 90 | +│ └── api.*.ts # API endpoints |
| 91 | +├── types/ # TypeScript type definitions |
| 92 | +└── utils/ # Shared utilities |
| 93 | +
|
| 94 | +electron/ # Electron desktop app code |
| 95 | +├── main/ # Main process |
| 96 | +└── preload/ # Preload scripts |
| 97 | +
|
| 98 | +docs/ # Documentation site |
| 99 | +``` |
| 100 | + |
| 101 | +### Key Architectural Patterns |
| 102 | + |
| 103 | +#### LLM Provider System |
| 104 | +The application uses a modular provider architecture located in `app/lib/modules/llm/`: |
| 105 | + |
| 106 | +- **BaseProvider** (`base-provider.ts`): Abstract class that all LLM providers extend |
| 107 | +- **Manager** (`manager.ts`): Orchestrates provider registration and model instantiation |
| 108 | +- **Registry** (`registry.ts`): Central registration of all provider classes |
| 109 | +- **Providers** (`providers/`): Individual provider implementations (OpenAI, Anthropic, Google, etc.) |
| 110 | + |
| 111 | +Each provider class defines: |
| 112 | +- Static models (pre-configured models) |
| 113 | +- Dynamic models (loaded from provider API) |
| 114 | +- API key configuration |
| 115 | +- Model instance creation |
| 116 | + |
| 117 | +To add a new LLM provider, create a class extending `BaseProvider` and register it in the registry. |
| 118 | + |
| 119 | +#### State Management |
| 120 | +Uses Nanostores (`app/lib/stores/`) for reactive state: |
| 121 | + |
| 122 | +- **workbench.ts**: File system, editor state, preview URLs (~29KB - complex) |
| 123 | +- **files.ts**: File operations, diff tracking, locking system (~28KB - complex) |
| 124 | +- **chat.ts**: Chat messages and conversation state |
| 125 | +- **settings.ts**: User preferences and provider configuration (~10KB) |
| 126 | +- **logs.ts**: Application logging with categorization (~12KB) |
| 127 | +- **previews.ts**: Preview server management (~8KB) |
| 128 | +- **terminal.ts**: Terminal session management |
| 129 | +- **theme.ts**: Theme switching and persistence |
| 130 | +- **editor.ts**: Editor-specific state and configuration |
| 131 | +- **netlify.ts**: Netlify deployment state |
| 132 | +- **supabase.ts**: Supabase connection and database state |
| 133 | +- **vercel.ts**: Vercel deployment state |
| 134 | +- **profile.ts**: User profile information |
| 135 | +- **streaming.ts**: Streaming state management |
| 136 | +- **mcp.ts**: Model Context Protocol configuration |
| 137 | + |
| 138 | +Stores are framework-agnostic and can be subscribed to from any component using `@nanostores/react`. |
| 139 | + |
| 140 | +#### Server-Side AI Streaming |
| 141 | +Located in `app/lib/.server/llm/`: |
| 142 | + |
| 143 | +- **stream-text.ts**: Main streaming logic for AI responses (~10KB) |
| 144 | +- **stream-recovery.ts**: Handles stream interruption recovery |
| 145 | +- **switchable-stream.ts**: Allows switching between models mid-stream |
| 146 | +- **create-summary.ts**: Generates conversation summaries (~6KB) |
| 147 | +- **select-context.ts**: Context selection for prompts (~8KB) |
| 148 | + |
| 149 | +These files run only on the server (Cloudflare Workers) and handle AI SDK integration. |
| 150 | + |
| 151 | +#### WebContainer Integration |
| 152 | +The app uses WebContainer API (`app/lib/webcontainer/`) to provide: |
| 153 | +- In-browser Node.js runtime |
| 154 | +- File system operations |
| 155 | +- Terminal command execution |
| 156 | +- Live preview server |
| 157 | + |
| 158 | +WebContainer enables running development servers (Vite, Next.js, etc.) entirely in the browser. |
| 159 | + |
| 160 | +#### Route Architecture |
| 161 | +Remix file-based routing in `app/routes/`: |
| 162 | + |
| 163 | +- `_index.tsx`: Main application page |
| 164 | +- `api.chat.ts`: AI chat streaming endpoint (~16KB) |
| 165 | +- `api.github-*.ts`: GitHub integration endpoints (user, stats, branches, templates) |
| 166 | +- `api.gitlab-*.ts`: GitLab integration endpoints (projects, branches) |
| 167 | +- `api.netlify-*.ts`: Netlify deployment endpoints |
| 168 | +- `api.supabase-*.ts`: Supabase database integration (user, query, variables) |
| 169 | +- `api.vercel-*.ts`: Vercel deployment endpoints |
| 170 | +- `api.models.ts`: Dynamic model loading |
| 171 | +- `api.enhancer.ts`: Prompt enhancement |
| 172 | +- `api.bug-report.ts`: Bug reporting functionality |
| 173 | +- `api.check-env-key.ts`: Environment key validation |
| 174 | +- `api.configured-providers.ts`: Lists configured LLM providers |
| 175 | +- `api.system.diagnostics.ts`: System diagnostics and health checks |
| 176 | +- `api.system.disk-info.ts`: Disk usage and file system information |
| 177 | +- `api.llmcall.ts`: Direct LLM API calls |
| 178 | +- `api.local-template.ts`: Local template management |
| 179 | +- `api.mcp-*.ts`: Model Context Protocol endpoints |
| 180 | +- `api.git-*.ts`: Git proxy and repository information |
| 181 | + |
| 182 | +API routes return streaming responses or JSON depending on the endpoint. |
| 183 | + |
| 184 | +## Configuration Files |
| 185 | + |
| 186 | +### Environment Variables |
| 187 | +Copy `.env.example` to `.env.local` and configure: |
| 188 | + |
| 189 | +**AI Providers**: |
| 190 | +- `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `GOOGLE_GENERATIVE_AI_API_KEY` |
| 191 | +- `GROQ_API_KEY`, `MISTRAL_API_KEY`, `COHERE_API_KEY` |
| 192 | +- `DEEPSEEK_API_KEY`, `XAI_API_KEY`, `PERPLEXITY_API_KEY` |
| 193 | +- And 10+ more providers |
| 194 | + |
| 195 | +**Local Models**: |
| 196 | +- `OLLAMA_API_BASE_URL` (use `http://127.0.0.1:11434`) |
| 197 | +- `LMSTUDIO_API_BASE_URL` (use `http://127.0.0.1:1234`) |
| 198 | + |
| 199 | +**Service Integrations** (all prefixed with `VITE_` for client access): |
| 200 | +- `VITE_GITHUB_ACCESS_TOKEN`: GitHub integration |
| 201 | +- `VITE_GITLAB_ACCESS_TOKEN`: GitLab integration |
| 202 | +- `VITE_VERCEL_ACCESS_TOKEN`: Vercel deployment |
| 203 | +- `VITE_NETLIFY_ACCESS_TOKEN`: Netlify deployment |
| 204 | +- `VITE_SUPABASE_URL`, `VITE_SUPABASE_ANON_KEY`: Supabase backend |
| 205 | + |
| 206 | +**Auto-Connection**: Services with `VITE_` prefixed tokens will auto-connect on startup if tokens are provided in `.env.local`. |
| 207 | + |
| 208 | +**Docker Setup**: |
| 209 | +For Docker, `.env` file is required for variable substitution. Either: |
| 210 | +- Run `./scripts/setup-env.sh` to sync `.env.local` to `.env` |
| 211 | +- Manually copy: `cp .env.local .env` |
| 212 | + |
| 213 | +### TypeScript Configuration |
| 214 | +- Path alias: `~/*` maps to `./app/*` |
| 215 | +- Target: ESNext with Bundler module resolution |
| 216 | +- Strict mode enabled |
| 217 | +- Types: Remix, Cloudflare Workers, Electron, Vite |
| 218 | + |
| 219 | +### Vite Configuration |
| 220 | +`vite.config.ts` includes: |
| 221 | +- Node.js polyfills for browser (buffer, process, stream) |
| 222 | +- Git metadata injection (commit hash, branch, author) |
| 223 | +- Package.json data injection as build-time constants |
| 224 | +- UnoCSS integration |
| 225 | +- Chrome 129 workaround middleware |
| 226 | +- Environment variable prefixes: `VITE_`, `OLLAMA_API_BASE_URL`, `LMSTUDIO_API_BASE_URL`, etc. |
| 227 | + |
| 228 | +### Cloudflare Workers |
| 229 | +`wrangler.toml`: |
| 230 | +- Compatibility flags: `nodejs_compat` |
| 231 | +- Build output: `./build/client` |
| 232 | +- Metrics disabled |
| 233 | + |
| 234 | +## Component Guidelines |
| 235 | + |
| 236 | +### UI Components |
| 237 | +Located in `app/components/ui/`: |
| 238 | +- Built with Radix UI primitives |
| 239 | +- Styled with UnoCSS utility classes |
| 240 | +- TypeScript interfaces for props |
| 241 | +- Support both light and dark themes via `data-theme` attribute |
| 242 | + |
| 243 | +### Feature Components |
| 244 | +Organized by domain: |
| 245 | +- **Chat**: Message display, input, AI response rendering |
| 246 | +- **Workbench**: File tree, editor panels, preview iframe |
| 247 | +- **Editor**: CodeMirror integration, language support, autocomplete |
| 248 | +- **Settings**: Provider configuration, API key management, service connections |
| 249 | + |
| 250 | +Use `ClientOnly` from `remix-utils/client-only` for browser-only components. |
| 251 | + |
| 252 | +## Testing |
| 253 | + |
| 254 | +- Test framework: Vitest with jsdom |
| 255 | +- Test files: Co-located with source files or in `__tests__` directories |
| 256 | +- Testing Library: React Testing Library for component tests |
| 257 | +- Commands: |
| 258 | + - Run all tests: `pnpm test` |
| 259 | + - Run single test file: `pnpm test path/to/file.test.ts` |
| 260 | + - Run tests in watch mode: `pnpm run test:watch` |
| 261 | + - Run tests matching a pattern: `pnpm test --grep "pattern"` |
| 262 | + |
| 263 | +## MCP (Model Context Protocol) |
| 264 | + |
| 265 | +CodinIT supports MCP for extending AI capabilities: |
| 266 | +- Configuration stored in `app/lib/stores/mcp.ts` |
| 267 | +- Server types: STDIO, SSE, Streamable HTTP |
| 268 | +- Tool execution requires user approval |
| 269 | +- MCP SDK: `@modelcontextprotocol/sdk` |
| 270 | + |
| 271 | +## Common Development Patterns |
| 272 | + |
| 273 | +### Adding a New LLM Provider |
| 274 | +1. Create provider class in `app/lib/modules/llm/providers/your-provider.ts` |
| 275 | +2. Extend `BaseProvider` and implement required methods |
| 276 | +3. Add to `app/lib/modules/llm/registry.ts` |
| 277 | +4. Add environment variable to `.env.example` |
| 278 | +5. Test with API key in settings |
| 279 | + |
| 280 | +### Adding a New Route |
| 281 | +1. Create file in `app/routes/` following Remix conventions |
| 282 | +2. Export `loader` for GET requests, `action` for POST/PUT/DELETE |
| 283 | +3. Use `json()` or streaming responses |
| 284 | +4. Server-only code imports from `.server` modules |
| 285 | + |
| 286 | +### Working with Stores |
| 287 | +```typescript |
| 288 | +import { useStore } from '@nanostores/react'; |
| 289 | +import { myStore } from '~/lib/stores/myStore'; |
| 290 | + |
| 291 | +function MyComponent() { |
| 292 | + const value = useStore(myStore); |
| 293 | + // Component re-renders when store changes |
| 294 | +} |
| 295 | +``` |
| 296 | + |
| 297 | +### File Operations |
| 298 | +Use stores in `app/lib/stores/files.ts`: |
| 299 | +- `filesStore`: File content and metadata |
| 300 | +- File locking system prevents conflicts |
| 301 | +- Diff tracking for version control |
| 302 | +- Auto-save and manual save modes |
| 303 | + |
| 304 | +## Deployment Targets |
| 305 | + |
| 306 | +1. **Cloudflare Pages** (primary): `pnpm run deploy` |
| 307 | +2. **Docker**: Multi-stage Dockerfile with development and production targets |
| 308 | +3. **Electron**: Desktop apps for macOS, Windows, Linux |
| 309 | +4. **Vercel/Netlify**: Via integrated deployment features |
| 310 | + |
| 311 | +## Known Issues & Workarounds |
| 312 | + |
| 313 | +- **Chrome 129**: Has Vite module loading bug. Use Chrome Canary for development. |
| 314 | +- **IPv6 Localhost**: Ollama and LMStudio don't work with `localhost`, use `127.0.0.1` |
| 315 | +- **Docker env**: Requires both `.env.local` and `.env` files |
| 316 | +- **WebContainer**: Limited to browser environments, not available in Electron main process |
| 317 | + |
| 318 | +## Git Workflow |
| 319 | + |
| 320 | +- Main branch: `main` |
| 321 | +- Git integration for import/export projects |
| 322 | +- GitHub and GitLab repository management |
| 323 | +- Automatic diff visualization |
| 324 | +- Version history tracking |
| 325 | + |
| 326 | +### Commit Workflow |
| 327 | +- After each file edit, add and commit the file immediately once completed |
| 328 | +- Do NOT include "Co-authored by Claude" or similar AI attributions in commit messages |
| 329 | +- Keep commits focused and atomic - one logical change per commit |
| 330 | +- Use clear, descriptive commit messages that explain the "why" not just the "what" |
0 commit comments