# souravinsights/fairforms architecture

> Architecture diagram of the GitHub repository souravinsights/fairforms, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/souravinsights/fairforms
- Repository: https://github.com/souravinsights/fairforms

## Overview

##### Main Components

A. Frontend Layer:
- Public Interface (Landing page, public form views)
- Protected Dashboard (Form builder, management)
- Authentication Layer (Clerk integration)
- Form Builder Components
- Form Viewer Components

B. Backend Layer:
- API Routes
- Database Layer
- External Services Integration

**[Client Layer]**

**[Next.js App Router Layer]**

**[API Layer]**

**[Service Layer]**

**[Database Layer]**

##### Component Relationships

A. Client-Side Flow:
**User Interface**
- Public Routes (/forms/[formId])
- Protected Routes (/dashboard/*)
- Auth Routes (Clerk managed)

B. Form Builder Flow:
**FormBuilder**
- ElementToolbar (Component Library)
- Canvas (Drag-n-Drop Area)
- Properties Panel

C. API Architecture:
**API Routes**
- /api/forms/* (CRUD operations)
- /api/templates/* (Template management)
- /api/waitlist/* (Waitlist management)

##### Key Interactions to Highlight

- Authentication flow with Clerk
- Form building process
- Form submission pipeline
- Database interactions
- Collaboration features

##### Technical Details

Technology implementations:
- Drizzle ORM integration
- TypeScript types system
- Clerk authentication flow
- PostgreSQL database
- Web3 provider setup

Create these distinct sections:
**┌─ Public Interface ─┐ ┌─ Protected Dashboard ─┐**
- Landing Page    │ │  - Form Builder       │
- Public Forms    │ │  - Form Management    │
- ┬─┘ └────────────┬─────────┘

- ┌──────┴────────────────┴───────┐
- API Layer              │
- ┬────────────────┬───────┘

- ┌─────────┴───┐    ┌──────┴───────┐
- Services   │    │  Database     │
- ┘    └──────────────┘

##### Implementation Notes

- Numbered sequence flows for complex operations

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        UI[User Interface]
        PUB[Public Interface]
        DASH[Protected Dashboard]:::dashboard
        FB[Form Builder]:::formbuilder
    end

    subgraph AppRouter[Next.js App Router]
        LP[Landing Page]:::page
        PFV["Public Form View"]:::page
        DashP["Dashboard Page"]:::page
        FMP["Form Management"]:::page
        Auth["Auth Layer"]:::auth
    end

    subgraph FormBuilder[Form Builder Components]
        FBC["Form Builder Component"]:::component
        ET["Element Toolbar"]:::component
        PP["Properties Panel"]:::component
        Canvas["Canvas"]:::component
    end

    subgraph FormViewer[Form Viewer Components]
        FV["Form View"]:::component
        FE["Form Elements"]:::component
        FN["Form Navigation"]:::component
    end

    subgraph APILayer[API Layer]
        FormsAPI["Forms API"]:::api
        TemplatesAPI["Templates API"]:::api
        WaitlistAPI["Waitlist API"]:::api
    end

    subgraph Services[Service Layer]
        FormService["Form Service"]:::service
        EmailService["Email Service"]:::service
        Web3Service["Web3 Service"]:::service
    end

    subgraph Database[Database Layer]
        Schema["Database Schema"]:::db
        Config["Database Config"]:::db
        Migrations["Migrations"]:::db
    end

    UI --> PUB & DASH
    PUB --> LP & PFV
    DASH --> DashP & FMP
    DASH --> FB
    FB --> FBC
    FBC --> ET & PP & Canvas
    PFV --> FV
    FV --> FE & FN
    DashP & FMP --> FormsAPI
    FormsAPI & TemplatesAPI & WaitlistAPI --> FormService
    FormService --> Schema
    Schema --> Config
    Config --> Migrations
    Auth --> UI

    %% Click Events
    click LP "https://github.com/SouravInsights/fairforms/blob/main/app/page.tsx"
    click PFV "https://github.com/SouravInsights/fairforms/blob/main/app/forms/[formId]/page.tsx"
    click DashP "https://github.com/SouravInsights/fairforms/blob/main/app/(dashboard)/dashboard/page.tsx"
    click FMP "https://github.com/SouravInsights/fairforms/blob/main/app/(dashboard)/dashboard/forms/[formId]/page.tsx"
    click FBC "https://github.com/SouravInsights/fairforms/blob/main/app/components/form-builder/FormBuilder.tsx"
    click ET "https://github.com/SouravInsights/fairforms/blob/main/app/components/form-builder/ElementToolbar.tsx"
    click PP "https://github.com/SouravInsights/fairforms/blob/main/app/components/form-builder/Properties.tsx"
    click Canvas "https://github.com/SouravInsights/fairforms/blob/main/app/components/form-builder/Canvas.tsx"
    click FV "https://github.com/SouravInsights/fairforms/blob/main/app/components/forms/FormView.tsx"
    click FE "https://github.com/SouravInsights/fairforms/tree/main/app/components/forms/elements/"
    click FN "https://github.com/SouravInsights/fairforms/blob/main/app/components/forms/FormNavigationButtons.tsx"
    click FormsAPI "https://github.com/SouravInsights/fairforms/tree/main/app/api/forms/"
    click TemplatesAPI "https://github.com/SouravInsights/fairforms/tree/main/app/api/templates/"
    click WaitlistAPI "https://github.com/SouravInsights/fairforms/tree/main/app/api/waitlist/"
    click Schema "https://github.com/SouravInsights/fairforms/blob/main/db/schema.ts"
    click Config "https://github.com/SouravInsights/fairforms/blob/main/db/index.ts"
    click Migrations "https://github.com/SouravInsights/fairforms/tree/main/drizzle/"
    click Auth "https://github.com/SouravInsights/fairforms/blob/main/app/(auth)/layout.tsx"
    click Web3Service "https://github.com/SouravInsights/fairforms/blob/main/app/components/providers/web3-provider.tsx"
    click EmailService "https://github.com/SouravInsights/fairforms/blob/main/lib/email/config.ts"
    click FormService "https://github.com/SouravInsights/fairforms/blob/main/lib/services/form-service.ts"

    %% Styles
    classDef page fill:#e1f5fe,stroke:#01579b
    classDef component fill:#e8f5e9,stroke:#2e7d32
    classDef api fill:#fff3e0,stroke:#ff6f00
    classDef service fill:#f3e5f5,stroke:#7b1fa2
    classDef db fill:#fce4ec,stroke:#c2185b
    classDef auth fill:#fff8e1,stroke:#ffa000
    classDef dashboard fill:#e8eaf6,stroke:#3f51b5
    classDef formbuilder fill:#e0f2f1,stroke:#00695c
```
