# whefter/nestjs-joi architecture

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

- Interactive diagram: https://gitdiagram.com/whefter/nestjs-joi
- Repository: https://github.com/whefter/nestjs-joi

## Overview

##### Main Components

a. Core Components:
- JoiPipe (Central Component)
- JoiPipeModule
- Schema Decorators System
- Validation Groups Handler
- Exception Handling System

b. Integration Points:
- NestJS Framework Integration
- Joi Validation Integration
- Microservices Support
- GraphQL Support

**┌─ Application Layer ─────────────────────────────────────┐**

- ┌─ NestJS Controllers/Resolvers ─┐                    │
- (@Body, @Query, @Param)    │                    │
- ┬────────────────┘                    │
- ↓                                      │
- ┌─ JoiPipeModule ───────────────────────────────┐    │

- ┌─ JoiPipe Core ─────┐  ┌─ Group Handler ─┐ │    │
- Schema Building  │  │  - DEFAULT      │ │    │
- Validation      │←→│  - CREATE       │ │    │
- Error Handling  │  │  - UPDATE       │ │    │
- ┬────────┘  └───────────────┘ │    │
- ↓                              │    │
- ┌─ Decorator System ──┐                   │    │
- @JoiSchema         │                   │    │
- @JoiSchemaOptions  │                   │    │
- @JoiSchemaExtends  │                   │    │
- ┘                   │    │
- ┘    │

- ┘

**┌─ Integration Layer ──────────────────────────────────┐**

- ┌─ Joi Integration ─┐  ┌─ Exception Handling ─┐    │
- Schema Validation │  │ BadRequestException  │    │
- Options Handling  │  │ ValidationException  │    │
- ┘  └────────────────────┘    │

- ┘

**┌─ Platform Support Layer ────────────────────────────┐**

- ┌─ HTTP ─┐  ┌─ GraphQL ─┐  ┌─ Microservices ─┐   │

- ┘  └───────────┘  └─────────────────┘   │

- ┘

##### Important Elements to Highlight

a. Data Flow:
- How validation requests flow from controllers through the pipe
- How schema building works with decorators
- Error propagation paths

b. Integration Points:
- Clear boundaries between NestJS and Joi
- Where platform-specific handling occurs (HTTP/GraphQL/Microservices)

##### Additional Notes

- Notes about the injection-enabled mode
- Validation groups system
- Relationship between decorators and schema building

##### Key Relationships to Emphasize

- JoiPipe's relationship with NestJS's pipe system
- Decorator system's connection to Joi schema building
- Exception handling flow
- Validation logic flow

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Application
        Controllers["NestJS Controllers/Resolvers<br/>(@Body, @Query, @Param)"]
        
        subgraph JoiPipeModule["JoiPipeModule"]
            JoiPipeCore["JoiPipe Core<br/>- Schema Building<br/>- Validation<br/>- Error Handling"]:::core
            GroupHandler["Group Handler<br/>- DEFAULT<br/>- CREATE<br/>- UPDATE"]:::core
            
            subgraph DecoratorSystem["Decorator System"]
                Decorators["@JoiSchema<br/>@JoiSchemaOptions<br/>@JoiSchemaExtends"]:::decorator
            end
            
            JoiPipeCore <--> GroupHandler
            JoiPipeCore --> Decorators
        end
        
        Controllers --> JoiPipeCore
    end
    
    subgraph Integration
        JoiIntegration["Joi Integration<br/>Schema Validation<br/>Options Handling"]:::integration
        ExceptionHandling["Exception Handling<br/>BadRequestException<br/>ValidationException"]:::exception
        
        JoiPipeCore <--> JoiIntegration
        JoiPipeCore --> ExceptionHandling
    end
    
    subgraph "Platform Support"
        HTTP["HTTP Support"]:::platform
        GraphQL["GraphQL Support"]:::platform
        Microservices["Microservices Support"]:::platform
    end
    
    JoiPipeCore --> HTTP
    JoiPipeCore --> GraphQL
    JoiPipeCore --> Microservices

    %% Click Events
    click JoiPipeCore "https://github.com/whefter/nestjs-joi/blob/master/src/internal/joi.pipe.ts"
    click JoiPipeModule "https://github.com/whefter/nestjs-joi/blob/master/src/internal/joi-pipe.module.ts"
    click Microservices "https://github.com/whefter/nestjs-joi/tree/master/src/microservice/"
    click ExceptionHandling "https://github.com/whefter/nestjs-joi/blob/master/src/microservice/joi-pipe-validation.rpc-exception-filter.ts"
    click GraphQL "https://github.com/whefter/nestjs-joi/blob/master/test/api/src/nestjs-integration-graphql.spec.ts"
    click HTTP "https://github.com/whefter/nestjs-joi/blob/master/test/api/src/nestjs-integration.spec.ts"
    click Microservices "https://github.com/whefter/nestjs-joi/blob/master/test/api/src/nestjs-integration-microservice.spec.ts"

    %% Styling
    classDef core fill:#2196F3,color:white
    classDef integration fill:#4CAF50,color:white
    classDef exception fill:#FF9800,color:white
    classDef platform fill:#9E9E9E,color:white
    classDef decorator fill:#E91E63,color:white

    %% Legend
    subgraph Legend
        CoreLegend["Core Components"]:::core
        IntegrationLegend["Integration Points"]:::integration
        ExceptionLegend["Exception Handling"]:::exception
        PlatformLegend["Platform Support"]:::platform
        DecoratorLegend["Decorators"]:::decorator
    end
```
