# ibrahimhyazouri/sureform architecture

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

- Interactive diagram: https://gitdiagram.com/ibrahimhyazouri/sureform
- Repository: https://github.com/ibrahimhyazouri/sureform

## Overview

##### Project type and purpose
- This is an open-source, schema-based validation library written in TypeScript. It provides a set of built-in rules (required, string, numeric, etc.), a factory for custom rules, and a core Validator that applies those rules to user data.
- Consumers import the library (npm install sureform) and call `new Validator(data, schema...)` to validate JavaScript/Vue.js payloads.

##### File structure
- Top-level files:
- package.json, tsconfig.json, vitest.config.* → Node/TypeScript project and test runner configuration
- src/ → TypeScript source code
- dist/ → Compiled output (ESM/CJS, `.js`, `.d.ts`)
- src/ subdirectories:
- core/ → Validator engine (AbstractRule, ValidationRule, Validator)
- factory/ → RuleFactory (Strategy/Factory pattern for creating rule instances)
- rules/ → Individual rule implementations (ArrayRule, Email, Max, etc.)
- tests/ → Unit tests for each rule and integration tests for Validator
- Build pipeline:
- tsc compiles src/ → dist/
- vitest runs tests against src or dist

##### README for architectural clues
- Core features emphasize a “fluent API,” “schema-based validation,” extensibility via RuleFactory, wildcard paths, and inline callback rules.
- Data flow: data + schema → Validator → ValidationResult (valid/errors)
- Plug-in points: custom rules through RuleFactory or inline functions

##### Detailed capture of essential elements
– Annotate key methods (e.g., `validate()`, `create()` in RuleFactory)
– Highlight plugin point: “RuleFactory.register(‘myRule’, MyRuleClass)”
– Include notes on wildcard support and inline callback rules

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Layer
    subgraph "API Layer"
        ConsumerApp["Consumer Application\n(JavaScript/Vue.js)"]:::api
        Entry["SureForm API\nsrc/index.ts"]:::api
        DistEntry["Compiled Entry\nindex.js\n(dist/index.js)"]:::api
    end

    %% Core Engine
    subgraph "Core Engine"
        Validator["Validator\nsrc/core/Validator.ts"]:::core
        ValidationRule["ValidationRule\nsrc/core/ValidationRule.ts"]:::core
        AbstractRule["AbstractRule\nsrc/core/AbstractRule.ts"]:::core
        RuleFactory["RuleFactory\nsrc/factory/RuleFactory.ts"]:::core
        ValidationResult["ValidationResult\n(valid:boolean, errors:Map)"]:::core
    end

    %% Rules
    subgraph "Built-in Rules" 
        direction TB
        ArrayRule["ArrayRule\nsrc/rules/ArrayRule.ts"]:::rules
        BetweenRule["BetweenRule\nsrc/rules/BetweenRule.ts"]:::rules
        BooleanRule["BooleanRule\nsrc/rules/Boolean.ts"]:::rules
        EmailRule["EmailRule\nsrc/rules/Email.ts"]:::rules
        FileTypeRule["FileTypeRule\nsrc/rules/FileType.ts"]:::rules
        InArrayRule["InArrayRule\nsrc/rules/InArray.ts"]:::rules
        MaxRule["MaxRule\nsrc/rules/MaxRule.ts"]:::rules
        MinRule["MinRule\nsrc/rules/MinRule.ts"]:::rules
        NotRegexRule["NotRegexRule\nsrc/rules/NotRegex.ts"]:::rules
        NumericRule["NumericRule\nsrc/rules/Numeric.ts"]:::rules
        RegexRule["RegexRule\nsrc/rules/Regex.ts"]:::rules
        RequiredRule["RequiredRule\nsrc/rules/Required.ts"]:::rules
        StringRule["StringRule\nsrc/rules/StringRule.ts"]:::rules
        UrlRule["UrlRule\nsrc/rules/Url.ts"]:::rules
    end

    %% Build & Distribution
    subgraph "Build & Distribution"
        TSCompiler["TypeScript Compiler\ntsc"]:::build
        DistOutput["Compiled Output\ndist/**/*.js & .d.ts"]:::build
        NpmRegistry["npm Registry\n(Distribution)"]:::build
    end

    %% Test Suite
    subgraph "Test Suite"
        Vitest["Vitest Tests\nsrc/tests/"]:::test
    end

    %% Connections
    ConsumerApp -->|"install & call"| Entry
    Entry -->|"imports & forwards"| Validator
    Validator -->|"validate()"| ValidationRule
    ValidationRule -.->|"extends"| AbstractRule
    Validator -->|"parses schema & loops"| RuleFactory
    RuleFactory -->|"creates instances"| ArrayRule
    RuleFactory --> BetweenRule
    RuleFactory --> BooleanRule
    RuleFactory --> EmailRule
    RuleFactory --> FileTypeRule
    RuleFactory --> InArrayRule
    RuleFactory --> MaxRule
    RuleFactory --> MinRule
    RuleFactory --> NotRegexRule
    RuleFactory --> NumericRule
    RuleFactory --> RegexRule
    RuleFactory --> RequiredRule
    RuleFactory --> StringRule
    RuleFactory --> UrlRule
    Validator -->|"aggregates results"| ValidationResult
    ValidationResult -->|"returns to"| ConsumerApp

    %% Build Pipeline
    Entry --> TSCompiler
    Validator --> TSCompiler
    RuleFactory --> TSCompiler
    ArrayRule --> TSCompiler
    BetweenRule --> TSCompiler
    BooleanRule --> TSCompiler
    EmailRule --> TSCompiler
    FileTypeRule --> TSCompiler
    InArrayRule --> TSCompiler
    MaxRule --> TSCompiler
    MinRule --> TSCompiler
    NotRegexRule --> TSCompiler
    NumericRule --> TSCompiler
    RegexRule --> TSCompiler
    RequiredRule --> TSCompiler
    StringRule --> TSCompiler
    UrlRule --> TSCompiler
    TSCompiler --> DistOutput
    DistOutput --> NpmRegistry
    Vitest --> Validator
    Vitest --> ArrayRule
    Vitest --> BetweenRule
    Vitest --> BooleanRule
    Vitest --> EmailRule

    %% Click Events
    click Entry "https://github.com/ibrahimhyazouri/sureform/blob/main/src/index.ts"
    click DistEntry "https://github.com/ibrahimhyazouri/sureform/blob/main/dist/index.js"
    click Validator "https://github.com/ibrahimhyazouri/sureform/blob/main/src/core/Validator.ts"
    click ValidationRule "https://github.com/ibrahimhyazouri/sureform/blob/main/src/core/ValidationRule.ts"
    click AbstractRule "https://github.com/ibrahimhyazouri/sureform/blob/main/src/core/AbstractRule.ts"
    click RuleFactory "https://github.com/ibrahimhyazouri/sureform/blob/main/src/factory/RuleFactory.ts"
    click ArrayRule "https://github.com/ibrahimhyazouri/sureform/blob/main/src/rules/ArrayRule.ts"
    click BetweenRule "https://github.com/ibrahimhyazouri/sureform/blob/main/src/rules/BetweenRule.ts"
    click BooleanRule "https://github.com/ibrahimhyazouri/sureform/blob/main/src/rules/Boolean.ts"
    click EmailRule "https://github.com/ibrahimhyazouri/sureform/blob/main/src/rules/Email.ts"
    click FileTypeRule "https://github.com/ibrahimhyazouri/sureform/blob/main/src/rules/FileType.ts"
    click InArrayRule "https://github.com/ibrahimhyazouri/sureform/blob/main/src/rules/InArray.ts"
    click MaxRule "https://github.com/ibrahimhyazouri/sureform/blob/main/src/rules/MaxRule.ts"
    click MinRule "https://github.com/ibrahimhyazouri/sureform/blob/main/src/rules/MinRule.ts"
    click NotRegexRule "https://github.com/ibrahimhyazouri/sureform/blob/main/src/rules/NotRegex.ts"
    click NumericRule "https://github.com/ibrahimhyazouri/sureform/blob/main/src/rules/Numeric.ts"
    click RegexRule "https://github.com/ibrahimhyazouri/sureform/blob/main/src/rules/Regex.ts"
    click RequiredRule "https://github.com/ibrahimhyazouri/sureform/blob/main/src/rules/Required.ts"
    click StringRule "https://github.com/ibrahimhyazouri/sureform/blob/main/src/rules/StringRule.ts"
    click UrlRule "https://github.com/ibrahimhyazouri/sureform/blob/main/src/rules/Url.ts"

    %% Styles
    classDef api fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef core fill:#E0F7E9,stroke:#28a745,color:#234D20;
    classDef rules fill:#FFF8DC,stroke:#ffcc00,color:#b8860b;
    classDef build fill:#F0F0F0,stroke:#6a737d,color:#6a737d;
    classDef test fill:#F3E6FF,stroke:#6f42c1,color:#4a235a;
```
