# vinejs/vine architecture

> Architecture diagram of the GitHub repository vinejs/vine, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vinejs/vine
- Repository: https://github.com/vinejs/vine

## Overview

VineJS is a Node.js form-data validation library. A caller defines a schema through the Vine API and schema builder, compiles it, then validates input; the validator applies compiled field rules and returns validated data or reports structured validation errors. The tree documents broad schema coverage, including primitives, collections, unions, enums, dates, files, and optional/conditional behavior. The graph groups related schema implementations for clarity. Most runtime links are supported by the source index or excerpts; unsampled implementation details are not inferred.

Main entry points: [`src/schema/builder.ts`](https://github.com/vinejs/vine/blob/4.x/src/schema/builder.ts) (Schema builder), [`src/vine/main.ts`](https://github.com/vinejs/vine/blob/4.x/src/vine/main.ts) (Vine API), [`src/vine/validator.ts`](https://github.com/vinejs/vine/blob/4.x/src/vine/validator.ts) (Validation engine), [`src/schema/string/main.ts`](https://github.com/vinejs/vine/blob/4.x/src/schema/string/main.ts) (Primitive schemas)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public API and execution"]
  node_vine["Vine API<br/>[main.ts]"]
  node_schema_builder["Schema builder<br/>[builder.ts]"]
  node_validator["Validation engine<br/>[validator.ts]"]
end

subgraph group_schemas["Schema definitions"]
  node_primitive_schemas["Primitive schemas<br/>[main.ts]"]
  node_numeric_date_schemas["Number and date schemas<br/>[main.ts]"]
  node_collection_schemas["Object and collection schemas<br/>[main.ts]"]
  node_variant_schemas["Variants and special schemas<br/>[main.ts]"]
  node_optional_schema["Optional schema<br/>[main.ts]"]
end

subgraph group_rules["Rules and shared logic"]
  node_base_schema["Base schema behavior<br/>[main.ts]"]
  node_literal_schema["Literal schema behavior<br/>[literal.ts]"]
  node_rule_engine["Rule construction<br/>[create_rule.ts]"]
  node_helpers["Validation helpers<br/>[helpers.ts]"]
end

subgraph group_feedback["Validation feedback"]
  node_defaults["Default messages<br/>[defaults.ts]"]
  node_messages["Message provider"]
  node_reporter["Error reporter"]
  node_validation_error["Validation error"]
end

node_caller(("Application caller"))

node_caller -->|"uses"| node_vine
node_vine -->|"compiles schema"| node_validator
node_vine -->|"creates schemas"| node_schema_builder
node_vine -->|"configures"| node_messages
node_vine -->|"configures"| node_reporter
node_schema_builder -->|"builds"| node_primitive_schemas
node_schema_builder -->|"builds"| node_numeric_date_schemas
node_schema_builder -->|"builds"| node_collection_schemas
node_schema_builder -->|"builds"| node_variant_schemas
node_schema_builder -->|"builds"| node_optional_schema
node_primitive_schemas -->|"extends"| node_literal_schema
node_numeric_date_schemas -->|"uses"| node_literal_schema
node_collection_schemas -->|"uses"| node_base_schema
node_optional_schema -->|"uses"| node_base_schema
node_primitive_schemas -->|"registers rules"| node_rule_engine
node_numeric_date_schemas -->|"uses"| node_helpers
node_validator -->|"loads defaults"| node_defaults
node_messages -.->|"uses defaults"| node_defaults
node_validator -.->|"reports failures"| node_reporter
node_reporter -->|"creates error"| node_validation_error

click node_vine "https://github.com/vinejs/vine/blob/4.x/src/vine/main.ts"
click node_schema_builder "https://github.com/vinejs/vine/blob/4.x/src/schema/builder.ts"
click node_validator "https://github.com/vinejs/vine/blob/4.x/src/vine/validator.ts"
click node_primitive_schemas "https://github.com/vinejs/vine/blob/4.x/src/schema/string/main.ts"
click node_numeric_date_schemas "https://github.com/vinejs/vine/blob/4.x/src/schema/number/main.ts"
click node_collection_schemas "https://github.com/vinejs/vine/blob/4.x/src/schema/object/main.ts"
click node_variant_schemas "https://github.com/vinejs/vine/blob/4.x/src/schema/union/main.ts"
click node_optional_schema "https://github.com/vinejs/vine/blob/4.x/src/schema/optional/main.ts"
click node_base_schema "https://github.com/vinejs/vine/blob/4.x/src/schema/base/main.ts"
click node_literal_schema "https://github.com/vinejs/vine/blob/4.x/src/schema/base/literal.ts"
click node_rule_engine "https://github.com/vinejs/vine/blob/4.x/src/vine/create_rule.ts"
click node_helpers "https://github.com/vinejs/vine/blob/4.x/src/vine/helpers.ts"
click node_defaults "https://github.com/vinejs/vine/blob/4.x/src/defaults.ts"
click node_messages "https://github.com/vinejs/vine/blob/4.x/src/messages_provider/simple_messages_provider.ts"
click node_reporter "https://github.com/vinejs/vine/blob/4.x/src/reporters/simple_error_reporter.ts"
click node_validation_error "https://github.com/vinejs/vine/blob/4.x/src/errors/validation_error.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_vine,node_schema_builder,node_validator toneBlue
class node_primitive_schemas,node_numeric_date_schemas,node_collection_schemas,node_variant_schemas,node_optional_schema toneAmber
class node_base_schema,node_literal_schema,node_rule_engine,node_helpers toneMint
class node_defaults,node_messages,node_reporter,node_validation_error toneRose
class node_caller toneIndigo
```

## Components

### Public API and execution

- [Vine API](https://github.com/vinejs/vine/blob/4.x/src/vine/main.ts): `src/vine/main.ts`
- [Schema builder](https://github.com/vinejs/vine/blob/4.x/src/schema/builder.ts): `src/schema/builder.ts`
- [Validation engine](https://github.com/vinejs/vine/blob/4.x/src/vine/validator.ts): `src/vine/validator.ts`

### Schema definitions

- [Primitive schemas](https://github.com/vinejs/vine/blob/4.x/src/schema/string/main.ts): `src/schema/string/main.ts`
- [Number and date schemas](https://github.com/vinejs/vine/blob/4.x/src/schema/number/main.ts): `src/schema/number/main.ts`
- [Object and collection schemas](https://github.com/vinejs/vine/blob/4.x/src/schema/object/main.ts): `src/schema/object/main.ts`
- [Variants and special schemas](https://github.com/vinejs/vine/blob/4.x/src/schema/union/main.ts): `src/schema/union/main.ts`
- [Optional schema](https://github.com/vinejs/vine/blob/4.x/src/schema/optional/main.ts): `src/schema/optional/main.ts`

### Rules and shared logic

- [Base schema behavior](https://github.com/vinejs/vine/blob/4.x/src/schema/base/main.ts): `src/schema/base/main.ts`
- [Literal schema behavior](https://github.com/vinejs/vine/blob/4.x/src/schema/base/literal.ts): `src/schema/base/literal.ts`
- [Rule construction](https://github.com/vinejs/vine/blob/4.x/src/vine/create_rule.ts): `src/vine/create_rule.ts`
- [Validation helpers](https://github.com/vinejs/vine/blob/4.x/src/vine/helpers.ts): `src/vine/helpers.ts`

### Validation feedback

- [Default messages](https://github.com/vinejs/vine/blob/4.x/src/defaults.ts): `src/defaults.ts`
- [Message provider](https://github.com/vinejs/vine/blob/4.x/src/messages_provider/simple_messages_provider.ts): `src/messages_provider/simple_messages_provider.ts`
- [Error reporter](https://github.com/vinejs/vine/blob/4.x/src/reporters/simple_error_reporter.ts): `src/reporters/simple_error_reporter.ts`
- [Validation error](https://github.com/vinejs/vine/blob/4.x/src/errors/validation_error.ts): `src/errors/validation_error.ts`

### Other components

- **Application caller**

## Connections

- Application caller → Vine API: uses
- Vine API → Validation engine: compiles schema (evidence: `src/vine/main.ts`)
- Vine API → Schema builder: creates schemas (evidence: `src/vine/main.ts`)
- Vine API → Message provider: configures (evidence: `src/vine/main.ts`)
- Vine API → Error reporter: configures (evidence: `src/vine/main.ts`)
- Schema builder → Primitive schemas: builds (evidence: `src/schema/builder.ts`)
- Schema builder → Number and date schemas: builds (evidence: `src/schema/builder.ts`)
- Schema builder → Object and collection schemas: builds (evidence: `src/schema/builder.ts`)
- Schema builder → Variants and special schemas: builds (evidence: `src/schema/builder.ts`)
- Schema builder → Optional schema: builds (evidence: `src/schema/builder.ts`)
- Primitive schemas → Literal schema behavior: extends (evidence: `src/schema/string/main.ts`)
- Number and date schemas → Literal schema behavior: uses (evidence: `src/schema/number/main.ts`)
- Object and collection schemas → Base schema behavior: uses (evidence: `src/schema/object/main.ts`)
- Optional schema → Base schema behavior: uses (evidence: `src/schema/optional/main.ts`)
- Primitive schemas → Rule construction: registers rules (evidence: `src/schema/string/main.ts`)
- Number and date schemas → Validation helpers: uses (evidence: `src/schema/number/main.ts`)
- Validation engine → Default messages: loads defaults (evidence: `src/vine/validator.ts`)
- Message provider → Default messages: uses defaults
- Validation engine → Error reporter: reports failures
- Error reporter → Validation error: creates error (evidence: `src/reporters/simple_error_reporter.ts`)
