Project Structure
Overview of the codebase layout and key directories.
├── app/[locale]/ # i18n routes
│ ├── (auth)/ # Auth pages (login, signup, forgot-password)
│ ├── (marketing)/ # Public pages (home, pricing, blog, contact)
│ ├── (protected)/ # Authenticated pages (dashboard, profile, credits)
│ ├── (admin)/ # Admin panel (users, subscriptions, credits)
│ ├── demo/ # AI demo pages (chat, image, video)
│ └── docs/ # Documentation (Fumadocs)
├── app/api/ # API routes
│ ├── auth/ # Better Auth + custom auth endpoints
│ ├── payments/ # checkout + dodo/webhook + waffo/webhook
│ ├── chat/ # Chat API (streaming)
│ ├── image/ # Image generation API
│ ├── video/ # Video generation API (async)
│ ├── admin/ # Admin operations API
│ └── cron/ # Scheduled tasks (credit grants)
├── components/ # Reusable UI components
├── features/ # Feature modules (auth, admin, forms, navigation)
├── lib/ # Core business logic
│ ├── auth.ts # Better Auth config
│ ├── db/ # Database connection and schema
│ ├── credits.ts # Credit system logic
│ ├── payments/ # provider-agnostic + providers/{dodo,waffo}
│ ├── billing/ # Subscription and credit scheduling
│ ├── volcano-engine/ # Volcano Engine API wrappers
│ └── email.ts # Email sending logic
├── constants/ # Constants
│ ├── billing.ts # Pricing plans and credit packs
│ ├── tier.ts # User tier definitions
│ └── website.ts # Site metadata
├── content/docs/ # Documentation content (MDX)
├── messages/ # i18n translation files (en, zh)
└── drizzle/ # Database migration files
| Group | Path | Access | Purpose |
|---|
(auth) | /login, /signup | Public | Authentication flows |
(marketing) | /, /pricing, /blog | Public | Marketing and SEO pages |
(protected) | /dashboard, /profile | Auth required | User app features |
(admin) | /admin/* | Admin role | Management panel |
demo | /demo/* | Public | AI feature demos |
docs | /docs/* | Public | Documentation |
| File | Purpose |
|---|
lib/auth.ts | Better Auth configuration with registration hooks |
lib/credits.ts | Credit deduction, refund, and balance check |
lib/db/schema.ts | Complete database schema (Drizzle ORM) |
constants/billing.ts | Pricing plans, credit amounts, product IDs per provider |
lib/payments/checkout.ts | Provider-agnostic checkout (product ID/price only from server config) |
lib/payments/apply-payment.ts | Grant credits, write payments, schedule installments, reverse refunds |
lib/payments/verify/{dodo,waffo}.ts | Signature verification, one file per provider |
lib/entitlements.ts | Single source of truth for whether a user has access |
lib/ratelimit/ | Shared rate limiting (Postgres-backed, Upstash optional) |
lib/features.ts | Feature flags — off means routes and APIs both 404 |
proxy.ts | Next.js proxy: i18n routing + 404 for disabled features |
i18n.config.ts | Locale configuration |