Problem
lib.rs is 9,491 lines with a single impl Db block containing 240 public methods. The majority are thin delegation wrappers that forward &self.pool to a free function in a domain module and add a #[datastore_span] attribute. This delegation layer alone accounts for ~5,000 lines of boilerplate.
Proposed change
Move each group of impl Db methods into their respective domain module files. Rust allows multiple impl Db blocks across files within the same crate, so channel.rs would own Db::create_channel, Db::add_member, etc. directly — eliminating the free-function-plus-wrapper indirection.
After this change, lib.rs would contain only:
- The
Db struct definition and fields
- Pool configuration (
DbConfig, connection setup)
ReadSession and replica routing infrastructure
mod declarations and re-exports
- Cross-cutting helpers (
insert_mentions, event_replacement_lock_key)
Target: ~800–1,000 lines in lib.rs.
Priority
High — biggest single-file maintainability problem, mechanical to execute, reduces merge conflicts.
Dependencies
None — can be done independently. Items like extracting community.rs (#TBD) and moving misplaced types (#TBD) are naturally done alongside this.
🤖 AI review update (2026-08-23)
The goal is clear, but this should be an incremental tracker rather than a single 9,000-line relocation. Split work by domain (replacement, community, channel membership, API token/allowlist, reminders), and require each slice to move its tests and datastore spans while preserving public API behavior. This lowers merge-conflict and review risk in an active codebase.
Problem
lib.rsis 9,491 lines with a singleimpl Dbblock containing 240 public methods. The majority are thin delegation wrappers that forward&self.poolto a free function in a domain module and add a#[datastore_span]attribute. This delegation layer alone accounts for ~5,000 lines of boilerplate.Proposed change
Move each group of
impl Dbmethods into their respective domain module files. Rust allows multipleimpl Dbblocks across files within the same crate, sochannel.rswould ownDb::create_channel,Db::add_member, etc. directly — eliminating the free-function-plus-wrapper indirection.After this change,
lib.rswould contain only:Dbstruct definition and fieldsDbConfig, connection setup)ReadSessionand replica routing infrastructuremoddeclarations and re-exportsinsert_mentions,event_replacement_lock_key)Target: ~800–1,000 lines in
lib.rs.Priority
High — biggest single-file maintainability problem, mechanical to execute, reduces merge conflicts.
Dependencies
None — can be done independently. Items like extracting
community.rs(#TBD) and moving misplaced types (#TBD) are naturally done alongside this.🤖 AI review update (2026-08-23)
The goal is clear, but this should be an incremental tracker rather than a single 9,000-line relocation. Split work by domain (replacement, community, channel membership, API token/allowlist, reminders), and require each slice to move its tests and datastore spans while preserving public API behavior. This lowers merge-conflict and review risk in an active codebase.