# go-playground/validator architecture

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

- Interactive diagram: https://gitdiagram.com/go-playground/validator
- Repository: https://github.com/go-playground/validator

## Overview

##### Core Components (Center
- It to these primary subcomponents:
- Field Level Validator
- Struct Level Validator
- Cache System
- Tag Parser

##### Validation Types Layer (Surrounding Core)
- Built-in Validators
- Network Validators
- String Validators
- Format Validators
- Comparison Validators
- Custom Validators
- Cross-Field Validators
- Struct Level Validators

##### Translation System (Side Component)
- Translation Manager
- Language Files Repository
- To supported languages (ar, en, es, fa, fr, etc.)
- Error Message Formatter

##### Integration Layer (Top Layer)
Integration points:
- Gin Framework Integration
- Custom Type Handling
- Interface Validation
- SQL Driver Support

- Input: Struct/Field → Validator Core
- Processing: Core → Specific Validators
- Output: Validation Results → Error Handling

##### Special Features (Side Panels)
- Dive Functionality (for slices/maps)
- Cache System
- Tag Parsing System
- Custom Error Formatting

Specific Implementation Details:

##### Clear separation between
- Tag Processing
- Validation Logic
- Error Handling
- Translation System

##### Files and their roles
- validator.go → Main Engine
- cache.go → Caching System
- translations/ → i18n Support
- baked_in.go → Built-in Validators

##### Important interfaces
- FieldLevel
- StructLevel
- Validator
- CustomTypeFunc

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core
        VC["Validator Core"]:::core
        FLV["Field Level Validator"]:::core
        SLV["Struct Level Validator"]:::core
        CS["Cache System"]:::core
        TP["Tag Parser"]:::core

        VC --> FLV
        VC --> SLV
        VC --> CS
        VC --> TP
    end

    subgraph "Validation Types"
        BV["Built-in Validators"]:::validator
        CV["Custom Validators"]:::validator
        CFV["Cross-Field Validators"]:::validator
        SV["Struct Validators"]:::validator

        subgraph "Built-in Categories"
            NV["Network Validators"]:::validator
            STR["String Validators"]:::validator
            FMT["Format Validators"]:::validator
            CMP["Comparison Validators"]:::validator
            
            BV --> NV
            BV --> STR
            BV --> FMT
            BV --> CMP
        end
    end

    subgraph "Translation System"
        TM["Translation Manager"]:::translation
        LFR["Language Files Repository"]:::translation
        EMF["Error Message Formatter"]:::translation
        
        LANG1["Arabic (ar)"]:::translation
        LANG2["English (en)"]:::translation
        LANG3["Spanish (es)"]:::translation
        LANG4["French (fr)"]:::translation

        TM --> LFR
        LFR --> LANG1
        LFR --> LANG2
        LFR --> LANG3
        LFR --> LANG4
        TM --> EMF
    end

    subgraph "Integration Layer"
        GIN["Gin Framework Integration"]:::integration
        CTH["Custom Type Handling"]:::integration
        IV["Interface Validation"]:::integration
        SQL["SQL Driver Support"]:::integration
    end

    subgraph "Special Features"
        DF["Dive Functionality"]:::feature
        CS2["Cache System"]:::feature
        TPS["Tag Parsing System"]:::feature
        CEF["Custom Error Formatting"]:::feature
    end

    VC --> BV
    VC --> CV
    VC --> CFV
    VC --> SV
    VC --> TM
    VC --> GIN
    VC --> CTH
    VC --> IV
    VC --> SQL
    VC --> DF
    VC --> CS2
    VC --> TPS
    VC --> CEF

    classDef core fill:#2374ab
    classDef validator fill:#57a773
    classDef translation fill:#ff8c42
    classDef integration fill:#9b5de5
    classDef feature fill:#45b7d1

    click VC "https://github.com/go-playground/validator/blob/master/validator.go"
    click FLV "https://github.com/go-playground/validator/blob/master/field_level.go"
    click SLV "https://github.com/go-playground/validator/blob/master/struct_level.go"
    click CS "https://github.com/go-playground/validator/blob/master/cache.go"
    click BV "https://github.com/go-playground/validator/blob/master/baked_in.go"
    click TM "https://github.com/go-playground/validator/blob/master/translations.go"
    click LFR "https://github.com/go-playground/validator/tree/master/translations/"
    click CV "https://github.com/go-playground/validator/tree/master/non-standard/validators/"
    click GIN "https://github.com/go-playground/validator/tree/master/_examples/gin-upgrading-overriding/"
    click CTH "https://github.com/go-playground/validator/tree/master/_examples/custom/"
    click SV "https://github.com/go-playground/validator/tree/master/_examples/struct-level/"
    click CEF "https://github.com/go-playground/validator/blob/master/errors.go"
    click DF "https://github.com/go-playground/validator/tree/master/_examples/dive/"
```
