Skip to content

buzz-db: break up lib.rs — move impl Db methods to domain modules #2

Closed

Description

@TheSentinel454

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.

Activity

  1. TheSentinel454 commented on Aug 25, 2026

    @TheSentinel454
    OwnerAuthor

    🤖 The remaining issue #2 store-extraction work is published as a 26-layer stack in block/buzz (block#6777 is merged; the remaining 25 PRs are drafts):

    1. #6777 — replaceable/addressable store (buzz-db: extract replaceable-event logic from lib.rs #6; merged)
    2. #6819 — canonical channel-roster test fixtures (buzz-db: split channel.rs into channel CRUD + membership #7 prerequisite)
    3. #6782 — channel lifecycle and dedicated membership/roster store (buzz-db: split channel.rs into channel CRUD + membership #7)
    4. #6783 — API-token store (buzz-db: move misplaced types to domain modules #12)
    5. #6784 — authentication allowlist store (buzz-db: move misplaced types to domain modules #12)
    6. #6787 — reminder query/claim/release lifecycle (buzz-db: extract reminders from event.rs into reminder.rs #13)
    7. #6788 — event/query store
    8. #6789 — thread store
    9. #6792 — reaction store
    10. #6820 — canonical 11,000-member feed fixture
    11. #6794 — feed projections
    12. #6796 — user and direct-message stores
    13. #6797 — push lifecycle
    14. #6798 — workflow lifecycle
    15. #6799 — workflow runs and approvals
    16. #6804 — relay membership
    17. #6805 — relay invites
    18. #6806 — product feedback
    19. #6808 — moderation
    20. #6809 — Git registry
    21. #6811 — archived identities
    22. #6812 — usage rollups and advisory-lock leadership
    23. #6813 — deployment-global admin moderation/feedback projections
    24. #6814 — partition and event d-tag maintenance
    25. #6815 — deletion facades and cross-domain serving-write boundary
    26. #6890 — final private runtime/ and store/ source layout with a thin compatibility facade

    The reconstructed stack removes crates/buzz-db/tests/store_ownership.rs everywhere and does not replace it with another path-sensitive ownership test. Each production patch remains byte-for-byte identical to its previously reviewed slice after that complete test-file diff is removed. The final structural PR makes ownership obvious in the source tree: runtime and genuinely cross-cutting infrastructure live under private runtime/ modules, domain persistence lives under private store/ modules, and existing consumer paths such as buzz_db::Db, buzz_db::channel::ChannelRecord, crate-root record exports, and inherent Db methods remain compatible through lib.rs re-exports.

    Final cumulative Blox evidence at 61304ccbdc39f9b17cd12ca248ac058f797b0e43: formatting, diff checks, strict buzz-db/buzz-relay clippy, buzz-db checks and docs, relay consumer compilation, 111 non-PostgreSQL DB library tests, and the observability source test pass. A separate clean exact-head review passed all 200 ignored PostgreSQL-backed buzz-db tests individually against fresh native-PostgreSQL databases and confirmed identical SQL-line, metric-name, and datastore-span multisets versus the parent. Every reconstructed PR also received its own fresh clean exact-base/exact-head Blox review; no findings remain.

    Final lib.rs: 56 physical lines. It contains module declarations and compatibility re-exports only; the private runtime/ and store/ namespaces are not exposed as new public API.

    No PR was merged by this work and no tracker issue was closed.

  2. TheSentinel454 commented on Aug 28, 2026

    @TheSentinel454
    OwnerAuthor

    🤖 The remaining issue #2 extraction work has been consolidated into one draft PR: block#6987 (main at e76c81968b65b0755b83efdd59dc3375c59ddf40 → codex/issue-2-store-extraction at cc14bc9d81ded60c30ec64c84234d37c9278b572). It covers API tokens, auth allowlists, reminders, event queries, threads, reactions, feeds, users/DMs, push, workflows/runs/approvals, relay membership/invites, product feedback, moderation/admin moderation, git repositories, archived identities, usage, partition maintenance, deletion, and the final private runtime/ / store/ layout. Merged block#6782 remains the channel-membership base. The prior remaining stack PRs will be closed as superseded only after block#6987 exact-head CI is green; no tracker issues are being closed here.

  3. TheSentinel454 commented on Sep 3, 2026

    @TheSentinel454
    OwnerAuthor

    Completed by the incremental extraction series block#6668, block#6777, block#6782, and block#6987. buzz-db now separates runtime infrastructure from domain stores, and lib.rs is a small compatibility facade.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions