Skip to content

itzzSPcoder/Imagica

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

29 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Imagica Logo

Imagica

AI Sketch-to-Component Workbench (Enterprise Edition)

๐ŸŒ imagicasite.xyz


Imagica is an elite, industrial-grade, AI-powered developer workbench that transforms hand-drawn sketches, structural wireframes, and UI screenshots into high-performance, responsive, production-ready web components. Inspired by the sleek, minimalist labs theme of Google AI Studio, Imagica integrates state-of-the-art vision models, secure authentication, live sandbox preview frames, and an optimized, token-efficient refinement chatbot.


โœจ Recent Updates (Changelog)

May 2026 โ€” Professional UI Generation & Stability

Professional output quality

  • Rewrote Gemini generation prompts to target production-grade SaaS aesthetics (Linear / Stripe / Vercel style) instead of flashy gradient-heavy templates
  • Default styling baseline applied when no custom instructions are provided โ€” restrained zinc/indigo palette, 8px spacing grid, subtle borders
  • Live preview shadcn/ui stubs upgraded to match professional zinc design tokens

Marketplace & billing

  • Design Marketplace โ€” list, browse, and buy sketch layouts with Imagica Credits
  • Seller dashboard with 60% Credits / 40% Cash revenue split
  • Pricing plans (weekly, monthly, yearly) with credit redemption and Stripe checkout simulation
  • Wallet sidebar showing credits, cash balance, and active plan badge

Bug fixes & reliability

  • Synced OpenAPI PaymentPlanStatus schema with backend (credits, cash, bank details, plan tiers)
  • Fixed sketch workbench crashes from invalid analysis JSON parsing
  • Generation stream errors now surface via toast notifications
  • Live preview iframe refreshes during code refinement
  • Preview page handles invalid sketch IDs gracefully
  • Root pnpm run typecheck fixed for Windows monorepo paths
  • Added Stripe dev dependency for API server type safety

Repository: github.com/itzzSPcoder/Imagica


๐ŸŽจ Tips for Best-Looking Generated UIs

  1. Use style instructions on the Convert page โ€” e.g. "Professional dark dashboard, zinc palette, indigo accents, like Linear"
  2. Pick React + shadcn/ui for the most polished component output
  3. Use Gemini Refiner Chat to iterate โ€” "Increase whitespace", "Use subtle borders instead of shadows", "Make typography more minimal"
  4. Choose Hi-Fi Vision mode when layout fidelity from the original sketch matters more than token savings

๐Ÿ—๏ธ System & Core Architecture Deep-Dive

Imagica is architected as a high-performance pnpm monorepo workspace. The entire ecosystem is divided into three distinct layers:

  1. Frontend Layer: The developer workbench interface and sandbox preview frame.
  2. Backend Services Layer: The Express API gate, database schema engines, and SSE stream handlers.
  3. Shared Monorepo Libraries: Reusable packages for Zod schemas, DB connections, API client generators, and Gemini SDK integrations.

๐Ÿ“Š Visual System Flows & Architecture Diagrams

1. Workspace Dependency & Monorepo Topology

This diagram illustrates the monorepo structure and how individual applications depend on shared type-safe library workspace layers:

graph TD
    classDef app fill:#4f46e5,stroke:#818cf8,stroke-width:2px,color:#fff;
    classDef lib fill:#0d9488,stroke:#2dd4bf,stroke-width:2px,color:#fff;
    classDef db fill:#d97706,stroke:#fbbf24,stroke-width:2px,color:#fff;
    classDef ai fill:#7c3aed,stroke:#a78bfa,stroke-width:2px,color:#fff;

    %% Applications
    SubComponent["๐Ÿ’ป sketch-to-component (React Workspace App)"]:::app
    MockupSandbox["๐Ÿ”ฌ mockup-sandbox (Preview Frame App)"]:::app
    ApiServer["โš™๏ธ api-server (Node/Express Backend Service)"]:::app

    %% Shared Packages
    ApiClient["๐Ÿ“ฆ api-client-react (Auto-Generated Hooks)"]:::lib
    ApiZod["๐Ÿ“ฆ api-zod (Type-safe Zod Schemas)"]:::lib
    ApiSpec["๐Ÿ“ฆ api-spec (OpenAPI Spec Definitions)"]:::lib
    Database["๐Ÿ—„๏ธ db (Drizzle Schema & SQLite Migration)"]:::db
    GeminiClient["๐Ÿง  integrations-gemini-ai (Gen AI Wrapper)"]:::ai

    %% Dependencies Flows
    SubComponent -->|Uses queries/mutations| ApiClient
    ApiClient -->|Generates endpoints from| ApiSpec
    ApiServer -->|Validates requests with| ApiZod
    ApiServer -->|Queries and persists to| Database
    ApiServer -->|Triggers multimodal LLMs via| GeminiClient
    SubComponent -->|Embeds preview iframe of| MockupSandbox
Loading

2. Multi-Model Robust Code Generation Pipeline

Here is the step-by-step pipeline when a user uploads a hand-drawn sketch. Notice the recursive Gemini Fallback Models Loop and Exponential Backoff Retry Gate that ensure zero downtime:

sequenceDiagram
    autonumber
    actor User as ๐Ÿ‘ค Developer / Designer
    participant UI as ๐Ÿ’ป Front-End App (React)
    participant Server as โš™๏ธ Express Backend (api-server)
    participant Auth as ๐Ÿ” Clerk Authentication
    participant Gemini as ๐Ÿง  Google Gemini Vision API
    participant DB as ๐Ÿ—„๏ธ Database (Drizzle SQLite)

    User->>UI: Upload hand-drawn UI sketch & select framework
    UI->>Auth: Validate user session token
    Auth-->>UI: Session token valid
    UI->>Server: POST /api/sketches (base64 image, framework, styling instructions)
    Note over Server: Server reads x-gemini-api-key header<br/>Falls back to environment keys if empty.

    rect rgb(30, 27, 75)
        Note over Server: [Model Fallback Loop & Retry Gate]
        Server->>Gemini: Attempt 1: gemini-2.0-flash (Upload base64 image + layout prompt)
        alt Case A: 429 Rate Limit / Quota Exhausted on Flash 2.0
            Gemini-->>Server: Error 429 (Resource Exhausted)
            Server->>Server: catch 429 -> Try next candidate model
            Server->>Gemini: Attempt 2: gemini-2.5-flash (Execute stream compilation)
        else Case B: Transient 503 / Network Timeout
            Gemini-->>Server: Error 503 (Service Overloaded)
            Server->>Server: withRetry helper waits 2s -> 4s -> 8s (Exponential Backoff)
            Server->>Gemini: Retry Attempt
        end
    end

    Gemini-->>Server: 200 OK: Complete React/HTML structured markup stream
    Server->>DB: Save Sketch details (generatedCode, framework, layout analysis JSON)
    DB-->>Server: Record created successfully
    Server-->>UI: HTTP 201 Created: Hydrated sketch state
    UI->>User: Launch code inside Developer Workbench (Interactive Live Sandbox)
Loading

3. Token-Optimized Refiner Chatbot Architecture (Refine Turn)

Unlike baseline sketch tools that upload giant base64 image payloads (~300,000+ tokens) on every single chat turns, Imagica implements a 95%+ token-saving strategy that completely bypasses free-tier TPM (Tokens Per Minute) quotas:

graph TD
    classDef regular fill:#ef4444,stroke:#f87171,stroke-width:2px,color:#fff;
    classDef optimized fill:#10b981,stroke:#34d399,stroke-width:2px,color:#fff;
    classDef text fill:#0d9488,stroke:#2dd4bf,stroke-width:2px,color:#fff;

    %% Input Trigger
    UserPrompt(["๐Ÿ’ฌ Chatturn: 'make it scrollable nd add light theme'"]) --> Choice{Prompt Structure}

    %% Regular Path
    Choice -->|Baseline Compilers| Baseline["โš ๏ธ Verbose Payload <br/> (Sends user text + complete code + base64 image)"]:::regular
    Baseline -->|Token Consumption| HeavyTokens["๐Ÿ’ฅ ~350,000 Tokens <br/> (Rate limit hit after 2 requests!)"]:::regular
    HeavyTokens -->|Result| QuotaError["๐Ÿšจ HTTP 429: Rate Limit Reached"]:::regular

    %% Optimized Path
    Choice -->|Imagica Refiner Engine| Imagica["โœ… Optimized Payload <br/> (Sends user text + current working code only)"]:::optimized
    Imagica -->|Token Consumption| LightTokens["โšก ~5,000 Tokens <br/> (Incredibly light, no image upload!)"]:::optimized
    LightTokens -->|Result| FastStream["๐Ÿš€ 5x Faster SSE Streaming Refinement"]:::optimized

    classDef result fill:#1e1b4b,stroke:#818cf8,stroke-width:2px,color:#fff;
    FastStream -->|Writes updates chunk-by-chunk| CodeUpdate["๐Ÿ“ Dynamic Code Sandbox Repersistence"]:::result
Loading

๐Ÿ› ๏ธ Complete Monorepo Technology Stack

Target Layer Framework / Module Highlights & Visual Customizations
Frontend Platform React 19, TypeScript Strict type safety, high-performance visual states, responsive dashboard grid
Monorepo Router wouter Blazing-fast router matching wildcards, trailing slashes normalizing, lightweight routing
Authentication @clerk/clerk-react Secure authentication locking down private workspace routes, fully integrated layout buttons
API Backend Node.js, Express, Pino Lightweight JSON API server, structured Pino logger streaming generation events
Database Engine Drizzle ORM, SQLite Fast SQLite database, type-safe queries, migration catalogs
Visual Styling Tailwind CSS v4, Lucide Spacey dark theme, HSL customized color palettes, seamless video loop landing page
Export Sandbox StackBlitz Custom SDK One-click export playgrounds assembling components instantly in live browser Sandboxes

๐Ÿ“ Repository Directory Structure

โ”œโ”€โ”€ artifacts/
โ”‚   โ”œโ”€โ”€ api-server/              # Express API Server (ports, DB controllers, Gemini routers, fallback loops)
โ”‚   โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ routes/          # Express route definitions (sketches stats, messages, refinement streams)
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ lib/             # Drizzle SQLite database configurations and Drizzle client connectors
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ index.ts         # Server entry point
โ”‚   โ”œโ”€โ”€ mockup-sandbox/          # Iframe Sandboxing server compiling user components for preview
โ”‚   โ””โ”€โ”€ sketch-to-component/     # Front-end workbench dashboard React client
โ”‚       โ”œโ”€โ”€ src/
โ”‚       โ”‚   โ”œโ”€โ”€ components/      # UI components (Header layout, settings modal, system statistics)
โ”‚       โ”‚   โ”œโ”€โ”€ pages/           # Pages (Landing page, Convert workbench, sketch details, preview tabs)
โ”‚       โ”‚   โ””โ”€โ”€ index.css        # Core custom-themed CSS and custom animation transitions
โ”œโ”€โ”€ lib/
โ”‚   โ”œโ”€โ”€ api-client-react/        # Auto-generated Tanstack Queries hooks querying the server
โ”‚   โ”œโ”€โ”€ api-spec/                # Monorepo OpenAPI contracts and Orval configurations
โ”‚   โ”œโ”€โ”€ api-zod/                 # Shared data validation Zod schemas (CreateSketch, Regenerate)
โ”‚   โ”œโ”€โ”€ db/                      # Shared SQLite migrations and schema tables (Conversations, Messages, Sketches)
โ”‚   โ””โ”€โ”€ integrations-gemini-ai/  # Shared Google Gen AI SDK client and resolution logic
โ”œโ”€โ”€ package.json                 # Monorepo workspace configuration
โ””โ”€โ”€ pnpm-workspace.yaml          # Monorepo dependencies definitions

โš™๏ธ Environment Configuration

To configure local or production instances, create separate .env files in their respective folders:

1. Frontend Configuration

Create artifacts/sketch-to-component/.env:

# Clerk Publishable Key (from clerk.com dashboard)
VITE_CLERK_PUBLISHABLE_KEY=pk_test_...

2. Backend Configuration

Create artifacts/api-server/.env:

# Clerk Secret Key (from clerk.com dashboard)
CLERK_SECRET_KEY=sk_test_...

Tip

You can also set GEMINI_API_KEY inside artifacts/api-server/.env to configure a default fallback key on the server side so your users don't need to configure one.


๐Ÿš€ Unified Execution Commands (Run and Build)

Imagica utilizes pnpm workspace filters to manage all packages from the root workspace directory. You never need to manually cd into individual folders.

๐Ÿ“ฆ 1. Installation

Install all monorepo dependencies, link local library packages, and compile workspace structures:

pnpm install

๐Ÿ’ป 2. Running in Development Mode

To start all servers (Frontend React App, Sandbox Preview Frame, and Backend Express API) concurrently in local development mode:

pnpm run dev
  • Frontend workbench Application: http://localhost:25383
  • Sandbox Preview Application: http://localhost:25384
  • API Backend Server: http://localhost:18080

๐Ÿ—๏ธ 3. Compiling for Production

To typecheck the entire monorepo and generate compiled production bundles:

pnpm run build

โš™๏ธ 4. Run Production Server

To start the compiled production Express server (which automatically serves the compiled frontend assets statically):

pnpm start

๐Ÿšจ 5. Typechecking & Linting

To perform isolated TypeScript compiler checks across all frontend libraries and backend services:

pnpm run typecheck

๐Ÿ”ฌ Isolated Sub-Project Operations

If you want to run commands inside specific sub-folders, you can use the --filter flag from the root directory:

  • Backend DB migrations generation:
    pnpm --filter @workspace/db run generate
  • Backend DB migrations execution:
    pnpm --filter @workspace/db run push
  • Regenerate frontend API client hooks from OpenAPI spec:
    pnpm --filter @workspace/api-spec run generate

Built with passion and ๐Ÿ”ฎ Google Gemini AI.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors