Skip to content

Domain Module Template

Migrated from root technical docs.

Use this when adding reusable business rules that should stay framework-light and runtime-light.

packages/domain-{name}/src/
index.ts
policies.ts
normalizers.ts
contracts.ts

Use only the files you need.

// packages/domain-{name}/src/policies.ts
export type {Domain}Status = "active" | "archived";
export function canArchive{Domain}(status: {Domain}Status): boolean {
return status === "active";
}
// packages/domain-{name}/src/contracts.ts
export interface {Domain}Repository {
findById(id: string): Promise<{ id: string; status: string } | null>;
}
// packages/domain-{name}/src/index.ts
export * 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