# pkorchak/form-builder-ui architecture

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

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

## Overview

##### Project Type and Purpose
- Type: Single‐Page Application (SPA) built with Angular.
- Purpose: JSON‐based dynamic form builder UI allowing users to create, edit, and render forms; communicates with a backend REST API via HTTP services.

##### File Structure
- Top‐Level Files:
– angular.json, tsconfig*.json, package.json – Angular build and configuration.
– proxy.config.json – dev‐time proxy to backend API.
- src/app:
– app.module.ts & app-routing.module.ts – root module & router.
– model/ – DTOs and form‐structure definitions.
– services/api/ – HTTP services (forms-http.service.ts, users-http.service.ts) for REST calls.
– services/ – factories and mappers for form elements.
– pages/ – feature modules (create-form, pre-built-forms) each with routing, components, and JSON templates.
– widgets/ – reusable component modules:
· auth – authentication UI
· form-container – top‐level wrapper
· form-editor – builder UI (drag & drop, settings panel)
· form-viewer – runtime form rendering
- src/assets & src/styles – static assets and global or component‐level styles.
- Testing: karma.conf.js (unit), cypress.config.ts (e2e).

##### Key Architectural Insights from README
- Uses ng-zorro-antd component library for UI.
- Provides dev server (localhost:4200) with live reload.
- Build produces a dist/ folder for deployment.
- E2E tests via Cypress, unit tests via Karma + Jasmine.

##### Main Components & Their Relationships
a. Browser / Client (Angular SPA)
– Core Modules: AppModule, Feature Modules (CreateFormModule, PreBuiltFormsModule)
– Shared Modules: Widget Modules (FormEditorModule, FormViewerModule, AuthModule)
– Model Layer: DTOs and FormStructure definitions
– Service Layer:
- HttpService – low‐level wrapper around HttpClient
- FormsHttpService – CRUD operations for forms
- UsersHttpService – registration/auth endpoints
- FormElementsFactory & FormStructureMapper – convert JSON ↔ component tree
b. External UI Library
– ng‐zorro‐antd components used within widgets for consistent look & feel
c. Backend REST API (external microservice)
– Endpoints: /forms, /users (proxied via proxy.config.json in dev)
d. Development Tooling
– Angular CLI (build, serve)
– Cypress & Karma for tests
– ESLint for linting

##### Architectural Patterns & Principles
- Component‐Based Architecture: UI broken into reusable, testable components bundled in feature & shared modules.
- Dependency Injection: Angular’s DI for services & factories.
- Separation of Concerns:
– Pages (routes) compose Widgets; Widgets encapsulate UI logic.
– Services handle data & HTTP.
– Model (DTOs) strictly typed contracts.
- Modularization: Lazy‐loaded feature modules for pages (via Angular Router).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Browser / Client" 
        direction TB
        Browser["Angular SPA"]:::presentation
    end

    subgraph "Presentation Layer (Components & Modules)" 
        direction TB
        AppModule["AppModule"]:::presentation
        Router["AppRoutingModule"]:::presentation
        subgraph "Feature Modules"
            direction TB
            CreateFormModule["CreateFormModule"]:::presentation
            PreBuiltFormsModule["PreBuiltFormsModule"]:::presentation
        end
        subgraph "Shared Widget Modules"
            direction TB
            AuthModule["AuthModule"]:::presentation
            FormContainerModule["FormContainerModule"]:::presentation
            FormEditorModule["FormEditorModule"]:::presentation
            FormViewerModule["FormViewerModule"]:::presentation
        end
    end

    %% Services Layer
    subgraph "Service Layer" 
        direction TB
        HttpService["HttpService"]:::services
        FormsHttpService["FormsHttpService"]:::services
        UsersHttpService["UsersHttpService"]:::services
        Factory["FormElementsFactory"]:::services
        Mapper["FormStructureMapper"]:::services
    end

    %% Data Layer
    subgraph "Data / Model Layer" 
        direction TB
        DTOs["DTOs"]:::data
        FormElementType["FormElementType"]:::data
        AbstractElement["AbstractFormElement"]:::data
        ConcreteElements["*FormElement classes"]:::data
        FormStructure["FormStructure"]:::data
    end

    %% External Dependencies
    subgraph "External" 
        direction TB
        NGZorro["ng-zorro-antd"]:::external
        BackendAPI["REST API"]:::external
    end

    %% Dev Tools
    subgraph "Dev Tooling & Config" 
        direction TB
        AngularCLI["angular.json / tsconfig*.json"]:::tooling
        Proxy["proxy.config.json"]:::tooling
        Cypress["cypress.config.ts"]:::tooling
        Karma["karma.conf.js"]:::tooling
        Package["package.json"]:::tooling
    end

    %% Connections
    Browser --> AppModule
    AppModule --> Router
    Router -->|"lazy loads"| CreateFormModule
    Router -->|"lazy loads"| PreBuiltFormsModule
    AppModule --> AuthModule
    AppModule --> FormContainerModule
    AppModule --> FormEditorModule
    AppModule --> FormViewerModule

    %% Injection relationships
    AuthModule -->|injects| UsersHttpService
    FormEditorModule -->|injects| Factory
    FormViewerModule -->|injects| Mapper
    CreateFormModule -->|injects| FormsHttpService
    PreBuiltFormsModule -->|injects| FormsHttpService

    %% Service call flows
    FormsHttpService -->|uses| HttpService
    UsersHttpService -->|uses| HttpService
    HttpService -->|HTTP calls| BackendAPI

    %% Data flow
    BackendAPI -->|returns JSON| Mapper
    BackendAPI -->|returns JSON| Factory
    Mapper -->|maps to DTOs & FormStructure| FormStructure
    Factory -->|creates component tree| ConcreteElements
    ConcreteElements -->|render| FormViewerModule

    %% Presentation dependency
    AuthModule --> NGZorro
    FormContainerModule --> NGZorro
    FormEditorModule --> NGZorro
    FormViewerModule --> NGZorro

    %% Dev tooling annotations
    AngularCLI -.-> AppModule
    Proxy -.-> HttpService
    Cypress -.-> Browser
    Karma -.-> ConcreteElements

    %% Click Events for component mapping
    click AppModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/app.module.ts"
    click Router "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/app-routing.module.ts"
    click CreateFormModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/pages/create-form/create-form.module.ts"
    click CreateFormModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/pages/create-form/create-form-routing.module.ts"
    click CreateFormModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/pages/create-form/create-form.component.ts"
    click PreBuiltFormsModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/pages/pre-built-forms/pre-built-forms.module.ts"
    click PreBuiltFormsModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/pages/pre-built-forms/pre-built-forms-routing.module.ts"
    click PreBuiltFormsModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/pages/pre-built-forms/pre-built-form.component.ts"
    click PreBuiltFormsModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/pages/pre-built-forms/register/register-form-structure.json"
    click PreBuiltFormsModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/pages/pre-built-forms/shipping/shipping-form-structure.json"
    click AuthModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/widgets/auth/auth.module.ts"
    click AuthModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/widgets/auth/auth.component.ts"
    click FormContainerModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/widgets/form-container/form-container.module.ts"
    click FormContainerModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/widgets/form-container/form-container.component.ts"
    click FormEditorModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/widgets/form-editor/form-editor.module.ts"
    click FormEditorModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/widgets/form-editor/form-editor.component.ts"
    click FormEditorModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/widgets/form-editor/label/editable-label.component.ts"
    click FormEditorModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/widgets/form-editor/settings-drawer/settings-drawer.component.ts"
    click FormViewerModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/widgets/form-viewer/form-viewer.module.ts"
    click FormViewerModule "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/widgets/form-viewer/form-viewer.component.ts"
    click HttpService "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/services/api/http.service.ts"
    click FormsHttpService "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/services/api/forms-http.service.ts"
    click UsersHttpService "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/services/api/users-http.service.ts"
    click Factory "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/services/form-elements-factory.ts"
    click Mapper "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/services/form-structure-mapper.ts"
    click DTOs "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/model/dto/rq/form-create-rq-dto.ts"
    click DTOs "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/model/dto/rq/register-user-rq-dto.ts"
    click DTOs "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/model/dto/rs/form-create-rs-dto.ts"
    click DTOs "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/model/dto/rs/register-user-rs-dto.ts"
    click FormElementType "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/model/form-element-type.ts"
    click AbstractElement "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/model/form-elements/abstract-form-element.ts"
    click ConcreteElements "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/model/form-elements/*-form-element.ts"
    click FormStructure "https://github.com/pkorchak/form-builder-ui/blob/main/src/app/model/form-structure.ts"
    click AngularCLI "https://github.com/pkorchak/form-builder-ui/blob/main/angular.json"
    click Proxy "https://github.com/pkorchak/form-builder-ui/blob/main/proxy.config.json"
    click Cypress "https://github.com/pkorchak/form-builder-ui/blob/main/cypress.config.ts"
    click Karma "https://github.com/pkorchak/form-builder-ui/blob/main/karma.conf.js"
    click Package "https://github.com/pkorchak/form-builder-ui/blob/main/package.json"

    %% Styles
    classDef presentation fill:#E3F2FD,stroke:#90CAF9;
    classDef services fill:#E8F5E9,stroke:#A5D6A7;
    classDef data fill:#FFFDE7,stroke:#FFF59D;
    classDef external fill:#ECEFF1,stroke:#CFD8DC;
    classDef tooling fill:#F3E5F5,stroke:#CE93D8;
```
