# joebuildsstuff/my-nextjs-supabase-starter-app architecture

> Architecture diagram of the GitHub repository joebuildsstuff/my-nextjs-supabase-starter-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/joebuildsstuff/my-nextjs-supabase-starter-app
- Repository: https://github.com/joebuildsstuff/my-nextjs-supabase-starter-app

## Overview

##### Project type and purpose
- This is a full-stack web application boilerplate built on Next.js (App Router) with TailwindCSS for styling, Shadcn/UI for pre-built UI components, and Supabase for auth, database, and serverless functions.
- Purpose: Provide a production-ready starter that demonstrates protected routes, dark-mode theming, form templates, and several table implementations (basic, advanced, complex) all backed by Supabase.

##### File structure
- Top-level config and scripts: `next.config.ts`, `tailwind.config.ts`, `eslint.config.mjs`, `jest.config.js`
- `src/app` holds all Next.js App Router pages and layouts, split into two primary routing groups:
- `(Auth)` for login, magic-link and OAuth callbacks
- `(Workspace)` for authenticated workspace pages (canvas, forms, tables, ui-stuff)
- `src/actions` for server-side actions (e.g., user signup, auth)
- `src/components` for shared UI components (Shadcn/UI wrappers, layout elements, theme provider)
- `src/hooks` for custom React hooks (use-toast, use-mobile, useTheme)
- `src/lib` / `src/utils` for shared code: Supabase client/middleware, store (zustand) for canvas, general helpers
- `public` for static assets
- Root-level `.cursor`, `.env.example`, `README.md`, `package.json`, `pnpm-lock.yaml`

##### Key points from README
- Authentication: Supabase OAuth & magic links with session & secure redirects
- Theming: next-themes via `ThemeProvider` + `ModeToggle`
- Data tables: three levels of complexity with server- and client-side Supabase queries
- Forms: React Hook Form + Zod validation templates for profile, settings, notifications
- Utilities: Radix UI, cmdk, clsx, zod, react-hook-form, date-fns, embla-carousel, recharts, sonner, tailwindcss-animate

##### Main components & relationships
- Client (Next.js React pages & components)
– Routes: Auth pages → public
– Routes: Workspace pages → protected
– Shared UI: `ThemeProvider`, navigation, sidebars (components)
– Canvas module: React components + Zustand store + Supabase functions (for saving)
– Tables & Forms: React components + React Hook Form + Zod + Supabase queries
- Server (Next.js server handlers + Supabase edge functions)
– `middleware.ts`: checks session cookie, redirects unauthenticated requests to login
– `src/actions/auth.ts`: server actions for sign-in/up
– Supabase database: tables for users, payments, invoices, etc.
– Supabase Edge Functions (in `.cursor/rules` for migrations & policies)
- External services
– Supabase Auth (OAuth providers, magic links)
– Supabase Database (Postgres)
– Supabase Edge Functions (optionally deployed via CLI)

##### Architectural patterns & design principles
- Next.js App Router: server-components + client-components for optimized data fetching
- Protected routes via middleware and session cookies
- Separation of concerns:
- UI (presentational) vs. state (Zustand, React Hook Form) vs. data layer (Supabase client in `utils`)
- Feature grouping: each workspace feature (canvas, forms, tables) self-contained under `(Workspace)`
- Progressive complexity in tables: blueprint for incremental feature adoption

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        AuthPages["Auth Pages"]:::ui
        WorkspacePages["Workspace Pages"]:::ui
        SharedUI["Shared UI Components"]:::ui
        CanvasModule["Canvas Module"]:::ui
        FormsModule["Forms Module"]:::ui
        TablesModule["Tables Module"]:::ui
        UIStuff["UI-Stuff Module"]:::ui
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        direction TB
        Middleware["Next.js Middleware"]:::infra
        ServerActions["Authentication Actions"]:::logic
        SupabaseUtils["Supabase Utils"]:::logic
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        SupabaseAuth["Supabase Auth Service"]:::external
        SupabaseDB["Supabase Postgres DB"]:::external
        EdgeFunctions["Supabase Edge Functions"]:::infra
    end

    %% Relationships
    AuthPages -->|"SSR/SSG & Client Fetch"| ServerActions
    WorkspacePages -->|"Protected Routes"| Middleware
    WorkspacePages -->|"UI Interaction"| SharedUI
    WorkspacePages -->|"Feature Access"| CanvasModule
    WorkspacePages -->|"Feature Access"| FormsModule
    WorkspacePages -->|"Feature Access"| TablesModule
    WorkspacePages -->|"Feature Access"| UIStuff

    CanvasModule -->|"State Mgmt"| SupabaseUtils
    FormsModule -->|"Form Validation & Fetch"| SupabaseUtils
    TablesModule -->|"Data Queries"| SupabaseUtils

    Middleware -->|"Validates Session"| SupabaseAuth
    ServerActions -->|"Calls Auth API"| SupabaseAuth
    ServerActions -->|"Database Requests"| SupabaseDB
    SupabaseUtils -->|"Server-Side Client"| SupabaseDB

    CanvasModule -->|"Direct Queries"| SupabaseDB
    FormsModule -->|"Direct Queries"| SupabaseDB
    TablesModule -->|"Direct Queries"| SupabaseDB

    AuthPages -->|"OAuth & Magic Links"| SupabaseAuth

    EdgeFunctions -->|"Migrations & RLS"| SupabaseDB

    %% Click Events
    click Middleware "https://github.com/joebuildsstuff/my-nextjs-supabase-starter-app/blob/main/middleware.ts"
    click ServerActions "https://github.com/joebuildsstuff/my-nextjs-supabase-starter-app/blob/main/src/actions/auth.ts"
    click AuthPages "https://github.com/joebuildsstuff/my-nextjs-supabase-starter-app/blob/main/src/app/(Auth)/login/page.tsx"
    click WorkspacePages "https://github.com/joebuildsstuff/my-nextjs-supabase-starter-app/blob/main/src/app/(Workspace)/workspace/layout.tsx"
    click CanvasModule "https://github.com/joebuildsstuff/my-nextjs-supabase-starter-app/tree/main/src/app/(Workspace)/workspace/canvas/components/"
    click FormsModule "https://github.com/joebuildsstuff/my-nextjs-supabase-starter-app/blob/main/src/app/(Workspace)/workspace/forms/page.tsx"
    click TablesModule "https://github.com/joebuildsstuff/my-nextjs-supabase-starter-app/blob/main/src/app/(Workspace)/workspace/tables/page.tsx"
    click UIStuff "https://github.com/joebuildsstuff/my-nextjs-supabase-starter-app/blob/main/src/app/(Workspace)/workspace/ui-stuff/page.tsx"
    click SharedUI "https://github.com/joebuildsstuff/my-nextjs-supabase-starter-app/blob/main/src/components/theme-provider.tsx"
    click SupabaseUtils "https://github.com/joebuildsstuff/my-nextjs-supabase-starter-app/blob/main/src/utils/supabase/client.ts"

    %% Styles
    classDef ui fill:#cfe2ff,stroke:#3a6ea5,color:#0b2e4f
    classDef logic fill:#d1e7dd,stroke:#40826d,color:#114032
    classDef external fill:#ffe5b4,stroke:#dd9a2d,color:#6b3f00
    classDef infra fill:#e2e3e5,stroke:#6c757d,color:#1b1e21
```
