Beztack

Architecture

System structure and components

Beztack is structured as a monorepo using Nx with pnpm, which lets us efficiently share code between apps through shared packages.

Directory Structure

/
├── apps/                          # Deployable applications
│   ├── api/                       # Backend (Nitro server)
│   ├── docs/                      # Landing & Documentation (Next.js + Fumadocs)
│   └── ui/                        # Frontend (React + Vite)
├── packages/                      # Shared libraries
│   ├── ai/                        # Vercel AI SDK re-exports + Amazon Bedrock provider
│   ├── auth/                      # Role and redirect helpers shared by API and UI
│   ├── cli/                       # Project scaffolding CLI (+ experimental template commands)
│   ├── db/                        # Database schema, client, migrations (Drizzle + PostgreSQL)
│   ├── email/                     # Email templates (React Email + Resend)
│   ├── env/                       # Centralized env validation (T3 Env + Zod)
│   ├── ocr/                       # OCR helper (Tesseract.js)
│   ├── payments/
│   │   ├── core/                  # Provider-agnostic types and PaymentProviderAdapter interface
│   │   ├── polar/                 # Polar payment provider
│   │   └── mercado-pago/          # MercadoPago payment provider
│   └── state/                     # URL state management (nuqs)

Applications

UI (apps/ui)

A React 19 app built with Vite.

  • Styling: Tailwind CSS v4 + shadcn/ui (Radix UI primitives).
  • Server State: TanStack Query (React Query).
  • Forms: React Hook Form + Zod validation.
  • Routing: React Router v7.
  • i18n: i18next for internationalization.
  • Animations: Motion.
  • Auth: Better Auth client.

API (apps/api)

A Nitro server (the engine behind Nuxt) that provides a fast and lightweight REST API.

  • Routes: File-based routing in server/routes/.
  • Unified payment routes: /api/subscriptions/* for all providers, including /api/subscriptions/plan-change/* (see Plan changes).
  • Admin routes: /api/auth/admin/plans/* for plan management and /api/auth/admin/plan-changes/* for failed plan changes.
  • Database: Drizzle ORM with PostgreSQL via @beztack/db.
  • Auth: Better Auth server with admin, organization, twoFactor, and (when Polar is the active provider) the Polar plugin.
  • Utilities: Server utilities in server/utils/ (auth, membership, payment provider).

Docs (apps/docs)

A Next.js app with Fumadocs for the landing page and documentation.

Shared Packages

Reusable code lives in packages/ to keep apps clean and DRY.

PackageDescription
@beztack/aiRe-exports the Vercel AI SDK and configures an Amazon Bedrock provider (not used by the apps yet)
@beztack/authRole parsing, organization role ranking and post-sign-in redirects shared by API and UI
beztack (packages/cli)Project scaffolding CLI; experimental template commands (see Template Sync)
@beztack/dbDatabase schema, Drizzle ORM client, and migrations for PostgreSQL
@beztack/emailEmail templates built with React Email, sent via Resend
@beztack/envCentralized environment variable validation using T3 Env + Zod
@beztack/ocrOne text extraction helper built on Tesseract.js
@beztack/paymentsProvider-agnostic payment types and PaymentProviderAdapter interface
@beztack/payments-polarPolar payment provider implementation
@beztack/mercadopagoMercadoPago payment provider implementation
@beztack/stateURL-based state management using nuqs

Payments Architecture

Beztack uses a provider-agnostic payment system. Apps import types and the factory only from @beztack/payments (core) — never from provider packages directly. The active provider is selected at runtime via the PAYMENT_PROVIDER environment variable.

See Payments Core for full details on the adapter interface, types, and how to add new providers.