TypeScript Design Patterns
When applying TypeScript design patterns, read and follow the policy guide:
Policy: docs/policies/typescript-patterns.md
When This Applies
- •Organizing source code into bounded contexts or domain folders
- •Designing public API surfaces with barrel exports (
index.ts) - •Choosing between function exports and class-based namespace exports
- •Naming APIs by business capability (not vendor/tool names)
- •Implementing the Adapter Pattern for swappable providers
- •Separating system interactions into
*.system.tsfiles - •Writing atomic tests that work in parallel execution
- •Structuring test folders to mirror source folders
Principles Checklist
- •Bounded context folders:
src/domains/by business domain, not technical layer - •Business capability naming:
ISecretStorenotIOnePasswordClient - •Class-based exports: group related operations under namespace classes
- •Barrel exports:
index.tsdefines public API, hides internals - •System separation:
*.system.tsfor external I/O, excluded from coverage - •TDD: RED -> GREEN -> REFACTOR with architecture-first skeleton
- •Unit tests without mocks: real in-memory implementations, mocks only for integration
- •Atomic tests: new mock instance per
test()block, no shared state
Read the full guide for patterns, examples, and anti-patterns.