# anayatkhan1/fuzora architecture

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

- Interactive diagram: https://gitdiagram.com/anayatkhan1/fuzora
- Repository: https://github.com/anayatkhan1/fuzora

## Overview

##### Project Type and Purpose
- Fuzora is a full-stack SaaS web application built with Next.js (app router).
- It exposes a rich React-Flow-based UI for building automation workflows, routes API endpoints for OAuth and webhooks, and persists data in a Postgres database via Prisma.
- It integrates with multiple external services (Google Drive, Slack, Discord, Notion, Stripe, Uploadcare, Clerk) to deliver triggers, actions, and billing.

##### File Structure
- src/app ─ React pages (Auth zone vs. Main zone) plus API routes under src/app/api.
- prisma/schema.prisma ─ Defines your Postgres data model.
- src/lib & src/providers ─ Shared utility and context providers (db connection, theme, billing, connections, editor).
- Middleware.ts ─ Global requests (auth enforcement, logging).
- Public folder, global CSS, Tailwind config ─ Static assets and styling.

##### Extract Architectural Insights from README
- Next.js handles both client-side UI and serverless API routes.
- Authentication via Clerk (hosted).
- OAuth flows (Google, Slack, Discord, Notion) using Next.js API routes for callbacks.
- Google Drive push notifications handled in /api/drive-activity/notification.
- Stripe used for subscriptions and metered billing (credits).

##### Main Components & Relationships
A. Client Layer
– Web Browser / User’s Device
- Renders Next.js pages (React + React Flow + Shadcn UI + Tailwind).
- Initiates OAuth flows and invokes API endpoints.
B. Edge / CDN (optional)
– Vercel / CDN for page assets, static files, Uploadcare CDN.
C. Next.js Application (Serverless)
1. Frontend (SSR/ISR/CSR)
- app/(auth) – Sign-in/Sign-up UIs (Clerk).
- app/(main) – Dashboard, Workflows editor, Billing, Connections UI.
2. API Routes (Business Logic)
- /api/auth/callback/* – OAuth callbacks for Discord, Notion, Slack.
- /api/drive-activity/notification – Google Drive webhooks.
- /api/drive, /api/drive-activity – Poll or webhook triggers.
- /api/payment – Stripe webhooks & credit usage.
- /api/clerk-webhook – User lifecycle events.
3. Middleware
- Guards routes, injects user context, route rewrites.
4. Context Providers
- Theme, connections, billing, editor.
D. Database Layer
– Neon Postgres
- Accessed via Prisma client (src/lib/db.ts).
- Stores users, connections, workflows, node definitions, billing credits.
E. External Services
- Clerk – Hosted auth & session management.
- OAuth Providers – Google Drive, Slack, Discord, Notion.
- Stripe – Billing, subscriptions, metered credit usage.
- Uploadcare – Profile picture uploads.
- Ngrok – Local dev tunneling (for callbacks).

- Browser → Next.js Frontend (HTTP/HTTPS).
- Frontend → Next.js API (fetch / WebSocket if any).
- API → Database (Prisma/SQL).
- API → External Services (REST/OAuth, webhooks).
- External Services → Next.js Webhooks (/api/…/route.ts).

##### Architectural Patterns & Design Principles
- Layered (Presentation → API Business Logic → Data).
- File-based routing (Next.js App Router).
- Context-based state management (React Context via providers).
- Serverless functions for each API route (scalable, single-purpose).
- OAuth handshake flows and webhooks for event-driven integrations.
- Modular React components with shadcn/ui and custom domain folders.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        Browser["Web Browser<br/>renders Next.js UI"]:::frontend
    end

    subgraph "Edge / CDN"
        CDN["Vercel / CDN"]:::external
        Assets["Static Assets"]:::external
    end

    subgraph "Next.js Application"
        subgraph "Frontend Layer"
            AuthUI["Auth Zone UI"]:::frontend
            MainUI["Main Zone UI"]:::frontend
        end
        subgraph "API Layer"
            OAuthDiscord["OAuth Callback: Discord"]:::serverless
            OAuthNotion["OAuth Callback: Notion"]:::serverless
            OAuthSlack["OAuth Callback: Slack"]:::serverless
            ClerkWebhook["Clerk Webhook"]:::serverless
            DriveNotif["Drive Webhook Notification"]:::serverless
            DriveActivity["Drive Activity"]:::serverless
            DriveAPI["Drive API Trigger"]:::serverless
            PaymentWebhook["Stripe Payment Webhook"]:::serverless
        end
        Middleware["Middleware: Auth & Logging"]:::provider
        subgraph "Context Providers"
            ThemeProv["Theme Provider"]:::provider
            ConnsProv["Connections Provider"]:::provider
            BillingProv["Billing Provider"]:::provider
            EditorProv["Editor Provider"]:::provider
            ModalProv["Modal Provider"]:::provider
        end
    end

    subgraph "Database Layer"
        DB["Postgres (Neon)"]:::database
    end

    subgraph "External Services"
        Clerk["Clerk"]:::external
        Stripe["Stripe"]:::external
        GoogleDrive["Google Drive"]:::external
        SlackService["Slack"]:::external
        DiscordService["Discord"]:::external
        NotionService["Notion"]:::external
        Uploadcare["Uploadcare"]:::external
        Ngrok["Ngrok"]:::external
    end

    Browser -->|HTTP| CDN
    CDN -->|serves| Assets
    CDN --> Browser

    Browser -->|renders| AuthUI
    Browser -->|renders| MainUI

    AuthUI -->|calls API| OAuthSlack
    MainUI -->|calls API| DriveAPI
    MainUI -->|calls API| DriveActivity
    MainUI -->|calls API| PaymentWebhook

    OAuthSlack -->|writes| DB
    OAuthDiscord -->|writes| DB
    OAuthNotion -->|writes| DB
    ClerkWebhook -->|updates| DB
    DriveNotif -->|triggers| MainUI
    DriveNotif -->|writes| DB
    DriveActivity -->|reads| DB
    DriveAPI -->|reads| DB
    PaymentWebhook -->|updates| DB

    MainUI -->|uses| Middleware
    AuthUI -->|uses| Middleware

    Middleware -->|provides context| ThemeProv
    Middleware -->|provides context| ConnsProv
    Middleware -->|provides context| BillingProv
    Middleware -->|provides context| EditorProv
    Middleware -->|provides context| ModalProv

    DB -->|via Prisma| MainUI
    DB -->|via Prisma| OAuthSlack

    OAuthSlack -->|OAuth| SlackService
    OAuthDiscord -->|OAuth| DiscordService
    OAuthNotion -->|OAuth| NotionService
    DriveAPI -->|REST| GoogleDrive
    DriveNotif -->|webhook| GoogleDrive
    PaymentWebhook -->|webhook| Stripe
    MainUI -->|uploads| Uploadcare
    MainUI -->|OAuth dev| Ngrok

    click AuthUI "https://github.com/anayatkhan1/fuzora/tree/main/src/app/(auth)"
    click MainUI "https://github.com/anayatkhan1/fuzora/tree/main/src/app/(main)"
    click DB "https://github.com/anayatkhan1/fuzora/blob/main/prisma/schema.prisma"
    click DB "https://github.com/anayatkhan1/fuzora/blob/main/src/lib/db.ts"
    click Middleware "https://github.com/anayatkhan1/fuzora/blob/main/src/middleware.ts"
    click ThemeProv "https://github.com/anayatkhan1/fuzora/blob/main/src/providers/theme-provider.tsx"
    click ConnsProv "https://github.com/anayatkhan1/fuzora/blob/main/src/providers/connections-provider.tsx"
    click BillingProv "https://github.com/anayatkhan1/fuzora/blob/main/src/providers/billing-provider.tsx"
    click EditorProv "https://github.com/anayatkhan1/fuzora/blob/main/src/providers/editor-provider.tsx"
    click ModalProv "https://github.com/anayatkhan1/fuzora/blob/main/src/providers/modal-provider.tsx"
    click OAuthDiscord "https://github.com/anayatkhan1/fuzora/blob/main/src/app/api/auth/callback/discord/route.ts"
    click OAuthNotion "https://github.com/anayatkhan1/fuzora/blob/main/src/app/api/auth/callback/notion/route.ts"
    click OAuthSlack "https://github.com/anayatkhan1/fuzora/blob/main/src/app/api/auth/callback/slack/route.tsx"
    click ClerkWebhook "https://github.com/anayatkhan1/fuzora/blob/main/src/app/api/clerk-webhook/route.ts"
    click DriveNotif "https://github.com/anayatkhan1/fuzora/blob/main/src/app/api/drive-activity/notification/route.ts"
    click DriveActivity "https://github.com/anayatkhan1/fuzora/blob/main/src/app/api/drive-activity/route.ts"
    click DriveAPI "https://github.com/anayatkhan1/fuzora/blob/main/src/app/api/drive/route.ts"
    click PaymentWebhook "https://github.com/anayatkhan1/fuzora/blob/main/src/app/api/payment/route.ts"

    classDef frontend fill:#7fbfff,stroke:#333,stroke-width:1px
    classDef serverless fill:#a2f5a2,stroke:#333,stroke-width:1px
    classDef database fill:#f5d76e,stroke:#333,stroke-width:1px
    classDef provider fill:#dddddd,stroke:#333,stroke-width:1px
    classDef external fill:#c9c9ff,stroke:#333,stroke-width:1px
```
