Skip to main content

Naming Conventions

Files and Directories

  • Routes: Use kebab-case for route files: user-profiles/routes.ts
  • Services: Use PascalCase for service files: UserProfileService.ts
  • Directories: Use kebab-case: user-api/, merchant-profiles/
  • API Endpoints: Use kebab-case in URLs: /user-profiles/, /merchant-settings/

Code Elements

  • Classes: PascalCase - UserService, ProductCatalogService
  • Methods: camelCase - getUserProfile(), createProduct()
  • Variables: camelCase - userId, productData, isAuthenticated
  • Constants: UPPER_SNAKE_CASE - DATABASE_URL, JWT_SECRET
  • Interfaces/Types: PascalCase - DBConnection, ApiRequest

Database Schema

  • Tables: snake_case - user_profiles, product_categories
  • Columns: snake_case - user_id, created_at, merchant_id
  • Multi-tenancy: Always include shop_id or merchant_id

Import Organization

Organize imports in the following order with blank lines between groups:

Module Structure

Service Class Pattern

All service classes must extend APIService and follow this pattern:

Route Handler Pattern

Route files must export a function that accepts DBConnection:

Error Handling

Custom Error Usage

Always use CustomError from the shared library:

Response Handling

Use the service.handleOk() pattern for consistent responses:

Database Access

Multi-tenancy Pattern

Always filter by merchant/shop ID for data isolation:

Query Patterns

Use Knex.js patterns consistently:

Authentication & Authorization

Request Context Usage

Access user context from authenticated requests:

Role-based Access

Check permissions using user context:

Event Publishing

Domain Events

Publish events for important domain actions:

TypeScript Usage

Type Safety

Use proper typing throughout:

Path Aliases

Use configured path aliases for imports: