Skip to content

How Schemas Become Components ​

System that transforms JSON into functional components β€” schema in, interface out.

Factories

Factory Pattern is the heart of schepta:

πŸ”§ What It Is: ​

InputFactoryOutputResult
Form JSONFormFactoryReact/Vue FormWorking interface
Menu JSONMenuFactoryReact/Vue NavigationComplete navigation
Component JSONComponentFactoryReact/Vue ComponentRendered component

πŸ“Š How It Works: ​

Automatic Process:

  1. JSON Schema defines structure and behavior
  2. Factory interprets schema and resolves components
  3. Component Registry provides React/Vue components to be rendered
  4. Middleware Pipeline transforms props
  5. React/Vue Component renders final interface

Quick Example:

json
{ "fields": [{ "name": "email", "x-component": "InputEmail" }] }

↓ FormFactory processes

jsx
<input type="email" name="email" />

πŸ’‘ Result: Structured JSON β†’ Functional React/Vue interface. Zero manual configuration!


πŸš€ Factory Types ​

Each Factory is specialized in a type of interface:

πŸ“ FormFactory - Dynamic Forms: ​

Schema PropertyFunctionExampleResult
fields[]Defines form fields[{ name: "email" }]Email field
x-componentInput type"InputText"Text input
requiredRequired validationtrueRequired field
x-rulesCustom validations{ minLength: 8 }Length validation

🧭 MenuFactory - Dynamic Navigation: ​

Schema PropertyFunctionExampleResult
properties{}Defines menu items{ "home": {...} }Navigation item
x-component-props.hrefNavigation link"/dashboard"Working link
activeVisibility control"\{\{ $segment.role === 'admin' \}\}"Permission-based menu
properties.submenuHierarchical submenuNested propertiesDropdown menu

πŸŽ›οΈ ComponentFactory - Generic Components: ​

Schema PropertyFunctionExampleResult
x-componentComponent type"Button"React/Vue button
x-component-propsSpecific props{ variant: "primary" }Styled button
x-uiLayout and positioning{ grid: { xs: 12 } }Responsive grid

βš™οΈ Factory Architecture ​

How the Factory Pattern works internally:

πŸ”„ Processing Pipeline: ​

JSON Schema
    ↓
Validate Schema (Correct structure?)
    ↓
Resolve Components (x-component β†’ React/Vue component)
    ↓
Transform Props (Middleware + context)
    ↓
Orchestrate Render (Final component tree)
    ↓
React/Vue Elements

🎯 How Factories Specialize: ​

Each Factory has specific logic for its domain:

  • FormFactory: Injects FormContext, applies validations, manages state
  • MenuFactory: Manages navigation, active states, menu hierarchy
  • ComponentFactory: Generic rendering, simple props, no specific context

Extension points: Component Registry (global/local), Middleware Pipeline (custom transformations), Context Providers (domain-specific state).


πŸ“Š Practical Use Cases ​

Factory Pattern solves real development problems:

🎯 Solved Scenarios: ​

SituationTraditional ProblemWith Factory PatternBenefit
Repetitive FormsCopy-paste JSXReusable schemaDRY principle
Complex ValidationsDuplicated codeRules in schemaCentralization
Dynamic MenusHardcoded conditionalsvisible expressionsFlexibility
Multi-tenant UIBranches per clientSchema per tenantScalability
A/B TestingComplex feature flagsDifferent schemasAgility

To UnderstandReadRelation to Factories
How to write schemas02. Schema LanguageSyntax that factories interpret
Internal pipeline04. Schema ResolutionHow factories process schemas
Rendering engine05. RendererSystem used by factories
Props transformations06. MiddlewarePipeline applied by factories
Global configuration03. ProviderHow to configure factories