Part of duplicate code analysis: #4711
Summary
Both UnifiedServer (internal/server/unified.go) and Server (internal/proxy/proxy.go) independently declare an identical set of DIFC component fields. This structural duplication means any addition of a new DIFC component requires updates in two separate structs.
Duplication Details
Pattern: Duplicated DIFC component fields in two structs
The initialization of these fields also uses the same difc.NewComponents(...) pattern in both packages (server via difc.NewComponents, proxy via explicit field assignment).
Impact Analysis
- Maintainability: Adding a new DIFC component (e.g. a new registry type) requires updating two structs.
- Bug Risk: Low, but the divergence (
guard.Registry in server vs single guard.Guard in proxy) indicates the two have already begun to diverge.
- Code Bloat: Minor (~8 lines), but sets a precedent for further divergence.
Refactoring Recommendations
- Introduce a
DIFCComponents struct in internal/difc/ (already partially exists as difc.NewComponents return):
type Components struct {
AgentRegistry *AgentRegistry
Capabilities *Capabilities
Evaluator *Evaluator
}
Both UnifiedServer and proxy Server embed *difc.Components instead of individual fields.
- Estimated effort: 1–2 hours
- Benefits: single definition, new components automatically propagate
Implementation Checklist
Parent Issue
See parent analysis report: #4711
Related to #4711
Generated by Duplicate Code Detector · ● 1M · ◷
Part of duplicate code analysis: #4711
Summary
Both
UnifiedServer(internal/server/unified.go) andServer(internal/proxy/proxy.go) independently declare an identical set of DIFC component fields. This structural duplication means any addition of a new DIFC component requires updates in two separate structs.Duplication Details
Pattern: Duplicated DIFC component fields in two structs
Severity: Medium
Occurrences: 2
Locations:
internal/server/unified.go—UnifiedServerstruct (lines ~100–104)internal/proxy/proxy.go—Serverstruct (lines ~41–44)Code Sample (server/unified.go):
Code Sample (proxy/proxy.go):
The initialization of these fields also uses the same
difc.NewComponents(...)pattern in both packages (server viadifc.NewComponents, proxy via explicit field assignment).Impact Analysis
guard.Registryin server vs singleguard.Guardin proxy) indicates the two have already begun to diverge.Refactoring Recommendations
DIFCComponentsstruct ininternal/difc/(already partially exists asdifc.NewComponentsreturn):UnifiedServerand proxyServerembed*difc.Componentsinstead of individual fields.Implementation Checklist
difc.NewComponentsalready returns a composable struct (it does — leverage it)*difc.Componentsin bothUnifiedServerand proxyServerParent Issue
See parent analysis report: #4711
Related to #4711