# sudershhh/saas-dm-automations architecture

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

- Interactive diagram: https://gitdiagram.com/sudershhh/saas-dm-automations
- Repository: https://github.com/sudershhh/saas-dm-automations

## Overview

##### Project type and purpose
- This is a full-stack Next.js application built with React, TypeScript, Tailwind CSS, Prisma, and Stripe.
- It provides an authenticated dashboard where users can manage “automations” (workflows), configure external integrations (e.g., Instagram), handle payments via Stripe, and receive/process webhooks.

##### File structure
- Top-level:
- `app/` – Next.js 13 App Router: UI pages, layouts, and serverless API routes under `(protected)/api/...`.
- `components/` – reusable React components divided into `global` domain-specific widgets (automation lists, billing UI) and generic `ui` primitives.
- `redux/` – global state management slices for automations, store setup.
- `react-query/` & `src/actions/` – client-side data-fetching queries and React-Query setup.
- `lib/` – utilities and clients: Prisma ORM, Stripe SDK, OpenAI client, fetch wrapper.
- `prisma/schema.prisma` – database schema.
- API routes in `app/(protected)/api/.../route.ts` – serverless handlers for payments and webhooks.
- `middleware.ts` – likely for auth/redirects.

##### README for additional insights
- Confirms usage of `next/font`, Vercel deployment, and local dev commands.

##### Elements
- Clear labels: “Next.js App Router”, “API Routes”, “Prisma Client”, “PostgreSQL”, “Redux Store”, “React-Query”.
- Browser → Next.js UI
- UI → Redux / React-Query → API
- API → Prisma → DB
- API ↔ External Services
- Rectangles for components (UI, API, DB).
- Clouds for external services.

##### Final advice
- Every folder/domain as a system component (authentication, automations, integrations, payment, webhooks).
- Be detailed: list the file paths or module names next to each component if needed (e.g., “Automation API: app/(protected)/api/automations”).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (Next.js App Router)"
        direction TB
        NextJSAppRouter["Next.js App Router"]:::frontend
        ProtectedDash["Protected Dashboard Pages"]:::frontend
        PublicPages["Website Public Pages"]:::frontend
        AuthSignIn["Auth Sign-In Page"]:::frontend
        AuthSignUp["Auth Sign-Up Page"]:::frontend
        ClerkAuthState["Clerk Auth State Component"]:::frontend
        AutomationList["Global Automation List"]:::frontend
        BillingUI["Billing UI"]:::frontend
        PaymentButton["Payment Button"]:::frontend
        ReduxStore["Redux Store Setup"]:::frontend
        AutomationsSlice["Automations Slice"]:::frontend
        ReactQueryProvider["React-Query Provider"]:::frontend
        ActionsAutomations["Automations Queries"]:::frontend
        ActionsIntegrations["Integrations Queries"]:::frontend
        ActionsUser["User Queries"]:::frontend
        ActionsWebhook["Webhook Queries"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Next.js Serverless Functions)"
        direction TB
        PaymentAPI["Payment API Route"]:::backend
        WebhookAPI["Webhook API Route"]:::backend
        IGWebhookAPI["Instagram Webhook API Route"]:::backend
        IGCallback["Instagram OAuth Callback"]:::backend
        PrismaClient["Prisma Client"]:::data
        Schema["Prisma Schema"]:::data
        Middleware["Middleware (Auth/Redirects)"]:::backend
        StripeClient["Stripe Client"]:::backend
        OpenAIClient["OpenAI Client"]:::backend
        FetchWrapper["Fetch Wrapper"]:::backend
    end

    %% Database
    PostgreSQL["PostgreSQL Database"]:::data

    %% External Services
    subgraph "External Services"
        direction TB
        StripeService["Stripe"]:::external
        InstagramService["Instagram"]:::external
        OpenAIService["OpenAI"]:::external
        ClerkService["Clerk"]:::external
    end

    %% Connections
    Browser["User Browser"]:::external -->|"visits"| PublicPages
    Browser -->|"visits"| ProtectedDash
    Browser -->|"visits"| AuthSignIn
    Browser -->|"visits"| AuthSignUp

    ProtectedDash -->|"uses"| ReduxStore
    ReduxStore -->|"includes"| AutomationsSlice
    ProtectedDash -->|"renders"| AutomationList
    ProtectedDash -->|"renders"| BillingUI
    ProtectedDash -->|"renders"| PaymentButton
    ProtectedDash -->|"wraps with"| ReactQueryProvider
    ReactQueryProvider --> ActionsAutomations
    ReactQueryProvider --> ActionsIntegrations
    ReactQueryProvider --> ActionsUser
    ReactQueryProvider --> ActionsWebhook

    ProtectedDash -->|"calls API"| PaymentAPI
    ProtectedDash -->|"calls API"| WebhookAPI
    ProtectedDash -->|"calls API"| IGWebhookAPI
    ProtectedDash -->|"callback"| IGCallback

    PaymentAPI -->|"uses"| StripeClient
    StripeClient -->|"calls"| StripeService
    PaymentAPI -->|"uses"| PrismaClient
    WebhookAPI -->|"uses"| PrismaClient
    IGWebhookAPI -->|"uses"| PrismaClient
    IGCallback -->|"uses"| PrismaClient

    PrismaClient -->|"reads/writes"| PostgreSQL
    OpenAIClient -->|"calls"| OpenAIService
    FetchWrapper -->|"wraps calls"| InstagramService
    ProtectedDash -->|"auth via"| ClerkAuthState
    ClerkAuthState -->|"calls"| ClerkService
    Middleware --> ProtectedDash

    %% Click Events
    click NextJSAppRouter "https://github.com/sudershhh/saas-dm-automations/tree/master/src/app/"
    click ProtectedDash "https://github.com/sudershhh/saas-dm-automations/tree/master/src/app/(protected)/dashboard/"
    click PublicPages "https://github.com/sudershhh/saas-dm-automations/blob/master/src/app/(website)/page.tsx"
    click AuthSignIn "https://github.com/sudershhh/saas-dm-automations/blob/master/src/app/(auth)/sign-in/[[...sign-in]]/page.tsx"
    click AuthSignUp "https://github.com/sudershhh/saas-dm-automations/blob/master/src/app/(auth)/sign-up/[[...sign-up]]/page.tsx"
    click PaymentAPI "https://github.com/sudershhh/saas-dm-automations/blob/master/src/app/(protected)/api/payment/route.ts"
    click WebhookAPI "https://github.com/sudershhh/saas-dm-automations/blob/master/src/app/(protected)/api/webhook/route.ts"
    click IGWebhookAPI "https://github.com/sudershhh/saas-dm-automations/blob/master/src/app/(protected)/api/webhook/instagram/route.ts"
    click IGCallback "https://github.com/sudershhh/saas-dm-automations/blob/master/src/app/(protected)/callback/instagram/page.tsx"
    click ReduxStore "https://github.com/sudershhh/saas-dm-automations/blob/master/redux/store.ts"
    click AutomationsSlice "https://github.com/sudershhh/saas-dm-automations/blob/master/redux/slices/automation.ts"
    click ReactQueryProvider "https://github.com/sudershhh/saas-dm-automations/blob/master/src/providers/react-query-provider.tsx"
    click ActionsAutomations "https://github.com/sudershhh/saas-dm-automations/blob/master/src/actions/automations/queries.ts"
    click ActionsIntegrations "https://github.com/sudershhh/saas-dm-automations/blob/master/src/actions/integrations/queries.ts"
    click ActionsUser "https://github.com/sudershhh/saas-dm-automations/blob/master/src/actions/user/queries.ts"
    click ActionsWebhook "https://github.com/sudershhh/saas-dm-automations/blob/master/src/actions/webhook/queries.ts"
    click PrismaClient "https://github.com/sudershhh/saas-dm-automations/blob/master/src/lib/prisma.ts"
    click Schema "https://github.com/sudershhh/saas-dm-automations/blob/master/prisma/schema.prisma"
    click StripeClient "https://github.com/sudershhh/saas-dm-automations/blob/master/src/lib/stripe.ts"
    click OpenAIClient "https://github.com/sudershhh/saas-dm-automations/blob/master/src/lib/oepnai.ts"
    click ClerkAuthState "https://github.com/sudershhh/saas-dm-automations/blob/master/src/components/global/clerk-auth-state/index.tsx"
    click FetchWrapper "https://github.com/sudershhh/saas-dm-automations/blob/master/src/lib/fetch.ts"

    %% Styles
    classDef frontend fill:#ddeeff,stroke:#3388ff,stroke-width:1px
    classDef backend fill:#ddffdd,stroke:#33aa33,stroke-width:1px
    classDef data fill:#f0f0f0,stroke:#888888,stroke-width:1px
    classDef external fill:#fffae6,stroke:#ffcc00,stroke-width:1px
```
