Skip to content

Traits & Lifecycle Behaviors

Base Traits package cross-cutting capabilities — tenant scoping, soft-delete recovery, audit timestamps, recursive trees, HIPAA read logging, sequential document numbering, and double-entry balance validation — so every entity gains consistent fields and runtime behavior in a single visual step.


1. Discovering & Attaching Base Traits in Studio

  1. Open Object Browser -> Data & Domain -> Traits (🧩). Check ☑️ Base to browse all 17 Base Traits alongside any custom traits defined in your workspace.
  2. Expand any Entity in Object Browser and click + Trait (or select the entity on the ERD canvas) to attach traits such as MultiTenant, SoftDelete, Auditable, Hierarchical, ePHIAudited, SequentialNumbering, BalancedTransaction, or PeriodLocked.
  3. Toggle 🧩 Traits on the Diagram View toolbar to display inherited fields (tenantId, deletedAt, parentId, createdAt, updatedAt) directly inside the entity card’s FROM TRAITS section, including dashed hierarchy loops for self-referencing trees.

2. Parameterizing Traits for Your Domain

Parameterized traits adapt cleanly to domain schemas directly inside Studio without duplicating boilerplate:

  • Hierarchical (parentId + parent / children relations): Adds self-referencing BelongsTo and HasMany relations so assets, organizational units, or charts of accounts form arbitrarily deep trees.
  • SequentialNumbering (targetField, prefix, useYear, padding): Generates gapless formatted identifiers (such as JE-2026-000010 or AST-00101) automatically on creation.
  • BalancedTransaction (childRelation, debitField, creditField, tolerance): Enforces double-entry sum(debit) === sum(credit) invariants across nested child line items inside the persistence transaction.
  • PeriodLocked (periodEntity, periodIdField, dateField, lockedStatus): Blocks mutations targeting closed or locked fiscal periods.
  • SoftDelete (deletedAt + Restore): Preserves historical rows on deletion, filters standard queries to active records, and adds a Restore mutation endpoint.

3. Service Transaction Lifecycle & Override Governance

Every entity that attaches traits compiles each CRUD operation (CreateOne, UpdateOne, DeleteOne, FetchOne, FetchMany) into an isolated, single-purpose TypeScript service running across three lifecycle zones:

  1. Zone 1 · Pre-Transaction (ON_REQUEST_INIT, ON_AUTHORIZE, PRE_VALIDATE, POST_VALIDATE): Executes custom action-point rules and validates or stamps MultiTenant (tenantId) identity from the verified execution context.
  2. Zone 2 · In-Transaction (PRE_CREATE, PRE_CHILD_CREATE, POST_CREATE): Applies Auditable timestamps (createdAt, updatedAt), executes atomic Prisma persistence inside the transaction scope, handles related child writes cleanly in one pass, and seals encrypted fields where configured.
  3. Zone 3 · Post-Commit (AFTER_COMMIT, ON_SUCCESS, ON_FAILURE): Dispatches ePHIAudited read/write events to perlite-audit-service, triggers downstream interfaces, and returns clean payloads.

4. Interactive Base Trait Reference (17 Base Traits)

Search and inspect every built-in Trait description, injected attribute, parameter, and generated function below:

Showing 17 Base Traits

5. Guided Example — Composing Traits onto Your Entities

Guided Build · Step 3 of 8
Attaching Multi-Trait Profiles & Verifying Generated Service Hooks
Previously in this build: In Step 2 you seeded FieldOpsDemo and inspected Customer, FieldAsset, WorkOrder, and Technician with their classification badges on the ERD canvas.
✅ Checkpoint:Entity cards display inherited FROM TRAITS fields (tenantId, deletedAt, parentId, createdAt, updatedAt) directly on the ERD canvas and CreateOne weaves trait hooks cleanly across Zones 1–3.
Primary TrackWorkOrder composes MultiTenant, SoftDelete, and Auditable (with status flagged for State Machine Studio), while FieldAsset stacks MultiTenant, Hierarchical, and Auditable for recursive parent-child asset trees.
  1. Attach & Inspect MultiTenant, SoftDelete & Auditable on WorkOrder: Expand WorkOrder in Object Browser (or click + Trait on the entity card) to confirm MultiTenant, SoftDelete, and Auditable alongside the stateMachine: true status attribute.
  2. Verify Hierarchical Equipment Trees on FieldAsset: Ensure 🧩 Traits is active on Diagram View and inspect the dashed Hierarchical children connector added automatically on FieldAsset (parentId + parent/children relations).
  3. Inspect All Three Generated Service Lifecycle Zones: Open "Under the Hood" below and switch to Generated CreateOne Service to trace Zone 1 (PRE_VALIDATE tenantId check), Zone 2 (PRE_CREATE Auditable timestamps, Prisma write, POST_CREATE), and Zone 3 (AFTER_COMMIT).