Naming Conventions
This document defines the naming conventions used throughout the ReX project, ensuring consistency in code, documentation, and APIs.
General Principles
- Consistency: Naming should be consistent across related elements
- Clarity: Names should clearly indicate purpose and behavior
- Explicitness: Prefer explicit, descriptive names over short, ambiguous names
- Context-Awareness: Names should reflect their operational context
File Naming Conventions
TypeScript/JavaScript Files
Implementation Files: Use
kebab-case.ts
for implementation files- Example:
content-store.ts
,filesystem-adapter.ts
- Example:
Type Definition Files: Use
kebab-case.types.ts
for standalone type files- Example:
content.types.ts
,adapter.types.ts
- Example:
Test Files: Use
kebab-case.test.ts
for test files- Example:
content-store.test.ts
,filesystem-adapter.test.ts
- Example:
Documentation Files
Markdown Files: Use
kebab-case.md
for documentation files- Example:
content-model.md
,layer-boundaries.md
- Example:
Architecture Decision Records: Use
ADR-NNN-Title-With-Hyphens.md
for ADRs- Example:
ADR-007-Compositional-Content-Architecture.md
- Example:
Code Naming Conventions
Interfaces and Types
Interfaces: Use PascalCase without
I
prefix for interfaces- Example:
ContentStore
,ContentAdapter
,ContentMetadata
- Example:
Type Aliases: Use PascalCase for type aliases
- Example:
ContentType
,AdapterOptions
,StorageOptions
- Example:
Generic Type Parameters: Use PascalCase single letters or descriptive names
- Example:
T
for general types,TData
for data types,TMetadata
for metadata types
- Example:
Options Interfaces
Options Interfaces: Use
{EntityName}Options
pattern for all options interfaces- Example:
ContentReadOptions
(not justReadOptions
) - Example:
LoggingMiddlewareOptions
(not justLoggingOptions
) - Example:
FileSystemAdapterOptions
(specific adapter options)
- Example:
Options Naming Patterns:
- Operation options:
Content{OperationName}Options
(e.g.,ContentReadOptions
,ContentWriteOptions
) - Middleware options:
{MiddlewareName}MiddlewareOptions
(e.g.,LoggingMiddlewareOptions
,CachingMiddlewareOptions
) - Adapter options:
{AdapterName}AdapterOptions
(e.g.,FileSystemAdapterOptions
,HttpAdapterOptions
) - Factory options:
{EntityName}FactoryOptions
(e.g.,ContentStoreFactoryOptions
)
- Operation options:
Functions and Methods
Factory Functions: Use
create
prefix for factory functions- Example:
createContentStore
,createFileSystemAdapter
- Example:
Higher-Order Functions: Use
with
prefix for higher-order functions (that enhance another function)- Example:
withValidation
,withCaching
,withLogging
- Example:
Event Handlers/Callbacks: Use
handle
oron
prefix for event handlers- Example:
handleChange
,onContentUpdate
- Example:
Asynchronous Functions: No special prefix, but always return Promises
- Example:
read
,write
,delete
(notreadAsync
, etc.)
- Example:
Boolean Functions/Properties: Use
is
,has
,can
, orshould
prefix for boolean functions/properties- Example:
isModified
,hasChanges
,canWrite
,shouldRevalidate
- Example:
Variables and Constants
Constants: Use
UPPER_SNAKE_CASE
for truly constant values- Example:
DEFAULT_TIMEOUT
,MAX_RETRY_COUNT
- Example:
Configuration Objects: Use camelCase for configuration objects
- Example:
storeConfig
,adapterOptions
- Example:
Regular Variables: Use camelCase for regular variables
- Example:
contentStore
,fileAdapter
,metadataValue
- Example:
CSS Classes and IDs
CSS Classes: Use kebab-case for CSS classes
- Example:
content-container
,editor-panel
- Example:
CSS Variables: Use kebab-case with double hyphens for variable namespace
- Example:
--primary-color
,--font-size-base
- Example:
URI/Path Conventions
Content URIs: Use kebab-case for path segments
- Example:
content/blog-posts/my-first-post
- Example:
API Endpoints: Use kebab-case for API endpoints
- Example:
/api/content-store/items
- Example:
Event Naming Conventions
Event Types: Use past tense to indicate something that happened
- Example:
created
,updated
,deleted
,moved
- Example:
Event Handlers: Use
on
prefix followed by the event name in present tense- Example:
onChange
,onUpdate
,onDelete
- Example:
Common Domain-Specific Terms
To maintain consistency across all documentation and code, the following terms should be used consistently:
- Content: The fundamental unit of data in the system (not “document”, “resource”, etc.)
- URI: The identifier for content (not “path”, “id”, etc.)
- Metadata: Structured data about content (not “meta”, “attributes”, etc.)
- Adapter: Storage implementation abstraction (not “provider”, “connector”, etc.)
- Middleware: Function that enhances operations (not “interceptor”, “handler”, etc.)
- Store: High-level content operations API (not “repository”, “service”, etc.)
Special Considerations
React Components
Component Files: Use PascalCase for component files
- Example:
ContentDisplay.tsx
,ContentEditor.tsx
- Example:
Component Names: Use PascalCase for component names
- Example:
ContentDisplay
,ContentEditor
- Example:
Hook Files: Use camelCase with
use
prefix for hook files- Example:
useContent.ts
,useContentStore.ts
- Example:
Hook Names: Use camelCase with
use
prefix for hook names- Example:
useContent
,useContentStore
- Example:
Versioning-Related Names
- Temporal Field Names: Use consistent timestamp field names
createdAt
: When the entity was createdupdatedAt
: When the entity was last updateddeletedAt
: When the entity was marked as deleted (for soft deletes)publishedAt
: When the entity was published/made active
Implementation in Code
When implementing these naming conventions:
- Update existing code during refactoring phases
- Ensure all new code follows these conventions
- Document any exceptions with clear rationale
- Include naming convention verification in code reviews
Tools and Enforcement
- Use ESLint naming convention rules to enforce these standards
- Configure IDE settings to suggest correct naming patterns
- Include naming conventions in pull request templates
Exceptions
Any exceptions to these naming conventions must be:
- Documented explicitly with rationale
- Approved by the architecture team
- Applied consistently within their specific context
- Added to this document as an authorized exception