# scylladb/vector-store architecture

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

- Interactive diagram: https://gitdiagram.com/scylladb/vector-store
- Repository: https://github.com/scylladb/vector-store

## Overview

##### Project type and purpose
- This is a standalone backend microservice (indexing service) written in Rust.
- Purpose: accept HTTP API calls to index and search vector data, persist metadata in ScyllaDB, and leverage either USearch or OpenSearch for vector search capabilities.

##### File structure
- src/main.rs + src/lib.rs: application entry point and library glue.
- src/httpserver.rs + src/httproutes.rs: HTTP server and routing layer.
- src/engine.rs: core business logic orchestrator.
- src/db.rs + src/db_index.rs: ScyllaDB connectivity & schema access.
- src/index/: modular index adapters – factory, actor, and two implementations (usearch.rs & opensearch.rs).
- src/monitor_*.rs: background tasks to monitor indexes and items.
- Cargo.toml, Dockerfile: build, dependencies, and containerization.

##### README for stack and runtime details
- Runs as a Docker container or via `cargo run`.
- Configurable via environment vars (`SCYLLADB_URI`, `SCYLLA_USEARCH_URI`, etc.).
- Exposes HTTP API for clients on configurable port.

##### Main components and boundaries
a. Clients
– External HTTP clients (e.g., CLI, other services) that issue REST calls.
b. HTTP Server Layer
– httpserver.rs: listens for HTTP requests.
– httproutes.rs: defines endpoints (index, search, health, etc.).
c. Engine Core
– engine.rs: validates requests, applies business rules, and dispatches work.
d. Indexing Subsystem
– factory.rs: selects appropriate adapter based on config (Usearch or OpenSearch).
– actor.rs: runs indexing tasks (possibly as actors/messages).
– usearch.rs / opensearch.rs: adapter implementations that call external vector‐search HTTP APIs.
e. Persistence Layer
– db.rs: handles connection pooling to ScyllaDB.
– db_index.rs: CRUD for index metadata (namespaces, item mappings).
f. Background Monitors
– monitor_indexes.rs & monitor_items.rs: scheduled jobs to sync or rebuild indexes.
g. External Services
– ScyllaDB: vector metadata store.
– USearch or OpenSearch HTTP API: actual vector search engine.

##### Interactions & data flows
- Client → HTTP Server: POST/GET JSON payloads.
- HTTP Server → Engine: function calls with parsed payloads.
- Engine → Persistence Layer: read/write metadata into Scylla.
- Engine → Indexing Subsystem: push vector data to the chosen external search engine.
- Background Monitors → Persistence + Indexing Subsystem: periodic reconciliation.
- All external calls over TCP/HTTP.

##### Architectural patterns & principles
- Modular adapters (Factory Pattern) for pluggable backends.
- Layered architecture: API Layer → Business Logic → Persistence/External Integration.
- Concurrency: background tasks decoupled via actor messaging.
- Configuration via environment (12-factor style).

- All major components labeled with module names.
- Annotations for protocols (HTTP, CQL) and config points (env vars, Docker).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Rust Service Container
    subgraph "Rust Service"
        direction TB
        Main["Application Entrypoint\n(src/main.rs)"]:::internal
        Lib["Library Module\n(src/lib.rs)"]:::internal

        subgraph "HTTP Server Layer"
            direction TB
            HTTPServer["HTTP Server\n(src/httpserver.rs)"]:::api
            HTTPRoutes["Route Definitions\n(src/httproutes.rs)"]:::api
        end

        subgraph "Engine Core"
            direction TB
            Engine["Engine Core\n(src/engine.rs)"]:::business
        end

        subgraph "Persistence Layer\n(ScyllaDB Client)"
            direction TB
            DBClient["DB Connection Pool\n(src/db.rs)"]:::db
            DBIndex["Index Metadata CRUD\n(src/db_index.rs)"]:::db
        end

        subgraph "Indexing Subsystem"
            direction TB
            IndexMod["Index Adapters Module\n(src/index/mod.rs)"]:::internal
            Factory["Adapter Factory\n(src/index/factory.rs)"]:::business
            Actor["Indexing Actor\n(src/index/actor.rs)"]:::business
            subgraph "Adapters"
                direction TB
                Usearch["USEARCH Adapter\n(src/index/usearch.rs)"]:::external
                Opensearch["OpenSearch Adapter\n(src/index/opensearch.rs)"]:::external
            end
        end

        subgraph "Background Monitors"
            direction TB
            MonitorIndexes["Index Monitor\n(src/monitor_indexes.rs)"]:::worker
            MonitorItems["Item Monitor\n(src/monitor_items.rs)"]:::worker
        end

        Main -->|starts| HTTPServer
        Main -->|loads| Lib
        HTTPServer -->|routes to| HTTPRoutes
        HTTPRoutes -->|calls| Engine
        Engine -->|CQL| DBClient
        Engine -->|CRUD calls| DBIndex
        Engine -->|select backend| Factory
        Factory -->|spawns| Actor
        Actor -->|uses HTTP| Usearch
        Actor -->|uses HTTP| Opensearch

        MonitorIndexes -->|CQL| DBClient
        MonitorIndexes -->|push tasks| Factory
        MonitorItems -->|CQL| DBIndex
        MonitorItems -->|push tasks| Factory
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        ScyllaDB["ScyllaDB\n(CQL)"]:::externalSystem
        USEArchAPI["USEARCH HTTP API"]:::externalSystem
        OpenSearchAPI["OpenSearch HTTP API"]:::externalSystem
    end

    Usearch -->|HTTP| USEArchAPI
    Opensearch -->|HTTP| OpenSearchAPI
    DBClient -->|CQL| ScyllaDB
    DBIndex -->|CQL| ScyllaDB

    %% Configuration & Build
    subgraph "Configuration & Build"
        direction TB
        Cargo["Cargo.toml"]:::config
        Docker["Dockerfile\n(env vars)"]:::config
    end

    Main -->|built by| Cargo
    Docker -->|runs| Main

    %% Click Events
    click HTTPServer "https://github.com/scylladb/vector-store/blob/master/src/httpserver.rs"
    click HTTPRoutes "https://github.com/scylladb/vector-store/blob/master/src/httproutes.rs"
    click Engine "https://github.com/scylladb/vector-store/blob/master/src/engine.rs"
    click DBClient "https://github.com/scylladb/vector-store/blob/master/src/db.rs"
    click DBIndex "https://github.com/scylladb/vector-store/blob/master/src/db_index.rs"
    click Factory "https://github.com/scylladb/vector-store/blob/master/src/index/factory.rs"
    click Actor "https://github.com/scylladb/vector-store/blob/master/src/index/actor.rs"
    click Usearch "https://github.com/scylladb/vector-store/blob/master/src/index/usearch.rs"
    click Opensearch "https://github.com/scylladb/vector-store/blob/master/src/index/opensearch.rs"
    click IndexMod "https://github.com/scylladb/vector-store/blob/master/src/index/mod.rs"
    click MonitorIndexes "https://github.com/scylladb/vector-store/blob/master/src/monitor_indexes.rs"
    click MonitorItems "https://github.com/scylladb/vector-store/blob/master/src/monitor_items.rs"
    click Main "https://github.com/scylladb/vector-store/blob/master/src/main.rs"
    click Lib "https://github.com/scylladb/vector-store/blob/master/src/lib.rs"
    click Cargo "https://github.com/scylladb/vector-store/blob/master/Cargo.toml"
    click Docker "https://github.com/scylladb/vector-store/tree/master/Dockerfile"

    %% Styles
    classDef internal fill:#ddf,stroke:#333,stroke-width:1px
    classDef api fill:#cfc,stroke:#333,stroke-width:1px
    classDef business fill:#cdf,stroke:#333,stroke-width:1px
    classDef db fill:#fcf,stroke:#333,stroke-width:1px
    classDef worker fill:#ffc,stroke:#333,stroke-width:1px
    classDef external fill:#eee,stroke:#666,stroke-dasharray: 5 5
    classDef externalSystem fill:#fdd,stroke:#900,stroke-width:1px
    classDef config fill:#efe,stroke:#070,stroke-width:1px
```
