Skip to content

[Architecture] Split EntglDb.Network into transport layer (EntglDb.Network) and sync algorithm (EntglDb.Sync)#20

Merged
mrdevrobot merged 3 commits into
mainfrom
copilot/split-transport-sync-projects
Mar 19, 2026
Merged

[Architecture] Split EntglDb.Network into transport layer (EntglDb.Network) and sync algorithm (EntglDb.Sync)#20
mrdevrobot merged 3 commits into
mainfrom
copilot/split-transport-sync-projects

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 19, 2026

EntglDb.Network mixed transport concerns with sync algorithm logic, coupling the TCP/UDP layer directly to IOplogStore, IDocumentStore, and ISnapshotService. This splits it into two focused assemblies.

Post-split dependency graph

EntglDb.Sync    → EntglDb.Network + EntglDb.Core
EntglDb.Core    → EntglDb.Network  (for moved shared types)
EntglDb.Network → runtime + Protobuf only  (zero Core dependency)

Changes

EntglDb.Network (transport only)

  • Removed <ProjectReference> to EntglDb.Core — zero Core dependency
  • Moved in from Core: HlcTimestamp, VectorClock, OplogEntry, OperationType (CoreTypes/, namespace unchanged); all EntglDb.Core.Network types — PeerNode, IPeerNodeConfigurationProvider, RemotePeerConfiguration, etc. (CoreNetwork/, namespace unchanged)
  • New ILocalInterestsProvider — replaces IDocumentStore in TcpSyncServer/UdpDiscoveryService (now optional)
  • New IRemotePeerListProvider — replaces IPeerConfigurationStore in CompositeDiscoveryService
  • AddEntglDbNetwork<T>() registers transport only (config, auth, discovery, server, telemetry) — no parameters (the useHostedService parameter has been removed as it was unused)

EntglDb.Sync (new project)

  • Houses: SyncOrchestrator, EntglDbNode, EntglDbNodeService, all 6 message handlers
  • AddEntglDbSync() registers handlers + orchestrator + hosted node service

EntglDb.Core

  • Adds <ProjectReference> to EntglDb.Network for the moved shared types
  • IDocumentStore extends ILocalInterestsProvider; IPeerConfigurationStore extends IRemotePeerListProvider — no breaking changes for existing implementations

Migration for consumers

// Before
services.AddEntglDbNetwork<MyConfigProvider>();

// After
services.AddEntglDbNetwork<MyConfigProvider>()
        .AddEntglDbSync(); // registers handlers + IEntglDbNode + hosted service

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

  • All 37 existing EntglDb.Network.Tests pass unchanged (including SnapshotReconnectRegressionTests which subclasses SyncOrchestrator via reflection)
  • All 94 existing EntglDb.Core.Tests pass unchanged
  • EntglDb.Network.csproj carries no reference to EntglDb.Core (verified via grep)
  • All sample projects (Console, AspNetCore, Avalonia, Demo.Game, Maui) build with 0 errors after DI call-site update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
Original prompt

This section details on the original issue you should resolve

<issue_title>[Architecture] Project split: separate transport (EntglDb.Network) from sync algorithm (EntglDb.Sync)</issue_title>
<issue_description>## Goal

Split EntglDb.Network into two separate projects:

  • EntglDb.Network: pure transport layer (TCP, UDP, framing, crypto, discovery, leadership, telemetry)
  • EntglDb.Sync (new): synchronization algorithm (oplog, vector clocks, snapshots, anti-entropy orchestrator)

Depends on: #16 (handler registry must be implemented first)

Motivation

EntglDb.Network currently mixes two very different responsibilities. The transport layer has direct knowledge of IOplogStore, IDocumentStore, ISnapshotService — concepts it should not know about. After the split, any service (not just database sync) can register itself on the network without depending on sync-specific code.

Target structure

EntglDb.Network (transport only)

  • Protocol/: ProtocolHandler, framing, compression, encryption
  • Security/: IAuthenticator, SecureHandshakeService, JWT, OAuth2, CryptoHelper
  • Leadership/: BullyLeaderElectionService
  • Telemetry/: NetworkTelemetryService, MetricType
  • TcpSyncServer — dispatch via IMessageHandler registry (no dependency on Core)
  • TcpPeerClient — generic client, no sync-specific methods
  • UdpDiscoveryService, CompositeDiscoveryService

Dependencies: NO dependency on EntglDb.Core

EntglDb.Sync (new project)

  • SyncOrchestrator, ISyncOrchestrator
  • EntglDbNode, EntglDbNodeService, IEntglDbNode
  • Handlers/: GetClockHandler, GetVectorClockHandler, PullChangesHandler, PushChangesHandler, GetChainRangeHandler, GetSnapshotHandler
  • SyncPeerClient (wraps TcpPeerClient with sync-specific methods)
  • sync.proto
  • SyncExtensions for DI registration

Dependencies: EntglDb.Network + EntglDb.Core

Post-split dependency graph

EntglDb.Sync --> EntglDb.Network (uses IMessageHandler, TcpPeerClient) --> EntglDb.Core (uses IOplogStore, IDocumentStore, ISnapshotService) EntglDb.Network --> runtime + Protobuf only (ZERO dependency on Core)

Files to move: Network -> Sync

Acceptance criteria

  • dotnet build EntglDb.Net.sln — 0 errors
  • All tests pass unchanged
  • EntglDb.Network.csproj does not reference EntglDb.Core
  • Smoke test with 2 nodes: sync works correctly
    </issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

…f transport layer

Co-authored-by: mrdevrobot <12503462+mrdevrobot@users.noreply.github.com>
Copilot AI changed the title [WIP] [Architecture] Split EntglDb.Network from EntglDb.Sync [Architecture] Split EntglDb.Network into transport layer (EntglDb.Network) and sync algorithm (EntglDb.Sync) Mar 19, 2026
Copilot AI requested a review from mrdevrobot March 19, 2026 11:31
@mrdevrobot mrdevrobot requested review from Copilot March 19, 2026 13:15
Copy link
Copy Markdown
Collaborator

@mrdevrobot mrdevrobot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useHostedService is not necessary anymore in the AddEntglDbNetwork, this could be a small breaking change that we can afford (it won't impact too much the users)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Splits EntglDb’s networking stack into a transport-only assembly (EntglDb.Network) and a sync-algorithm assembly (EntglDb.Sync), reducing coupling between the transport layer and Core storage services while keeping sync features available via a dedicated package.

Changes:

  • Introduces EntglDb.Sync project containing the sync orchestrator, node lifecycle hosted service, and the six sync message handlers.
  • Refactors EntglDb.Network to remove the Core project reference and adds transport-facing abstractions (ILocalInterestsProvider, IRemotePeerListProvider).
  • Updates EntglDb.Core interfaces and consumer projects/samples to use AddEntglDbNetwork(...).AddEntglDbSync().

Reviewed changes

Copilot reviewed 29 out of 48 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/EntglDb.Network.Tests/EntglDb.Network.Tests.csproj Adds reference to EntglDb.Sync for tests that depend on moved sync components.
src/EntglDb.Sync/SyncOrchestrator.cs Adds sync orchestration implementation into the new sync assembly.
src/EntglDb.Sync/SyncExtensions.cs Adds DI extension AddEntglDbSync() to register sync handlers + orchestrator/node.
src/EntglDb.Sync/ISyncOrchestrator.cs Adds sync orchestrator interface in sync assembly.
src/EntglDb.Sync/IEntglDbNode.cs Adds node abstraction interface in sync assembly.
src/EntglDb.Sync/Handlers/PushChangesHandler.cs Implements PushChanges request handler in sync assembly.
src/EntglDb.Sync/Handlers/PullChangesHandler.cs Implements PullChanges request handler in sync assembly.
src/EntglDb.Sync/Handlers/GetVectorClockHandler.cs Implements GetVectorClock request handler in sync assembly.
src/EntglDb.Sync/Handlers/GetSnapshotHandler.cs Implements snapshot streaming handler in sync assembly.
src/EntglDb.Sync/Handlers/GetClockHandler.cs Implements GetClock request handler in sync assembly.
src/EntglDb.Sync/Handlers/GetChainRangeHandler.cs Implements GetChainRange request handler in sync assembly.
src/EntglDb.Sync/EntglDbNodeService.cs Adds hosted service that starts/stops the node via IEntglDbNode.
src/EntglDb.Sync/EntglDbNode.cs Updates node implementation after move into sync assembly.
src/EntglDb.Sync/EntglDb.Sync.csproj New sync project definition and dependencies.
src/EntglDb.Network/UdpDiscoveryService.cs Replaces IDocumentStore dependency with optional ILocalInterestsProvider.
src/EntglDb.Network/TcpSyncServer.cs Uses ILocalInterestsProvider (instead of IDocumentStore) for handshake interest advertisement.
src/EntglDb.Network/PeerDbNetworkExtensions.cs Updates AddEntglDbNetwork to register transport services only.
src/EntglDb.Network/IRemotePeerListProvider.cs Adds transport-facing abstraction for persisted peer list retrieval.
src/EntglDb.Network/ILocalInterestsProvider.cs Adds transport-facing abstraction for local collection interests.
src/EntglDb.Network/EntglDb.Network.csproj Removes Core reference and adjusts netstandard dependencies + protobuf itemgroup.
src/EntglDb.Network/CoreTypes/VectorClock.cs Moves vector clock type into Network assembly while keeping Core namespace.
src/EntglDb.Network/CoreTypes/OplogEntry.cs Adjusts moved oplog entry type (removes annotations dependency).
src/EntglDb.Network/CoreTypes/HlcTimestamp.cs Moves HLC timestamp type into Network assembly while keeping Core namespace.
src/EntglDb.Network/CoreNetwork/StaticPeerNodeConfigurationProvider.cs Adds static configuration provider to Network assembly (Core namespace preserved).
src/EntglDb.Network/CoreNetwork/RemotePeerConfiguration.cs Moves remote peer configuration type into Network assembly.
src/EntglDb.Network/CoreNetwork/PeerType.cs Adds peer classification enum.
src/EntglDb.Network/CoreNetwork/PeerNodeConfiguration.cs Adds/moves peer node configuration types.
src/EntglDb.Network/CoreNetwork/PeerNode.cs Adds/moves peer node model and interest list.
src/EntglDb.Network/CoreNetwork/OAuth2Configuration.cs Adds OAuth2 config model for cloud peers.
src/EntglDb.Network/CoreNetwork/NodeRole.cs Adds node role enum for cloud gateway scenarios.
src/EntglDb.Network/CoreNetwork/IPeerNodeConfigurationProvider.cs Moves configuration provider contract into Network assembly.
src/EntglDb.Network/CompositeDiscoveryService.cs Refactors to use IRemotePeerListProvider instead of Core storage interface.
src/EntglDb.Core/Storage/IPeerConfigurationStore.cs Extends IRemotePeerListProvider to preserve behavior without breaking implementations.
src/EntglDb.Core/Storage/IDocumentStore.cs Extends ILocalInterestsProvider and removes duplicated InterestedCollection member.
src/EntglDb.Core/EntglDb.Core.csproj Adds project reference to EntglDb.Network for moved shared types.
src/EntglDb.AspNet/EntglDb.AspNet.csproj References EntglDb.Sync to align with split and DI registration.
samples/EntglDb.Test.Maui/MauiProgram.cs Updates DI wiring to AddEntglDbNetwork(...).AddEntglDbSync().
samples/EntglDb.Test.Maui/EntglDb.Test.Maui.csproj Adds EntglDb.Sync project reference.
samples/EntglDb.Test.Avalonia/EntglDb.Test.Avalonia.csproj Adds EntglDb.Sync project reference.
samples/EntglDb.Test.Avalonia/App.axaml.cs Updates DI wiring to AddEntglDbNetwork(...).AddEntglDbSync().
samples/EntglDb.Sample.Console/Program.cs Updates DI wiring to AddEntglDbNetwork(...).AddEntglDbSync().
samples/EntglDb.Sample.Console/EntglDb.Sample.Console.csproj Adds EntglDb.Sync project reference.
samples/EntglDb.Sample.AspNetCore/Program.cs Updates DI wiring to split transport vs hosted sync service registration.
samples/EntglDb.Sample.AspNetCore/EntglDb.Sample.AspNetCore.csproj Adds EntglDb.Sync project reference.
samples/EntglDb.Demo.Game/Program.cs Updates DI wiring to AddEntglDbNetwork(...).AddEntglDbSync().
samples/EntglDb.Demo.Game/EntglDb.Demo.Game.csproj Adds EntglDb.Sync project reference.
samples/EntglDb.Demo.Game.MonoGame/Program.cs Updates DI wiring to AddEntglDbNetwork(...).AddEntglDbSync().
EntglDb.Net.sln Adds the new EntglDb.Sync project to the solution.
Comments suppressed due to low confidence (1)

src/EntglDb.Network/PeerDbNetworkExtensions.cs:33

  • AddEntglDbNetwork still exposes useHostedService, but the parameter is no longer used (the hosted node service moved to AddEntglDbSync). This is misleading for callers. Consider marking the parameter as obsolete/ignored in docs, or remove it in the next major version; at minimum, document that it's kept only for backward compatibility and has no effect.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines 77 to 81
/// <param name="handlers">
/// All registered <see cref="INetworkMessageHandler"/> instances injected via DI.
/// This includes the built-in core handlers registered by <c>AddEntglDbNetwork</c>
/// as well as any user-defined handlers. When two handlers target the same
/// <see cref="MessageType"/>, the last one registered takes precedence.
Co-authored-by: mrdevrobot <12503462+mrdevrobot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 19, 2026

useHostedService is not necessary anymore in the AddEntglDbNetwork, this could be a small breaking change that we can afford (it won't impact too much the users)

Done in 723c837 — removed useHostedService from AddEntglDbNetwork<T>() entirely and cleaned up all call sites in the samples.

Copilot AI requested a review from mrdevrobot March 19, 2026 13:23
@mrdevrobot mrdevrobot marked this pull request as ready for review March 19, 2026 13:29
@mrdevrobot mrdevrobot merged commit 34822c6 into main Mar 19, 2026
@mrdevrobot mrdevrobot deleted the copilot/split-transport-sync-projects branch March 19, 2026 13:29
Copilot AI review requested due to automatic review settings March 23, 2026 19:44
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.

[Architecture] Project split: separate transport (EntglDb.Network) from sync algorithm (EntglDb.Sync)

3 participants