Skip to content

Create Constants File for Magic Strings and Values #30

@prasadhonrao

Description

@prasadhonrao

Description

Extract magic strings and hardcoded values into a centralized constants file for better maintainability.

Current State

Magic strings scattered throughout the codebase:

  • Service names: 'admin-service'
  • Error codes: 'INTERNAL_ERROR'
  • Default values: 'no-trace', 'no-span'
  • HTTP status codes used directly

Proposed Solution

Create src/constants/index.js:

export const SERVICE_NAME = 'admin-service';
export const SERVICE_VERSION = '1.0.0';

export const ERROR_CODES = {
  INTERNAL_ERROR: 'INTERNAL_ERROR',
  VALIDATION_ERROR: 'VALIDATION_ERROR',
  NOT_FOUND: 'NOT_FOUND',
  UNAUTHORIZED: 'UNAUTHORIZED',
};

export const HTTP_STATUS = {
  OK: 200,
  CREATED: 201,
  NO_CONTENT: 204,
  BAD_REQUEST: 400,
  UNAUTHORIZED: 401,
  FORBIDDEN: 403,
  NOT_FOUND: 404,
  INTERNAL_SERVER_ERROR: 500,
  SERVICE_UNAVAILABLE: 503,
};

export const TRACE_DEFAULTS = {
  NO_TRACE: 'no-trace',
  NO_SPAN: 'no-span',
};

Benefits

  • Single source of truth for constant values
  • Easier to update values globally
  • Better code readability
  • Type safety (when migrating to TypeScript)

Priority

High - Fundamental code organization improvement

Related Files

  • All controllers and middlewares

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions