Files and Directories

General Files

  • Use lowercase and hyphen-separated names (kebab-case) for files and directories
    • βœ… user-profile.ts
    • ❌ UserProfile.ts
  • Group related files in directories with descriptive plural names
    • βœ… components, services, utils
    • ❌ component, util

Special Files

  • Configuration files should follow framework conventions
    • βœ… next.config.mjs, tailwind.config.js
  • Test files should mirror source files with .test or .spec suffix
    • βœ… user-service.test.ts for user-service.ts
  • Database migration files should include timestamp and description
    • βœ… 20241017124431_add_documents_and_insights.sql

Code Symbols

Variables and Functions

  • Use camelCase for variables and function names
    • βœ… fetchUserData, isLoading, handleSubmit
    • ❌ FetchUserData, is_loading
  • Boolean variables should use is/has/should prefix
    • βœ… isVerifyEmailEnabled, hasPermission, shouldDisplay
  • Async functions should use verb prefixes suggesting async
    • βœ… fetchData, createUser, updateProfile

Classes and Types

  • Use PascalCase for:
    • Classes: Config, Client, ResponseAPI
    • Interfaces: TSurveySummaryResponse, ApiConfig
    • Type aliases: TResponseData, TJsTrackProperties
  • Prefix types with T and interfaces with I (when helpful)
    • βœ… TStats, TResponseData, IApiConfig
  • Enum names should be PascalCase, values in UPPER_SNAKE_CASE
    enum ProjectFeatureKeys {
      FREE = "free",
      STARTUP = "startup",
      SCALE = "scale"
    }
    

Constants

  • Use UPPER_SNAKE_CASE for constant values
    • βœ… API_TIMEOUT, MAX_RETRIES, CONTAINER_ID
  • Use PascalCase for constant references/objects
    • βœ… ErrorCodes, Config

Database Models

  • Use PascalCase singular form for model names
    • βœ… Survey, Response, Document
  • Use camelCase for field names
    • βœ… createdAt, environmentId, isSpam
  • Use snake_case for database column names
    • βœ… created_at, updated_at

Components

  • Use PascalCase for React components and their files
    • βœ… SurveyCard.tsx, UserProfile.tsx
  • Component-specific types should be prefixed with component name
    • βœ… SurveyCardProps, UserProfileData

API and Endpoints

  • Use kebab-case for API endpoints
    • βœ… /api/user-profile, /api/survey-responses
  • Use camelCase for query parameters
    • βœ… /api/surveys?pageSize=10&sortOrder=desc

Schema and Validation

  • Prefix Zod schemas with Z
    • βœ… ZSurvey, ZDocument, ZInsight
  • Use descriptive names for validation schemas
    • βœ… ZUpdateDocumentAction, ZGenerateDocumentObjectSchema

Error Handling

  • Suffix error classes with β€œError”
    • βœ… ValidationError, DatabaseError, AuthenticationError
  • Use descriptive names for error types
    • βœ… SURVEY_NOT_FOUND, INVALID_RESPONSE

Best Practices

  • Keep names descriptive but concise
  • Be consistent within each context
  • Follow existing patterns in the codebase
  • Use full words instead of abbreviations unless widely accepted
    • βœ… configuration vs ❌ config (except in standard terms)
    • βœ… id, url (standard abbreviations are acceptable)

By following these conventions, we maintain consistency and clarity across the codebase, making it more maintainable and easier to understand for all team members.