# harshitp002/saas-website-builder architecture

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

- Interactive diagram: https://gitdiagram.com/harshitp002/saas-website-builder
- Repository: https://github.com/harshitp002/saas-website-builder

## Overview

- Frontend Application: Represent the Next.js application that handles both server and client rendering. Break this section into:
- Page Routes and Layouts: Note that the application’s “src/app” directory is divided into different route segments (e.g., agency, subaccount, domain) that deliver different views. Clearly label separate modules for authentication (sign-in/sign-up), dashboards, funnel editor, and so on.
- Providers & Global State: Represent the reusable providers (theme, modal, editor) that wrap the application to manage state and share contextual data.
- Backend REST/Serverless API Endpoints: Identify the API endpoints under “src/app/api” which include Stripe integration endpoints (create-checkout-session, create-subscription, webhook), Uploadthing, etc. These endpoints represent the server-side logic called by the frontend.
- Database: Highlight the use of Prisma (with files in the “prisma” folder) that connects to a MySQL database. Mark how the application persists its data for agencies, subaccounts, funnels, user-generated content, etc.
- Third-Party Services: Show integrations with external systems:
- Stripe Connect for payment processing, subscriptions, and billing.
- Clerk for handling user authentication.
- Possibly others (e.g., Uploadthing for media uploads).

##### Relationships and Data Flow
- Next.js application interacting with server-side API endpoints (for example, the Stripe checkout session creation or webhook calls).
- External third-party integrations by drawing connections:
- API calls from Stripe endpoints to the Stripe Connect service.
- Authentication requests routed through Clerk.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Emphasize the clear split between the Frontend (UI/UX) and Backend logic (API routes, database interactions).
- Modular Routing and Layouts: The use of dynamic directories like “[agencyId]” and “[subaccountId]” in the file tree implies a modular routing system using Next.js’s new app directory.
- Middleware & Providers: Don’t forget to show that global middleware (src/middleware.ts) and context providers (in src/providers) play roles in handling cross-cutting concerns such as authentication and state management.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global nodes
    Browser("User's Browser"):::browser

    %% Frontend Application (Next.js)
    subgraph "Frontend Application (Next.js)"
        Routes("Page Routes & Layouts"):::frontend
        AgencyAuth("Agency Auth Pages"):::frontend
        CoreUI("Core UI Components"):::frontend
        UIStyling("UI Styling & Components"):::frontend
        UIIcons("UI Icons"):::frontend
        GlobalUI("Global UI"):::frontend
        Providers("Providers & Global State"):::frontend
    end

    %% Backend API Endpoints
    subgraph "Backend API Endpoints"
        GlobalMiddleware("Global Middleware"):::backend
        StripeAPI("Stripe API Endpoints"):::backend
        UploadthingAPI("Uploadthing API Endpoint"):::backend
    end

    %% Database Layer
    Database("Prisma/MySQL Database"):::db

    %% Third-Party Services
    subgraph "Third-Party Services"
        StripeConnect("Stripe Connect"):::thirdparty
        Clerk("Clerk"):::thirdparty
        UploadthingLib("Uploadthing Library"):::thirdparty
    end

    %% Connections
    Browser -->|"initiates"| Routes
    Routes -->|"navigates"| AgencyAuth
    Routes -->|"calls"| GlobalMiddleware
    AgencyAuth -->|"authenticates"| Clerk

    GlobalMiddleware -->|"routes to"| StripeAPI
    GlobalMiddleware -->|"routes to"| UploadthingAPI
    
    StripeAPI -->|"CRUD operations"| Database
    UploadthingAPI -->|"CRUD operations"| Database

    StripeAPI -->|"billing"| StripeConnect
    UploadthingAPI -->|"uploads"| UploadthingLib

    %% Styles
    classDef browser fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef db fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef thirdparty fill:#FFB6C1,stroke:#333,stroke-width:2px;

    %% Click Events
    click Routes "https://github.com/harshitp002/saas-website-builder/tree/master/src/app/(main)"
    click AgencyAuth "https://github.com/harshitp002/saas-website-builder/tree/master/src/app/(main)/agency/(auth)"
    click CoreUI "https://github.com/harshitp002/saas-website-builder/tree/master/src/components"
    click UIStyling "https://github.com/harshitp002/saas-website-builder/tree/master/src/components/ui"
    click UIIcons "https://github.com/harshitp002/saas-website-builder/tree/master/src/components/icons"
    click GlobalUI "https://github.com/harshitp002/saas-website-builder/tree/master/src/components/global"
    click Providers "https://github.com/harshitp002/saas-website-builder/tree/master/src/providers"
    click GlobalMiddleware "https://github.com/harshitp002/saas-website-builder/blob/master/src/middleware.ts"
    click StripeAPI "https://github.com/harshitp002/saas-website-builder/tree/master/src/app/api/stripe"
    click UploadthingAPI "https://github.com/harshitp002/saas-website-builder/tree/master/src/app/api/uploadthing"
    click Database "https://github.com/harshitp002/saas-website-builder/blob/master/prisma/schema.prisma"
    click StripeConnect "https://github.com/harshitp002/saas-website-builder/tree/master/src/lib/stripe"
    click UploadthingLib "https://github.com/harshitp002/saas-website-builder/blob/master/src/lib/uploadthing.ts"
```
