A generative UI system using recursive idea-based expansion with LangGraph. The system takes natural language prompts and generates hierarchical component structures through parallel LLM expansion.
.
├── backend/ # Python FastAPI backend
│ ├── main.py # FastAPI application with streaming endpoints
│ ├── graph/ # LangGraph workflow
│ │ ├── workflow.py # Graph definition
│ │ ├── nodes.py # Expansion nodes
│ │ ├── state.py # State management with reducers
│ │ └── components.py # Component library (30+ components)
│ └── pyproject.toml # Python project configuration
└── frontend/ # React frontend
├── src/
│ ├── pages/
│ │ └── GraphDebug.jsx # Graph state viewer
│ ├── main.jsx # Application entry point
│ ├── App.jsx # Router configuration
│ └── index.css # Global styles
├── index.html
├── package.json
└── vite.config.js
Recursive Idea-Based Expansion:
- Components can contain "idea" fields - high-level descriptions that spawn recursive LLM calls
- LangGraph state reducers automatically merge parallel expansions into the component tree
- Map-reduce pattern for parallel idea expansion using
Send[]
Component Library: 30+ pre-defined components across categories:
- Layout: rail, stack, cluster, grid
- Content: card, panel, tabs, accordion
- Typography: header, text, code, blockquote
- Media: image, icon, avatar, video
- Interactive: button, input, select, checkbox
- Data Display: table, list, stat, chart
- Navigation: breadcrumb, menu, link
Graph Flow:
- Root expansion: User prompt → top-level component tree
- Parallel expansion: All components with "idea" fields expand simultaneously
- Recursive loop: Process continues until no pending ideas remain
- State reducer: Merges all updates into final tree
- Python 3.11+
- uv - Fast Python package installer
- Node.js 18+
- Just command runner
- OpenAI API key (set in
backend/.env)
Install uv:
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Or with pip
pip install uvInstall Just:
# macOS
brew install just
# Linux
cargo install just
# Or download from releasesCreate backend/.env with your OpenAI API key:
OPENAI_API_KEY=your-api-key-here# Install all dependencies
just install
# Run both backend and frontend
just devjust # List all commands
just install # Install all dependencies
just install-backend # Install backend dependencies only
just install-frontend # Install frontend dependencies only
just dev # Run both servers in parallel
just dev-backend # Run backend only (localhost:8000)
just dev-frontend # Run frontend only (localhost:5173)
just build # Build frontend for production
just clean # Remove all build artifacts and dependenciescd backend
uv venv
uv pip install -r pyproject.toml
uv run uvicorn main:app --reloadBackend runs at http://localhost:8000
cd frontend
npm install
npm run devFrontend runs at http://localhost:5173
GET /api/health- Health check endpointPOST /api/generate-ui- Generate component tree from prompt (returns final result)POST /api/generate-ui/stream- Stream graph state updates in real-time (SSE)
curl -X POST http://localhost:8000/api/generate-ui \
-H "Content-Type: application/json" \
-d '{"prompt": "Create a dashboard with metrics and charts"}'The /stream endpoint sends Server-Sent Events with graph state updates:
const response = await fetch('http://localhost:8000/api/generate-ui/stream', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prompt: 'your prompt' })
})
const reader = response.body.getReader()
// Process SSE events: state_update, done, error- Backend auto-reloads on file changes
- Frontend hot-reloads on file changes
- Graph Debug UI at http://localhost:5173 shows real-time state evolution
- Console logs show expansion progress and parallel execution
- Prompt Input: User provides natural language UI description
- Root Expansion: LLM generates top-level structure with "idea" placeholders
- Parallel Processing: All "idea" fields expand simultaneously via
Send[] - State Merging: Custom reducer merges child expansions into parent components
- Recursive Loop: Process repeats until no "idea" fields remain
- Final Tree: Complete component hierarchy ready for rendering