A production-ready AI-powered UI generator that converts natural language descriptions into working React components using a deterministic component library. Built with multi-step AI agent orchestration.
This application demonstrates:
- Multi-step AI agent orchestration (Planner โ Generator โ Explainer)
- Deterministic component system (fixed library, no arbitrary generation)
- Incremental code modification (not full rewrites)
- Live preview with real-time rendering
- Version history and rollback capability
- Safety validation (component whitelist, prompt injection protection)
The system uses a three-step agent architecture:
User Intent โ [Planner] โ [Generator] โ [Explainer] โ UI Code + Explanation
Planner Agent
- Analyzes user intent
- Chooses layout structure
- Selects components from fixed library
- Outputs structured JSON plan
Generator Agent
- Converts plan to React code
- Uses only whitelisted components
- Enforces prop constraints
- Produces valid, formatted code
Explainer Agent
- Explains design decisions
- References specific choices
- Provides context and reasoning
Fixed Component Library:
Button- Interactive button with variants (primary, secondary, outline, ghost)Card- Container with title, content, and footerInput- Form input with labelTable- Data table with columns and rowsModal- Overlay dialogSidebar- Navigation sidebarNavbar- Top navigation barChart- Charts using recharts (line, bar, pie, area)
Design Principles:
- Components are immutable - implementation never changes
- Only composition and props can vary
- No inline styles or custom CSS allowed
- Tailwind core utilities only
- Visual consistency enforced through validation
Component Whitelist Enforcement:
- Validates all components against whitelist
- Blocks unauthorized component usage
- Prevents inline styles and dynamic CSSPrompt Injection Protection:
- Structured JSON responses
- Validation before rendering
- Error handling for invalid outputs
Code Validation:
- Syntax checking
- Component usage validation
- Prop validation
- Node.js 18+
- Anthropic API key
- Clone the repository:
git clone <your-repo-url>
cd ai-ui-generator- Install dependencies:
npm install- Set up environment variables:
cp .env.example .env.local- Add your Anthropic API key to
.env.local:
ANTHROPIC_API_KEY=your_api_key_here
- Run development server:
npm run devnpm run build
npm start-
Describe your UI in the chat panel (left)
- Example: "Create a dashboard with sales charts and a table"
-
View generated code in the middle panel
- Fully editable
- Syntax highlighted
- Live updates
-
See live preview in the right panel
- Real-time rendering
- Uses actual component library
- Error handling
-
Iterate with chat
- "Add a modal for user settings"
- "Make the table sortable"
- AI modifies existing code incrementally
-
Rollback if needed
- Version history tracks all generations
- One-click restore to previous versions
Dashboard:
Create a sales dashboard with:
- Navbar at the top
- Sidebar with navigation
- Cards showing KPIs
- Charts for trends
Form:
Build a user profile form with:
- Input fields for name, email, password
- Save and Cancel buttons
- Validation messages
Data View:
Make a data table showing user information with:
- Columns for name, email, role, status
- Striped rows
- Action buttons
Incremental Edits:
Add a modal that opens when clicking the settings button
Make the cards elevated instead of outlined
Change the navbar to dark variant
- Frontend: Next.js 14, React 18, TypeScript
- AI: Anthropic Claude (Sonnet 4)
- Styling: Tailwind CSS
- Charts: Recharts
- State: React hooks + Zustand (lightweight)
- Syntax Highlighting: Prism.js
- Notifications: React Hot Toast
ai-ui-generator/
โโโ app/
โ โโโ api/
โ โ โโโ generate/
โ โ โโโ route.ts # API endpoint for AI generation
โ โโโ globals.css # Global styles
โ โโโ layout.tsx # Root layout
โ โโโ page.tsx # Main application page
โโโ components/
โ โโโ ui/ # Fixed component library
โ โ โโโ Button.tsx
โ โ โโโ Card.tsx
โ โ โโโ Input.tsx
โ โ โโโ Table.tsx
โ โ โโโ Modal.tsx
โ โ โโโ Sidebar.tsx
โ โ โโโ Navbar.tsx
โ โ โโโ Chart.tsx
โ โโโ ChatPanel.tsx # Chat interface
โ โโโ CodeEditor.tsx # Code editing panel
โ โโโ Preview.tsx # Live preview renderer
โ โโโ VersionHistory.tsx # Version management
โโโ lib/
โ โโโ agent.ts # AI agent orchestrator
โ โโโ components.ts # Component library definitions
โโโ types/
โ โโโ index.ts # TypeScript types
โโโ README.md
โ
Select components from the library
โ
Compose layouts using allowed components
โ
Set props within allowed values
โ
Provide content and data
โ
Modify existing code incrementally
โ Create new components
โ Modify component implementations
โ Use inline styles
โ Generate arbitrary CSS
โ Use external UI libraries
โ Access components outside the whitelist
Each generation involves three distinct AI calls with separate prompts, ensuring:
- Clear separation of concerns
- Traceable decision-making
- Explainable outputs
Same intent + same state โ same output
- Component library is fixed
- No randomness in component selection
- Consistent visual results
When modifying existing UI:
- AI analyzes current code
- Makes targeted changes
- Preserves working components
- Avoids unnecessary rewrites
- Component whitelist enforcement
- Prop validation
- Syntax checking before rendering
- Error boundaries
- Graceful degradation
- Predictability: Users know what's possible
- Consistency: Visual coherence across generations
- Safety: No arbitrary code execution
- Performance: Pre-built, optimized components
- Transparency: Each step is visible and debuggable
- Quality: Specialized prompts for each task
- Flexibility: Easy to add new steps or modify existing ones
- SSR Support: Better performance and SEO
- API Routes: Backend logic in same codebase
- TypeScript: Type safety throughout
- Hot Reload: Instant feedback during development
-
Component Library Size: Limited to 8 components
- Could be extended with more components
- Current set covers most common use cases
-
Styling Flexibility: Only Tailwind core classes
- Prevents arbitrary styling
- Ensures visual consistency
- Trade-off for safety
-
Complex Interactions: Limited to prop-based state
- No custom hooks or complex state management
- Suitable for presentational UIs
- Could be extended with state management
-
Error Recovery: Basic error handling
- Could add more sophisticated validation
- Better error messages for users
- Retry mechanisms
With more time, I would add:
- Streaming AI Responses: Real-time generation feedback
- Diff View: Visual comparison between versions
- Component Schema Validation: JSON schema for components
- Static Analysis: AST-based code validation
- Export Functionality: Download generated code
- Import Existing Code: Upload and modify existing UIs
- Undo/Redo: Granular history navigation
- Code Formatting: Prettier integration
- Dark Mode: Theme switching
- Keyboard Shortcuts: Power user features
- Guided Tutorials: Interactive onboarding
- Layout Suggestions: Visual layout options
- Component Recommendations: Smart suggestions
- Accessibility Checks: A11y validation
- Performance Analysis: Optimization hints
- Multi-Language Support: i18n generation
- Authentication: User accounts and persistence
- Database: Save projects across sessions
- Collaboration: Real-time multi-user editing
- API Rate Limiting: Production-ready rate limits
- Monitoring: Error tracking and analytics
ANTHROPIC_API_KEY=sk-ant-... # Required: Your Anthropic API keynpm testnpm run lintnpx tsc --noEmitMIT License - See LICENSE file for details
This is a demonstration project for the Ryze AI assignment. For production use, consider:
- Adding comprehensive tests
- Implementing authentication
- Adding database persistence
- Setting up monitoring
- Implementing rate limiting
For questions about this assignment, please contact the Ryze AI team.
Built with โค๏ธ for Ryze AI Full-Stack Assignment