domain-entity-uuidv4-ids
Domain Entity UUIDv4 IDs
Goal
Represent domain entity identifiers with UUIDv4.
When the programming language or standard library provides a built-in UUID type, prefer that type for domain entity IDs. When no such built-in type exists, use string for domain entity IDs and keep UUIDv4 generation and validation explicit.
Treat this skill as identity-format guidance for domain entities. It determines the identifier format (UUIDv4) and the underlying type (built-in UUID or string). Whether to wrap that underlying type in a distinct type per domain entity — such as OrderId or CustomerId — is a separate concern handled by the domain-entity-typed-ids skill.
The key question is whether the edited code defines, carries, validates, stores, serializes, or exposes the identifier of a domain entity.
What Counts as In Scope
Apply this skill to code that does one or more of these things:
- defines the ID field or property of a domain entity
- defines constructor parameters or factory inputs for domain entity identity
- defines the type used to carry a domain entity ID through the domain model
- parses, validates, serializes, or deserializes domain entity IDs
- maps domain entity IDs to persistence, transport, or integration boundaries
- creates new domain entity IDs
- compares or stores identity values used to distinguish one entity from another
UUIDv4 Rule
-
Use UUIDv4 for every domain entity identifier touched by the task.
- Preserve UUIDv4 semantics across in-memory representation, persistence mappings, and exchanged payloads.
- Do not weaken the identifier representation to an unconstrained string when a built-in UUID type exists.
-
Prefer the language's built-in UUID type when available.
- Use the native or standard-library UUID type directly when the language makes it available and the project conventions allow it.
- Do not fall back to
stringwhen a built-in UUID type exists.
-
When no built-in UUID type exists, use
string.- Use
stringas the underlying identifier type. - Keep generation, parsing, and validation explicit enough that UUIDv4 remains the enforced format.
- This rule determines the underlying type only. Whether to wrap it in a typed ID such as
OrderIdis determined by thedomain-entity-typed-idsskill.
- Use
Detection Workflow
-
Find the identity boundary first.
- Locate the fields, properties, constructor arguments, factory inputs, or persistence mappings that represent domain entity identity.
- Check whether the identifier appears in domain code, serialization code, persistence code, or communication contracts.
-
Detect UUID type support in the stack.
- Identify whether the language or standard library offers a UUID type.
- Follow the project's established conventions for importing, constructing, and storing that type.
-
Trace generation and conversion points.
- Identify where new IDs are created.
- Identify where IDs are parsed from text, converted for storage, or emitted across boundaries.
- Verify that UUIDv4 remains the enforced format at each point.
Writing or Changing Domain Entity IDs
-
Keep UUIDv4 explicit in the model.
- Name ID fields and parameters clearly.
- Use the built-in UUID type when available, otherwise use
string.
-
Prefer native UUID handling over ad hoc strings.
- Use the built-in UUID type when available instead of representing IDs as generic text.
- Keep conversions at boundaries small and explicit.
-
Use
stringwhen the language has no built-in UUID type.- Keep the UUIDv4 contract explicit at parsing, validation, serialization, and generation points.
- This determines the underlying type. Whether to wrap it in a typed ID is a separate concern.
-
Preserve identity consistency end to end.
- Verify that the same UUIDv4 value can move through constructors, domain methods, persistence mappings, serializers, and external contracts without losing meaning.
- Verify that new IDs are generated as UUIDv4, not merely accepted in that format.
-
Keep validation close to parsing or construction.
- Reject malformed or non-UUIDv4 inputs when IDs enter the system as text or external data.
- Make the valid construction path obvious in the code.
Review Questions
When reading or reviewing code, ask:
- Is this code defining or carrying the identity of a domain entity?
- Is that identity represented as UUIDv4?
- Does the stack provide a built-in UUID type that should be used here?
- If not, is the identity represented as
stringwith explicit UUIDv4 handling? - Where is UUIDv4 generated, parsed, validated, stored, or serialized?
- Would changing this code risk weakening the UUIDv4 guarantee for domain entity identity?
If the answer is yes, apply this skill.
Report the Outcome
When finishing the task:
- state which domain entity IDs were identified or changed
- state whether a built-in UUID type or
stringwas used, and why - state where UUIDv4 generation, parsing, validation, or conversion was implemented or preserved
More from code-sherpas/agent-skills
neverthrow-return-types
Require `neverthrow`-based return types in TypeScript and JavaScript code whenever the surrounding technology allows it. Use when creating, refactoring, reviewing, or extending standalone functions, exported module functions, class methods, object methods, service methods, repository methods, and similar APIs that should expose explicit success and failure result types in their signatures. Prefer `Result<T, E>` for synchronous code and `ResultAsync<T, E>` for asynchronous code. Only skip a `neverthrow` return type when a framework, library, runtime interface, or externally imposed contract is incompatible and requires a different return shape.
16neverthrow-wrap-exceptions
Capture exceptions and promise failures with `neverthrow` instead of hand-written `try/catch` in TypeScript and JavaScript code. Use when wrapping synchronous functions that may throw, promise-returning functions that may throw before returning, existing `PromiseLike` values that may reject, or third-party APIs such as parsers, database clients, HTTP clients, file-system helpers, serializers, and SDK calls. Prefer `Result.fromThrowable` for synchronous throwers, `ResultAsync.fromThrowable` for promise-returning functions that may throw or reject, and `ResultAsync.fromPromise` when you already have a `PromiseLike` value in hand. Only keep `try/catch` when the language construct, cleanup requirement, or framework boundary truly requires it.
11atomic-design
Create or update web UI components with a strict reuse-first workflow. Use when building, refactoring, restyling, or extending frontend or template components while minimizing raw DOM or HTML by reusing or generalizing existing components first.
10write-persistence-representations
Create or update persistence-layer data representations in any stack, including ORM entities, schema definitions, table mappings, document models, collection definitions, and similar database-facing code. Use when agents needs to add or change persisted fields, identifiers, relationships, indexes, timestamps, auditing fields, or storage mappings in frameworks, libraries, or ORMs such as Prisma, TypeORM, Sequelize, Drizzle, Mongoose, Hibernate/JPA, Doctrine, Ecto, Active Record, or equivalent persistence technologies.
7business-logic
Identify, interpret, review, or write business logic in code. Use when an agent needs to decide whether code expresses business rules, business algorithms, or business workflows, or when it must implement, preserve, or refactor code that creates, stores, or transforms data according to real business policies.
7immutable-domain-entities
Require the immutable design pattern for domain entities. Use when an agent needs to create, modify, review, or interpret domain entities and should preserve identity while expressing state changes through new immutable instances. Domain entities must be modeled as immutable classes, not as plain type aliases or interfaces paired with standalone functions.
7