# reservoirprotocol/indexer-public architecture

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

- Interactive diagram: https://gitdiagram.com/reservoirprotocol/indexer-public
- Repository: https://github.com/reservoirprotocol/indexer-public

## Overview

##### Project type and purpose
- This is a monorepo (“turbo.json”) that contains multiple packages:
- packages/contracts – Solidity smart-contract code + Hardhat deployments/tests
- packages/indexer – a TypeScript “indexer” backend service (API server, sync jobs, queues)
- packages/sdk – TypeScript client library/SDK to talk to the indexer or directly on-chain
- packages/mint-interface – a small TS helper library for mint UI/flow
- The overall purpose is to deploy on-chain contracts and run an off-chain service that watches blockchains, indexes NFT/marketplace data into databases and search, and exposes a REST/WebSocket API and SDK.

##### File structure
- Top-level: Dockerfiles, ESLint, Prettier, Turborepo config
- packages/contracts: Hardhat config, `contracts/`, `scripts/`, `test/`
- packages/indexer:
- src/api – REST endpoints
- src/jobs – RabbitMQ and Kafka‐backed workers (sync, backfill, CDC, monitoring, WebSocket listeners)
- src/common, src/utils – shared clients for Postgres, Redis, Elasticsearch, Kafka, RabbitMQ, Tracing, Logger
- src/models & src/migrations – TypeORM or similar entities and SQL migrations for Postgres
- src/elasticsearch – indexing pipelines into ES
- src/pubsub – events published via Kafka
- setup.ts + routes.ts to wire everything up
- packages/sdk & mint-interface: pure TS libraries, no external services

##### README for additional insights
- The top-level README simply names it “Reservoir Indexer” and points you to each package’s own README.
- packages/indexer/README.md will explain how to run the service (likely Docker Compose), environment variables, and dependencies.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Cloud
    BlockchainNetwork["Blockchain Network"]:::cloud

    %% Smart Contract Deployment
    HardhatBox["Smart-Contract Deployment (Hardhat)"]:::service

    %% Indexer Service Components
    subgraph "Indexer Service"
        direction TB
        Entry["Entry Point (index.ts)"]:::service
        Setup["Setup (setup.ts)"]:::service
        SyncWorkers["Sync Workers & CDC Jobs"]:::service
        BackfillJobs["Backfill & Monitoring Jobs"]:::service
        WebSocketListeners["WebSocket Listeners"]:::service
        APILayer["HTTP REST & WebSocket API"]:::service
    end

    %% Message Brokers
    RabbitMQ["RabbitMQ"]:::broker
    Kafka["Kafka"]:::broker

    %% Data Stores
    Postgres["PostgreSQL"]:::db
    Redis["Redis"]:::db
    Elasticsearch["Elasticsearch"]:::db

    %% Client Libraries
    SDK["SDK Client Library"]:::client
    Mint["Mint Interface Helper Library"]:::client

    %% Connections
    HardhatBox -->|deploys to| BlockchainNetwork
    BlockchainNetwork -->|emits events to| SyncWorkers
    SyncWorkers -->|publish raw events| RabbitMQ
    SyncWorkers -->|publish raw events| Kafka
    RabbitMQ -->|jobs consume| BackfillJobs
    Kafka -->|jobs consume| BackfillJobs
    BackfillJobs -->|write/update| Postgres
    BackfillJobs -->|index/update| Elasticsearch
    APILayer -->|reads| Postgres
    APILayer -->|reads| Elasticsearch
    APILayer -->|caches| Redis
    SDK -->|calls API| APILayer
    Mint -->|uses SDK| SDK
    Entry -->|initializes| Setup
    Setup -->|wires| SyncWorkers
    Setup -->|wires| BackfillJobs
    Setup -->|wires| WebSocketListeners
    Setup -->|wires| APILayer

    %% Click Events
    click HardhatBox "https://github.com/reservoirprotocol/indexer-public/tree/main/packages/contracts"
    click Entry "https://github.com/reservoirprotocol/indexer-public/blob/main/packages/indexer/src/index.ts"
    click Setup "https://github.com/reservoirprotocol/indexer-public/blob/main/packages/indexer/src/setup.ts"
    click APILayer "https://github.com/reservoirprotocol/indexer-public/tree/main/packages/indexer/src/api"
    click APILayer "https://github.com/reservoirprotocol/indexer-public/blob/main/packages/indexer/src/api/routes.ts"
    click SyncWorkers "https://github.com/reservoirprotocol/indexer-public/tree/main/packages/indexer/src/jobs"
    click RabbitMQ "https://github.com/reservoirprotocol/indexer-public/blob/main/packages/indexer/src/common/rabbit-mq.ts"
    click Kafka "https://github.com/reservoirprotocol/indexer-public/blob/main/packages/indexer/src/common/kafka-stream-producer.ts"
    click SharedClients "https://github.com/reservoirprotocol/indexer-public/tree/main/packages/indexer/src/common"
    click Postgres "https://github.com/reservoirprotocol/indexer-public/tree/main/packages/indexer/src/models"
    click Postgres "https://github.com/reservoirprotocol/indexer-public/tree/main/packages/indexer/src/migrations"
    click Elasticsearch "https://github.com/reservoirprotocol/indexer-public/tree/main/packages/indexer/src/elasticsearch"
    click PubSub "https://github.com/reservoirprotocol/indexer-public/tree/main/packages/indexer/src/pubsub"
    click WebSocketListeners "https://github.com/reservoirprotocol/indexer-public/tree/main/packages/indexer/src/websockets"
    click Config "https://github.com/reservoirprotocol/indexer-public/tree/main/packages/indexer/src/config"
    click SDK "https://github.com/reservoirprotocol/indexer-public/tree/main/packages/sdk"
    click Mint "https://github.com/reservoirprotocol/indexer-public/tree/main/packages/mint-interface"

    %% Styles
    classDef service fill:#D0E8FF,stroke:#0366D6,color:#0366D6,stroke-width:1px;
    classDef db fill:#F0E0FF,stroke:#6F42C1,color:#6F42C1,stroke-width:1px;
    classDef broker fill:#FFE8CD,stroke:#D29922,color:#D29922,stroke-width:1px;
    classDef cloud fill:#EDEDED,stroke:#6A737D,color:#6A737D,stroke-width:1px;
    classDef client fill:#E6FFFA,stroke:#1F9D55,color:#1F9D55,stroke-width:1px;
```
