---
name: "mikro-orm-unit-of-work-identity-map"
description: "Manage database state with enterprise Unit of Work and Identity Map patterns using MikroORM."
metadata:
  author: "MikroORM"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "use mikro-orm entitymanager"
  - "mikro-orm unit of work flush"
  - "identity map mikro-orm"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# MikroORM Unit of Work Pattern & Identity Map Architecture

Implements MikroORM: defining entities with @Entity and Property decorators, EntityManager with fork() scoping per request, automated change tracking (flushing dirty entities), and preventing duplicate entity loads.

## When to Invoke
Invoke this skill whenever you need to:
- use mikro-orm entitymanager
- mikro-orm unit of work flush
- identity map mikro-orm

## Execution SOP & Rules
1. Initialize: const orm = await MikroORM.init(config).
2. Fork EntityManager per request: const em = orm.em.fork() to isolate unit-of-work transactions.
3. Mutate entities directly: user.name = 'New Name'; em.persist(newOrder); await em.flush().
4. Leverage automated dirty tracking to emit minimal SQL UPDATE statements for changed columns only.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
