Skip to content
MSO CloudDocumentation

Coding standards

On this page

The standards a change to application code must meet. The Rule column names where the rule is written; the Guard column names what fails when it is broken. "Review only" means no script checks it.

Language and types#

Standard Rule Guard
TypeScript runs with strict, noUncheckedIndexedAccess and noImplicitOverride. Every workspace extends tsconfig.base.json. AGENTS.md Conventions pnpm run typecheck (tsc via turbo)
No any. Use unknown and narrow it. AGENTS.md Conventions ESLint @typescript-eslint/no-explicit-any through tseslint.configs.recommended in each workspace config; packages/exports switches it off, which is an exception, not a precedent
No as unknown as casts beyond the recorded baseline. AGENTS.md Conventions scripts/audit/as-unknown-as-ratchet.py
A script that package.json runs is named in a typecheck program, because scripts/ belongs to no workspace. §120 audit:all compiles the tsconfig.*-scripts.json programs
Prefer discriminated unions over boolean flags. AGENTS.md Conventions Review only, except widget config: scripts/audit/widget-config-typed-union.py

Boundaries#

  • apps/web stays thin. Business rules, schemas, formatting and connector logic live in workspace packages under packages/. Server components serve read-heavy pages; client components are small interactive islands. A route handler validates input, calls a typed server function and returns a narrow response. Guard: review, plus scripts/audit/browser-barrel-server-deps.py and §157 for the server/client import boundary.
  • Name exports in reusable modules. Next pages and layouts use default exports; route handlers export named HTTP methods. Guard: review only.
  • Put a named Zod schema at every boundary: tRPC input, queue payload, webhook body, environment. Guard: review, plus scripts/audit/event-envelope-single-schema.py and scripts/audit/api-body-cap.py (§138) for the body-size cap.

Tenancy#

  • Every query on an org-scoped table goes through orgProcedure (or brandProcedure for brand-scoped data). A function that reaches an org-scoped table owns its RLS scope (§122). RLS context holds only inside runWithRlsContext (§66). A procedure that takes a brand id checks the grant (§198). Guard: pnpm run verify:rls (tenancy gate), scripts/audit/brand-input-asserted.py, scripts/audit/org-actor-read-path.py.
  • Tenant differences are data: the tenant's declared capabilities and configuration, read by shared logic. Never branch on an organization, slug or customer name (§132). Guard: scripts/audit/no-per-customer-hardcodes.py.
  • Super-admin access branches on isSuperAdmin inside the procedure, not by bypassing it.

Copy, charts and AI#

Standard Rule Guard
User-facing strings live in @yng/i18n; Vietnamese (vi) is the source of truth and en must carry every key. ui-copy-i18n.md scripts/audit/i18n-key-sync.ts, scripts/audit/i18n-hardcoded-vi.py
Straight quotes only, in code, comments and copy. §85 scripts/audit/straight-quotes-in-copy.py
No toFixed() in display code; use the formatting helpers. §24 scripts/audit/locale-tofixed.py
Charts come from @yng/charts; call registerYngTheme() before the first render. ui-charts-copy.md Review only
Every AI call goes through @yng/ai; the model name is never shown to end users. §61 scripts/audit/ai-adapter-boundary.py
Money is stored as integer VND. ecom-data.md scripts/audit/fabricated-multiplier-kpis.py covers invented multipliers; integer storage itself is review only
UI uses design tokens, not raw colours. ui-theme-tokens.md scripts/audit/css-semantic-tokens.py

Errors, jobs and performance#

  • A queue processor classifies each failure as permanent or transient through the one shared wrapper, never retry-then-dead-letter on its own (AGENTS.md Conventions). Guard: scripts/audit/job-failure-classification.py.
  • Work that must survive a crash is enqueued through the transactional outbox in the same transaction as the data change (§66). Guard: scripts/audit/durable-job-outbox.py.
  • No N+1 query in a router or server component; fetch independent data with Promise.all (security-tenancy.md §7). Guard: review only. Request, bundle and provider boundaries: §72-§74, scripts/audit/performance-boundaries.py.
  • Every numeric limit or budget is a row in the limits registry (§200). Guard: scripts/audit/limits-registry.py. Route bundle budgets: pnpm run performance:budget.
  • New list queries apply a server-side limit; bulk inserts above 1,000 rows are chunked. Guard: review only.

Comments, dead code and size#

  • A comment is one short line that states a non-obvious why. It does not restate the code, narrate a change, or cite a commit, ticket or customer. Guard: scripts/audit/slop-audit-added.py (§225) checks lines added since the merge base only, so older narration is not flagged.
  • Delete dead code; do not comment it out or keep it for later. Guard: commented-out code in added lines is flagged by §225; unused exports have no guard (review only).
  • Do not grow a file that is already over its size budget without extracting from it. Guard: review only.

Lint and format#

  • Prettier is configured in .prettierrc.json (single quotes, semicolons, 100 columns, trailing commas). pnpm run format:check checks the tree; pnpm run format rewrites it. Pre-commit formats staged files for you.
  • There is no root ESLint config. Each workspace has an eslint.config.mjs (typescript-eslint recommended plus oxlint overrides); pnpm run lint runs them all through turbo.