How denvudd/plura works
Project type and purpose
• This is a full-stack, multi-tenant SaaS web application built with Next.js 14 (App Router), Bun, Prisma (MySQL), Tailwind CSS, and Stripe Connect.
• It provides an agency→sub-account hierarchy, a drag-and-drop website & funnel builder, project management (Kanban board), media storage, billing/subscriptions, and dashboards.
File structure and infer the layers
• src/app: Next.js App Router pages and layouts, split into two primary zones:
• (main): authenticated area under “/agency” and “/subaccount” with nested routing and domain-based routing.
• /[domain]/...: client-hosted funnels/websites.
• /api: serverless API routes for Stripe (checkout, customer, subscription, webhook) and file uploads (UploadThing).
• src/components: reusable UI (common, forms, modules, navigation, providers, ui) – purely client components.
• src/lib & src/queries: business logic, ORM (Prisma) wrappers, Stripe wrappers, validators, DB utilities.
• prisma/schema.prisma: data model for agencies, subaccounts, users, funnels, tickets, subscriptions, etc.
• Configuration: next.config.js, bun.lockb, tailwind.config.ts, tsconfig.json.
README for additional insights
• Multi-vendor B2B2B SaaS: agency vs. sub-account tenancy.
• Full website & funnel builder: editor module with drag-drop, layers, media upload.
• Stripe Connect for payment flows and subscription management.
• Kanban board for project management.
• Role-based access and custom dashboards.
Main components
a. Client / Browser (React × Next.js)
• Renders pages (SSR+CSR) and the drag-and-drop editor UI.
• Issues fetch()/Mutation requests to API routes.
b. Next.js Server (Bun runtime)
• App Router SSR/SSG handlers; serves static assets from /public.
• API routes under src/app/api/… handle:
• Stripe checkout, customer, subscription, webhook.
• UploadThing file upload.
c. Business Logic Layer
• src/lib, src/queries: Prisma ORM, validation, Stripe-client utilities.
d. Database (MySQL via Prisma)
• Stores tenants, users, funnels, tickets, media metadata, subscription records.
e. External Services
• Stripe Connect: payment flows, webhooks.
• UploadThing (or underlying S3/Cloud Storage): media file storage.
• (Optional): Email provider for invitations/notifications.
f. Static Assets / CDN
• Public folder assets, built JS/CSS served via Next.js or edge CDN.
Relationships and data flows
• Browser → Next.js Server: page requests (SSR/CSR) & API calls (fetch to /api/…).
• Next.js Server → Business Logic Layer: calls into src/queries & src/lib.
• Business Logic Layer → Database: Prisma queries & mutations on MySQL.
• Business Logic Layer → Stripe API: create checkout sessions, customers, subscriptions, handle webhooks.
• Business Logic Layer → UploadThing SDK: file upload initiation and completion.
• Stripe Webhook → Next.js Server: /api/stripe/webhook route to update DB.
• Browser ← Next.js Server: Push real-time updates (optional polling or subscription).
Architectural patterns and design principles
• Layered architecture:
• Presentation (Next.js pages + React components)
• API (Next.js serverless routes)
• Domain/Business Logic (lib, queries, validators)
• Data Persistence (Prisma + MySQL)
• Domain-driven modules: “agency,” “subaccount,” “funnels,” “pipelines,” “media,” etc.
• Multi-tenant design: tenant ID routing, role-based access.
• Component-based UI: atomic UI elements in src/components/ui, domain modules in src/components/modules.