Skip to content

Codebase restructure and cleanup #29

@nevermore23274

Description

@nevermore23274

The codebase has grown significantly through v0.3–v0.8 and several files have accumulated multiple responsibilities. I think some of the functionality from files (specifically App.rs which is over 1k lines) should be removed and thoughtfully placed in a core section to make the code more reusable and readable for maintainability.

Current pain points I can see

  • app.rs (1068 lines): holds the App struct, all enums, PerfStats/FrameTiming (~100 lines), three async RadioBrowser fetch functions and FetchResult (~180 lines), NowPlaying, SongLogEntry, and every App method. Too many concerns in one file.
  • main.rs (455 lines): the event loop is ~350 lines of inline keybinding dispatch across overlays (theme picker, genre picker, settings, normal mode). Makes it rough to navigate.
  • pipe.rs (570 lines): mixes a reusable generic (SeqLock), the FFT implementation, and the FIFO reader/PCM pipeline.
  • No core/ module: domain types, perf tracking, and radio API logic live alongside UI state in app.rs.

The Proposed Structure

src/
├── main.rs                   Event loop only (slim)
├── core/
│   ├── mod.rs
│   ├── app.rs                App struct, construction, core methods
│   ├── types.rs              InputMode, ActivePanel, Overlay, QueryKind, NowPlaying, SongLogEntry
│   ├── radio.rs              FetchResult, fetch_blended_by_tag/name, fetch_more, filter_spam
│   └── perf.rs               PerfStats, FrameTiming, PerfSummary
├── audio/
│   ├── mod.rs
│   ├── player.rs             (unchanged)
│   ├── pipe.rs               FIFO reader + PCM pipeline only
│   ├── fft.rs                fft_in_place, compute_band_edges, group_into_bands, compute_band_energies
│   ├── seqlock.rs            Generic SeqLock<T> (reusable)
│   └── visualizer.rs         (unchanged)
├── input/
│   ├── mod.rs
│   └── handler.rs            Keybinding dispatch extracted from main.rs
├── storage/                  (unchanged)
└── ui/                       (unchanged)

Breakdown

Extract core/ module from app.rs

  • core/types.rs: move InputMode, ActivePanel, Overlay, QueryKind, NowPlaying, SongLogEntry
  • core/radio.rs: move FetchResult, fetch_blended_by_tag, fetch_blended_by_name, fetch_more, filter_spam
  • core/perf.rs: move PerfStats, FrameTiming, PerfSummary and their impls
  • core/app.rs: what remains: App struct and its methods

Split pipe.rs

  • audio/seqlock.rs: The generic SeqLock<T: Copy> with its safety docs
  • audio/fft.rs: fft_in_place, compute_band_edges, group_into_bands, compute_band_energies, and the test suite
  • audio/pipe.rs: AudioAnalysis, SharedAnalysis, FIFO creation, spawn_reader, reader_loop

Extract input handling from main.rs

  • input/handler.rs: keybinding dispatch for each overlay and normal mode
  • main.rs: event loop skeleton, terminal setup/teardown, tick timing

Metadata

Metadata

Labels

documentationImprovements or additions to documentationenhancementNew feature or requestperformanceIssues related to performance.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions