Skip to content

Refactor frontend codebase to improve DRY, SRP, and structure #71

@Ayush8923

Description

@Ayush8923

Describe the current behavior
The current frontend codebase has multiple inconsistencies and repeated logic across files.

  • API calls are duplicated across many route.ts files with similar fetch configurations.
  • SVG icons are directly hardcoded inside page components, making them less reusable and harder to manage.
  • Utility/helper functions (e.g., escapeCSVValue) are defined inside page files instead of shared utility modules.

This leads to violations of DRY (Don't Repeat Yourself) and SRP (Single Responsibility Principle), making the code harder to maintain and scale.

Describe the enhancement you'd like
Refactor the frontend codebase to improve structure, reusability, and maintainability:

  1. Introduce a centralised API client (e.g., apiClient or backendFetch) to handle all API requests and remove duplicated fetch logic.
  2. Create a dedicated components/icons directory to store reusable SVG components instead of hardcoding them in pages.
  3. Move reusable helper functions (e.g., escapeCSVValue) to a shared utils or lib directory.

Why is this enhancement needed?

  • Reduces code duplication (DRY compliance)
  • Improves code readability and maintainability
  • Encourages proper separation of concerns (SRP)
  • Makes the codebase easier to scale and extend
  • Simplifies future updates (e.g., changing headers or API logic in one place)

Additional context
Example of duplicated API logic:

const response = await fetch(`${backendUrl}/api/v1/configs/`, {
  headers: {
    'X-API-KEY': apiKey || '',
  },
});

Proposed centralized approach:

const { status, data } = await apiClient(
  request,
  `/api/v1/configs/${config_id}`
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions