Skip to content

Decompose indexer main.rs monolith into focused modules #33

@rustydb

Description

@rustydb

Priority: P1

Source

Senior Architect Code Review (2026-04-03)

Problem

apps/indexer/src/main.rs is an 849-line monolith containing:

  • Configuration parsing (IndexerConfig)
  • Database connection and schema management (Database)
  • Sui RPC client and all API call methods (SuiRpcClient)
  • Event processing pipeline (process_page, poll_until_caught_up)
  • Cursor/state management (CursorState, merge_state)
  • Health check HTTP server (start_health_check_server)
  • All RPC response deserialization types (RpcEnvelope, RpcEventPage, etc.)
  • Utility functions (parse_i64, parse_timestamp_ms, etc.)
  • ~150 lines of inline tests

Meanwhile, handlers.rs and models.rs exist but the actual database interactions bypass the TurretEventStore trait entirely — main.rs has its own Database struct with direct tokio_postgres calls.

Recommendation

Extract into focused modules:

Module Contents
config.rs IndexerConfig, env parsing helpers
database.rs Database struct, schema management, cursor CRUD, event insertion
rpc.rs SuiRpcClient, all RPC types (RpcEnvelope, RpcEventPage, etc.)
pipeline.rs process_page, poll_until_caught_up, PollSummary, PageOutcome
health.rs start_health_check_server
main.rs Entrypoint only — config, wiring, tokio::spawn

Also reconcile the TurretEventStore trait in handlers.rs with the actual database operations in main.rs.

Acceptance Criteria

  • main.rs is under 100 lines (entrypoint and wiring only)
  • Each module has a single responsibility
  • The TurretEventStore trait is either used by the production path or removed
  • All existing tests continue to pass
  • No behavioral changes

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestrustPull requests that update rust code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions