persistence-patterns

persistence-patterns is a skill for Claude Code, Codex from garrettw/php-arch-skills. It costs 58 tokens per session (2,285 once invoked), scanned A, original, MPL-2.0.

Guidance for storing application data in databases and choosing between simple database models and more separated structures such as mappers and repositories. A mapper translates between database records and application objects; a repository provides an application-facing way to retrieve them.

In plain words
What is it for?
Use it when implementing PHP database persistence, selecting data-source patterns, defining repositories, writing mappers, or deciding how much database code belongs in the domain.
Why use it?
It helps avoid unnecessary database abstraction for simple data while preserving separation when business rules are complex or storage may change. It also clarifies how to split large repositories.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it when implementing PHP database persistence, selecting data-source patterns, defining repositories, writing mappers, or deciding how much database code belongs in the domain.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/garrettw/php-arch-skills/persistence-patterns
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add garrettw/php-arch-skills --skill persistence-patterns
Clone the repo
git clone --depth 1 https://github.com/garrettw/php-arch-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for persistence-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/garrettw/php-arch-skills/persistence-patterns/github.svg)](https://agentmods.dev/skills/garrettw/php-arch-skills/persistence-patterns)
Your own site
<a href="https://agentmods.dev/skills/garrettw/php-arch-skills/persistence-patterns"><img src="https://agentmods.dev/badge/skills/garrettw/php-arch-skills/persistence-patterns/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for persistence-patterns

Your own site · 80×15
<a href="https://agentmods.dev/skills/garrettw/php-arch-skills/persistence-patterns"><img src="https://agentmods.dev/badge/skills/garrettw/php-arch-skills/persistence-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 58 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,285 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00058 $0.02285
Opus 5.5 $0.00023 $0.00914
Sonnet 5.5 $0.00012 $0.00457
Haiku 4.5 $0.00006 $0.00229

Measured 15d ago against content hash 7dbb35b802bf, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

persistence-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 15d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/persistence-patterns/SKILL.md · 101 lines

How it starts

The opening of the file, as written. The whole thing — 101 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Persistence, Mappers & Repositories in PHP

When to Use Rich Persistence vs. Simple ORM

Rich persistence (Mapper + Repository) is only worth the ceremony when the application has complex invariants that persistence concerns would otherwise compromise. Easy storage swaps are rarely the real benefit (see data-mapper.md). Use simple ORM for straightforward CRUD.

Use Rich Persistence (Mapper + Repository) Use Simple ORM (Entity + Query Builder)
Complex business invariants to protect Single-table CRUD with few rules
Domain must stay free of persistence code The schema is the model
Tests must run without DB for domain logic Schema changes hand-in-hand with feature
Long-lived system, evolving requirements Prototype, MVP, throwaway code

A library or package that simply exposes data objects should not include mappers or repository interfaces.

Data Source Spectrum & Gateway vs Repository

Persistence structure is a separate axis from domain-logic style. There is a progression of increasing separation between business logic and storage: Table Data Gateway → Row Data Gateway → Active Record → Data Mapper. Pick the lightest one that fits the area: a Table Data Gateway for rows with no behavior, Active Record for CRUD-heavy areas with modest rules, and a Data Mapper when a rich domain model must stay free of persistence concerns. Avoid Row Data Gateway in new code. data-source-patterns.md is the full treatment of the spectrum, its philosophy, and when Active Record has outgrown its limits.

The distinction between a Gateway and a Repository is subtle but critical:

  • A Gateway thinks in tables: "How do I fetch rows from this table?" It returns rows/recordsets and uses persistence language.
  • A Repository thinks in business concepts: "How do I retrieve domain objects?" It returns domain objects in the ubiquitous language.

Read the full file on GitHub · 101 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 15d ago Changed · +1 tokens per session 7dbb35b802bf
  2. 18d ago Changed · +2 lines 9c0cf4a6ee1b
  3. 19d ago Changed · -3 lines 6e91d8ce1d0c
  4. 20d ago Changed · +4 lines 3fc4806a3ba5
  5. 3mo ago First seen · 98 lines · 57 tokens per session scan A 8616ffc1def1

Subscribe to this mod's changes

persistence-patterns is a skill published in the GitHub repository garrettw/php-arch-skills (17 stars, last pushed 2d ago), licensed MPL-2.0. It adds 58 tokens to every session and 2,285 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

persistence-patterns compared with skills from other repositories

persistence-patterns next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
persistence-patternsgarrettw/php-arch-skillsSkill172d agoMPL-2.0A58Claude Code, Codex
cqrs-event-sourcing-designercodebygarv/Ai-skillsSkill283mo agoMITA30Claude Code, Codex
architecture-paradigm-cqrs-esathola/claude-night-marketSkill358yesterdayMITA33Claude Code
bitrix-performancebxmaximum/bitrix-framework-skillsSkill78yesterdayMITA51Claude Code, Codex
bitrix-postgresqlbxmaximum/bitrix-framework-skillsSkill78yesterdayMITA51Claude Code, Codex
doctrine-batch-processingdev-toolings/superpowers-symfonySkill23622d agoMITA29Claude Code
doctrine-eventsdev-toolings/superpowers-symfonySkill23622d agoMITA32Claude Code