Thanks to visit codestin.com
Credit goes to github.com

Skip to content

PictelAI is an AI-powered component generator where I learned to integrate an LLM model into a web application using OpenRouter. It features unique capabilities like in-click UI selection and real-time editing, making component creation faster, smarter, and more interactive for modern web developers.

Notifications You must be signed in to change notification settings

tareksabbir/PictelAi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿง  PictelAI โ€” Full-Stack AI-Powered UI Generator

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.


๐Ÿš€ Key Features

  • ๐Ÿ’ฌ 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-30b model 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.

๐Ÿงฉ Technology Stack

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

โš™๏ธ Installation & Setup

๐Ÿง  Prerequisites

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

๐Ÿ”ง 1. Clone the Repository

git clone https://github.com/tareksabbir/pictelai.git
cd pictelai

๐Ÿ“ฆ 2. Install Dependencies

npm install
# or
yarn install

๐Ÿ”‘ 3. Environment Variables

Create 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>

๐Ÿงฑ 4. Database Migration

Run Drizzle migration to sync schema:

npm run db:push

โ–ถ๏ธ 5. Start Development Server

npm run dev

Open your browser at http://localhost:3000


๐Ÿง  System Architecture

PictelAIโ€™s architecture consists of five main layers:

  1. Frontend Playground (User Interface) Handles chat, AI interaction, and iframe rendering.

  2. AI Code Generation Pipeline Uses lib/aiPromt.ts and OpenRouter API to stream HTML/CSS/JS code via Server-Sent Events (SSE).

  3. Database Persistence Layer Built with Neon PostgreSQL and Drizzle ORM, maintaining hierarchical relationships:

    • usersTable โ†’ projectTable โ†’ frameTable โ†’ chatTable
  4. API Layer (Next.js API Routes) Handles CRUD operations for projects, frames, and messages.

  5. Authentication & Authorization Layer Managed by Clerk with credit-based access control.


๐Ÿ—๏ธ Core Components Overview

1. Playground System

๐Ÿ“ 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.

2. AI Code Generation Pipeline

๐Ÿ“ 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.

3. WebsiteDesign Iframe Renderer

๐Ÿ“ 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).

4. API Routes

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

๐Ÿ” Authentication & Credits System

  • 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.

๐Ÿงฎ Data Model

Tables:

  • usersTable: stores user info, credits
  • projectTable: maps to a single project
  • frameTable: stores design iterations & generated code
  • chatTable: stores conversation messages as JSON

Relationships:

User โ†’ Project โ†’ Frame โ†’ Chat

Fields of Interest:

  • frameTable.designCode: stores generated HTML/CSS
  • chatTable.chatMessage: stores AI conversation history

๐Ÿ”„ Workflow Summary

๐Ÿงฉ Project Creation Flow

  1. Check credits or unlimited plan
  2. Create projectId and frameId
  3. Save initial user message
  4. Call AI model โ†’ stream code
  5. Render inside iframe and auto-save changes

โšก Real-Time Streaming

  • AI response streamed via SSE
  • Chunks accumulated in codeBufferRef
  • Cleaned HTML injected into iframe root
  • Libraries initialized dynamically
  • Debounced auto-save triggered after edits

โšก Performance Optimizations

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

๐Ÿง  Prompt Engineering

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.

๐Ÿ“ธ Screenshots (Optional Section)

(You can later add screenshots or GIFs showing AI conversation, live preview, and editing.)


๐Ÿงฐ Commands Reference

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

๐Ÿค Contributing

  1. Fork the repository

  2. Create a feature branch

    git checkout -b feature/awesome-idea
  3. Commit your changes

    git commit -m "Add awesome idea"
  4. Push and create a Pull Request


๐Ÿ“œ License

This project is licensed under the MIT License. You are free to use, modify, and distribute it with attribution.


โœจ Author

Md. Tarek Rahman ๐Ÿ  Chittagong, Bangladesh ๐Ÿ’ป Full-Stack Developer | AI & Web Enthusiast ๐Ÿ”— GitHub | LinkedIn

About

PictelAI is an AI-powered component generator where I learned to integrate an LLM model into a web application using OpenRouter. It features unique capabilities like in-click UI selection and real-time editing, making component creation faster, smarter, and more interactive for modern web developers.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published