# loris/api-query-params architecture

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

- Interactive diagram: https://gitdiagram.com/loris/api-query-params
- Repository: https://github.com/loris/api-query-params

## Overview

##### Main Components

a) Input Layer:
- Query String Parser
- Parameter Type Detection
- Custom Options Handler

b) Processing Layer:
- Query Parameter Processor
- Type Casting System
- Operator Mapping System

c) Output Layer:
- MongoDB Query Builder
- Query Object Formatter

**┌─────────────────────────────────────────────────┐**
- INPUT LAYER                    │
- ┘
- ↓
**┌─────────────────────────────────────────────────┐**
- PROCESSING LAYER                  │
- ┘
- ↓
**┌─────────────────────────────────────────────────┐**
- OUTPUT LAYER                     │
- ┘

##### Component Details

For each layer, include these specific elements:

Input Layer:
- Raw query string input (e.g., "status=sent&timestamp>2016-01-01")
- Configuration options object
- Parameter parsing logic

Processing Layer:
- Operator detection (=, >, <, !=, etc.)
- Type casting system (Number, RegExp, Date, Boolean)
- Custom casters handling
- Blacklist/Whitelist filtering

Output Layer:
- MongoDB query object construction
- Filter object
- Projection object
- Sort parameters
- Skip/Limit values
- Population options (Mongoose-specific)

##### Important Relationships

- Data flow from raw query string to parsed parameters
- Parameter transformation through type casting
- Query object construction flow
- Integration points with MongoDB/Mongoose

##### Notes for Implementation

- The library's role as a middleware/utility
- Its independence from specific web frameworks
- The transformation process from URL parameters to MongoDB queries
- Extension points for customization

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        L1[Standard Operators]:::legend
        L2[MongoDB Operators]:::legend
        L3[Custom Caster Functions]:::legend
        L4[Configuration Options]:::legend
    end

    subgraph "Input Layer"
        RawInput[Raw Query String Input]:::input
        ConfigOptions[Configuration Options]:::input
        ParamParser[Parameter Parser]:::input
    end

    subgraph "Processing Layer"
        OpDetect[Operator Detection]:::process
        TypeCast[Type Casting System]:::process
        CustomCast[Custom Casters]:::process
        Filtering[Blacklist/Whitelist]:::process
    end

    subgraph "Output Layer"
        MongoBuilder[MongoDB Query Builder]:::output
        FilterObj[Filter Object]:::output
        ProjectionObj[Projection Object]:::output
        SortParams[Sort Parameters]:::output
        PaginationOpts[Skip/Limit Values]:::output
        PopulationOpts[Population Options]:::output
    end

    RawInput --> ParamParser
    ConfigOptions --> ParamParser
    ParamParser --> OpDetect
    OpDetect --> TypeCast
    TypeCast --> CustomCast
    CustomCast --> Filtering
    Filtering --> MongoBuilder
    MongoBuilder --> FilterObj
    MongoBuilder --> ProjectionObj
    MongoBuilder --> SortParams
    MongoBuilder --> PaginationOpts
    MongoBuilder --> PopulationOpts

    click ParamParser "https://github.com/loris/api-query-params/blob/master/src/index.js"
    click TypeCast "https://github.com/loris/api-query-params/blob/master/src/index.js"
    click MongoBuilder "https://github.com/loris/api-query-params/blob/master/src/index.js"
    click ConfigOptions "https://github.com/loris/api-query-params/blob/master/types.d.ts"
    click FilterObj "https://github.com/loris/api-query-params/blob/master/types.d.ts"
    click ProjectionObj "https://github.com/loris/api-query-params/blob/master/types.d.ts"

    classDef input fill:#3498db,stroke:#2980b9,color:white
    classDef process fill:#2ecc71,stroke:#27ae60,color:white
    classDef output fill:#e67e22,stroke:#d35400,color:white
    classDef legend fill:#95a5a6,stroke:#7f8c8d,color:white
```
