# arb/celebrate architecture

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

- Interactive diagram: https://gitdiagram.com/arb/celebrate
- Repository: https://github.com/arb/celebrate

## Overview

##### Project Type Analysis
This is an open-source middleware library that serves as a bridge between Express.js and Joi validation library. The project is focused on request validation in Express applications.

##### Main Components

a. Core Components:
- Express Application (Client)
- Celebrate Middleware
- Joi Validation Engine
- Error Handler

b. Request Segments (Validation Targets):
- Headers
- Parameters
- Query
- Body
- Cookies
- Signed Cookies

**[HTTP Request] → [Express Application] → [Celebrate Middleware] → [Route Handler]**

**Celebrate Middleware**
- Schema Validator
- Joi Engine Integration
- Error Handler

**Request Validation Segments**
- Headers
- Parameters
- Query
- Body
- Cookies
- Signed Cookies

##### Specific Implementation Details

- The middleware's position in the request lifecycle
- The validation order (as specified in the README)
- Error handling flow
- The two available validation modes (PARTIAL and FULL)

##### Component Relationships

Key interactions:
- Request flow through the middleware
- Schema validation process
- Error propagation to the error handler
- Successful request continuation to route handlers

##### Technical Details

Annotations for:
- Joi version compatibility
- Express version support (4 and 5)
- Integration points with body-parser and cookie-parser
- Configuration options (joiOptions, reqContext, mode)

##### Notes Section

Important notes about:
- Mutation behavior
- GET request body validation exclusion
- Request context usage
- Schema transformation effects

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Request["Request Flow"]
        direction TB
        HTTP[HTTP Request]
        EA[Express Application]
        CM[Celebrate Middleware]:::middleware
        RH[Route Handler]
        
        HTTP --> EA
        EA --> CM
        CM --> RH
    end

    subgraph Validation["Validation Components"]
        direction TB
        SV[Schema Validator]:::validator
        JE[Joi Engine Integration]
        EH[Error Handler]:::error
        
        CM --> SV
        SV --> JE
        SV --> EH
    end

    subgraph Segments["Request Validation Segments"]
        direction TB
        H[Headers]
        P[Parameters]
        Q[Query]
        B[Body]
        C[Cookies]
        SC[Signed Cookies]
    end

    SV --> H
    SV --> P
    SV --> Q
    SV --> B
    SV --> C
    SV --> SC

    subgraph Config["Configuration"]
        direction TB
        VM["Validation Modes"]
        CO["Configuration Options"]
        direction TB
        VM1["PARTIAL"]
        VM2["FULL"]
        VM --> VM1
        VM --> VM2
    end

    subgraph Legend["Legend"]
        direction TB
        L1["Main Components"]:::main
        L2["Validation Flow"]:::validator
        L3["Error Handling"]:::error
        L4["Optional Components"]:::optional
    end

    classDef main fill:#2374ab
    classDef validator fill:#57a773
    classDef error fill:#ed474a
    classDef optional stroke-dasharray: 5 5
    classDef middleware fill:#0496ff

    click CM "https://github.com/arb/celebrate/blob/master/lib/celebrate.js"
    click EH "https://github.com/arb/celebrate/blob/master/lib/CelebrateError.js"
    click SV "https://github.com/arb/celebrate/blob/master/lib/schema.js"
    click CO "https://github.com/arb/celebrate/blob/master/lib/constants.js"
    click CM "https://github.com/arb/celebrate/blob/master/lib/index.d.ts"
    click CM "https://github.com/arb/celebrate/blob/master/lib/index.js"
```
