Skip to content

refactor(backend): split dockerNetworkProvider into focused modules#57

Merged
OthmaneZ05 merged 1 commit into
mainfrom
othmane/network-provider-refactor
Jul 14, 2026
Merged

refactor(backend): split dockerNetworkProvider into focused modules#57
OthmaneZ05 merged 1 commit into
mainfrom
othmane/network-provider-refactor

Conversation

@OthmaneZ05

@OthmaneZ05 OthmaneZ05 commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Summary of Changes

dockerNetworkProvider.ts was a 974-line file dominated by a single 780-line applyPlan method (manual IPAM, NAT wiring, host iptables bypass, per-container firewall rules, Nginx config generation) with 5-6 levels of indentation and zero test coverage. This PR splits it into focused, unit-tested modules — subnetAddressing.ts (CIDR/gateway helpers), natResolution.ts (NAT route/endpoint lookup), firewallRules.ts (iptables rule builders, also deduping a ~70-line block that was copy-pasted verbatim for two different gateway IPs), and nginxConfigBuilder.ts (load-balancer Nginx config) — and decomposes applyPlan into small, named private methods on DockerNetworkProvider, which keeps the same public API. No behavior change.

Types of Changes

  • New feature / node type addition
  • Bug fix (non-breaking change resolving an issue)
  • Refactoring / structural cleanup
  • Documentation update

Verification & Testing

Automated Checks

  • Run npm run lint successfully with no errors
  • Run npm run build successfully with no compilation errors
  • Run npm test successfully (all tests pass)

Manual Verification

Ran the app against real Docker: created a project with two Ubuntu nodes in two subnets and a security-group rule, applied the network config, and compared the resulting iptables -S ruleset and /etc/hosts output against the same scenario run with the original (pre-refactor) code — byte-for-byte identical.

Checklist

  • My code follows the repository's code style and lint standards
  • I have updated the documentation or instructions if necessary
  • All unit and integration tests are passing

Break the 974-line dockerNetworkProvider.ts (one 780-line applyPlan
method) into pure, unit-tested modules for CIDR/gateway addressing,
NAT route resolution, iptables rule building, and Nginx config
generation, and decompose applyPlan into small named private methods.
Dedupes a ~70-line iptables block that was copy-pasted for two gateway
IPs. No behavior change: verified against real Docker that the
generated iptables ruleset is identical before and after.
@OthmaneZ05
OthmaneZ05 requested a review from Derssa as a code owner July 14, 2026 17:28
@OthmaneZ05
OthmaneZ05 merged commit d361eb4 into main Jul 14, 2026
2 checks passed
@OthmaneZ05
OthmaneZ05 deleted the othmane/network-provider-refactor branch July 14, 2026 17:33
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.

2 participants