TS Standards
Overview
Enforce a dense, functional, Effect-first TypeScript style with minimal exports, algorithmic derivation, and maximum use of external libraries.
Non-negotiables
- •No imperative statements: no
if,for,while,try/catch,let,var. - •Use
Match,Option,Either,Effect,Stream,Schedule, andEffect.iteratefor control flow. - •Avoid
anyand ad-hoc casts; derive types from schemas, tables, or library types. - •Avoid wrappers, redundant aliases, and indirection; import official library objects directly.
- •Avoid helpers until after implementation proves duplication; if needed, consolidate into one namespace object.
- •Prefix all private/internal values with
_. - •Avoid default exports, inline exports, and barrel files; export via a dedicated
[EXPORT]section. - •Use comments only to explain "why", never "what".
API Shape
- •Expose one primary export per file (max three).
- •Provide unified polymorphic APIs; one function handles single and batch inputs.
- •Preserve input shape on output; do not split APIs into
get/getManyoremit/emitBatch. - •Prefer callable objects via
Object.assignwhen a function needs attached metadata.
Types, Schemas, Constants
- •Derive types from schemas/tables (e.g.,
type X = S.Schema.Type<typeof XSchema>). - •Use
S.ClassandS.TaggedErrorfor schema-coupled classes and errors. - •Inline types/consts to strengthen inference; avoid type/const spam.
- •Use a dense tuning object (
_CONFIG,Tuning,limits) withas constandsatisfiesinstead of scattered literals. - •Use
as constandsatisfiesto preserve literals and avoid redundant aliases.
Effect Patterns
- •Compose with
pipe,Effect.map,Effect.flatMap,Effect.andThen,Effect.tap,Effect.gen,Effect.fn. - •Use
Data.TaggedErrororData.taggedEnumfor error ADTs not tied to Schema. - •Use
Context.TagorEffect.Servicefor services andLayer.*for wiring. - •Use
Match.value(...).pipe(Match.when/Match.tag/Match.orElse/Match.exhaustive)for branching. - •Use dispatch tables for variants; ternary only for binary cases.
- •Prefer
Effect.tryPromise,Effect.promise,Either.tryinstead oftry/catch.
Libraries and Imports
- •Always use explicit imports; never rely on implicit globals or re-exported wrappers.
- •Prefer canonical sources: core types/utilities from
effect, platform features from@effect/platform*, data access from@effect/sql*, tracing from@effect/opentelemetry. - •Available libraries (catalog):
effect,@aws-sdk/client-s3,@aws-sdk/s3-request-presigner,@effect-aws/client-s3,@effect/cli,@effect/cluster,@effect/experimental,@effect/opentelemetry,@effect/platform,@effect/platform-node,@effect/platform-node-shared,@effect/printer,@effect/printer-ansi,@effect/rpc,@effect/sql,@effect/sql-pg,@effect/workflow. - •Common
effectimports to consider for consistency:Match,Duration,Layer,Option,Order,pipe,Record,Schedule,Schema as S,Metric,Redacted,Data,Effect,FiberId,FiberRef,Array as A,Chunk,Clock,Either,Stream,STM,TMap,Encoding,Number as N,Cache,Config,HashMap,HashSet,Predicate,Function as F,Scope,Cause. - •Import
constantanddualfromeffect/Functionwhen needed; avoid redefining them. - •Always check these libraries before hand-rolling utilities.
Platform Integration (Parametric Portal)
- •Always use
packages/server/src/platform/cache.tsfor caching. Do not roll custom cache or bypass cache layer. - •Always use
packages/server/src/utils/resilience.tsfor retry, circuit, bulkhead, timeout, hedge, or memoization. - •Always integrate
packages/server/src/observe/telemetry.tsfor tracing. PreferTelemetry.spanandMetricsService.trackEffectoverEffect.fn. - •Always integrate
packages/server/src/observe/metrics.tsfor metrics. Prefer domain-specific metrics (for example cluster metrics) and fall back to generic metrics only when needed. - •Always respect request context. Read and follow
packages/server/src/context.tsandpackages/server/src/middleware.tspatterns for headers, cookies, auth, tenant scoping, and request metadata. AssumeContext.Requestis available and must be propagated in effects.
File Layout
- •Use section separators and standard order; match existing patterns.
- •Keep internal constants/functions near usage; keep public API in
[ENTRY_POINT]and[EXPORT].
Workflow
- •Read nearby files for patterns before editing.
- •Implement logic inline first; refactor into a helper only if duplication is proven.
- •Normalize
T | ReadonlyArray<T>viaArray.isArraywithMatchor ternary; preserve output shape. - •Maximize library usage; do not re-implement existing library features.
Parametric Portal-Specific
- •Read and follow
AGENTS.md,REQUIREMENTS.md,CLAUDE.md, andpackages/server/src/domain/REBUILD.md. - •Consult
references/patterns.mdandreferences/repo-conventions.md. - •Default exports are only allowed in
*.config.tsand database migration files.