# Frontend Builder Agent > SF-03 — Automated Frontend Project Generation ## Overview The Frontend Builder Agent consumes PRD (SF-01) + Architecture (SF-02) and generates a **complete, runnable Next.js project** with TypeScript and Tailwind CSS. Every page is a **real component** with meaningful JSX, state management, and API integration patterns — no stubs. ## Quick Start ```bash # From PRD + Architecture files node scripts/frontend-builder-agent.mjs --prd prd-example.json --arch architecture-example.json --verbose # Full pipeline from one sentence node scripts/frontend-builder-agent.mjs --input-text "做一个宠物管理 App" --output my-app ``` ## Output Structure ``` frontend/ ├── app/ # Next.js App Router pages │ ├── page.tsx # Home page │ ├── layout.tsx # (in src/app/) │ ├── pet/[id]/page.tsx # Dynamic route │ ├── schedule/page.tsx │ ├── daily-log/page.tsx │ ├── album/page.tsx │ ├── hospitals/page.tsx │ └── profile/page.tsx ├── components/ │ ├── ui/ # Shared UI (Button, Card, Input, Modal, EmptyState) │ ├── layout/ # Sidebar, BottomNav │ └── {domain}/ # Domain components (PetCard, ProductCard, NoteCard) ├── hooks/ # Custom React hooks │ ├── usePets.ts # Per-resource data hooks │ ├── useSchedules.ts │ ├── useForm.ts # Generic hooks │ └── useDebounce.ts ├── services/ # API service layer │ ├── api.ts # Base API client (get/post/put/delete) │ ├── pets.ts # Per-resource API functions │ └── schedules.ts ├── types/ │ └── index.ts # TypeScript interfaces ├── package.json ├── tsconfig.json ├── tailwind.config.ts ├── next.config.ts └── postcss.config.js ``` ## Architecture ``` ┌─────────────────────────────────────────────────────┐ │ SF-03 Frontend Builder │ │ │ │ PRD + Architecture ──▶ │ │ │ │ 1. Type Generator │ │ Domain → TS interfaces (User, Pet, Order...) │ │ Always: ApiResponse, PaginatedResponse │ │ │ │ 2. Config Generator │ │ package.json, tsconfig, tailwind, next.config │ │ │ │ 3. Layout Generator │ │ Root layout + Sidebar (desktop) + BottomNav │ │ Auto-generates nav from PRD pages │ │ │ │ 4. UI Component Generator │ │ Button, Card, Input, Modal, EmptyState │ │ All with props, variants, accessibility │ │ │ │ 5. Domain Component Generator │ │ pet → PetCard, ScheduleCard │ │ ecommerce → ProductCard │ │ note → NoteCard │ │ │ │ 6. Page Generator │ │ Per-route page with real JSX │ │ Domain-specific layouts & interactions │ │ Loading, error, and empty states │ │ │ │ 7. Hook Generator │ │ Per-resource: usePets, useSchedules... │ │ Generic: useForm, useDebounce │ │ │ │ 8. API Service Generator │ │ Base client with fetch wrapper │ │ Per-resource: get/post/put/delete functions │ │ │ │ ──────────────▶ frontend/ directory │ └─────────────────────────────────────────────────────┘ ``` ## Page Quality Every generated page contains: - **Layout**: Heading, description, grid/flex layout - **State**: `useState` for interactive elements - **Hooks**: `useEffect` for data loading simulation - **Loading state**: Spinner animation - **Error state**: Error message with retry button - **Empty state**: Illustrated empty state with CTA - **Data display**: Cards, lists, grids with real-looking mock data - **Interactivity**: Buttons, toggles, modals, forms No page is a simple `return