# jellydn/next-validations architecture

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

- Interactive diagram: https://gitdiagram.com/jellydn/next-validations
- Repository: https://github.com/jellydn/next-validations

## Overview

##### Main Components

a) Core Library Components:
- Validation Middleware Layer
- Schema Adapter System
- Multiple Validation Library Support Hub
- Request Mode Handler (query/body)

b) Integration Points:
- NextJS API Routes
- External Validation Libraries
- TypeSchema Universal Adapter

**┌─────────────────────────────────────────────┐**
- NextJS API Route               │
- ┬─────────────────────────┘
- ↓
**┌─────────────────────────────────────────────┐**
- next-validations Middleware         │
- ┤
- ┌─────────────┐  ┌──────────┐  ┌─────────┐ │
- Request   │  │ Schema   │  │ Error   │ │
- Parser    │  │ Resolver │  │ Handler │ │
- ┘  └──────────┘  └─────────┘ │
- ┬─────────────────────────┘
- ↓
**┌─────────────────────────────────────────────┐**
- TypeSchema Adapter                │
- ┬─────────────────────────┘
- ↓
**┌─────────────────────────────────────────────┐**
- Validation Libraries                │
- ┬──────┬─────┬──────────┬────────────┤
- Yup  │ Joi  │ Zod │ Valibot  │  Fastest   │
- ┴──────┴─────┴──────────┴────────────┘

##### Important Elements to Highlight

a) Request Flow:
- How requests flow from NextJS API routes through the validation middleware
- Validation modes (query/body) processing
- Error handling paths

b) Integration Points:
- Clear connection points with TypeSchema
- Demonstrate how different validation libraries connect
- Configuration entry points

##### Specific Implementation Details

- withValidation.ts implementation
- resolver.ts schema handling
- Multiple validation modes support

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph NextJS
        API[NextJS API Routes]
    end

    subgraph Middleware
        VM[Validation Middleware]
        RP[Request Parser]
        SR[Schema Resolver]
        EH[Error Handler]
        VM --> RP
        VM --> SR
        VM --> EH
    end

    subgraph Adapter
        TS[TypeSchema Universal Adapter]
    end

    subgraph "Validation Libraries"
        YUP[Yup]
        JOI[Joi]
        ZOD[Zod]
        VAL[Valibot]
        FST[Fastest Validator]
    end

    API --> VM
    RP --> SR
    SR --> TS
    TS --> YUP & JOI & ZOD & VAL & FST
    EH --> API

    subgraph Examples
        direction TB
        C["/api/contact"]
        G["/api/greeter"]
        H["/api/hello"]
        R["/api/register"]
        S["/api/support"]
        U["/api/user"]
    end

    API --> Examples

    classDef default fill:#f9f9f9,stroke:#333,stroke-width:1px
    classDef middleware fill:#b3e0ff,stroke:#333,stroke-width:1px
    classDef adapter fill:#98fb98,stroke:#333,stroke-width:1px
    classDef validation fill:#ffd700,stroke:#333,stroke-width:1px
    classDef example fill:#ddd,stroke:#333,stroke-width:1px

    class VM,RP,SR,EH middleware
    class TS adapter
    class YUP,JOI,ZOD,VAL,FST validation
    class C,G,H,R,S,U example

    click VM "https://github.com/jellydn/next-validations/blob/main/src/withValidation.ts"
    click SR "https://github.com/jellydn/next-validations/blob/main/src/resolver.ts"
    click API "https://github.com/jellydn/next-validations/blob/main/src/index.ts"
    click C "https://github.com/jellydn/next-validations/blob/main/example/pages/api/contact.ts"
    click G "https://github.com/jellydn/next-validations/blob/main/example/pages/api/greeter.ts"
    click H "https://github.com/jellydn/next-validations/blob/main/example/pages/api/hello.ts"
    click R "https://github.com/jellydn/next-validations/blob/main/example/pages/api/register.ts"
    click S "https://github.com/jellydn/next-validations/blob/main/example/pages/api/support.ts"
    click U "https://github.com/jellydn/next-validations/blob/main/example/pages/api/user.ts"
```
