# zforrester/tabletop architecture

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

- Interactive diagram: https://gitdiagram.com/zforrester/tabletop
- Repository: https://github.com/zforrester/tabletop

## Overview

##### Main Components

a. Client-Side Layer:
- Components for:
- Pages (Account, Login, Error)
- Client-side Components
- Client-side Supabase Instance

b. Next.js Server Layer:
- Include:
- App Router
- Server Components
- API Routes (auth/confirm, auth/signout)
- Server Actions
- Middleware

c. External Services:
- Authentication
- Database
- Real-time subscriptions (if used)

##### Component Relationships

- Client → Next.js Server (HTTP/API requests)
- Next.js Server → Supabase (Database/Auth operations)
- Middleware → Supabase (Auth checks)
- Client → Supabase (Direct client connections for real-time features)

##### Specific Implementation Details

Key architectural elements:
- Middleware authentication flow
- Server-side Supabase client
- Client-side Supabase instance
- Next.js App Router structure
- API routes for auth flows

**┌─────────────────────────────────┐**
- Client Layer           │
- (Browser/Next.js Client/React)  │
- ┘
- ↕
**┌─────────────────────────────────┐**
- Next.js Server Layer       │
- (App Router/Server Components) │
- ┘
- ↕
**┌─────────────────────────────────┐**
- Supabase Platform         │
- (Auth/Database/Real-time)    │
- ┘

##### Important Details to Highlight

- The middleware.ts file handling authentication
- The separation between client.ts and server.ts Supabase instances
- The auth flow through confirm and signout routes
- The account management functionality
- The login flow and actions

##### Notes

Annotations for:
- Authentication flow
- Data fetching patterns
- Server/Client component boundaries
- Middleware intervention points

Remember to emphasize the modern Next.js 13+ features like Server Components, Server Actions, and the App Router structure, as these are fundamental to how the application operates.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Browser["Browser"]
        ClientSupabase["Client Supabase Instance"]:::client
        Pages["Pages"]:::client
        ClientComponents["Client Components"]:::client
        
        subgraph Pages
            LoginPage["Login Page"]:::page
            AccountPage["Account Page"]:::page
            ErrorPage["Error Page"]:::page
        end
    end

    subgraph Server
        AppRouter["App Router"]:::server
        ServerComponents["Server Components"]:::server
        Middleware["Authentication Middleware"]:::middleware
        SupabaseMiddleware["Supabase Middleware Utils"]:::middleware
        ServerSupabase["Server Supabase Instance"]:::server
        
        subgraph "API Routes"
            AuthConfirm["/auth/confirm"]:::api
            AuthSignout["/auth/signout"]:::api
        end
        
        subgraph "Server Actions"
            LoginActions["Login Actions"]:::action
            AccountActions["Account Actions"]:::action
        end
    end

    subgraph External
        Supabase["Supabase Platform"]:::external
        subgraph "Supabase Services"
            Auth["Authentication"]:::external
            Database["Database"]:::external
            Realtime["Real-time"]:::external
        end
    end

    Browser --> Pages
    Pages --> ClientComponents
    ClientComponents --> ClientSupabase
    ClientSupabase --> Supabase
    
    Browser --> AppRouter
    AppRouter --> Middleware
    Middleware --> SupabaseMiddleware
    SupabaseMiddleware --> ServerSupabase
    ServerSupabase --> Supabase
    
    AppRouter --> ServerComponents
    AppRouter --> AuthConfirm
    AppRouter --> AuthSignout
    
    AuthConfirm --> Auth
    AuthSignout --> Auth
    
    LoginActions --> Auth
    AccountActions --> Database

    %% Click Events
    click ClientSupabase "https://github.com/zforrester/tabletop/blob/main/src/utils/supabase/client.ts"
    click ServerSupabase "https://github.com/zforrester/tabletop/blob/main/src/utils/supabase/server.ts"
    click Middleware "https://github.com/zforrester/tabletop/blob/main/middleware.ts"
    click SupabaseMiddleware "https://github.com/zforrester/tabletop/blob/main/src/utils/supabase/middleware.ts"
    click AccountPage "https://github.com/zforrester/tabletop/blob/main/src/app/account/account-form.tsx"
    click LoginPage "https://github.com/zforrester/tabletop/blob/main/src/app/login/page.tsx"
    click LoginActions "https://github.com/zforrester/tabletop/blob/main/src/app/login/actions.ts"
    click AuthConfirm "https://github.com/zforrester/tabletop/blob/main/src/app/auth/confirm/route.ts"
    click AuthSignout "https://github.com/zforrester/tabletop/blob/main/src/app/auth/signout/route.ts"
    click ErrorPage "https://github.com/zforrester/tabletop/blob/main/src/app/error/page.tsx"
    
    %% Styling
    classDef client fill:#2196F3,color:white
    classDef server fill:#4CAF50,color:white
    classDef middleware fill:#9E9E9E,color:white
    classDef external fill:#9C27B0,color:white
    classDef api fill:#FF9800,color:white
    classDef action fill:#FF5722,color:white
    classDef page fill:#03A9F4,color:white

    %% Legend
    subgraph Legend
        Client_["Client Component"]:::client
        Server_["Server Component"]:::server
        Middleware_["Middleware"]:::middleware
        External_["External Service"]:::external
        API_["API Route"]:::api
        Action_["Server Action"]:::action
        Page_["Page Component"]:::page
    end
```
