AnotherWrapper mostly uses App Router route handlers. Many “API features” don’t live in one central
/api folder — app-specific routes live right next to the app that owns them.Two Main API Areas
Shared API Routes (app/api/*)
These are routes used across the whole product:
- Better Auth handler and provider callbacks
- Avatar uploads
- OG image generation
- Payment webhooks
App-Specific API Routes
These live inside the product apps themselves, keeping logic close to the UI it belongs to:app/(apps)/chat/api/*app/(apps)/image-studio/api/*app/(apps)/video-studio/api/*app/(apps)/voice/api/*app/(apps)/audio/api/*app/(apps)/vision/api/*app/(apps)/marketing-plan/api/*app/(apps)/launch-simulator/api/*
Common Backend Patterns
Auth-first route protection
Auth-first route protection
Many routes use helpers like
requireApiUser() so protected actions fail fast if the user isn’t logged in. No guessing, no silent failures.Credit reservation and refund
Credit reservation and refund
AI generation routes typically follow this pattern:
- Authenticate the user
- Reserve credits
- Call the AI provider
- Store the result
- Refund credits if the generation fails
Provider abstraction
Provider abstraction
The backend doesn’t hardcode one provider flow per page. Instead, it routes through shared model/provider helpers. This means you can swap models without rewriting routes.
File-backed workflows
File-backed workflows
Uploads go through storage first. Then the stored asset URL is passed into the downstream generation or analysis flow. This keeps your file handling consistent across all apps.
Important Route Groups
Auth
Auth
Route:
app/api/auth/[...all]/route.tsThe catch-all auth handler powered by Better Auth. Handles sign-in, sign-up, sessions, and provider callbacks.Payments
Payments
Route:
app/api/payments/[provider]/route.tsThe shared webhook entrypoint for supported payment providers (Polar, Stripe, LemonSqueezy). Handles purchase verification, purchase persistence, credit allocation, and plan-state updates.Chat
Chat
The chat area has the deepest API surface:
- Streaming chat
- Conversation history
- Document generation
- Document upload/link/unlink/delete
- Document vectorization
- File upload
Generative Apps
Generative Apps
Image Studio, Video Studio, Voice Studio, Vision, Audio, Marketing Plan, and Launch Simulator each have their own generation routes with their own validation and provider requirements.

