Skip to content

Tech Debt: Consolidate duplicated business logic between REST API and GraphQL #2664

Description

@filiperochalopes

User story

As a developer, I want REST API and GraphQL endpoints to share the same business logic so new features, bug fixes, and maintenance only need to be implemented once.

Use case

As CIEL Lab evolves, many features become available through both the REST API and GraphQL. Today, similar functionality is implemented and maintained independently, increasing development effort and the risk of behavioral inconsistencies.

Requirements

  • Review the current REST API and GraphQL capabilities and identify overlapping functionality.
  • Document redundant endpoints, queries, mutations, and business workflows.
  • Define a shared service layer responsible for business logic.
  • Refactor GraphQL resolvers to delegate business logic to the shared service layer where applicable.
  • Refactor REST endpoints to delegate business logic to the same shared service layer where applicable.
  • Preserve existing API contracts unless an explicit breaking change is approved.
  • Ensure authorization, validation, auditing, and error handling remain consistent across both interfaces.
  • Identify functionality that should exist exclusively in one interface and document the rationale.
  • Produce migration recommendations for remaining duplicated implementations.

Acceptance criteria

  • A technical assessment identifies redundant functionality between the REST API and GraphQL layers.
  • Shared business logic is clearly separated from transport-specific code.
  • REST and GraphQL produce consistent behavior for equivalent operations.
  • New functionality can be implemented once and exposed through both interfaces with minimal duplication.
  • A migration plan is available for remaining duplicated components.

More details

Technical context

CIEL Lab currently exposes both REST API and GraphQL interfaces. While this provides flexibility for different clients, it also increases maintenance cost because equivalent operations may evolve independently.

The goal of this task is not to remove either interface, but to reduce duplicated implementation by introducing a common application/service layer responsible for business rules.

The review should identify:

  • duplicated validation logic
  • duplicated authorization logic
  • duplicated data transformation
  • duplicated persistence workflows
  • inconsistent error handling
  • inconsistent response behavior
  • opportunities for shared abstractions

The expected outcome is a cleaner architecture where REST and GraphQL become thin transport layers over the same business services.

Reference interfaces:

Metadata

Metadata

Labels

signal/large-scopeAffects multiple areas or systemssignal/needs-specMissing detail or ambiguous requirementsstage/triagedAI triage complete — scored and classifiedtype/refactorCode restructuring, no behavior change

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions