How midnightntwrk/midnight-indexer works
Project type and purpose
• This is a Rust-based, domain-driven set of microservices (chain-indexer, indexer-api, wallet-indexer) plus a “standalone” mode that bundles all three into one binary with an in-process SQLite database.
• Purpose: pull block/tx data from a Midnight Node, index it into a database, publish real-time events, and expose a GraphQL API for client apps (e.g. wallets).
1. Midnight Node (external data source)
2. Chain Indexer service
– Fetch module (WebSocket client)
– Domain logic (block, tx, contract actions)
– Storage infra (Postgres or SQLite adapters)
– Pub/Sub publisher (NATS or in-mem)
3. Persistent store
– Postgres cluster (cloud mode) or SQLite file (standalone)
4. Pub/Sub broker
– NATS (cloud) or in-mem pub/sub (standalone)
5. Wallet Indexer service
– Subscribes to transaction events
– Filters & associates wallet addresses
– Persists wallet-specific state
– (Uses same DB, pub/sub infra)
6. Indexer API service
– GraphQL HTTP + WebSocket server
– Queries DB for historical data
– Subscribes to pub/sub for real-time events
7. Clients
– Wallet UI or other end-user applications
• Node → Chain Indexer (WebSocket “fetch blocks/tx”)
• Chain Indexer → Database (write blocks, tx)
• Chain Indexer → Pub/Sub broker (publish new-block, new-tx events)
• Wallet Indexer → Pub/Sub broker (subscribe tx events)
• Wallet Indexer → Database (write wallet-view state)
• Indexer API → Database (graphql queries for blocks/tx)
• Indexer API → Pub/Sub broker (subscribe events for subscriptions)
• Clients ↔ Indexer API (HTTP queries & WebSocket subscriptions)
Important architectural patterns & design principles
• Layered “application / domain / infra” structure in each service crate
• Domain-driven design: clear domain models (block, transaction, contract_action)
• Microservices (chain, wallet, API) share common “indexer-common” crate
• Polyglot storage adapters (Postgres vs SQLite) via trait-based infra modules
• Pub/Sub messaging for decoupled real-time notifications (NATS/in-mem)
• Docker & Docker Compose for “cloud” multi-service vs “standalone” unified deployments