# m31coding/fuzzy-search architecture

> Architecture diagram of the GitHub repository m31coding/fuzzy-search, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/m31coding/fuzzy-search
- Repository: https://github.com/m31coding/fuzzy-search

## Overview

##### Main Components

a) Core Search Engine Components:
- Searcher Factory (Entry Point)
- Dynamic Searchers
- Entity Searchers
- String Searchers
- Fuzzy Searchers
- Normalization Pipeline

b) Data Processing Components:
- N-gram Computer
- Quality Computer
- Result Merger
- Inverted Index

c) Supporting Components:
- Web Worker Integration
- Configuration System
- Utilities Layer

**┌─ Public API Layer ─────────────────────┐**
- SearcherFactory                        │
- ┬────────────────────┘
- ↓
**┌─ Core Search Layer ───────────────────────────────────────────┐**
- ┌─────────────┐ ┌─────────────┐ ┌────────────┐ ┌──────────┐ │
- Dynamic   │ │   Entity    │ │   String   │ │  Fuzzy   │ │
- Searchers  │ │  Searchers  │ │ Searchers  │ │Searchers │ │
- ┘ └─────────────┘ └────────────┘ └──────────┘ │
- ┬──────────────────────────────┘
- ↓
**┌─ Processing Layer ──────────────────────────────────────────┐**
- ┌─────────────┐ ┌─────────────┐ ┌──────────┐ ┌──────────┐ │
- N-gram    │ │   Quality   │ │ Result   │ │ Inverted │ │
- Computer   │ │  Computer   │ │ Merger   │ │  Index   │ │
- ┘ └─────────────┘ └──────────┘ └──────────┘ │
- ┬──────────────────────────────┘
- ↓
**┌─ Normalization Layer ────────────────────────────────────────┐**
- ┌────────────┐ ┌────────────┐ ┌───────────┐ ┌────────────┐ │
- Default   │ │   Multi    │ │  N-gram   │ │ Variation  │ │
- Normalizer  │ │Normalizer  │ │Normalizer │ │Normalizer  │ │
- ┘ └────────────┘ └───────────┘ └────────────┘ │
- ┘

##### Important Flows to Highlight

a) Indexing Flow:
**Input → Normalization → N-gram Generation → Inverted Index Building**

b) Search Flow:
**Query → Normalization → N-gram Matching → Quality Computation → Result Merging**

##### Additional Elements

- External interfaces (e.g., Web Worker API)
- Performance-critical paths with special highlighting

##### Implementation Details to Note

- N-gram processing pipeline
- Where character sorting occurs
- Normalization pipeline stages
- Where quality calculations are performed

- Fast query processing
- Multilingual support
- Dynamic entity management
- Normalization pipeline
- N-gram based fuzzy matching

This system design should help developers understand both the high-level architecture and the detailed interactions between components, while highlighting the unique aspects of the fuzzy search implementation.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef api fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef processing fill:#e67e22,stroke:#d35400,color:white
    classDef normalization fill:#9b59b6,stroke:#8e44ad,color:white
    classDef utility fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Public API Layer
    SearcherFactory["Searcher Factory"]:::api
    Config["Configuration System"]:::utility

    %% Core Search Layer
    subgraph CoreSearch
        DynamicSearcher["Dynamic Searchers"]:::core
        EntitySearcher["Entity Searchers"]:::core
        StringSearcher["String Searchers"]:::core
        FuzzySearcher["Fuzzy Searchers"]:::core
    end

    %% Processing Layer
    subgraph Processing
        NGramComputer["N-gram Computer"]:::processing
        QualityComputer["Quality Computer"]:::processing
        ResultMerger["Result Merger"]:::processing
        InvertedIndex["Inverted Index"]:::processing
    end

    %% Normalization Layer
    subgraph Normalization
        DefaultNorm["Default Normalizer"]:::normalization
        MultiNorm["Multi Normalizer"]:::normalization
        NGramNorm["N-gram Normalizer"]:::normalization
        VarNorm["Variation Normalizer"]:::normalization
    end

    %% Utility Components
    WebWorker["Web Worker Integration"]:::utility

    %% Relationships
    SearcherFactory --> CoreSearch
    SearcherFactory --> Config
    
    DynamicSearcher --> Processing
    EntitySearcher --> Processing
    StringSearcher --> Processing
    FuzzySearcher --> Processing
    
    Processing --> Normalization
    
    WebWorker --> SearcherFactory

    %% Click Events
    click SearcherFactory "https://github.com/m31coding/fuzzy-search/blob/main/src/searcher-factory.ts"
    click DynamicSearcher "https://github.com/m31coding/fuzzy-search/blob/main/src/dynamic-searchers/default-dynamic-searcher.ts"
    click EntitySearcher "https://github.com/m31coding/fuzzy-search/blob/main/src/entity-searchers/default-entity-searcher.ts"
    click StringSearcher "https://github.com/m31coding/fuzzy-search/tree/main/src/string-searchers/"
    click FuzzySearcher "https://github.com/m31coding/fuzzy-search/blob/main/src/fuzzy-searchers/fuzzy-searcher.ts"
    click NGramComputer "https://github.com/m31coding/fuzzy-search/blob/main/src/fuzzy-searchers/ngram-computer.ts"
    click QualityComputer "https://github.com/m31coding/fuzzy-search/blob/main/src/fuzzy-searchers/quality-computer.ts"
    click ResultMerger "https://github.com/m31coding/fuzzy-search/blob/main/src/dynamic-searchers/result-merger.ts"
    click InvertedIndex "https://github.com/m31coding/fuzzy-search/blob/main/src/fuzzy-searchers/inverted-index.ts"
    click WebWorker "https://github.com/m31coding/fuzzy-search/blob/main/usage-examples/worker/indexing-worker.js"
    click Config "https://github.com/m31coding/fuzzy-search/blob/main/src/config.ts"
    click DefaultNorm "https://github.com/m31coding/fuzzy-search/blob/main/src/normalization/default-normalizer.ts"
    click MultiNorm "https://github.com/m31coding/fuzzy-search/blob/main/src/normalization/multi-normalizer.ts"
    click NGramNorm "https://github.com/m31coding/fuzzy-search/blob/main/src/normalization/ngram-normalizer.ts"
    click VarNorm "https://github.com/m31coding/fuzzy-search/blob/main/src/normalization/variation-normalizer.ts"

    %% Legend
    subgraph Legend
        API["API Layer"]:::api
        Core["Core Components"]:::core
        Proc["Processing Components"]:::processing
        Norm["Normalization Components"]:::normalization
        Util["Utility Components"]:::utility
    end
```
