Skip to main content

Code conventions

Naming

TypeConventionExample
Variablelower_snake_caseuser_name, order_id
FunctioncamelCasegetUserName(), createOrder()
Class, Interface, Enum, TypePascalCaseOrderService, IConfig
ConstantUPPER_SNAKE_CASESECRET_KEY, MAX_RETRY
  • Do not use var, prefer let
  • Do not use ; (semicolons)
  • Prefer ' ' over " "

Comments

  • Write in Vietnamese
  • JSDoc /** */ before variables, functions, constants, classes, interfaces, types
  • // for inline logic comments
  • Comment each field when declaring interfaces/types

Code style

  • JS: 80 columns, HTML: 120 columns
  • Do not let for/if push code deeper than 40 columns — break out of nesting
  • Duplicate logic must be extracted into functions/components
{
"printWidth": 80,
"tabWidth": 2,
"singleQuote": true,
"semi": false,
"singleAttributePerLine": true,
"arrowParens": "avoid"
}

SOLID

Required for all services/business logic:

  • S — A class should have only one reason to change
  • O — Open for extension, closed for modification
  • L — Subtypes must be substitutable for their base types
  • I — Split interfaces, avoid large ones
  • D — Depend on abstractions, not implementations

Class pattern

//#region ____ - ....
// -------------------------------------------------------
/** Configuration .... */
export interface IConfig____ {}
/** Input context .... */
export interface IContext____ {}
/** Return result .... */
export interface IResult____ {}
/** Service contract .... */
export interface I____ {
exec(context: IContext____): Promise<IResult____>
}
/** Concrete implementation .... */
export class ____ implements I____ {
constructor(
private readonly CONFIG: IConfig____ = {},
private readonly SERVICE_ABC: IAbc = new Abc(),
) {}
async exec({}: IContext____) {
return {}
}
}
// -------------------------------------------------------
//#endregion

Git

  • DO NOT commit/push to main or master
  • Always create a separate branch and submit a pull request
  • Run pnpm lint and pnpm test before committing
  • Do not commit .env* files (except .env.example)

Security

  • Do not hardcode API keys, secret keys, or tokens in source code
  • Verify signatures before processing webhooks/IPN
  • Do not expose Secret Key or Access Key to non-owner users