# ipni/go-indexer-core architecture

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

- Interactive diagram: https://gitdiagram.com/ipni/go-indexer-core
- Repository: https://github.com/ipni/go-indexer-core

## Overview

##### Project Type and Purpose
- The README and file tree show that this is a specialized storage component, “go-indexer-core,” meant to serve as the data storage backend for a broader indexing service.
- Its purpose is to store mappings between multihashes (keys) and provider metadata (values), optimized for indexing contexts with potentially large key sets and a smaller set of provider data.
- It provides pluggable components like a configurable cache (using implementations such as radixcache) and a selection of persistent storage systems (e.g., Pebble-based storage, an in-memory option, and others).

##### Key Components Identified from the File Structure
- Engine (engine/engine.go & engine/option.go): Acts as the “glue” for the core functionality. This component likely encapsulates the logic to put, retrieve, and remove indexing data.
- Cache (cache/ directory): Holds the interface definition along with an implementation (e.g., cache/radixcache). This component manages in-memory caching to speed up index lookups.
- Persistent Storage (store/ directory): Contains multiple implementations:
- store/pebble: Implements persistent storage backed by Pebble.
- store/memory: Provides an in-memory variant.
- Additional storage implementations (e.g., dhstore, vsinfo) that allow flexibility in the choice of storage engine.
- Interface files (interface.go and value.go): Define the common data types and interfaces used throughout the system.
- Benchmarks (bench/ directory): Though not part of the runtime architecture, this folder provides performance evaluation tools that might be noted in the architecture as testing/benchmarking support.
- Metrics (metrics/ directory): Code for gathering performance or usage metrics, which can provide insight into the system’s health and performance.
- Documentation (doc/ directory): Contains additional context (e.g., data storage details) that supports technical decisions in the design.

##### Relationships and Interactions
- External Clients or Indexing Service (not depicted in this component but assumed by the README) interact with the engine.
- The Engine component sits at the core: it receives “put” and “get” commands.
- For a “get” request, the Engine first queries the integrated Cache. If data isn’t present in the cache, it then queries the underlying Persistent Storage (selected from Pebble, memory, etc.).
- For “put” requests, the Engine writes directly to the Persistent Storage and optionally updates the cache.
- The choice of Persistent Storage is abstracted by a common interface, meaning each implementation (pebble, in-memory, etc.) is interchangeable.
- The Cache also implements a common interface, enabling alternate caching mechanisms to be plugged in if necessary.
- Bench and metrics components serve supportive roles by providing test performance metrics and usage tracking/diagnostics.

##### Architectural Patterns and Design Principles
- Layered Architecture: The separation between the Engine, Cache, and Storage facilities is a classic layered approach.
- Interface Driven Design: Both the Cache and Storage systems expose interfaces so that implementations can be easily swapped or extended.
- Plugin-Like Flexibility: The presence of multiple backends and the ability to configure them (and disable cache if needed) emphasizes high configurability.
- Simple Data Flow: Data flows from external calls to the Engine, then through caching to underlying storage, and vice versa for lookup operations.
- Use of Side Components: Benchmarks and metrics allow for performance monitoring without cluttering core functionalities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client / External API"]:::client
    Engine["Engine"]:::engine
    Client -->|"Request"| Engine

    subgraph "Cache Subsystem"
        CacheInterface["Cache Interface"]:::cache
        RadixCache["Radix Cache Implementation"]:::cache
        CacheInterface --> RadixCache
    end

    subgraph "Persistent Storage Subsystem"
        PebbleStorage["Pebble Storage"]:::storage
        InMemoryStorage["In-Memory Storage"]:::storage
        DHStoreStorage["DHStore Storage"]:::storage
        VSInfoStorage["VSInfo Storage"]:::storage
    end

    Engine -->|"CacheLookup"| CacheInterface
    Engine -->|"FallbackOrPut"| PebbleStorage
    Engine -->|"FallbackOrPut"| InMemoryStorage
    Engine -->|"FallbackOrPut"| DHStoreStorage
    Engine -->|"FallbackOrPut"| VSInfoStorage

    InterfaceDef["Interface Definitions"]:::support
    InterfaceDef -->|"defines"| CacheInterface
    InterfaceDef -->|"defines"| PebbleStorage
    InterfaceDef -->|"defines"| InMemoryStorage
    InterfaceDef -->|"defines"| DHStoreStorage
    InterfaceDef -->|"defines"| VSInfoStorage

    Metrics["Metrics"]:::support
    Engine -.->|"metrics"| Metrics
    CacheInterface -.->|"metrics"| Metrics
    PebbleStorage -.->|"metrics"| Metrics
    InMemoryStorage -.->|"metrics"| Metrics
    DHStoreStorage -.->|"metrics"| Metrics
    VSInfoStorage -.->|"metrics"| Metrics

    Benchmarks["Benchmarks"]:::support
    Engine -.->|"tests"| Benchmarks

    Documentation["Documentation"]:::support

    %% Click Events
    click Engine "https://github.com/ipni/go-indexer-core/blob/main/engine/engine.go"
    click CacheInterface "https://github.com/ipni/go-indexer-core/blob/main/cache/interface.go"
    click RadixCache "https://github.com/ipni/go-indexer-core/blob/main/cache/radixcache/radixcache.go"
    click PebbleStorage "https://github.com/ipni/go-indexer-core/tree/main/store/pebble"
    click InMemoryStorage "https://github.com/ipni/go-indexer-core/tree/main/store/memory"
    click DHStoreStorage "https://github.com/ipni/go-indexer-core/tree/main/store/dhstore"
    click VSInfoStorage "https://github.com/ipni/go-indexer-core/tree/main/store/vsinfo"
    click InterfaceDef "https://github.com/ipni/go-indexer-core/blob/main/interface.go"
    click Benchmarks "https://github.com/ipni/go-indexer-core/tree/main/bench"
    click Metrics "https://github.com/ipni/go-indexer-core/tree/main/metrics"
    click Documentation "https://github.com/ipni/go-indexer-core/tree/main/doc"

    %% Styles
    classDef client fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef engine fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px;
    classDef cache fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef storage fill:#FFCDD2,stroke:#D32F2F,stroke-width:2px;
    classDef support fill:#D1C4E9,stroke:#512DA8,stroke-width:2px;
```
