Skip to content

Split the sqlite_store and node_service god-objects into concern modules (#1503) - #1588

Merged
mstomar125 merged 1 commit into
NodeSpaceAI:mainfrom
mstomar125:issue-1503-split-god-objects
Jul 9, 2026
Merged

mstomar125 merged 1 commit into
NodeSpaceAI:mainfrom
mstomar125:issue-1503-split-god-objects

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

db/sqlite_store.rs (4931 lines / 93 methods) and services/node_service/mod.rs (4095 lines) were god-objects mixing node CRUD, relationships, embeddings/vector, and search. This decomposes each into concern-focused modules behind an unchanged public surface, with zero behavior change — a pure relocation of method bodies.

Groundwork for the ADR-053 daemon multi-database work (#1532): the service-assembly refactor there builds on clean seams here, so this lands first to avoid a double refactor.

Approach

Each child module is an additional impl block over the same struct (use super::* gives child modules access to the parent's private fields, consts, and helpers), so nothing about privacy or the public API changes.

sqlite_store.rs → db/sqlite_store/:

module concern
mod.rs struct, constructor, schema init/migration, event/notifier plumbing, row mappers, embedded tests
nodes.rs node CRUD, hierarchy/tree/query, move/reorder, schema, bulk, task
relationships.rs mentions, collections/membership, generic relationships, orders/counts
embeddings.rs embedding storage, stale markers, vector/BM25 search
search.rs text content search

node_service/mod.rs: keeps the constructor, seeding, and accessors; its hierarchy / tree-navigation / move-reorder methods move to a new hierarchy.rs, and mention_autocomplete joins the existing query.rs. The existing crud/relationship/embedding/bulk/schema submodules are untouched.

Verification

  • Public surface identical — the sorted set of pub / pub(crate) method signatures is byte-for-byte unchanged for both types (diffed old monolith vs. new modules).
  • Pure relocation — method bodies are byte-identical; the diff is +5880/−5855 (the delta is only module declarations, use super::*, impl wrappers, and module doc-comments).
  • cargo fmt --check clean; cargo clippy -p nodespace-core --all-targets -- -D warnings clean.
  • cargo test -p nodespace-core --lib — 985/985 pass.
  • nodespace-daemon, nodespace-agent, and the Tauri nodespace-app all compile against the unchanged API.

Acceptance criteria

  • sqlite_store and node_service split into focused modules
  • Public API unchanged; behavior unchanged
  • quality:fix / clippy clean; tests pass

Closes #1503

`db/sqlite_store.rs` (4931 lines) and `services/node_service/mod.rs` (4095
lines) mixed node CRUD, relationships, embeddings/vector, and search in single
files. Decompose each behind an unchanged public surface by relocating method
groups into concern-focused child modules — each an additional `impl` block over
the same struct, so privacy and the public API are preserved (child modules read
the parent's private fields, consts, and helpers via `use super::*`).

sqlite_store.rs becomes db/sqlite_store/:
- mod.rs   — struct, constructor, schema init/migration, event/notifier plumbing,
             row mappers, and the embedded tests (unchanged).
- nodes.rs — node CRUD, hierarchy/tree/query, move/reorder, schema, bulk, task.
- relationships.rs — mentions, collections/membership, generic relationships,
             relationship orders/counts.
- embeddings.rs — embedding storage, stale markers, vector/BM25 search.
- search.rs — text content search.

node_service/mod.rs keeps the constructor, seeding, and accessors; its hierarchy,
tree-navigation, and move/reorder methods move to a new hierarchy.rs, and
mention_autocomplete joins query.rs. The existing crud/relationship/embedding/
bulk/schema submodules are untouched.

Pure relocation — method bodies are byte-identical; the set of public and
pub(crate) method signatures is unchanged for both types. cargo fmt/clippy
(-D warnings) clean, nodespace-core lib tests 985/985 green, and the daemon,
agent, and desktop app all compile against the unchanged API.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE (code); one merge gate below.

I treated this as a refactor and verified behavior-preservation directly rather than trusting "pure relocation":

  • Method sets are identical. Diffing the sorted fn signature set old-monolith vs new-modules: sqlite_store 139 = 139 and node_service 123 = 123 — zero methods dropped, added, or renamed.
  • Bodies are byte-identical. A whitespace-normalized line-multiset diff of the old sqlite_store.rs vs the concatenated new sqlite_store/* modules comes back clean except one substantive line: include_str!("schema.sql") → include_str!("../schema.sql"). That's the correct and necessary path fixup — schema.sql lives in db/, and mod.rs now sits one level deeper at db/sqlite_store/. Every other new-only line is scaffolding (impl … {, use super::*;, mod …;, doc comments). So no logic moved or changed.
  • Seam approach is sound — each child module is an additional impl block with use super::*, so private fields/consts/helpers stay reachable and the public surface is untouched; the PR's own "sorted pub signature set unchanged" + cross-crate compile (daemon/agent/app) corroborate.
  • Good sequencing rationale: landing this before the ADR-053 multi-DB service-assembly work (Daemon database manager: registry, per-database services, and gRPC routing #1532) avoids a double refactor.

Merge gate: at review time test:all / test:e2e were still pending/blank — since this is a 5.9k-line move, hold the merge until both are green (the 985 lib tests + cross-crate compile are the real safety net for a relocation). No code changes requested.

@mstomar125
mstomar125 merged commit 5977810 into NodeSpaceAI:main Jul 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split the sqlite_store and node_service god-objects by concern

1 participant