Skip to content

About

AI-powered React component generator using Gherkin specifications and specialized agent pipelines.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

1 Commit

Folders and files

Repository files navigation

πŸ€– react-agents

AI-powered React component generator using Gherkin specifications and specialized agent pipelines.

πŸ“‹ Overview

react-agents generates production-ready React components directly from Gherkin feature files. Each component includes TypeScript code, CSS Module styles, Jest tests, and Ladle story filesβ€”all generated in parallel by specialized AI agents.

Workflow:

  1. Write component specs in Gherkin (.feature files)
  2. Run generator: pnpm run generate avatar
  3. Get: Component + Styles + Tests + Stories automatically
  4. Visualize stories in Ladle dev server
  5. Iterate

πŸ› οΈ Tech Stack

  • Monorepo: Turborepo + pnpm workspaces
  • Generator: TypeScript, Node.js
  • LLM API: OpenAI-compatible (Ollama local or OpenAI remote)
  • Component Framework: React 19, TypeScript
  • Styling: CSS Modules
  • Testing: Jest + React Testing Library
  • Visualization: Ladle.dev (component story browser)
  • Local LLM: Ollama (OpenAI-compatible API)

πŸ—οΈ Architecture

react-agents (monorepo)
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ generator/        # CLI: Gherkin β†’ Components
β”‚   β”œβ”€β”€ ladle/            # Story visualizer
β”‚   └── ...
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ shared/           # Shared types (future)
β”‚   └── ...
└── pnpm-workspace.yaml

βš™οΈ Requirements

Local Setup

  • Node.js 18+
  • pnpm 9.0+
  • Ollama running locally on port 11434
  • Qwen2.5-Coder model (ollama pull qwen2.5-coder)

Alternative (OpenAI API)

Set OPENAI_API_KEY environment variable instead of using Ollama.

πŸ“¦ Installation

# Install pnpm if needed
npm install -g pnpm@9

# Clone and install
git clone <repo>
cd react-agents
pnpm install

πŸš€ Quick Start

1. Start Ollama

ollama serve
# In another terminal:
ollama pull qwen2.5-coder

2. Generate a Component

# From repo root
pnpm run generate avatar
# or: pnpm run generate text, imagebutton, button

This creates in apps/ladle/stories/:

  • Avatar.tsx - Component
  • Avatar.module.css - Styles
  • Avatar.test.tsx - Tests
  • Avatar.story.tsx - Ladle story

3. View in Ladle

pnpm -F @react-agents/ladle dev
# Visit http://localhost:3000

πŸ’» Commands

Build

pnpm build                    # Build all apps
pnpm -F @react-agents/generator build  # Build generator only

Generate Components

pnpm run generate avatar      # Use avatar.feature file
pnpm run generate text        # Use text.feature file
pnpm run generate button      # Use button.feature file
node apps/generator/dist/index.js avatar  # Direct execution

Development

pnpm dev                      # Start all dev servers (ladle + generator watch)
pnpm -F @react-agents/ladle dev       # Start ladle only

Testing

pnpm test                     # Run all tests
pnpm test:watch              # Watch mode
pnpm -F @react-agents/generator test  # Generator tests only

✨ Adding a New Component

1. Create Feature File

Create apps/generator/features/mycomponent.feature:

Feature: MyComponent
  Brief description of what component does

  Scenario: Primary use case
    Given a MyComponent
    When props are set to X
    Then component renders as Y
    And displays Z

2. Generate Component

pnpm run generate mycomponent
# or: pnpm run generate mycomponent.feature

3. View in Ladle

pnpm -F @react-agents/ladle dev
# Visit http://localhost:3000
# Component story appears under MyComponent

Files created automatically:

  • apps/ladle/stories/MyComponent.tsx
  • apps/ladle/stories/MyComponent.module.css
  • apps/ladle/stories/MyComponent.test.tsx
  • apps/ladle/stories/MyComponent.story.tsx

Edit files as needed. Next generation overwrites them.

πŸ§ͺ Feature Files (Gherkin)

Located in apps/generator/features/:

Feature: Avatar
  Display user avatar as circular image

  Scenario: Render avatar from URL
    Given an Avatar component
    When provided with imageUrl prop
    Then the avatar displays the image
    And the image is circular (border-radius: 50%)
    And the image has fixed size (48px)

⚑ Configuration

Local vs Remote LLM

Default (Ollama, local):

pnpm run generate avatar
# Uses http://localhost:11434/v1 automatically

OpenAI API:

OPENAI_API_KEY=sk_... pnpm run generate avatar

Model Selection

Edit apps/generator/src/agents/pipeline.json:

{
  "model": "qwen2.5-coder",  // Change to gpt-4, claude-3, etc
  "pipeline": [...]
}

πŸ”„ Pipeline

Generator runs agents in parallel:

  1. GherkinParser β€” Parse .feature β†’ ComponentModel
  2. ReactGenerator β€” Generate React component (TypeScript validation)
  3. StyleGenerator βˆ₯ TestGenerator βˆ₯ StoryGenerator β€” Run in parallel
    • StyleGenerator β†’ CSS Modules
    • TestGenerator β†’ Jest tests
    • StoryGenerator β†’ Ladle story

πŸ”§ Troubleshooting

"Cannot find module" errors

Ensure all relative imports have .js extensions in compiled output (handled automatically).

Ollama connection refused

Check Ollama is running:

ollama serve

Model not found

ollama pull qwen2.5-coder
# List available: ollama list

TypeScript errors in generated code

Non-critical. Generator logs them but continues (see ⚠️ Some TypeScript errors remain).

πŸ“ Project Structure

  • apps/generator/src/ β€” Main CLI
    • index.ts β€” Entry point
    • OrchestratorAgent.ts β€” Pipeline orchestrator
    • sub-agents/ β€” Specialized AI agents
    • agents/pipeline.json β€” Agent pipeline config
    • features/ β€” Gherkin files
  • apps/ladle/ β€” Component visualizer
    • stories/ β€” Generated component stories
  • .ladle/config.mjs β€” Ladle configuration
  • turbo.json β€” Turborepo task config
  • pnpm-workspace.yaml β€” Workspace definition

🎯 Next Steps

  • Add more Gherkin feature files
  • Generate component library
  • Deploy Ladle as static site
  • Extend agents for more languages (Vue, Svelte)
  • Add E2E tests with Playwright

About

AI-powered React component generator using Gherkin specifications and specialized agent pipelines.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages