Transform rough sketches into professional diagrams with AI
An intelligent whiteboard application that uses Google Gemini to refine hand-drawn sketches into clean, publication-ready diagrams.
ChalkAI-Demo.mp4
| Feature | Description |
|---|---|
| ποΈ Interactive Whiteboard | Full-featured drawing canvas powered by tldraw with support for freehand drawing, shapes, arrows, and more |
| π€ AI-Powered Refinement | Leverages Google Gemini 2.5 Flash to transform rough sketches into professional diagrams |
| π€ Voice Input | Describe your diagram intent using voice commands with automatic idle detection |
| β‘ Quick Enhance | One-click enhancement to instantly improve any sketch |
| π― Selection-Aware | Refine specific parts of your canvas by selecting shapes before generating |
| β¨οΈ Keyboard Shortcuts | Accept suggestions with Tab, reject with Esc for rapid iteration |
| π¨ Glass Morphism UI | Modern, sleek interface with smooth animations powered by Framer Motion |
- Node.js 18+ or Bun runtime
- Google Gemini API Key (Get one here)
# Clone the repository
git clone https://github.com/yourusername/ChalkAI.git
cd ChalkAI/frontend
# Install dependencies
npm install
# or
bun installCreate a .env.local file in the frontend directory:
GOOGLE_GENERATIVE_AI_API_KEY=your_api_key_herenpm run dev
# or
bun run devOpen http://localhost:3000 in your browser.
|
1οΈβ£ |
Draw β Sketch your diagram idea on the whiteboard |
|
2οΈβ£ |
Describe β Type or speak what your diagram represents |
|
3οΈβ£ |
Generate β Click the |
|
4οΈβ£ |
Review β See the AI-generated diagram in the preview panel |
|
5οΈβ£ |
Accept β Press |
- Click the microphone button to start listening
- Describe your diagram verbally
- Stop speaking for 4.5 seconds or click the mic again
- The AI automatically generates based on your voice description
graph TD
A[User Draws Sketch] --> B[tldraw Canvas]
B --> C[Export to PNG]
C --> D["/api/complete-diagram"]
D --> E["Google Gemini 2.5 Flash"]
E --> F[Generated PNG]
F --> G[Preview Panel]
G -->|Tab| H[Accept & Replace]
G -->|Esc| I[Reject & Keep Original]
frontend/
βββ app/
β βββ api/
β β βββ complete-diagram/
β β βββ route.ts # AI processing endpoint
β βββ page.tsx # Main application page
β βββ layout.tsx # Root layout with metadata
β βββ globals.css # Global styles & theme
βββ components/
β βββ ui/ # Reusable UI components
β β βββ button.tsx # Button component with variants
β βββ whiteboard.tsx # tldraw canvas wrapper
β βββ intent-input.tsx # Text input for diagram intent
βββ lib/
β βββ utils.ts # Utility functions (cn helper)
βββ types/
βββ speech-recognition.d.ts # TypeScript declarations
| Category | Technology |
|---|---|
| Framework | Next.js 16 (App Router) |
| UI Library | React 19 |
| Language | TypeScript 5 |
| Styling | Tailwind CSS 4 |
| Animations | Framer Motion |
| Whiteboard | tldraw v4 |
| AI Integration | Vercel AI SDK + Google Gemini |
| Components | Custom + shadcn/ui patterns |
Generates a refined diagram from a sketch and text description.
Request Body:
{
"prompt": "A flowchart showing user authentication process",
"image_data": "base64_encoded_png_data"
}Response:
{
"image_data": "base64_encoded_generated_png"
}Error Response:
{
"error": "Error message",
"details": "Additional error details"
}| Shortcut | Action |
|---|---|
Tab |
Accept the AI suggestion |
Esc |
Reject the AI suggestion |
| tldraw shortcuts | All standard tldraw shortcuts work |
The core canvas component wrapping tldraw. Handles:
- Canvas mounting and export functionality
- Selection-aware image export
- AI suggestion acceptance (Tab key)
- Drawing activity detection for voice input
A minimal text input for describing diagram intent with:
- 120 character limit
- Clean, borderless design
- Submit on Enter
# Development server with hot reload
npm run dev
# Production build
npm run build
# Start production server
npm run start
# Run ESLint
npm run lintβ API Key Issues
- Ensure
.env.localis in thefrontenddirectory - Restart the dev server after modifying environment variables
- Verify your API key is valid at Google AI Studio
β LightningCSS Binary Error (Windows)
If you see an error about lightningcss.win32-x64-msvc.node:
npm install lightningcss-win32-x64-msvc
Copy-Item "node_modules\lightningcss-win32-x64-msvc\lightningcss.win32-x64-msvc.node" "node_modules\lightningcss\lightningcss.win32-x64-msvc.node"
Remove-Item -Recurse -Force .next
npm run devβ No Image Generated
- Make sure you've drawn something on the canvas
- Check that your Gemini API key has access to image generation models
- Look at browser console and terminal for detailed error messages
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License β feel free to use this project for personal or commercial purposes.
Made with β€οΈ using Next.js, tldraw, and Google Gemini