# dhvaniparghi2003/plura-production architecture

> Architecture diagram of the GitHub repository dhvaniparghi2003/plura-production, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dhvaniparghi2003/plura-production
- Repository: https://github.com/dhvaniparghi2003/plura-production

## Overview

##### Project type and purpose
- From the README and file‐tree, this is a full-stack, multi-tenant SaaS application (Next.js 14 + Bun) offering an agency→sub-account website/funnel builder, project management, analytics, and Stripe-based billing.
- It supports role-based access (agency vs. sub-account), Stripe Connect for multivendor payments, and uses Prisma + MySQL as its primary datastore.

##### File structure
- Top level: configuration files (.env.example, tsconfig.json, bun.lockb, prisma/schema.prisma), Next.js config (next.config.js), Tailwind config, package.json.
- `prisma/`: database schema → Prisma client.
- `src/app/`: Next.js 14’s App Router with page.tsx, layout.tsx, nested folders for dynamic routing. Contains:
- Authentication routes under `(main)/agency/(auth)`
- Agency pages, sub-account pages, launchpads, funnels, kanban pipelines, media, settings, billing.
- `src/app/api/`: Route handlers (Stripe checkout, customer, subscription, webhook; UploadThing).
- `src/lib/`: Business logic and integrations (db.ts, queries.ts, Stripe client/actions, uploadthing, utils).
- `src/providers/`: React Context providers (editor, modal, theme).
- Middleware: global request middleware (e.g., for auth, multi-tenant resolution).

##### README for additional insights
- Tech stack: Next.js 14 / Bun runtime, Prisma + MySQL, Stripe Connect, Clerk (authentication), UploadThing, Tailwind CSS, Radix UI.
- Features: multi-vendor B2B2B, site & funnel builder, subscription billing, role‐based dashboards, real-time analytics, kanban board, notifications, file uploads.

##### Details to capture
- Multi-tenant routing + middleware enforcement
- Stripe Connect flow (Checkout Session → Webhook → DB)
- File upload flow through UploadThing
- Context providers’ roles (editor state, theme, modal)
- Static asset delivery via `public/assets` + CDN
- Prisma’s role as the single source of truth for data access

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Presentation Layer
  subgraph "Presentation Layer"
    Browser["Browser (React UI & Tailwind)"]:::frontend
    CDN["CDN / Static Assets"]:::frontend
  end

  %% Application Layer
  subgraph "Application Layer"
    NextApp["Next.js App Router (UI & Pages)"]:::app
    Middleware["Global Middleware (auth & multi-tenant)"]:::app

    subgraph "Pages"
      AuthRoutes["Agency Authentication Routes"]:::app
      AgencyPages["Agency Dashboard & Management Pages"]:::app
      SubPages["Sub-account Dashboard & Features"]:::app
      RoutingHelpers["Public/Multi-tenant Routing Helpers"]:::app
    end

    subgraph "API Routes"
      Checkout["Create Checkout Session"]:::api
      CreateCustomer["Create Customer"]:::api
      Subscription["Create Subscription"]:::api
      Webhook["Webhook Handler"]:::api
      UploadRoute["UploadThing Route"]:::api
      UploadCore["UploadThing Core"]:::api
    end

    subgraph "UI Components & Providers"
      Components["Reusable UI Components & Primitives"]:::ui
      EditorProv["Editor Provider"]:::ui
      ModalProv["Modal Provider"]:::ui
      ThemeProv["Theme Provider"]:::ui
    end
  end

  %% Integration Layer
  subgraph "Integration Layer"
    AuthService["Auth Service (Clerk)"]:::external
    StripeExt["Stripe Connect"]:::external
    UploadExt["UploadThing Service"]:::external
  end

  %% Data Layer
  subgraph "Data Layer"
    DB["MySQL Database\\n(Prisma)"]:::db
    PrismaSchema["Prisma Schema & Client"]:::db
    BusinessLogic["Shared Logic & Queries"]:::db
    StripeLib["Stripe Client & Actions Library"]:::db
    UploadLib["UploadThing Client Wrapper"]:::db
  end

  %% Connections
  Browser --> NextApp
  Browser --> CDN

  NextApp --> Components
  Components --> EditorProv
  Components --> ModalProv
  Components --> ThemeProv

  NextApp --> Middleware
  NextApp --> AuthRoutes
  NextApp --> AgencyPages
  NextApp --> SubPages
  NextApp --> RoutingHelpers

  AuthRoutes --> Middleware
  AgencyPages --> Middleware
  SubPages --> Middleware
  RoutingHelpers --> Middleware

  Middleware --> Checkout
  Middleware --> CreateCustomer
  Middleware --> Subscription
  Middleware --> Webhook
  Middleware --> UploadRoute
  Middleware --> UploadCore

  Checkout --> StripeExt
  CreateCustomer --> StripeExt
  Subscription --> StripeExt
  Webhook -.-> StripeExt
  UploadRoute --> UploadExt
  UploadExt --> UploadRoute

  Checkout --> DB
  CreateCustomer --> DB
  Subscription --> DB
  Webhook --> DB
  UploadRoute --> DB

  Middleware --> PrismaSchema
  PrismaSchema --> DB
  BusinessLogic --> PrismaSchema

  StripeLib --> StripeExt
  StripeLib --> BusinessLogic

  UploadLib --> UploadExt
  UploadLib --> BusinessLogic

  %% Click Events
  click NextApp "https://github.com/dhvaniparghi2003/plura-production/tree/main/src/app"
  click AuthRoutes "https://github.com/dhvaniparghi2003/plura-production/tree/main/src/app/(main)/agency/(auth)"
  click AgencyPages "https://github.com/dhvaniparghi2003/plura-production/tree/main/src/app/(main)/agency/[agencyId]"
  click SubPages "https://github.com/dhvaniparghi2003/plura-production/tree/main/src/app/(main)/subaccount/[subaccountId]"
  click RoutingHelpers "https://github.com/dhvaniparghi2003/plura-production/tree/main/src/app/[domain]"
  click Checkout "https://github.com/dhvaniparghi2003/plura-production/blob/main/src/app/api/stripe/create-checkout-session/route.ts"
  click CreateCustomer "https://github.com/dhvaniparghi2003/plura-production/blob/main/src/app/api/stripe/create-customer/route.ts"
  click Subscription "https://github.com/dhvaniparghi2003/plura-production/blob/main/src/app/api/stripe/create-subscription/route.ts"
  click Webhook "https://github.com/dhvaniparghi2003/plura-production/blob/main/src/app/api/stripe/webhook/route.ts"
  click UploadRoute "https://github.com/dhvaniparghi2003/plura-production/blob/main/src/app/api/uploadthing/route.ts"
  click UploadCore "https://github.com/dhvaniparghi2003/plura-production/blob/main/src/app/api/uploadthing/core.ts"
  click PrismaSchema "https://github.com/dhvaniparghi2003/plura-production/blob/main/prisma/schema.prisma"
  click PrismaSchema "https://github.com/dhvaniparghi2003/plura-production/blob/main/src/lib/db.ts"
  click BusinessLogic "https://github.com/dhvaniparghi2003/plura-production/blob/main/src/lib/queries.ts"
  click StripeLib "https://github.com/dhvaniparghi2003/plura-production/blob/main/src/lib/stripe/index.ts"
  click UploadLib "https://github.com/dhvaniparghi2003/plura-production/blob/main/src/lib/uploadthing.ts"
  click Middleware "https://github.com/dhvaniparghi2003/plura-production/blob/main/src/middleware.ts"
  click EditorProv "https://github.com/dhvaniparghi2003/plura-production/tree/main/src/providers/editor"
  click ModalProv "https://github.com/dhvaniparghi2003/plura-production/blob/main/src/providers/modal-provider.tsx"
  click ThemeProv "https://github.com/dhvaniparghi2003/plura-production/blob/main/src/providers/theme-provider.tsx"
  click Components "https://github.com/dhvaniparghi2003/plura-production/tree/main/src/components"
  click CDN "https://github.com/dhvaniparghi2003/plura-production/tree/main/public/assets"

  %% Styles
  classDef frontend fill:#add8e6,stroke:#000
  classDef app fill:#90ee90,stroke:#000
  classDef api fill:#90ee90,stroke:#000
  classDef ui fill:#add8e6,stroke:#000
  classDef external fill:#ffa500,stroke:#000
  classDef db fill:#d3d3d3,stroke:#000
```
