# Voice Clone Microsite — Master Build Plan

**Stack:** PHP 8 + MySQL + vanilla JS front-end. Stripe for payments. Resemble AI for TTS/cloning (pending licensing confirmation — see Pre-flight).
**Design principle:** boring, simple, maintainable. No frameworks that need a full-time developer.

---

## PRE-FLIGHT (do these before/while building — no code required)

1. **Email Resemble sales.** Describe the business: "a marketplace where my customers pay to generate voiceovers using stock voices and consented actor clones." Get the required plan tier and reseller permission IN WRITING. Do not launch without this.
2. **Turn on Stripe Tax** in your Stripe dashboard (handles EU VAT automatically).
3. **Draft the two legal docs:** (a) Voice Actor Cloning Agreement (consent, revenue share, revocation right, prohibited uses); (b) Client Terms of Service (prohibited content, license granted for generated audio). Have a lawyer review both.
4. Ask an accountant to confirm the non-Union OSS VAT position for B2C EU sales.

---

## PHASE 1 — Foundation (build first)
- [ ] Import `sql/schema.sql` into MySQL
- [ ] `config/config.php` — DB credentials, API keys (server-side only, NEVER in public/)
- [ ] Client signup / login / password reset (standalone auth; `legacy_user_id` column links to main site later)
- [ ] Simple admin login (separate table or hardcoded admin list to start)

## PHASE 2 — Money (build second — nothing generates until credits exist)
- [ ] Credit packages page (e.g. Starter 1,000 / Pro 5,000 / Studio 20,000 credits)
- [ ] Stripe Checkout integration + webhook that adds credits via `credit_ledger`
- [ ] RULE: credit_balance is ONLY ever changed through a ledger insert + balance update in one transaction. Never update the balance directly.
- [ ] VAT: country + optional VAT-number field at checkout; Stripe Tax does the math

## PHASE 3 — Stock voice MVP (this is the fast-revenue launch)
- [ ] Voice browse page (filter by gender/language/style, play sample clips)
- [ ] Project creation: pick voice → paste script
- [ ] Script splitter: break script into sentences → `script_segments` rows
- [ ] THE EDITOR (the heart of the product):
      - each segment is a card: text, emotion dropdown, generate button, audio player
      - emotion dropdown maps to hidden SSML/style prompts (client never sees markup)
      - word highlight → "Fix pronunciation" (sounds-like box) → saved to pronunciation_rules
      - regenerate a single segment without touching the others
      - multiple takes per segment; client picks the winner
      - "Add pause" between segments
- [ ] Moderation filter: blocked-terms check on every segment BEFORE the API call; log to moderation_flags
- [ ] Credit check BEFORE every generation; deduct via ledger; fail politely if broke
- [ ] Stitch selected takes into final MP3/WAV (ffmpeg concat) → project download page
- [ ] Audit log on every generation

## PHASE 4 — Actor clones (the premium product)
- [ ] Actor onboarding: invite → consent e-sign → recording upload (store OUR master copy) → send to provider → clone trains → ACTOR APPROVAL GATE (actor listens + approves own clone) → live
- [ ] Clone voices priced with price_multiplier (e.g. 2–3x stock)
- [ ] actor_earnings row written automatically on every clone take
- [ ] Actor dashboard: their earnings, usage stats, pause/revoke button
- [ ] Monthly payout admin page

## PHASE 5 — Polish / later
- [ ] Link auth to main site (legacy_user_id) — needs main-site files/developer
- [ ] Import actor profiles from main site
- [ ] Speech-to-speech premium tier (client or actor records delivery, converts to clone)
- [ ] File retention policy + "permanent storage" upsell

---

## PRICING MODEL (starting point — adjust after seeing real API costs)
- 1 credit ≈ 1 character of generated text is simplest to explain.
- Set credit price so revenue per character ≈ 4–6x your API cost per character (covers regenerations, storage, Stripe fees, actor royalties, profit).
- Clone voices: price_multiplier 2.5x. Actor gets revenue_share_pct (default 30%) of clone-generation credits.
- Regenerations cost credits too (that's why the credit system exists), but sentence-level regen keeps it cheap for clients.

## SECURITY RULES (non-negotiable)
1. Provider API key lives in config/, server-side only. Public/ contains no secrets.
2. Every generation request: authenticate client → moderation check → credit check → API call → ledger deduct. In that order.
3. All DB access via prepared statements (PDO). No string-built SQL, ever.
4. Passwords: password_hash()/password_verify() only.
5. Stripe webhooks verified with the signing secret.

## FIRST PROMPT TO GIVE CLAUDE CODE
"Read docs/BUILD-PLAN.md and sql/schema.sql in this folder. We're starting Phase 1.
Build config/config.php (with a config.example.php template), a PDO database
connection helper in src/db.php, and the client signup/login pages in public/.
PHP 8, PDO prepared statements, password_hash. Explain what you built in
plain English when done."
