Domain Module Template
Section titled “Domain Module Template”Use this when adding reusable business rules that should stay framework-light and runtime-light.
Canonical shape
Section titled “Canonical shape”packages/domain-{name}/src/ index.ts policies.ts normalizers.ts contracts.tsUse only the files you need.
Starter example
Section titled “Starter example”// packages/domain-{name}/src/policies.tsexport type {Domain}Status = "active" | "archived";
export function canArchive{Domain}(status: {Domain}Status): boolean { return status === "active";}// packages/domain-{name}/src/contracts.tsexport interface {Domain}Repository { findById(id: string): Promise<{ id: string; status: string } | null>;}// packages/domain-{name}/src/index.tsexport * from "./policies";export * from "./contracts";- okay: pure business rules, validators, policies, interfaces, value objects
- not okay: React, route files, TanStack Query, Cloudflare env, D1/KV access
- if runtime access is required, keep implementation local to server or worker code and export only contracts or pure policy helpers here