How ankitsingh-git2/ai-canvas works
Project Type and Purpose
• This is a full-stack, AI-driven 2D-to-3D modeling web application called “Ai Canvas – Cursor for 3D Modeling.”
• Frontend: Next.js + React UI with TLDraw for 2D sketching, Three.js for 3D rendering, and Zustand for client state.
• Backend: FastAPI HTTP/SSE API, Celery workers for asynchronous AI tasks, Redis for pub/sub, plus connectors to external AI services (Claude, Gemini, Cerebras, PiAPI).
Top-Level File Structure Insights
• “frontend/” directory contains Next.js pages, React components, CSS, Three.js integrations, state store, and utility libraries.
• “backend/” directory holds a FastAPI app, Celery configuration, task definitions, Redis client, Dockerfiles, and docker-compose setup.
• Config files (.env.example, requirements.txt, package.json) and Docker orchestrations highlight containerized deployment.
Key Architectural Patterns
• Client-Server separation: Single-page React app communicates with a REST/SSE backend.
• Asynchronous Task Queue: Celery + Redis decouple AI computation from HTTP request lifecycle.
• Pub/Sub & SSE: Real-time feedback from backend task progress to frontend via Server-Sent Events.
• Micro-services style: API server and worker processes run in separate containers, defined in docker-compose.
Main Components
a. Frontend Layer
• React/Next.js App (pages, layout, routing)
• TLDraw Canvas (2D sketch UI)
• Three.js 3D Viewport (3D model rendering)
• Zustand Store (client state)
• Network Module (REST calls + SSE listener)
b. API Layer
• FastAPI Server (HTTP endpoints & SSE endpoint)
• API Routes: /improve-drawing, /make-3d, /export, etc.
• Config & Dependency Injection (config.py, redis.py)
c. Asynchronous Processing Layer
• Celery Broker & Backend (Redis)
• Worker Processes (cerebras_tasks, claude_tasks, gemini_tasks, generic tasks)
• Task Queue (task definitions and routing)
d. External AI Services
• Claude API
• Gemini API
• Cerebras API
• PiAPI (optional)
e. Data Store & Messaging
• Redis Instance (broker + pub/sub + result store)
• SSE Stream for real-time progress
f. Deployment & Orchestration
• Docker Containers: frontend, backend API, Celery worker
• Docker-Compose for local orchestration
• Environment Configuration (.env)
Relationships and Data Flows
• User interaction → React UI dispatches REST call to FastAPI.
• FastAPI enqueues a Celery task (via Redis broker).
• Worker picks up task, invokes external AI service, streams progress events back to Redis pub/sub.
• FastAPI SSE endpoint subscribes to Redis channel, pushes updates to client.
• On completion, FastAPI returns result (enhanced image or 3D model data) to frontend.
• Frontend caches/presents result in Zustand store and updates TLDraw/Three.js scenes.
Which Architectural Patterns to Highlight
• API-gateway + Worker pattern (FastAPI + Celery)
• Event-driven updates (Redis pub/sub → SSE)
• Component-based UI (2D vs 3D separation)
• Containerized services orchestrated via docker-compose