Skip to content

refactor: Systematic reduction of file bloat #2016

@sanity

Description

@sanity

Problem

We have significant technical debt from large files that are difficult to navigate and maintain. Files over 1500 lines become code smells, especially when they contain large test modules that could be separated.

Goals

  1. Split large test modules into separate files (modern Rust module.rs + module/tests.rs pattern)
  2. Extract logical sub-modules from large implementation files
  3. Improve code navigability without changing functionality
  4. Establish patterns for future file organization

Statistics (files >1000 lines)

2231  handshake.rs           ← In progress (#2015)
2214  priority_select.rs     ← In progress (#2012)
1995  connection_handler.rs
1778  client_events/mod.rs
1682  p2p_protoc.rs
1598  tracing/mod.rs
1502  node/mod.rs
1413  operations/connect.rs
1407  operations/put.rs
1337  operations/get.rs
1281  contract/executor/runtime.rs
1235  config/mod.rs
1191  operations/update.rs
1055  topology/mod.rs

Phased Approach

To avoid overwhelming reviewers and minimize merge conflicts, we'll tackle this in phases:

Phase 1: Test Module Extraction (Low Risk) ✅

Simple mechanical splits - extract test modules to separate files.

Status: 2 PRs in merge queue

Phase 2: Operations Module Reorganization (Medium Risk) 🔄

Extract message types and state definitions into submodules.

  • operations/put.rs - Extract messages module (already exists inline)
  • operations/get.rs - Similar structure
  • operations/update.rs - Similar structure
  • operations/connect.rs - Similar structure

Approach: Each operations file already has some internal structure. Extract message definitions, state types, and potentially split large impl blocks.

Phase 3: Complex Module Reorganization (Higher Risk) 📋

Requires more design thought and careful review.

  • p2p_protoc.rs - Protocol state machine
  • connection_handler.rs - Transport layer with utilities
  • node/mod.rs - Core node logic
  • client_events/mod.rs - Client event handling
  • config/mod.rs - Configuration management

Phase 4: Other Large Files 📋

  • tracing/mod.rs
  • contract/executor/runtime.rs
  • topology/mod.rs

Principles

  1. No logic changes - Pure refactoring only
  2. All tests must pass - Every PR verified with full test suite
  3. Modern Rust idioms - Use module_name.rs + module_name/ not mod.rs
  4. Reviewable chunks - 2-3 PRs at a time maximum
  5. Phased execution - Wait for previous phase to merge before starting next

Progress Tracking

Each completed item will be checked off and linked to its PR. Discussion and feedback welcome on the approach!

🤖 Generated with Claude Code

[AI-assisted debugging and comment]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-developer-xpArea: developer experienceP-mediumMedium priorityT-trackingType: Meta-issue tracking multiple related issues

    Type

    No type

    Projects

    Status

    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions