# yaserrar/form-builder architecture

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

- Interactive diagram: https://gitdiagram.com/yaserrar/form-builder
- Repository: https://github.com/yaserrar/form-builder

## Overview

##### Main System Components

a. Frontend Layer (Next.js Application)
- Client-side Components
- Server-side Components
- Form Management System
- UI Component Library
- Validation Layer

##### Component Relationships

Use the following symbols and connections:

**┌─────────────────────────────────────────────┐**
- UI Layer                     │
- ┌─────────────┐ ┌─────────────┐ ┌────────┐ │
- ShadCN UI  │ │   Dialogs   │ │  Pages │ │
- ┘ └─────────────┘ └────────┘ │
- ┘
- ↕ (State & Events)
**┌─────────────────────────────────────────────┐**
- Form Management Layer             │
- ┌─────────────┐        ┌─────────────────┐ │
- React Hook   │ ←──→   │  Form State     │ │
- Form         │        │  Management     │ │
- ┘        └─────────────────┘ │
- ┘
- ↕ (Validation)
**┌─────────────────────────────────────────────┐**
- Validation Layer                  │
- ┌─────────────┐        ┌─────────────────┐ │
- Zod Schemas  │ ←──→   │  Type Safety    │ │
- Layer          │ │
- ┘        └─────────────────┘ │
- ┘

##### Important Details

A. UI Components (components/ui/*)
- Form-related components (input, select, checkbox, etc.)
- Their relationship with ShadCN

B. Dialog System (app/(dialogs)/*)
- How dialogs interact with form components
- State management flow

C. Validation Flow
- How Zod schemas (/validations/*) connect to form components
- Error message propagation

##### Data Flow Indicators

- User input flow
- Validation triggers
- Form submission flow
- Error propagation
- State updates

##### The real-time validation feedback loop

Remember to maintain a balance between detail and clarity, focusing on the architectural decisions that make this form builder unique, such as the integration of Zod with React Hook Form and the use of ShadCN UI components.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef ui fill:#3498db,color:white
    classDef form fill:#2ecc71,color:white
    classDef validation fill:#e67e22,color:white
    classDef utility fill:#95a5a6,color:white
    classDef dialog fill:#9b59b6,color:white

    %% UI Layer
    subgraph UI
        UI_Base["Base UI Components"]
        Button["Button Component"]
        Input["Input Component"]
        Select["Select Component"]
        Checkbox["Checkbox Component"]
        ErrorDisplay["Error Display"]
        Header["Header"]
        Footer["Footer"]
    end

    %% Dialog System
    subgraph Dialogs
        InputDialog["Input Dialog"]
        SelectDialog["Select Dialog"]
        CheckboxDialog["Checkbox Dialog"]
        FileDialog["File Dialog"]
        TextareaDialog["Textarea Dialog"]
    end

    %% Form Management Layer
    subgraph FormManagement
        MainForm["Main Form Component"]
        FormLayout["Form Layout"]
        MainPage["Main Page Component"]
    end

    %% Validation Layer
    subgraph Validation
        FormValidation["Form Validation"]
        InputSchema["Input Schema"]
        SelectSchema["Select Schema"]
        CheckboxSchema["Checkbox Schema"]
        FileSchema["File Schema"]
    end

    %% Utility Layer
    subgraph Utility
        Utils["Utility Functions"]
        DataManagement["Data Management"]
    end

    %% Relationships
    UI_Base --> MainForm
    Button --> MainForm
    Input --> MainForm
    Select --> MainForm
    Checkbox --> MainForm
    ErrorDisplay --> MainForm

    InputDialog --> MainForm
    SelectDialog --> MainForm
    CheckboxDialog --> MainForm
    FileDialog --> MainForm
    TextareaDialog --> MainForm

    MainForm --> FormValidation
    FormValidation --> InputSchema
    FormValidation --> SelectSchema
    FormValidation --> CheckboxSchema
    FormValidation --> FileSchema

    Utils --> MainForm
    DataManagement --> MainForm

    Header --> FormLayout
    Footer --> FormLayout
    FormLayout --> MainPage

    %% Click Events
    click UI_Base "https://github.com/yaserrar/form-builder/tree/main/components/ui/*"
    click Button "https://github.com/yaserrar/form-builder/blob/main/components/ui/button.tsx"
    click Input "https://github.com/yaserrar/form-builder/blob/main/components/ui/input.tsx"
    click Select "https://github.com/yaserrar/form-builder/blob/main/components/ui/select.tsx"
    click Checkbox "https://github.com/yaserrar/form-builder/blob/main/components/ui/checkbox.tsx"
    click ErrorDisplay "https://github.com/yaserrar/form-builder/blob/main/components/ui/error-message.tsx"
    click InputDialog "https://github.com/yaserrar/form-builder/blob/main/app/(dialogs)/input-dialog.tsx"
    click SelectDialog "https://github.com/yaserrar/form-builder/blob/main/app/(dialogs)/select-dialog.tsx"
    click CheckboxDialog "https://github.com/yaserrar/form-builder/blob/main/app/(dialogs)/checkbox-dialog.tsx"
    click FileDialog "https://github.com/yaserrar/form-builder/blob/main/app/(dialogs)/file-dialog.tsx"
    click TextareaDialog "https://github.com/yaserrar/form-builder/blob/main/app/(dialogs)/textarea-dialog.tsx"
    click MainForm "https://github.com/yaserrar/form-builder/blob/main/app/form.tsx"
    click FormLayout "https://github.com/yaserrar/form-builder/blob/main/app/layout.tsx"
    click MainPage "https://github.com/yaserrar/form-builder/blob/main/app/page.tsx"
    click FormValidation "https://github.com/yaserrar/form-builder/blob/main/validations/form.ts"
    click InputSchema "https://github.com/yaserrar/form-builder/blob/main/validations/input-schema.ts"
    click SelectSchema "https://github.com/yaserrar/form-builder/blob/main/validations/select-schema.ts"
    click CheckboxSchema "https://github.com/yaserrar/form-builder/blob/main/validations/checkbox-schema.ts"
    click FileSchema "https://github.com/yaserrar/form-builder/blob/main/validations/file-schema.ts"
    click Header "https://github.com/yaserrar/form-builder/blob/main/components/header.tsx"
    click Footer "https://github.com/yaserrar/form-builder/blob/main/components/footer.tsx"
    click Utils "https://github.com/yaserrar/form-builder/blob/main/lib/utils.ts"
    click DataManagement "https://github.com/yaserrar/form-builder/blob/main/lib/data.ts"

    %% Style Applications
    class UI_Base,Button,Input,Select,Checkbox,ErrorDisplay,Header,Footer ui
    class InputDialog,SelectDialog,CheckboxDialog,FileDialog,TextareaDialog dialog
    class MainForm,FormLayout,MainPage form
    class FormValidation,InputSchema,SelectSchema,CheckboxSchema,FileSchema validation
    class Utils,DataManagement utility
```
