Skip to main content
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/*
Good rule of thumb: if a route is tightly tied to one app’s UX, keep it in that app’s folder. If it’s shared across the whole product, it belongs under app/api.

Common Backend Patterns

Many routes use helpers like requireApiUser() so protected actions fail fast if the user isn’t logged in. No guessing, no silent failures.
AI generation routes typically follow this pattern:
  1. Authenticate the user
  2. Reserve credits
  3. Call the AI provider
  4. Store the result
  5. Refund credits if the generation fails
This pattern shows up across multiple AI app routes and keeps your credit system reliable.
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.
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

Route: app/api/auth/[...all]/route.tsThe catch-all auth handler powered by Better Auth. Handles sign-in, sign-up, sessions, and provider callbacks.
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.
The chat area has the deepest API surface:
  • Streaming chat
  • Conversation history
  • Document generation
  • Document upload/link/unlink/delete
  • Document vectorization
  • File upload
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.