# manticoresoftware/manticoresearch architecture

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

- Interactive diagram: https://gitdiagram.com/manticoresoftware/manticoresearch
- Repository: https://github.com/manticoresoftware/manticoresearch

## Overview

##### Project Type and Purpose
- Manticore Search is an open-source, high-performance search database engine written in C++. It provides:
- SQL interface (MySQL wire protocol)
- HTTP/JSON REST interface
- Batch indexing (indexer tool) and real-time indexing
- Multi-master replication (Galera)
- Row-wise, columnar and docstore storage engines
- Plugin/UDF extensibility

##### High-Level Architectural Components
A. Clients & External Interfaces
- MySQL-compatible clients (e.g., mysql CLI, connectors)
- HTTP/JSON clients (curl, REST tools)
- Language-specific SDKs (Python, Ruby, Go, etc.)
B. Search Daemon (searchd)
- Network Front-Ends
- MySQL protocol handler
- HTTP/JSON handler
- Parser & Planner
- SQL parser (bison/flex)
- JSON schema manager
- Cost-based query optimizer
- Query Execution Engine
- Query operators (filter, aggregator, join, KNN)
- Inverted-index & PGM-index access
- Columnar/row-wise storage layer
- Real-Time Index Engine
- In-memory RT segment management
- Binary log writer/reader
- Replication Module
- Galera client library interface
- Cluster state manager, binlog applier
- Storage Subsystems
- On-disk index files, columnar library
- Docstore for raw payload retrieval
- Auxiliary Services
- Configuration reloader
- Crash log and query log subsystem
- Monitoring / metrics (telemetry)
C. Batch Indexing Tool
- indexer CLI
- Connector submodules (source_mysql, source_xml, source_csv, ODBC, Kafka)
- Schema configurator
- Output: on-disk index files
D. Build & Packaging
- CMake build system with modular cmake/Find*.cmake
- Docker build pipelines (dist/build_dockers)
- Packaging scripts (deb, rpm, nsis)
E. Documentation and Test Suite
- manual/ (user docs)
- test/ (CLT tests, unit tests, benchmarks)

##### Relationships and Data Flows
- Client → (MySQL/TCP or HTTP/JSON) → searchd Front-End
- Front-End → Parser → Query Planner → Execution Engine
- Execution → Storage Access → Disk/Memory
- Real-Time Inserts → RT Engine → Memory segments & Binlog
- Batch Indexing (indexer) → Reads source → Builds index files → searchd picks up on rotate
- Replication → Galera over network → Applies changes to local RT segments & binlogs
- Configuration changes → Config Reloader → Restarts sub-components

##### Architectural Patterns & Principles
- Modular C++ components split by function (networking, parsing, storage, replication)
- Layered architecture: protocol → parser → planner → executor → storage
- Plugin extensibility: UDFs, tokenizers, searchd plugins
- Multi-threaded design: request dispatch, worker threads for query & indexing
- Separate batch and real-time indexing pipelines

##### Essential Details to Capture
- Dual front-end (MySQL vs HTTP) converging into the same query engine
- Distinct paths for batch vs real-time indexing
- Replication logic separate from query execution but writing/applying binlogs
- Storage engine pluggability (columnar library as external submodule)
- Build and packaging layers as supporting infrastructure

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Clients Layer
  subgraph "Clients & External Interfaces"
    direction TB
    MySQLClient["MySQL Clients"]:::external
    HTTPClient["HTTP/JSON Clients"]:::external
    SDKs["Language SDKs"]:::external
  end

  %% Search Daemon Layer
  subgraph "Search Daemon (searchd)"
    direction TB

    subgraph "Network Front-Ends"
      direction TB
      MPH["MySQL Protocol Handler"]:::network
      HTTPH["HTTP/JSON Handler"]:::network
    end

    subgraph "Parser & Planner"
      direction TB
      SQLP["SQL Parser"]:::core
      JSONSM["JSON Schema Manager"]:::core
      QO["Query Optimizer"]:::core
    end

    subgraph "Query Execution Engine"
      direction TB
      Operators["Query Operators"]:::core
      IndexAccess["Inverted & PGM-Index Access"]:::storage
      StorageLayer["Columnar/Row-wise Storage"]:::storage
    end

    subgraph "Real-Time Index Engine"
      direction TB
      RT["RT Segment Manager"]:::pipeline
      Binlog["Binlog Writer/Reader"]:::pipeline
    end

    subgraph "Replication Module"
      direction TB
      Galera["Galera Client Library"]:::replication
      ClusterMgr["Cluster State Manager"]:::replication
    end

    subgraph "Storage Subsystems"
      direction TB
      DiskIdx["On-disk Index Files"]:::storage
      Docstore["Docstore"]:::storage
    end

    subgraph "Auxiliary Services"
      direction TB
      ConfigR["Config Reloader"]:::aux
      Logs["Crash & Query Logging"]:::aux
      Metrics["Monitoring/Telemetry"]:::aux
    end
  end

  %% Batch Indexer
  subgraph "Batch Indexing Tool"
    direction TB
    IndexerCLI["indexer CLI"]:::pipeline
    Connectors["Indexing Connectors"]:::pipeline
    SchemaCfg["Schema Configurator"]:::pipeline
  end

  %% DevOps Support
  subgraph "Build & Packaging"
    direction TB
    CMake["CMake Build System"]:::devops
    Docker["Docker Build Pipelines"]:::devops
    Packaging["Packaging Scripts"]:::devops
  end

  subgraph "Documentation & Tests"
    direction TB
    Docs["Documentation"]:::docs
    Tests["Test Suite"]:::docs
  end

  %% Data Flows
  MySQLClient -->|"MySQL wire protocol"| MPH
  HTTPClient -->|"JSON over HTTP"| HTTPH
  SDKs -->|"Protocol"| MPH
  SDKs -->|"Protocol"| HTTPH

  MPH -->|"SQL text"| SQLP
  HTTPH -->|"JSON query"| JSONSM
  JSONSM -->|"Normalized AST"| QO
  SQLP -->|"AST"| QO
  QO -->|"Query plan"| Operators

  Operators -->|"Access index"| IndexAccess
  Operators -->|"Access storage"| StorageLayer
  IndexAccess --> DiskIdx
  StorageLayer --> DiskIdx
  Operators --> Docstore

  HTTPClient -->|"Real-time insert"| RT
  RT --> Binlog
  Binlog --> DiskIdx
  Binlog --> ClusterMgr

  IndexerCLI -->|"Read source"| Connectors
  Connectors -->|"Generate index files"| DiskIdx
  SchemaCfg --> Connectors

  ClusterMgr --> Galera
  Galera --> ClusterMgr

  DiskIdx -->|"Picked up on rotate"| MPH

  ConfigR --> MPH
  Logs --> Metrics
  Metrics --> MPH

  CMake --> Docker
  Docker --> Packaging

  Docs --> SDKs
  Docs --> IndexerCLI
  Tests --> MPH
  Tests --> IndexerCLI

  %% Click Events
  click MPH "https://github.com/manticoresoftware/manticoresearch/blob/master/src/searchdsql.cpp"
  click HTTPH "https://github.com/manticoresoftware/manticoresearch/blob/master/src/searchdhttp.cpp"
  click HTTPH "https://github.com/manticoresoftware/manticoresearch/blob/master/src/json/cJSON.c"
  click SQLP "https://github.com/manticoresoftware/manticoresearch/blob/master/src/sphinxql.l"
  click SQLP "https://github.com/manticoresoftware/manticoresearch/blob/master/src/sphinxql.y"
  click QO "https://github.com/manticoresoftware/manticoresearch/blob/master/src/costestimate.cpp"
  click JSONSM "https://github.com/manticoresoftware/manticoresearch/blob/master/src/jsonsi.cpp"
  click JSONSM "https://github.com/manticoresoftware/manticoresearch/blob/master/src/jsonqueryfilter.cpp"
  click Operators "https://github.com/manticoresoftware/manticoresearch/blob/master/src/aggrexpr.cpp"
  click IndexAccess "https://github.com/manticoresoftware/manticoresearch/blob/master/src/indexfiles.cpp"
  click StorageLayer "https://github.com/manticoresoftware/manticoresearch/blob/master/src/columnarlib.cpp"
  click Docstore "https://github.com/manticoresoftware/manticoresearch/blob/master/src/docstore.cpp"
  click RT "https://github.com/manticoresoftware/manticoresearch/blob/master/src/sphinxrt.cpp"
  click Binlog "https://github.com/manticoresoftware/manticoresearch/blob/master/src/binlog.cpp"
  click ClusterMgr "https://github.com/manticoresoftware/manticoresearch/tree/master/src/replication/"
  click ConfigR "https://github.com/manticoresoftware/manticoresearch/blob/master/src/config_reloader.cpp"
  click Logs "https://github.com/manticoresoftware/manticoresearch/blob/master/src/daemon/crash_logger.cpp"
  click Metrics "https://github.com/manticoresoftware/manticoresearch/blob/master/src/daemon/api_search.cpp"
  click IndexerCLI "https://github.com/manticoresoftware/manticoresearch/blob/master/src/indexer.cpp"
  click Connectors "https://github.com/manticoresoftware/manticoresearch/tree/master/src/indexing_sources/"
  click SchemaCfg "https://github.com/manticoresoftware/manticoresearch/blob/master/src/indexing_sources/schema_configurator.h"
  click CMake "https://github.com/manticoresoftware/manticoresearch/blob/master/CMakeLists.txt"
  click Docker "https://github.com/manticoresoftware/manticoresearch/tree/master/dist/build_dockers/"
  click Packaging "https://github.com/manticoresoftware/manticoresearch/tree/master/dist/deb/"
  click Docs "https://github.com/manticoresoftware/manticoresearch/tree/master/doc/"
  click Tests "https://github.com/manticoresoftware/manticoresearch/tree/master/src/gtests/"

  %% Styles
  classDef external fill:#A0C4FF,stroke:#0275d8,color:#000
  classDef network fill:#89CFF0,stroke:#0177b7,color:#000
  classDef core fill:#A8E6CF,stroke:#379237,color:#000
  classDef storage fill:#FFD97D,stroke:#E6A800,color:#000
  classDef pipeline fill:#FFB347,stroke:#ff8c00,color:#000
  classDef replication fill:#D7BDE2,stroke:#7D3C98,color:#000
  classDef aux fill:#FFE5B4,stroke:#E67E22,color:#000
  classDef devops fill:#D6EAF8,stroke:#2874A6,color:#000
  classDef docs fill:#F9E79F,stroke:#B7950B,color:#000
```
