# mithyalabs/react-forms-lite architecture

> Architecture diagram of the GitHub repository mithyalabs/react-forms-lite, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mithyalabs/react-forms-lite
- Repository: https://github.com/mithyalabs/react-forms-lite

## Overview

##### Project Type & Purpose
- This is an open-source React component library (“react-forms-lite”) focused on a modular form builder.
- It exports a single entrypoint (`src/index.ts` → `ReactForm`) that in turn composes a suite of field components (TextField, SelectField, Radio, etc.) plus utilities and styling.

##### File‐Structure Analysis
- src/
- index.ts → library entrypoint
- lib/ReactForm.tsx → top‐level component
- lib/ml-form-builder/… → folder of submodules:
– Utils.tsx, index.tsx (barrel)
– lib/CheckBox, ConditionalOperations, FieldArray, FileInput, PhoneField, PlainText, Radio, SelectField, Switch, TextField, Types, Constants (each with .tsx + .scss)
- rollup.config.js & vite.config.ts → build and dev server configurations
- dist/ → published artifacts (CJS, ESM, CSS, .d.ts)
- package.json → scripts, dependencies, exports

##### Key Architectural Elements & Relationships
- Consumer App
- Imports `react-forms-lite` from npm
- Renders `<ReactForm …>`
- ReactForm (entrypoint)
- Delegates to ml-form-builder index module
- Applies global styles (dist/index.css)
- ml-form-builder Module
- Exports field components & helpers
- Each field is atomic, imports its own SCSS module for styling
- Utils and Constants provide shared logic/data (e.g., country lists, conditional rules)
- Build Pipeline
- TypeScript compiler (tsconfig.json, tsconfig.node.json)
- Rollup bundles into dist/ (ESM & CJS), extracts CSS
- Vite config for local demo (index.html)

- Consumer Application
- NPM Registry (optional)
- Library ➔ ReactForm (entrypoint)
- ml-form-builder barrel
- Field Components (grouped)
- Utils / Constants
- SCSS Modules
- Build Tools (TypeScript, Rollup, Vite)
- Dist Artifacts (JS, CSS, .d.ts)
- Consumer → ReactForm import
- ReactForm → ml-form-builder index → individual field modules
- Field modules → SCSS modules
- Source files → Build Tools → Dist Artifacts
- Dist Artifacts → Consumer (via npm or bundler)

##### Architectural Patterns & Design Principles
- Component-based and atomic design: each form element isolated in its own folder.
- Barrel exports for neat public API (`src/lib/ml-form-builder/index.tsx`).
- Separation of concerns: styling co-located but compiled separately.
- Build optimization: dual module outputs (CJS + ESM) + type declarations.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Consumer
    ConsumerApp["Consumer Application"]:::external

    %% Distribution Artifacts
    subgraph "Distribution Artifacts"
        direction TB
        DistJS["dist/index.js"]:::output
        DistESM["dist/index.es.js"]:::output
        DistCSS["dist/index.css"]:::output
        DistDTS["dist/index.d.ts"]:::output
    end

    %% Library Source Code
    subgraph "Library Source Code"
        direction TB
        ReactFormEntry["src/index.ts → ReactForm"]:::source
        ReactFormComp["src/lib/ReactForm.tsx"]:::source

        subgraph "ml-form-builder Module"
            direction TB
            Barrel["index.tsx (barrel)"]:::source
            ConstantsGroup["Constants"]:::source
            UtilsComp["Utils.tsx"]:::source
            TypesComp["Types"]:::source
            SCSSUtils["SCSS Utilities"]:::source

            subgraph "Field Components"
                direction TB
                CheckBox["CheckBox"]:::source
                ConditionalOps["ConditionalOperations"]:::source
                FieldArray["FieldArray"]:::source
                FileInput["FileInput"]:::source
                PhoneField["PhoneField"]:::source
                PlainText["PlainText"]:::source
                RadioField["Radio"]:::source
                SelectField["SelectField"]:::source
                SwitchField["Switch"]:::source
                TextField["TextField"]:::source
                HelperText["HelperText"]:::source
            end
        end
    end

    %% Build Tools
    subgraph "Build Tools & Config"
        direction TB
        Rollup["rollup.config.js"]:::build
        Vite["vite.config.ts"]:::build
        TSConfig["tsconfig.json & tsconfig.node.json"]:::build
        DemoHTML["index.html (Vite Demo)"]:::build
    end

    %% Connections: Consumer to Distribution
    ConsumerApp -->|"npm install / import"| DistJS
    ConsumerApp --> DistESM
    ConsumerApp --> DistCSS
    ConsumerApp --> DistDTS

    %% Distribution to Library Source
    DistJS --> ReactFormEntry
    DistESM --> ReactFormEntry
    DistDTS --> ReactFormEntry

    %% Entry to Implementation
    ReactFormEntry --> ReactFormComp
    ReactFormComp --> Barrel

    %% Barrel to modules
    Barrel --> CheckBox
    Barrel --> ConditionalOps
    Barrel --> FieldArray
    Barrel --> FileInput
    Barrel --> PhoneField
    Barrel --> PlainText
    Barrel --> RadioField
    Barrel --> SelectField
    Barrel --> SwitchField
    Barrel --> TextField
    Barrel --> HelperText
    Barrel --> UtilsComp
    Barrel --> ConstantsGroup
    Barrel --> TypesComp
    Barrel --> SCSSUtils

    %% Source to Build
    ReactFormEntry --> Rollup
    ReactFormComp --> Rollup
    Barrel --> Rollup
    TSConfig --> Rollup
    Rollup --> DistJS
    Rollup --> DistESM
    Rollup --> DistCSS
    Rollup --> DistDTS

    DemoHTML --> Vite
    ReactFormComp --> Vite
    Barrel --> Vite

    %% Click Events for component mapping
    click ReactFormEntry "https://github.com/mithyalabs/react-forms-lite/blob/main/src/index.ts"
    click ReactFormComp "https://github.com/mithyalabs/react-forms-lite/blob/main/src/lib/ReactForm.tsx"
    click DistJS "https://github.com/mithyalabs/react-forms-lite/blob/main/dist/index.js"
    click DistESM "https://github.com/mithyalabs/react-forms-lite/blob/main/dist/index.es.js"
    click DistCSS "https://github.com/mithyalabs/react-forms-lite/blob/main/dist/index.css"
    click DistDTS "https://github.com/mithyalabs/react-forms-lite/blob/main/dist/index.d.ts"
    click Barrel "https://github.com/mithyalabs/react-forms-lite/blob/main/src/lib/ml-form-builder/index.tsx"
    click UtilsComp "https://github.com/mithyalabs/react-forms-lite/blob/main/src/lib/ml-form-builder/Utils.tsx"
    click ConstantsGroup "https://github.com/mithyalabs/react-forms-lite/blob/main/src/lib/ml-form-builder/lib/Constants/index.ts"
    click CheckBox "https://github.com/mithyalabs/react-forms-lite/blob/main/src/lib/ml-form-builder/lib/CheckBox/index.tsx"
    click ConditionalOps "https://github.com/mithyalabs/react-forms-lite/blob/main/src/lib/ml-form-builder/lib/ConditionalOperations/index.tsx"
    click FieldArray "https://github.com/mithyalabs/react-forms-lite/blob/main/src/lib/ml-form-builder/lib/FieldArray/index.tsx"
    click FileInput "https://github.com/mithyalabs/react-forms-lite/blob/main/src/lib/ml-form-builder/lib/FileInput/index.tsx"
    click PhoneField "https://github.com/mithyalabs/react-forms-lite/blob/main/src/lib/ml-form-builder/lib/PhoneField/index.tsx"
    click PlainText "https://github.com/mithyalabs/react-forms-lite/blob/main/src/lib/ml-form-builder/lib/PlainText/index.tsx"
    click RadioField "https://github.com/mithyalabs/react-forms-lite/blob/main/src/lib/ml-form-builder/lib/Radio/index.tsx"
    click SelectField "https://github.com/mithyalabs/react-forms-lite/blob/main/src/lib/ml-form-builder/lib/SelectField/index.tsx"
    click SwitchField "https://github.com/mithyalabs/react-forms-lite/blob/main/src/lib/ml-form-builder/lib/Switch/index.tsx"
    click TextField "https://github.com/mithyalabs/react-forms-lite/blob/main/src/lib/ml-form-builder/lib/TextField/index.tsx"
    click HelperText "https://github.com/mithyalabs/react-forms-lite/blob/main/src/lib/ml-form-builder/lib/HelperText/index.tsx"
    click TypesComp "https://github.com/mithyalabs/react-forms-lite/blob/main/src/lib/ml-form-builder/lib/Types/index.ts"
    click Rollup "https://github.com/mithyalabs/react-forms-lite/blob/main/rollup.config.js"
    click Vite "https://github.com/mithyalabs/react-forms-lite/blob/main/vite.config.ts"
    click TSConfig "https://github.com/mithyalabs/react-forms-lite/blob/main/tsconfig.json"
    click DemoHTML "https://github.com/mithyalabs/react-forms-lite/blob/main/index.html"

    %% Styles
    classDef external fill:#f0f0f0,stroke:#333,stroke-width:1px
    classDef source fill:#cce5ff,stroke:#0366d6,stroke-width:1px
    classDef build fill:#d4edda,stroke:#155724,stroke-width:1px
    classDef output fill:#ffe5b4,stroke:#e69500,stroke-width:1px
```
