Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
260 commits
Select commit Hold shift + click to select a range
d9ce55a
Refactor networking package into specialized components (Phase 3)
claude Nov 16, 2025
060b4e3
Add mock implementations for testing (Phase 7.2)
claude Nov 16, 2025
1714cc7
Add networking mocks for comprehensive testing (Week 5-6 complete)
claude Nov 16, 2025
81f61f0
Implement Phase 6: Service Layer
claude Nov 16, 2025
575427b
Implement Phase 4: Refactor Commands to use Service Layer
claude Nov 16, 2025
ef86407
Update PLAN.md with completed phase status
claude Nov 16, 2025
c4acca1
Implement Phase 9: Extract utilities - Builder patterns
claude Nov 16, 2025
0a01141
Update PLAN.md: Mark Phase 9 as complete
claude Nov 16, 2025
bed2c1d
Implement Phase 8: Add comprehensive documentation
claude Nov 16, 2025
5127d66
Update PLAN.md: Mark Phase 8 complete and all phases finished
claude Nov 16, 2025
384d68f
Update CONTEXT.md with comprehensive technical documentation
claude Nov 16, 2025
a1d87ca
Fix TestInterfaceSelector_IsUsable impossible nil condition
claude Nov 17, 2025
6a79cc1
Fix service daemon interface monitoring to prevent unnecessary route …
claude Nov 17, 2025
4e0c177
Fix nil dependency issues in networking and service layers
claude Nov 17, 2025
b8002d9
Document dependency injection pattern in CONTEXT.md
claude Nov 17, 2025
f107747
Implement Phase 3: Dependency Injection Container
claude Nov 17, 2025
f06539a
Complete Phase 4: Migrate all remaining commands to DI container
claude Nov 17, 2025
4fbe706
Implement dual-route strategy with permanent blackhole fallback
claude Nov 17, 2025
60d3f1b
Optimize dual-route strategy to minimize downtime
claude Nov 17, 2025
e83a552
Fix route churn caused by empty Keenetic connected field
claude Nov 17, 2025
27296f9
Optimize interface system-name lookup with bulk requests
claude Nov 17, 2025
4ab417a
Fix inconsistent interface state by preferring parent interfaces
claude Nov 17, 2025
2c8541b
Fix Keenetic RCI bulk API URL to include trailing slash
claude Nov 17, 2025
c3f8181
Reduce logging verbosity for service operations
claude Nov 17, 2025
cf04923
Add kill_switch setting for ipset routing configuration
claude Nov 17, 2025
3cc7680
Add comprehensive deprecation refactoring plan
claude Nov 17, 2025
b11b3b5
Remove deprecated configuration fields (Phase 1)
claude Nov 17, 2025
c8ea2b0
Refactor self-check command to use dependency injection (Phase 2)
claude Nov 17, 2025
dcc7575
Refactor commands to use Keenetic client dependency injection
claude Nov 17, 2025
0bf82c9
Remove all deprecated global functions (Phase 3 & 4)
claude Nov 17, 2025
924a09b
Final cleanup (Phase 5)
claude Nov 17, 2025
d9fbfa6
Use interface index as metric for default routes
claude Nov 17, 2025
c601615
Merge pull request #8 from maksimkurb/claude/fix-keenetic-api-url-01S…
maksimkurb Nov 17, 2025
74f398c
Add API implementation plan adapted for feature/3.0 branch
claude Nov 17, 2025
831ecf4
Implement REST API for keen-pbr configuration management
claude Nov 17, 2025
d8d0a3c
Add comprehensive REST API documentation
claude Nov 17, 2025
d59fdef
Update GET /v1/lists to return statistics instead of inline entries
claude Nov 17, 2025
d749588
Add caching for list statistics to improve API performance
claude Nov 17, 2025
23a22bd
Refactor list statistics caching to use opportunistic collection
claude Nov 17, 2025
d4bfabe
Optimize statistics collection to update cache once per list
claude Nov 17, 2025
e9fd2c1
Separate download status from cached statistics
claude Nov 17, 2025
20127e6
Add test job
maksimkurb Nov 18, 2025
5988c9c
Fix test build errors after keenetic API refactoring
claude Nov 18, 2025
a135e38
Init shadcn
maksimkurb Nov 18, 2025
7cdcb90
Add frontend embedding and TypeScript API client
claude Nov 18, 2025
ada31e3
Install Bun in GitHub workflow for frontend build
claude Nov 18, 2025
e91fa7b
Replace Bun with Node.js for frontend build
claude Nov 18, 2025
2df91ec
Fix
maksimkurb Nov 18, 2025
b3539f7
Bind API server to 0.0.0.0 with private subnet restriction
claude Nov 18, 2025
ae6b7d4
Make API bind address configurable and log whitelisted subnets
claude Nov 18, 2025
b017c0d
Disable access logs and create UI implementation plan
claude Nov 18, 2025
cbfd3f0
Fix Node.js installation in GitHub workflow
claude Nov 18, 2025
726e26e
Implement UI foundation with routing, i18n, and layout components
claude Nov 18, 2025
65baa7d
Fix unused import in middleware.go
claude Nov 18, 2025
84d7c58
Implement Dashboard page with status monitoring and domain checker
claude Nov 18, 2025
0bb0846
Add build version information and improve status API
claude Nov 18, 2025
8986cd8
Improve service status monitoring and add service control buttons
claude Nov 18, 2025
0473e6f
Implement service control functionality and add dnsmasq restart endpoint
claude Nov 18, 2025
3973cdb
Fix service control API to use state-based parameters
claude Nov 18, 2025
792b884
Fix API client request body wrapper issue
claude Nov 18, 2025
b9a0152
Implement in-process service control with ServiceManager
claude Nov 18, 2025
b7ba819
Implement Domain/IP Routing Checker API endpoints
claude Nov 18, 2025
ab50f41
Implement fully functional DomainCheckerWidget with all three check t…
claude Nov 18, 2025
d060f5f
Fix routing check to detect IPs in IPSets using ipset test command
claude Nov 18, 2025
ae0cb67
Completely redesign Domain/IP checker with SSE streaming and detailed…
claude Nov 18, 2025
c577292
Fix routing check to detect domains in file-based lists and add place…
claude Nov 18, 2025
fcd4684
Fix false 'Connection to server lost' error in ping/traceroute SSE st…
claude Nov 18, 2025
21beb31
Merge pull request #9 from maksimkurb/claude/plan-keen-pbr-api-01JEFF…
maksimkurb Nov 18, 2025
aaa0c9b
Fix missing iptables rules during service startup
claude Nov 18, 2025
9acbe41
Implement General Settings tab in UI
claude Nov 18, 2025
d9b861c
Fix General Settings form to match API response format and remove bin…
claude Nov 18, 2025
ebdf7f1
Implement Lists management page with full CRUD functionality
claude Nov 18, 2025
ad8db77
Add JSON tags to Go structs for proper lowercase API field names
claude Nov 18, 2025
2d669a9
Convert GeneralSettings API to use snake_case field names
claude Nov 18, 2025
d8d236d
Update proxy
maksimkurb Nov 18, 2025
9f232b4
Enhance Lists API with renaming prevention, inline hosts editing, and…
claude Nov 18, 2025
f7c2eaa
Add list download functionality and UI improvements
claude Nov 18, 2025
026c2af
Add i18n translations and distinguish between updated vs unchanged li…
claude Nov 18, 2025
fced5ec
Implement Routing Rules page with full CRUD functionality
claude Nov 18, 2025
fc0666e
Enhance routing rule forms with improved UI components and network in…
claude Nov 18, 2025
7eaebf2
Update CONTEXT.md with web interface and REST API documentation
claude Nov 18, 2025
970891d
Add Sentry error tracking to frontend
claude Nov 18, 2025
db303af
Add dark theme, mobile responsiveness, and update Sentry config
claude Nov 18, 2025
eadd133
Fix crash when opening interface combobox in routing rules
claude Nov 18, 2025
f8e06ad
Fix interface combobox data structure issue
claude Nov 18, 2025
03dc9b1
Make dialogs responsive with mobile drawers
claude Nov 18, 2025
0789a70
Fix UI
maksimkurb Nov 19, 2025
81766c3
Fix interface selector scrolling, filtering, and drawer text blur
claude Nov 19, 2025
5bffc45
Update Dialog
maksimkurb Nov 19, 2025
548173f
Unify Create and Edit dialogs into single smart components
claude Nov 19, 2025
26f45cd
Update styles
maksimkurb Nov 19, 2025
4c47549
Add comprehensive i18n support with browser language detection
claude Nov 19, 2025
cf12816
Complete i18n implementation for all remaining components
claude Nov 19, 2025
7df6235
Add advanced RuleDialog features: interface reordering, custom interf…
claude Nov 19, 2025
fed5256
Add i18n support for IPTables Rules section and fix template variable…
claude Nov 19, 2025
3539d85
Implement self-check API endpoint and remove i18n from technical plac…
claude Nov 19, 2025
d99d510
Add Configuration Self-Check widget to Dashboard
claude Nov 19, 2025
c3ac809
Improve self-check widget: track failures, add context, commands, and…
claude Nov 19, 2025
6d48f08
Merge pull request #10 from maksimkurb/claude/fix-keen-startup-01ChDt…
maksimkurb Nov 19, 2025
a3e74ce
Refactor self-check API: add dnsmasq check, support SSE and JSON mode…
claude Nov 19, 2025
b39951c
Add NetworkingComponent abstraction for unified apply and self-check …
claude Nov 19, 2025
3c64d66
Refactor self-check API to use NetworkingComponent abstraction
claude Nov 19, 2025
b20c8fe
Update NETWORK_REFACTOR.md: mark phases 1-3 and 5 (partial) as complete
claude Nov 19, 2025
71f71e6
Complete Phase 5: Migrate SSE mode to use NetworkingComponent abstrac…
claude Nov 19, 2025
455150e
Complete Phase 4: Refactor apply logic to use NetworkingComponent abs…
claude Nov 19, 2025
2bcced5
Update NETWORK_REFACTOR.md: mark Phases 4-5 complete, core refactorin…
claude Nov 19, 2025
8f83ee2
Complete Phase 6: Add comprehensive test suite for NetworkingComponen…
claude Nov 19, 2025
e9a3ea5
Complete Phase 7: Add comprehensive inline documentation and finalize…
claude Nov 19, 2025
7d6cb12
Fix SelfCheckWidget: add ?sse=true parameter to self-check endpoint
claude Nov 19, 2025
975f452
Fix blackhole route logic: use kill-switch setting instead of interfa…
claude Nov 19, 2025
2a77cbf
Redesign self-check UI: display as table with Rule/Check/Expected/Act…
claude Nov 19, 2025
f62d284
Add command display to self-check table with colspan
claude Nov 19, 2025
dd64035
Add rowspan to Rule column to group checks by ipset
claude Nov 19, 2025
27db31a
Add comprehensive plan for ConfigHasher feature
claude Nov 19, 2025
a12a8e5
Rename plan file: CONFIG_HASHER_PLAN.md -> CONFIG_HASH.md
claude Nov 19, 2025
d195258
Implement configuration hash tracking and change detection
claude Nov 19, 2025
48a0a59
Fix build errors in ConfigHasher implementation
claude Nov 19, 2025
b53a591
Refactor ConfigHasher as DI component with caching and auto-reset
claude Nov 19, 2025
b179b20
Fix config hash update and remove redundant applied_config_hash
claude Nov 19, 2025
10cbf43
Implement dnsmasq configuration hash tracking via DNS CNAME
claude Nov 19, 2025
aef920a
Add dnsmasq configuration validation to self-check and dashboard
claude Nov 19, 2025
3508bf2
Fix dnsmasq status to show actual state when misconfigured
claude Nov 19, 2025
f47b900
Use separate badges for service status and config state
claude Nov 19, 2025
597fa72
Auto-download lists at service start and handle missing lists gracefully
claude Nov 19, 2025
183573b
Show all interfaces with UP/DOWN state icons in interface selector
claude Nov 19, 2025
f7052c4
Replace ArrowUp/ArrowDown icons with Unplug icon for interface state
claude Nov 19, 2025
d30987b
Configure interface loading with 5s cache and auto-refresh in dialog
claude Nov 19, 2025
362e3a0
Add line-numbered textarea, inline list validation, and UI improvements
claude Nov 19, 2025
52352ee
Add tooltips and i18n to line-numbered textarea
claude Nov 19, 2025
2798cef
Improve service startup logging with context and fix false change det…
claude Nov 19, 2025
ea983c4
Implement immutable config pattern for service lifecycle
claude Nov 19, 2025
bd3481c
Fix routing config to use dedicated routing manager
claude Nov 19, 2025
1b51881
Improve service startup logging with context and fix false change det…
claude Nov 19, 2025
a31b2c1
Add auto-update schedules and make interfaces optional
claude Nov 19, 2025
e58980e
Add UI for auto-update settings
claude Nov 19, 2025
caeadc2
Fix settings API to return proper default values
claude Nov 19, 2025
bf3e7fc
Fix auto_update_lists to return boolean instead of null
claude Nov 19, 2025
ce27fdc
Remove api_bind_address from API and add missing list downloads
claude Nov 19, 2025
bd0badc
Fix URL
maksimkurb Nov 19, 2025
e936d97
Fix GetDNSServers to parse Keenetic proxy-status response
claude Nov 19, 2025
56b6890
Implement centralized DNS resolution with Keenetic tracking
claude Nov 19, 2025
97a4aa5
Add default gateway support for routing rules
claude Nov 19, 2025
27c85f2
Fix critical startup and mutex issues, update route metrics
claude Nov 19, 2025
aa59245
Fix service startup deadlock caused by DNS server retrieval
claude Nov 19, 2025
834cb21
Fix service startup deadlock caused by mutex contention
claude Nov 19, 2025
5850cc8
Fix missing Badge import in ServiceStatusWidget
claude Nov 19, 2025
825ed30
Fix dnsmasq config hash mismatch by setting Keenetic client
claude Nov 19, 2025
135b7ed
Comprehensive UI/UX improvements for routing rules and settings
claude Nov 19, 2025
350f516
Implement UI improvements and interface monitoring control
claude Nov 19, 2025
c1d8f40
Fix crash bugs and improve error handling
claude Nov 19, 2025
0b74e55
Simplify JSON export by including full status object
claude Nov 19, 2025
27b954c
Fix interface monitoring save and enhance list downloads
claude Nov 20, 2025
8060d37
Add backend auto-priority selection for routing rules
claude Nov 20, 2025
d65c224
Rework priority/table/fwmark fields in routing rules dialog
claude Nov 20, 2025
6e000b2
Group IPTables and routing fields under Advanced Configuration
claude Nov 20, 2025
4bbe927
Add i18n for self-check table and extract configuration warning to gl…
claude Nov 20, 2025
296f63f
Merge pull request #11 from maksimkurb/claude/fix-service-startup-dea…
maksimkurb Nov 20, 2025
62a2316
Add DNS Check feature - Backend implementation complete
claude Nov 20, 2025
2da7a6a
Add DNS Check feature - Frontend implementation complete
claude Nov 20, 2025
3d13146
Refactor DNSCheckWidget: Extract business logic to custom hook
claude Nov 20, 2025
13d20be
Extract DNS check logic to service and integrate with self-check
claude Nov 20, 2025
6f06df6
Fix: Change Subscribe/Unsubscribe to use bidirectional channels
claude Nov 20, 2025
7c47c7e
Improve DNS check reliability and UX
claude Nov 21, 2025
f0be22c
Refactor DNS check hook and reorganize Dashboard widgets
claude Nov 21, 2025
a97d1f3
Update API and CONTEXT
maksimkurb Nov 21, 2025
053337e
Delete old files
maksimkurb Nov 21, 2025
9756eb2
Merge pull request #13 from maksimkurb/claude/dns-check-feature-018be…
maksimkurb Nov 21, 2025
fadc88f
Add changelog
maksimkurb Nov 21, 2025
860885f
Remove dead code
maksimkurb Nov 21, 2025
7b57dfb
Add tests stage
maksimkurb Nov 21, 2025
5ffb102
Fix workflow
maksimkurb Nov 21, 2025
f6634e8
Update UI, fix dns-check
maksimkurb Nov 22, 2025
586c6cf
Implement dns server
maksimkurb Nov 22, 2025
d9e69d2
Fix upstream parser
maksimkurb Nov 22, 2025
7db83b6
Use batch inserting
maksimkurb Nov 22, 2025
4c64bc3
Refactor DNS rule into network component
maksimkurb Nov 22, 2025
1dad56e
Remove useless field
maksimkurb Nov 22, 2025
5f34989
Remove useless method
maksimkurb Nov 22, 2025
4175014
Update makefile
maksimkurb Nov 22, 2025
d727ac7
Fix linting problems
maksimkurb Nov 22, 2025
a7b0c57
Use IP for Keenetic RCI
maksimkurb Nov 22, 2025
c9784db
Remove dnsmasq integration
maksimkurb Nov 22, 2025
d6cca36
Remove dead code and fix DNS listener
maksimkurb Nov 22, 2025
5eacef2
Update DNS server
maksimkurb Nov 22, 2025
45e3962
Refactor upstream DNS servers
maksimkurb Nov 22, 2025
49d35a0
Fix matching logic
maksimkurb Nov 22, 2025
44a02e9
Fix iptables
maksimkurb Nov 22, 2025
0a37e82
Remove unused vars
maksimkurb Nov 23, 2025
22052b7
Refactor records cache
maksimkurb Nov 23, 2025
da593ba
Fix alias duplicates
maksimkurb Nov 23, 2025
085489b
Relocate frontend dist from embedded binary to /opt/usr/share/keen-pb…
claude Nov 23, 2025
00d6d78
Merge service and server commands, add memory optimizations
claude Nov 23, 2025
2a43503
Fix staticcheck warnings and revert -s -w flags
claude Nov 23, 2025
b2ebe35
Remove unused routingRunner field
claude Nov 23, 2025
f5e4ff9
Add code reduction refactoring plan
claude Nov 23, 2025
0e7a32f
Merge pull request #15 from maksimkurb/claude/relocate-frontend-dist-…
maksimkurb Nov 23, 2025
910a08c
Update plan
maksimkurb Nov 23, 2025
26f3471
Refactor: Apply code reduction plan (Phases 0-6)
claude Nov 23, 2025
3ba159e
Refactor: Consolidate validation logic (Phase 8)
claude Nov 23, 2025
5ea763f
Update REFACTOR_PLAN.md with completion status and results
claude Nov 23, 2025
cc14462
Refactor: Unify CLI and API Methods (Phase 2)
claude Nov 23, 2025
207da5e
Update REFACTOR_PLAN.md with Phase 2 completion
claude Nov 23, 2025
e1665be
Refactor: Simplify dependency injection (Phase 7)
claude Nov 23, 2025
f669004
Merge pull request #16 from maksimkurb/claude/apply-refactor-plan-018…
maksimkurb Nov 23, 2025
028b1de
Add optional pprof debugging
maksimkurb Nov 23, 2025
8445f50
Fix DNS
maksimkurb Nov 23, 2025
29e20e7
Server stop should close all SSE listeners
maksimkurb Nov 23, 2025
043c1ae
UI fixes
maksimkurb Nov 24, 2025
fc185b9
Update UI
maksimkurb Nov 24, 2025
1846a00
Update title
maksimkurb Nov 24, 2025
6565973
Update middleware scripts
maksimkurb Nov 24, 2025
7b1ac48
Update version
maksimkurb Nov 24, 2025
21fd3c0
Update self-check
maksimkurb Nov 24, 2025
4b03716
Update i18n
maksimkurb Nov 24, 2025
b8559ed
Update UI
maksimkurb Nov 24, 2025
6f6e1cb
Update hooks
maksimkurb Nov 24, 2025
49456e6
Update triggers
maksimkurb Nov 24, 2025
6a3e2f2
Update hooks
maksimkurb Nov 24, 2025
9ac4b8f
Upd DNS
maksimkurb Nov 24, 2025
736cfe6
Configure DNS interfaces
maksimkurb Nov 24, 2025
a5a76ed
Add DNS settings
maksimkurb Nov 24, 2025
46232a9
Use getters
maksimkurb Nov 24, 2025
34be0d9
Fix test
maksimkurb Nov 24, 2025
3c003a9
Refactor
maksimkurb Nov 25, 2025
828856b
Fix script
maksimkurb Nov 26, 2025
d2cb85f
Update UI
maksimkurb Nov 26, 2025
7ad08ab
Update UI
maksimkurb Nov 27, 2025
d37f12d
Enable profiling for dev
maksimkurb Nov 27, 2025
9d5366c
Add benchmark
maksimkurb Nov 27, 2025
9237aab
Update matcher
maksimkurb Nov 28, 2025
0a41b1a
Clean local cache on service restart
maksimkurb Nov 28, 2025
5ec2dcf
Fix lists selector
maksimkurb Nov 28, 2025
110082c
Update UI
maksimkurb Nov 28, 2025
a709151
Fix editor
maksimkurb Nov 28, 2025
486929c
Fix lists
maksimkurb Nov 28, 2025
2e0300d
Fix UI
maksimkurb Nov 28, 2025
574f23f
Split TTLs
maksimkurb Nov 28, 2025
3eb67fb
Update API
maksimkurb Nov 29, 2025
587c750
Update API
maksimkurb Nov 29, 2025
c852ba6
Update validation
maksimkurb Nov 29, 2025
2a5531d
Update validation
maksimkurb Nov 29, 2025
cbadd58
Update UI
maksimkurb Nov 30, 2025
34557f6
Format code
maksimkurb Nov 30, 2025
854eedf
Fix typescript errors
maksimkurb Nov 30, 2025
a611a00
Format code
maksimkurb Nov 30, 2025
ff4f253
Update UI
maksimkurb Nov 30, 2025
763b812
Update UI
maksimkurb Nov 30, 2025
b5830bc
Fix UI
maksimkurb Nov 30, 2025
ef0dcb7
UI Updates
maksimkurb Dec 1, 2025
d1b5863
Enhance rule matching
maksimkurb Dec 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,213 changes: 1,213 additions & 0 deletions .claude/CONTEXT.md

Large diffs are not rendered by default.

172 changes: 172 additions & 0 deletions .claude/REFACTOR_PLAN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Code Reduction & Unification Refactoring Plan

## Status: Mostly Completed

**Completed Phases:** 0, 1, 2, 3, 4, 6, 7, 8
**Deferred Phases:** 5

**Actual Results:**
| Category | Lines Changed | Status |
|----------|---------------|--------|
| Phase 0: Unify Apply/Check | ~100 removed | COMPLETED |
| Phase 1: Remove apply/undo commands | ~350 removed | COMPLETED |
| Phase 2: Unify CLI/API Methods | +320 (shared services) | COMPLETED |
| Phase 3: Remove unused interfaces | ~50 removed | COMPLETED |
| Phase 4: Eliminate Builder Pattern | ~40 removed | COMPLETED |
| Phase 6: Simplify Service Layer | ~100 removed | COMPLETED |
| Phase 7: Simplify DI (interfaces) | ~50 removed | COMPLETED |
| Phase 8: Consolidate Validation | ~300 removed | COMPLETED |
| **Total** | **~990 lines removed** | |

---

## Completed Phases

### Phase 0: Unify Apply/Check Logic - COMPLETED

Updated `commands/self_check.go` to use the same `ComponentBuilder` pattern as `api/check.go`:
- Both CLI and API now use `networking.ComponentBuilder.BuildComponents()`
- Both check `component.IsExists()` vs `component.ShouldExist()`
- Consistent output formatting and messages

### Phase 1: Remove Deprecated Commands - COMPLETED

Deleted:
- `src/internal/commands/apply.go`
- `src/internal/commands/apply_test.go`
- `src/internal/commands/undo.go`

Updated:
- `src/cmd/keen-pbr/main.go` - removed command registrations and help text

Alternative workflow: Users should use `keen-pbr service` (daemon mode) or web UI.

### Phase 3: Remove Unused Interfaces - COMPLETED

Deleted from `src/internal/domain/interfaces.go`:
- `RouteManager` interface
- `InterfaceProvider` interface
- `ConfigLoader` interface

These were defined but never implemented or used.

### Phase 4: Eliminate Builder Pattern - COMPLETED

Converted builder pattern to simple functions in `networking/builders.go`:
- `NewIPTablesBuilder(cfg).Build()` → `BuildIPTablesRules(cfg)`
- `NewIPRuleBuilder(cfg).Build()` → `BuildIPRuleFromConfig(cfg)`

Updated all call sites in:
- `component_iprule.go`
- `component_iptables.go`
- `persistent.go`

### Phase 6: Simplify Service Layer - COMPLETED

Deleted:
- `src/internal/service/routing_service.go` - no longer used after removing apply command

IPSetService remains for download command functionality.

### Phase 8: Consolidate Validation - COMPLETED

Deleted:
- `src/internal/service/validation_service.go`
- `src/internal/service/validation_service_test.go`

Updated `commands/common.go` to use only `config.ValidateConfig()`.
Interface validation is handled separately by `networking.ValidateInterfacesArePresent()`.

---

### Phase 2: Unify CLI and API Methods - COMPLETED

Created shared services for DNS and interfaces:

- `service/dns_service.go` - DNSService with GetDNSServers() and FormatDNSServers()
- `service/interface_service.go` - InterfaceService with GetInterfaces() and FormatInterfacesForCLI()

Updated CLI commands:
- `commands/dns.go` uses DNSService
- `commands/interfaces.go` uses InterfaceService

Updated API:
- `api/interfaces.go` GetInterfaces() now includes Keenetic metadata
- New `GET /api/v1/dns-servers` endpoint added
- Shared `DNSServerInfo` type used across API

---

## Deferred Phases

### Phase 5: Simplify Component Abstraction - DEFERRED

**Reason:** After analysis, consolidating component files would NOT reduce code significantly:
- `component_dns_redirect.go` alone is 362 lines
- Total component files are 600+ lines of actual implementation logic
- Consolidating into single file would hurt readability without reducing code

Current component file structure is well-organized and maintainable.

### Phase 7: Simplify Dependency Injection - COMPLETED

**Changes made:**

1. **Removed IPSetManager interface** - replaced with concrete `*networking.IPSetManagerImpl`:
- No mocks existed for this interface
- Reduced memory footprint (interface values are 16 bytes vs 8 bytes for pointer)
- Enables compiler inlining and direct method calls
- Updated: `domain/interfaces.go`, `domain/container.go`, `service/ipset_service.go`, `dnsproxy/proxy.go`

2. **Created local InterfaceLister interface** in networking package:
- Avoids circular import between `domain` ↔ `networking`
- Only defines `GetInterfaces()` method needed by InterfaceSelector
- Both `*keenetic.Client` and mock implementations satisfy this interface

3. **Updated InterfaceSelector/ComponentBuilder/Manager** to accept interface:
- Changed from `*keenetic.Client` to `InterfaceLister`
- Removed keenetic import from manager.go and component_builder.go

4. **Removed 4 type casting hacks**:
- `domain/container.go` - no longer needs `keeneticClient.(*keenetic.Client)`
- `api/check.go` (2 locations) - now passes interface directly
- `commands/self_check.go` - now passes interface directly

**Memory footprint reduction:**
- `AppDependencies.ipsetManager`: 16 → 8 bytes
- `IPSetService.ipsetManager`: 16 → 8 bytes
- `DNSProxy.ipsetManager`: 16 → 8 bytes
- Total: 24 bytes saved per service instance

**Note:** KeeneticClient interface is retained for test mocking in:
- `dnsproxy/upstreams/keenetic_test.go`
- `config/hasher_deadlock_test.go`

---

## What NOT to Change

These patterns are well-designed and should be kept:

1. **NetworkManager facade** - Good orchestration
2. **PersistentConfigManager / RoutingConfigManager** - Clean separation
3. **InterfaceSelector** - Smart interface selection
4. **ConfigHasher** - Useful for change detection
5. **RestartableRunner** - Clean crash isolation
6. **DNS Proxy architecture** - Well-designed async handling
7. **Component files separation** - Good maintainability

---

## Code Smell Checklist (Post-Refactor)

All issues resolved:

- [x] No interface has single implementation - FIXED (IPSetManager interface removed)
- [x] No wrapper just delegates to another type - FIXED
- [x] No builder that could be a function - FIXED
- [x] No service that just calls one manager method - FIXED
- [x] No type casting between interface and concrete type - FIXED (via InterfaceLister interface)
- [x] No duplicate validation logic - FIXED
- [x] CLI and API share same business logic - FIXED (dns/interfaces now share services)
- [x] Apply and Check use same component building logic - FIXED
Loading