# AI Profile Builder Feature

**Location:** `/worker/profile/build`  
**Status:** ✅ Complete  
**Committed:** 2026-02-05

## Overview

A streamlined 4-step wizard that uses AI to generate complete worker profiles in under 30 seconds. Workers answer simple questions, AI generates a professional bio with skills and certifications, and workers can review/edit before saving.

## User Flow

1. **Trade Selection** — Grid of 16 common trades (Carpenter, Electrician, etc.)
2. **Experience** — 5 options from "Less than 1 year" to "10+ years"
3. **Location** — Free-form text input for suburb/area
4. **Availability** — 4 options (Full-time, Casual, Weekends, Flexible)
5. **AI Generation** — Shows animated loading screen while GPT-4o-mini generates profile
6. **Review & Edit** — Workers can edit bio, remove skills/certs they don't want

## Design Principles

Following UX research findings for construction workers:

- **64px touch targets** — Glove-friendly buttons
- **Bottom sticky CTAs** — Primary actions always at thumb reach
- **Mobile-first** — Optimized for phone use on job sites
- **Under 30 seconds** — Streamlined flow, minimal taps
- **Uber-style simplicity** — One question per screen, clear progress

## Technical Implementation

### Frontend (`/src/app/worker/profile/build/page.tsx`)
- Next.js 16 client component
- shadcn/ui components (Button, Input, Label, Card)
- Tailwind CSS styling
- 6 step states: trade → experience → location → availability → generating → review
- Editable review with textarea for bio, removable chips for skills/certs

### Backend (`/src/app/api/ai/generate-profile/route.ts`)
- Next.js API Route
- OpenAI SDK (GPT-4o-mini model)
- JSON response format enforced
- Generates:
  - **Bio:** 2-3 sentence professional summary (50-80 words)
  - **Skills:** 6-10 trade-specific technical skills
  - **Certifications:** 3-5 relevant Australian construction certifications

### Database
Saves to `worker_profiles` table:
```sql
{
  profile_id: uuid,
  trades: string[],
  experience_years: integer,
  availability: enum,
  certifications: string[],
  bio: text,
  ai_extracted: jsonb  -- Stores original AI output + metadata
}
```

## Setup Instructions

### 1. Environment Variables
Add to `.env.local`:
```bash
OPENAI_API_KEY=your_openai_api_key_here
```

Get your API key from: https://platform.openai.com/api-keys

### 2. Install Dependencies
Already installed via `package.json`:
```bash
npm install openai
```

### 3. Run Development Server
```bash
npm run dev
```

Navigate to: `http://localhost:3000/worker/profile/build`

## Cost Estimation

Using GPT-4o-mini (cheapest OpenAI model):
- **Input:** ~250 tokens (prompt with user data)
- **Output:** ~200 tokens (bio + skills + certs)
- **Cost per generation:** ~$0.0003 USD (less than 1 cent)
- **For 1000 profiles:** ~$0.30 USD

Extremely affordable at scale.

## Example AI Output

**Input:**
- Trade: Carpenter
- Experience: 4 years
- Location: Parramatta
- Availability: Full-time

**Generated Bio:**
> "Experienced carpenter with 4 years in residential and commercial construction. Based in Parramatta, available for full-time work. Skilled in framing, finishing, formwork, and blueprint reading. Holds White Card, Working at Heights, and First Aid certifications."

**Generated Skills:**
- Framing & structural carpentry
- Finish carpentry & joinery
- Formwork installation
- Blueprint reading
- Power tool operation
- Measurement & layout
- Timber & composite materials
- Site safety compliance

**Generated Certifications:**
- White Card (General Construction Induction)
- Working at Heights
- First Aid Level 2
- Hand & Power Tool Safety

## Next Steps

- [ ] Add voice input option (alternative to typing)
- [ ] Allow uploading resume/CV to auto-fill
- [ ] Add photo upload for profile picture
- [ ] Implement skills auto-complete/suggestions
- [ ] Add certification verification (photo upload of cards)
- [ ] A/B test different AI prompts for better output

## Notes

- TypeScript compilation passes ✅
- Follows existing app patterns (same header, progress bar, step structure as worker signup)
- Mobile-optimized with proper safe-area handling
- Error handling for API failures
- Loading states for all async operations
- Auth check redirects unauthenticated users to login
