Skip to content

Code Quality: Large source files need modularization #984

@EffortlessSteven

Description

@EffortlessSteven

Issue

Several library files exceed recommended size limits and contain many functions, suggesting they may benefit from modularization:

Large Files Identified

File Lines Functions (approx)
crates/tokmd-analysis-format/src/lib.rs 3,163 70+
crates/tokmd-cockpit/src/lib.rs 2,766 96
crates/tokmd-analysis-types/src/lib.rs 1,852 -
crates/tokmd-analysis-complexity/src/lib.rs 1,594 -
crates/tokmd-types/src/lib.rs 1,477 -
crates/tokmd-format/src/lib.rs 2,139 -

Problem

Large files with many functions:

  1. Are harder to navigate and understand
  2. Increase compile times (especially for incremental compilation)
  3. Reduce code reuse potential
  4. Make testing and mocking more difficult
  5. Violate single responsibility principle

Suggested Refactoring

tokmd-analysis-format/src/lib.rs (3,163 lines)

Split into modules by format type:

  • markdown.rs - Markdown rendering
  • json.rs - JSON/JSON-LD rendering
  • xml.rs - XML rendering
  • visual.rs - SVG, Mermaid, Tree rendering
  • fun.rs - OBJ, MIDI fun outputs
  • utils.rs - Shared formatting utilities

tokmd-cockpit/src/lib.rs (2,766 lines)

Split by functionality:

  • diff.rs - Diff-related operations
  • coverage.rs - Coverage analysis
  • gate.rs - Gating logic
  • report.rs - Report generation
  • config.rs - Configuration handling

tokmd-format/src/lib.rs (2,139 lines)

Split by output format:

  • tables.rs - Table formatting
  • trees.rs - Tree view formatting
  • stats.rs - Statistics display
  • utils.rs - Shared utilities

Severity

Medium - Technical debt and maintainability

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions