Code Organization
Naming Conventions
This section outlines the guidelines for naming conventions across the codebase, ensuring consistency and clarity in the project.
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
foruser-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
- Classes:
- Prefix types with T and interfaces with I (when helpful)
- β
TStats
,TResponseData
,IApiConfig
- β
- Enum names should be PascalCase, values in UPPER_SNAKE_CASE
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.
Was this page helpful?