How samuraigpt/ai-hair-style-simulator works
This is a Next.js virtual hairstyle makeover SaaS. A signed-in user uploads a portrait, chooses style and color parameters, and submits a generation; results are saved for the personal gallery. Separate branches cover Google/API-key authentication and one-time Stripe credit purchases. The README documents these capabilities; implementation excerpts show generation, credit, and persistence calls, while unsampled UI and webhook wiring is represented only where documented.
Main entry points: schema.prisma PostgreSQL data · route.js Hairstyle generation · billing.js Billing service · page.js Makeover studio
Components 21
Makeover workflow
- Makeover studio
src/app/page.js - Portrait upload
src/app/api/upload/route.js - Hairstyle generation
src/app/api/generation/route.js - Generation callback
src/app/api/webhook/muapi/route.js
Accounts and credits
- Login page
src/app/login/page.js - Authentication
src/lib/auth.js - Auth endpoint
src/app/api/auth/[...nextauth]/route.js - Account navigation
src/components/Navbar.js - API key management
src/app/api/user/apikey/route.js - Credit operations
src/lib/services/user.js
Showroom and storage
- Personal gallery
src/app/gallery/page.js - Creation management
src/app/api/creations/route.js - Single creation
src/app/api/creations/[id]/route.js - PostgreSQL data
prisma/schema.prisma
Credit billing
- Credit packs
src/app/pricing/page.js - Checkout endpoint
src/app/api/checkout/route.js - Billing service
src/lib/services/billing.js - Stripe webhook
src/app/api/stripe/webhook/route.js
Other components
- User
- MuAPI AI
- Stripe
Connections 27
- User → Makeover studio: chooses styles
README.md - Makeover studio → Portrait upload: uploads portrait
- Portrait upload → MuAPI AI: uploads image
src/app/api/upload/route.js - Makeover studio → Hairstyle generation: submits parameters
- Hairstyle generation → Credit operations: deducts credits
src/app/api/generation/route.js - Hairstyle generation → MuAPI AI: requests image
src/app/api/generation/route.js - Hairstyle generation → PostgreSQL data: saves creation
src/app/api/generation/route.js - MuAPI AI → Generation callback: sends result
README.md - Generation callback → PostgreSQL data: updates result
- User → Login page: signs in
README.md - Login page → Auth endpoint: starts authentication
- Auth endpoint → Authentication: uses options
src/app/api/auth/[...nextauth]/route.js - Authentication → PostgreSQL data: persists accounts
src/lib/auth.js - Account navigation → API key management: saves key
src/components/Navbar.js - API key management → PostgreSQL data: stores key
src/app/api/user/apikey/route.js - Personal gallery → Creation management: browses designs
- Creation management → PostgreSQL data: lists and deletes
src/app/api/creations/route.js - Single creation → PostgreSQL data: reads and deletes
src/app/api/creations/[id]/route.js - Creation management → MuAPI AI: checks status
src/app/api/creations/route.js - User → Credit packs: chooses pack
README.md - Credit packs → Checkout endpoint: starts purchase
- Checkout endpoint → Billing service: creates session
src/app/api/checkout/route.js - Billing service → Stripe: creates checkout
src/lib/services/billing.js - Stripe → Stripe webhook: reports completion
README.md - Stripe webhook → Billing service: handles event
src/app/api/stripe/webhook/route.js - Billing service → Credit operations: adds credits
src/lib/services/billing.js - Credit operations → PostgreSQL data: updates balances
src/lib/services/user.js