This document outlines the established coding standards and best practices for contributing to the Binary Coffee API project. Adherence to these rules ensures code consistency, maintainability, and a high quality codebase across all modules.
Language Requirement: Effective immediately, this entire project must exclusively use TypeScript (TS). All new files, modifications, and additions must adhere to TypeScript syntax, types, interfaces, and modern Node.js module patterns. Please ensure appropriate type definitions are used throughout the codebase.
Code Scope Limitation: For development, testing, and feature implementation, focus your efforts primarily within these directories:
src/: Contains all core application source code (controllers, services, utility functions).tests/: Dedicated directory for unit and integration tests.config/: Holds project configuration files (e.g., environment variables handling, module settings).
Changes outside these primary directories should be minimized or explicitly documented if necessary.
- Module Design: Services and controllers within
src/must be designed to handle single responsibilities (Single Responsibility Principle - SRP). Avoid placing large blocks of logic in one file; break down complexity into smaller, dedicated utility modules. - Imports: Use absolute imports where possible (
@/utils/filenameor similar alias) instead of relative paths (../../../). - Naming Conventions:
- Components/Modules: PascalCase (e.g.,
UserService,DatabaseClient). - Functions/Methods: camelCase (e.g.,
fetchUserData,processData). - Variables/Constants: camelCase or SCREAMING_SNAKE_CASE for constants (
MAX_RETRIES).
- Components/Modules: PascalCase (e.g.,
- Type Safety is Mandatory: Every function, class, and module must be strongly typed. Avoid using
anytype unless absolutely unavoidable and clearly documented with a comment explaining the rationale. - Interfaces vs Types: Use TypeScript Interfaces (
interface) for object shapes that describe public contracts (like data transfer objects - DTOs). Use Types (type) for unions, intersections, or primitive aliases.
- Coverage Goal: Aim for high unit test coverage (>80%) across all business logic in
src/. - Test Structure: Tests should use TypeScript and the
.spec.tssuffix (for example,tests/integration/user/search-users.spec.ts); this is the naming pattern discovered by the Mocha configuration. Unit tests should live alongside the code they are testing (e.g.,src/services/UserService.tsshould have a correspondingtests/user.service.spec.ts). - Async Handling: All asynchronous operations must be properly mocked and tested using async/await or appropriate Promise handling.
- Always add a newline at the end of each file to comply with POSIX standards and avoid unnecessary diffs in version control.
- Feature Implementation: Always start by defining the necessary types (interfaces) first to model the data flow.
- Review: Before committing, run linting (
npm run lint), formatting checks (npm run format:check), and type-checking (npm run build/tsc --noEmit). Usenpm run lint:fixornpm run formatto apply automatic fixes, then review the changes. - Contribution Guide: For detailed steps on setting up environments or complex architectural decisions, please
refer to the project's main
CONTRIBUTING.mdguide.
This document was generated based on current best practices and is subject to revision.