Skip to content

[duplicate-code] Duplicate Code Pattern: DIFC Component Fields Duplicated in Server and Proxy Structs #4713

@github-actions

Description

@github-actions

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

  • Severity: Medium

  • Occurrences: 2

  • Locations:

    • internal/server/unified.goUnifiedServer struct (lines ~100–104)
    • internal/proxy/proxy.goServer struct (lines ~41–44)
  • Code Sample (server/unified.go):

    guardRegistry *guard.Registry
    agentRegistry *difc.AgentRegistry
    capabilities  *difc.Capabilities
    evaluator     *difc.Evaluator
  • Code Sample (proxy/proxy.go):

    guard         guard.Guard
    evaluator     *difc.Evaluator
    agentRegistry *difc.AgentRegistry
    capabilities  *difc.Capabilities

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

  1. 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

  • Review duplication findings
  • Check if difc.NewComponents already returns a composable struct (it does — leverage it)
  • Embed *difc.Components in both UnifiedServer and proxy Server
  • Update all field references to use the embedded struct
  • Verify no functionality broken

Parent Issue

See parent analysis report: #4711
Related to #4711

Generated by Duplicate Code Detector · ● 1M ·

  • expires on May 5, 2026, 6:23 AM UTC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions