# CLAUDE.md — RateRight v2 Build Instructions

## What You're Building
An AI-first construction hiring marketplace. Read PRODUCT-SPEC.md for the full spec.

## Tech Stack
- **Frontend:** Next.js 14+ with App Router, Tailwind CSS, shadcn/ui
- **Backend:** Supabase (Postgres, Auth, Realtime, Edge Functions, Storage)
- **AI Layer:** OpenAI/Anthropic for LLM features, Whisper for voice transcription
- **Payments:** Stripe ($50 flat fee per hire)
- **Deployment:** Vercel

## Supabase Connection (NEW PROJECT: rateright-v2)
- **Project ref:** `eciepjpcyfurbkfzekok`
- **URL:** `https://eciepjpcyfurbkfzekok.supabase.co`
- **Anon Key:** In `.env.local` as `NEXT_PUBLIC_SUPABASE_ANON_KEY`
- **Service Role Key:** In `.env.local` as `SUPABASE_SERVICE_ROLE_KEY`. Use for admin operations that bypass RLS.
- **Access Token:** `$SUPABASE_ACCESS_TOKEN` env var (set in bashrc). Use for Supabase CLI and Management API.
- **CLI linked:** `npx supabase` is linked to this project. Use `npx supabase db push` for migrations.

### Running SQL Migrations
You have THREE ways to run SQL against the database:
1. **Management API (preferred):** `curl -s "https://api.supabase.com/v1/projects/eciepjpcyfurbkfzekok/database/query" -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" -H "Content-Type: application/json" -d '{"query": "YOUR SQL HERE"}'`
2. **Supabase CLI:** `SUPABASE_ACCESS_TOKEN=$SUPABASE_ACCESS_TOKEN npx supabase db push`
3. **Node.js admin client:** Use `createClient(url, serviceRoleKey)` for CRUD operations (not DDL)

**DO NOT say you can't access the database. You have full access via the Management API.**

### Current Schema (11 tables)
profiles, companies, worker_profiles, jobs, matches, ratings, payments, notifications, conversations, conversation_participants, messages

All have RLS enabled with proper policies. Auth trigger `handle_new_user` auto-creates profiles on signup.

## MVP Priority (Build in this order)
1. Project scaffolding (Next.js + Supabase + Tailwind + shadcn/ui)
2. Database schema (see PRODUCT-SPEC.md section 7)
3. Auth flow (Supabase Auth — email/phone signup)
4. Contractor signup with AI company research
5. Worker signup (simple form, 5 questions)
6. Job posting with AI suggestions
7. Smart matching + worker browsing
8. One-tap hire flow
9. Stripe payment ($50)
10. Ratings system
11. Push notifications

## Design Principles
- **Mobile-first** — designed for construction workers on phones
- **One-tap everything** — minimize clicks/taps
- **AI does the work** — pre-fill, suggest, auto-complete
- **Ultra simple** — if a screen has more than 3 actions, simplify it
- **Fast** — every page loads in <1 second
- **Australian** — use AUD, Australian English, local references

## Code Style
- TypeScript everywhere
- Server components by default, client components only when needed
- Supabase client via @supabase/ssr
- Environment variables in .env.local
- Keep components small and focused
- Use shadcn/ui for all UI components

## Database Operations — You Have Full Access
- **Supabase CLI:** `npx supabase` available for migrations
- **Direct SQL:** Use service role key to run SQL against the database directly via curl or supabase-js admin client
- **Migrations:** Create in `supabase/migrations/`, run via Supabase dashboard SQL Editor or CLI
- **RLS policies:** You can create, modify, delete RLS policies
- **Triggers/Functions:** You can create/update database triggers and functions
- **Schema changes:** You can add columns, tables, indexes — just document what you changed
- **DO NOT** drop tables or delete data without confirmation
- **DO** fix broken triggers, add missing policies, update functions
- When you find a DB issue, fix it directly — don't just document it

## Git — Push Your Work
- `git add`, `git commit`, `git push` — you have full permissions
- Commit messages: descriptive, prefixed (fix:, feat:, audit:, chore:)
- Push to main branch directly

## Agent Teams
- You can spawn sub-agents for parallel work
- Use agent teams for: security review + code fixes + build verification simultaneously
- Each agent gets its own context — assign clear, scoped tasks

## Important
- This is a REAL business with REAL users coming
- Quality matters — no shortcuts on auth, payments, or data handling
- Mobile experience is MORE important than desktop
- Every AI feature should have a manual fallback
