Prisma Domain Mapper Generator

Generate bidirectional mappers converting Domain Entities to Prisma Models and back.

Updated Oct 31, 2025
One-click install
npx skills add https://github.com/RomualdP/hoki --skill prisma-domain-mapper-generator
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Prisma Domain Mapper Generator
Source: https://github.com/RomualdP/hoki/tree/main/.claude/skills/prisma-mapper
Command: npx skills add https://github.com/RomualdP/hoki --skill prisma-domain-mapper-generator

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @prisma/client.

What problem does it solve?

This Skill solves the problem of coupling the Domain Layer to the database technology (Prisma) by generating robust bidirectional mappers, ensuring the core business logic remains pure, testable, and independent of persistence details.

Core Features & Use Cases

  • Bidirectional Mapping: Creates static toDomain() (Prisma Model → Domain Entity) and toPrisma() (Domain Entity → Prisma Input) methods for seamless data conversion.
  • Value Object Reconstruction: Guides on correctly reconstructing Value Objects from primitive database values when mapping to the domain.
  • Relation Handling: Provides patterns for mapping 1-to-1 and 1-to-many relations, including handling nullable fields and nested creates.
  • Use Case: When fetching a Club from the database, the ClubRepository uses ClubMapper.toDomain() to convert the raw Prisma Club model into a rich Club domain entity with its associated ClubName Value Object, ready for business logic.

Quick Start

To create a mapper, define static toDomain(prismaModel: PrismaModel): DomainEntity and static toPrisma(domainEntity: DomainEntity): PrismaCreateInput methods. Ensure toDomain() reconstructs Value Objects and toPrisma() extracts primitives.

Frequently Asked Questions about Prisma Domain Mapper Generator

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I separate my domain logic from Prisma database models?

Domain isolation uses bidirectional mappers that convert Prisma models to domain entities and back. Static `toDomain()` and `toPrisma()` methods keep your core business logic independent of database technology, ensuring testability and clean architecture while maintaining type safety across the persistence boundary.

What's the best way to map Prisma relations to domain entities?

Mapper patterns handle 1-to-1 and 1-to-many relations by reconstructing Value Objects from database primitives in `toDomain()`, and extracting primitives for create/update inputs in `toPrisma()`. Nullable fields and nested creates are managed through explicit relation handling that preserves domain invariants.

How do I reconstruct Value Objects when fetching data from Prisma?

The `toDomain()` method converts raw Prisma model primitives into rich Value Objects by calling their constructors with database values. This reconstruction ensures domain entities carry validated, immutable values rather than raw database columns, restoring business logic semantics.

Can I use Prisma mappers with repositories for database abstraction?

Yes. Repositories use mapper methods to abstract persistence details: `ClubRepository` calls `ClubMapper.toDomain()` when fetching, converting raw Prisma results into domain entities ready for business logic, and `toPrisma()` when persisting changes back to the database.

Do I need to maintain separate input types for Prisma create and update operations?

Yes. The `toPrisma()` method handles mapping domain entities to Prisma input types that match your create/update operations, extracting only the primitives needed while respecting Prisma's input constraints and maintaining type safety throughout the persistence layer.

Why should I use mappers instead of exposing Prisma models directly to my domain?

Direct exposure couples your business logic to database schema changes and Prisma implementation details. Mappers maintain a contract between layers: domain entities remain pure and testable, persist independently of ORM evolution, and define explicit boundaries for data transformation rules.