Skip to content
This repository was archived by the owner on May 6, 2026. It is now read-only.

Latest commit

 

History

History
44 lines (31 loc) · 1.42 KB

File metadata and controls

44 lines (31 loc) · 1.42 KB

Frontend Constants Guidelines

This section provides conventions and examples for defining and using constants in the frontend codebase. Constants improve readability, maintainability, and help eliminate magic numbers or strings scattered throughout the code.


Example: Message Constants and UI Offsets

import { EasyAIMessage, MessageOriginType, StreamMessageType } from "../types/message";

export const EMPTY_STREAM_AI_MESSAGE: Readonly<EasyAIMessage> = {
  origin: MessageOriginType.Stream,
  message: "",
  type: StreamMessageType.Message,
};

export const ACTIVATOR_POSITION_OFFSET_TOP_PX = 25;
export const ACTIVATOR_POSITION_OFFSET_LEFT_PX = 5;

Usage Example

import { EMPTY_STREAM_AI_MESSAGE } from "@/src/shared/constants/messages";

function createInitialMessage() {
  return { ...EMPTY_STREAM_AI_MESSAGE }; // Safe to copy, can't be mutated
}

Best Practices

  • Group constants by purpose into logically named files (e.g., constants/ui.ts, constants/messages.ts).
  • Use explicit type annotations for structured or domain-specific constants.
  • Write descriptive names that clarify intent and usage.
  • Use export const to guarantee immutability.
  • Use UPPER_SNAKE_CASE for all constant names.
  • Include unit suffixes in names when applicable (e.g., _PX, _MS, _CHARS) to clarify what the value represents.
  • Use Readonly<Type> for object constants to prevent accidental mutation.