PictelAI is a full-stack AI-driven web application that generates production-ready UI components and full web layouts through natural language conversation. It integrates LLM-based code generation with a real-time iframe rendering system, enabling users to design, edit, and preview live web interfaces instantly.
- ๐ฌ Conversational UI Design โ Generate HTML/CSS/Tailwind-based interfaces from natural language prompts.
- โก Real-Time Rendering โ Instantly preview generated UIs in an interactive iframe sandbox.
- ๐ Auto-Save System โ Automatically stores design changes with a debounce mechanism.
- ๐ User Authentication โ Secure login and credits management via Clerk.
- ๐งฉ Component Libraries โ Flowbite, AOS, Swiper, Chart.js, and Tippy.js integrated for generated code.
- ๐ง LLM Integration โ Uses OpenRouter.ai with
tongyi-deepresearch-30bmodel for intelligent UI generation. - โ๏ธ Serverless Backend โ Built on Next.js 14, Neon PostgreSQL, and Drizzle ORM.
- ๐งฑ Modular Architecture โ Clear separation between playground, generation pipeline, and persistence layer.
| Layer | Technology | Purpose |
|---|---|---|
| Frontend Framework | Next.js 15+ (App Router) | SSR, routing, API routes |
| UI Components | Radix UI, Tailwind CSS | Accessible primitives, utility-first styling |
| Authentication | Clerk | Secure auth and session management |
| Database | Neon PostgreSQL | Scalable serverless database |
| ORM | Drizzle ORM | Type-safe SQL queries |
| AI Service | OpenRouter.ai (Tongyi DeepResearch 30B) | LLM code generation |
| Image Processing | ImageKit | Image upload and optimization |
| Generated Code Libraries | Flowbite, AOS, Swiper, Chart.js, Tippy.js | Animations and UI interactions |
Make sure you have installed:
- Node.js >=18
- npm or yarn
- PostgreSQL (Neon DB or local)
- Clerk account (for authentication)
- OpenRouter API key
- ImageKit credentials
git clone https://github.com/tareksabbir/pictelai.git
cd pictelainpm install
# or
yarn installCreate a .env.local file in the project root and add:
DATABASE_URL="postgresql://<your_neon_connection_string>"
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=<your_clerk_publishable_key>
CLERK_SECRET_KEY=<your_clerk_secret_key>
OPENROUTER_API_KEY=<your_openrouter_api_key>
NEXT_PUBLIC_IMAGEKIT_URL_ENDPOINT=<your_imagekit_url>
IMAGEKIT_PRIVATE_KEY=<your_imagekit_private_key>
IMAGEKIT_PUBLIC_KEY=<your_imagekit_public_key>Run Drizzle migration to sync schema:
npm run db:pushnpm run devOpen your browser at http://localhost:3000
PictelAIโs architecture consists of five main layers:
-
Frontend Playground (User Interface) Handles chat, AI interaction, and iframe rendering.
-
AI Code Generation Pipeline Uses
lib/aiPromt.tsand OpenRouter API to stream HTML/CSS/JS code via Server-Sent Events (SSE). -
Database Persistence Layer Built with Neon PostgreSQL and Drizzle ORM, maintaining hierarchical relationships:
usersTableโprojectTableโframeTableโchatTable
-
API Layer (Next.js API Routes) Handles CRUD operations for projects, frames, and messages.
-
Authentication & Authorization Layer Managed by Clerk with credit-based access control.
๐ app/playground/[projectId]/page.tsx
-
Main workspace where users chat and see generated code.
-
Uses custom hooks:
usePlaygroundData()โ manages project/frame state.useCodeGeneration()โ streams and buffers code from AI.
๐ lib/aiPromt.ts
- Builds detailed prompt from user input.
- Calls OpenRouter API for LLM output.
- Streams response via SSE.
- Cleans markdown fences and injects code into iframe.
๐ app/playground/_components/WebsiteDesign.tsx
- Injects base HTML and scripts into iframe.
- Initializes libraries sequentially (AOS, Swiper, Chart.js, Flowbite).
- Enables live inline editing with auto-save debounce (2s).
| Route | Description |
|---|---|
POST /api/projects |
Creates new project & frame, deducts credit |
GET /api/frames |
Fetches frame data and chat history |
PUT /api/frames |
Updates frameโs designCode after editing |
- Managed by Clerk.
- New users receive 2 free credits.
- Each project creation deducts 1 credit unless on unlimited plan.
- Users with unlimited plans can create projects without restriction.
Tables:
usersTable: stores user info, creditsprojectTable: maps to a single projectframeTable: stores design iterations & generated codechatTable: stores conversation messages as JSON
Relationships:
User โ Project โ Frame โ Chat
Fields of Interest:
frameTable.designCode: stores generated HTML/CSSchatTable.chatMessage: stores AI conversation history
- Check credits or unlimited plan
- Create
projectIdandframeId - Save initial user message
- Call AI model โ stream code
- Render inside iframe and auto-save changes
- AI response streamed via SSE
- Chunks accumulated in
codeBufferRef - Cleaned HTML injected into iframe root
- Libraries initialized dynamically
- Debounced auto-save triggered after edits
| Technique | Purpose |
|---|---|
React.memo |
Prevents re-renders |
useCallback |
Stable function references |
useRef |
Persistent state storage |
| Debounce | Limits auto-save calls |
| Lazy Initialization | Delays library loading until ready |
| Code Buffering | Smooth streaming experience |
The core logic inside lib/aiPromt.ts defines the AIโs behavior:
- Defines generation rules for UI, layout, and interactivity.
- Instructs LLM to output clean HTML/CSS/JS (not markdown).
- Provides CDN-based imports for Flowbite, Swiper, AOS, etc.
(You can later add screenshots or GIFs showing AI conversation, live preview, and editing.)
| Command | Description |
|---|---|
npm run dev |
Start development server |
npm run build |
Build production bundle |
npm run start |
Run production server |
npm run db:push |
Apply database schema |
npm run lint |
Run ESLint checks |
-
Fork the repository
-
Create a feature branch
git checkout -b feature/awesome-idea
-
Commit your changes
git commit -m "Add awesome idea" -
Push and create a Pull Request
This project is licensed under the MIT License. You are free to use, modify, and distribute it with attribution.
Md. Tarek Rahman ๐ Chittagong, Bangladesh ๐ป Full-Stack Developer | AI & Web Enthusiast ๐ GitHub | LinkedIn