1.0 KiB
1.0 KiB
Entities Layer — Innermost, Zero Dependencies
Rules
- NEVER import from application/, infrastructure/, interface-adapters/, or di/
- NEVER import external libraries except Zod (for schema validation)
- Everything here is pure — no side effects, no I/O, no async
- Models are Zod schemas with inferred TypeScript types
- Errors are custom Error subclasses with domain-specific semantics
Adding a New Model
- Create
src/entities/models/{name}.ts - Define Zod schema and export inferred type:
import { z } from "zod"; export const {name}Schema = z.object({ ... }); export type {Name} = z.infer<typeof {name}Schema>; - Export from
src/entities/models/index.ts
Adding a New Error
- Create or edit
src/entities/errors/{domain}.ts - Extend Error with constructor accepting message + options:
export class {Name}Error extends Error { constructor(message: string, options?: ErrorOptions) { super(message, options); } } - Export from
src/entities/errors/index.ts