# locastic/next-web3-hybrid-starter architecture

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

- Interactive diagram: https://gitdiagram.com/locastic/next-web3-hybrid-starter
- Repository: https://github.com/locastic/next-web3-hybrid-starter

## Overview

##### Main Components

Frontend Layer:
- Next.js Application (App Router)
- RainbowKit Web3 Components
- UI Components (shadcn/ui)
- Client-side Authentication State

Backend Layer:
- Next.js Server Components & Server Actions
- Authentication Middleware
- Database Layer (PostgreSQL/Supabase)
- Web3 Integration Layer

**┌─ Client Layer ─────────────────────┐**
- ┌─ Next.js App Router ───────────┐ │
- Root Layout                  │ │
- Dashboard                    │ │
- Security                     │ │
- ┘ │
- ┌─ Web3 Components ──────────────┐ │
- RainbowKit Provider         │ │
- Wallet Connection           │ │
- ┘ │
- ┘

**┌─ Server Layer ──────────────────────┐**
- ┌─ Authentication ───────────────┐  │
- JWT Cookies                 │  │
- Middleware Protection       │  │
- ┘  │
- ┌─ Server Actions ──────────────┐  │
- Auth Actions               │  │
- User Actions              │  │
- ┘  │
- ┘

**┌─ Data Layer ───────────────────────┐**
- ┌─ Supabase ──────────────────┐   │
- Auth Users               │   │
- Public Profiles         │   │
- RLS Policies           │   │
- ┘   │
- ┌─ Web3 Integration ────────────┐   │
- Client Operations         │   │
- Server Operations        │   │
- ┘   │
- ┘

##### Important Flows to Highlight

Authentication Flow:
**User → RainbowKit → JWT Cookies → Server Middleware → Protected Routes**

Data Flow:
**Client → Server Actions → RLS Wrapper → Database**

##### Technical Details

- DrizzleORM integration with Supabase
- Next.js App Router structure
- Server Actions middleware stack
- Web3 client/server separation

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        AppRouter["Next.js App Router"]:::frontend
        Web3Provider["RainbowKit Web3 Provider"]:::web3
        UIComponents["UI Components"]:::frontend
        Layout["Layout Components"]:::frontend
        
        AppRouter --> Layout
        AppRouter --> Web3Provider
        AppRouter --> UIComponents
    end

    subgraph Server
        ServerActions["Server Actions"]:::server
        AuthSystem["Authentication System"]:::auth
        Middleware["Middleware Protection"]:::auth
        
        ServerActions --> AuthSystem
        AuthSystem --> Middleware
    end

    subgraph Data
        Database["Database Layer"]:::database
        Web3Integration["Web3 Integration"]:::web3
        SupabaseClient["Supabase Client"]:::database
        Utils["Utility Functions"]:::util
        
        Database --> SupabaseClient
        Web3Integration --> Database
    end

    subgraph Protected
        Dashboard["Dashboard"]:::protected
        Security["Security Settings"]:::protected
    end

    AppRouter --> ServerActions
    Web3Provider --> AuthSystem
    AuthSystem --> Database
    Middleware --> Protected
    ServerActions --> Web3Integration
    Utils --> ServerActions

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef server fill:#2ecc71,stroke:#27ae60,color:white
    classDef auth fill:#e67e22,stroke:#d35400,color:white
    classDef database fill:#9b59b6,stroke:#8e44ad,color:white
    classDef web3 fill:#f1c40f,stroke:#f39c12,color:black
    classDef protected fill:#e74c3c,stroke:#c0392b,color:white
    classDef util fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Click Events
    click AppRouter "https://github.com/Locastic/next-web3-hybrid-starter/tree/main/app/(root)/"
    click Web3Provider "https://github.com/Locastic/next-web3-hybrid-starter/blob/main/app/(root)/_components/web3-provider.tsx"
    click UIComponents "https://github.com/Locastic/next-web3-hybrid-starter/tree/main/components/ui/"
    click Layout "https://github.com/Locastic/next-web3-hybrid-starter/blob/main/app/(root)/layout.tsx"
    click ServerActions "https://github.com/Locastic/next-web3-hybrid-starter/blob/main/lib/actions/index.ts"
    click AuthSystem "https://github.com/Locastic/next-web3-hybrid-starter/blob/main/lib/actions/auth.ts"
    click Middleware "https://github.com/Locastic/next-web3-hybrid-starter/blob/main/middleware.ts"
    click Database "https://github.com/Locastic/next-web3-hybrid-starter/blob/main/lib/db/schema.ts"
    click Web3Integration "https://github.com/Locastic/next-web3-hybrid-starter/blob/main/lib/web3/index.ts"
    click SupabaseClient "https://github.com/Locastic/next-web3-hybrid-starter/blob/main/lib/supabase.ts"
    click Utils "https://github.com/Locastic/next-web3-hybrid-starter/blob/main/lib/utils.ts"
    click Dashboard "https://github.com/Locastic/next-web3-hybrid-starter/tree/main/app/(root)/dashboard/"
    click Security "https://github.com/Locastic/next-web3-hybrid-starter/tree/main/app/(root)/dashboard/security/"
```
