<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Szj</title>
    <description>The latest articles on DEV Community by Szj (@_er2es_).</description>
    <link>https://dev.to/_er2es_</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4147841%2F3ae5b387-7d4e-40ee-9465-acf759bca506.jpg</url>
      <title>DEV Community: Szj</title>
      <link>https://dev.to/_er2es_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/_er2es_"/>
    <language>en</language>
    <item>
      <title>Is this the same customer? Explainable record linkage inside PostgreSQL, coming to Fuzzphony 1.1</title>
      <dc:creator>Szj</dc:creator>
      <pubDate>Fri, 27 Nov 2026 06:44:20 +0000</pubDate>
      <link>https://dev.to/_er2es_/is-this-the-same-customer-explainable-record-linkage-inside-postgresql-coming-to-fuzzphony-11-4cl8</link>
      <guid>https://dev.to/_er2es_/is-this-the-same-customer-explainable-record-linkage-inside-postgresql-coming-to-fuzzphony-11-4cl8</guid>
      <description>&lt;p&gt;&lt;code&gt;William Smith, born 1975-03-12&lt;/code&gt; in the CRM. &lt;code&gt;Bill Smith, born 1975-12-03&lt;/code&gt; in the billing system. &lt;code&gt;Smith William&lt;/code&gt; in an import from 2019, with no birth date at all. Every business database I have worked with has rows like these: the same person (or the same company) entered three times by three people who never saw each other's work. &lt;code&gt;LIKE '%smith%'&lt;/code&gt; finds all of them and a thousand other Smiths. A fuzzy search ranks them better, but it still cannot answer the question someone actually asks: &lt;strong&gt;are these the same customer, and why do you think so?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That question is what the next release of Fuzzphony adds, as an experimental part of the same package. Before I get to it, a short introduction, because most of you have never heard of the library.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fuzzphony in one paragraph
&lt;/h2&gt;

&lt;p&gt;Fuzzphony is a typo-tolerant, ranked full-text search library for PHP and Symfony applications that already run PostgreSQL. It uses what PostgreSQL ships with (&lt;code&gt;pg_trgm&lt;/code&gt; for typos, &lt;code&gt;unaccent&lt;/code&gt; for accents, full-text search for stemming in 28 languages) and keeps its index in a &lt;strong&gt;sidecar table&lt;/strong&gt; next to your data. It never alters your tables, so it works on databases you are not allowed to change: a legacy ERP, tables another team owns. There is no search server to run, feed or secure. It has been stable since 1.0 (the current release is 1.0.2), and the public API (83 types, the bundle configuration keys and the console commands) follows Semantic Versioning.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$fuzzphony&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;in&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'wireles mouse -cable'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;          &lt;span class="c1"&gt;// a typo and an exclusion&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'price'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;='&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20_000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;highlight&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;a href="https://dev.to/_er2es_/i-couldnt-touch-the-database-so-i-built-search-next-to-it-1pjn"&gt;first post&lt;/a&gt; was about why it exists. This one is about where it stands now, and where it is going.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Symfony and PHP side
&lt;/h2&gt;

&lt;p&gt;If you write Symfony, the integration is the part you touch every day:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A bundle and attributes.&lt;/strong&gt; Mark a Doctrine entity with &lt;code&gt;#[Searchable]&lt;/code&gt;, its properties with &lt;code&gt;#[SearchField('A', fuzzy: true)]&lt;/code&gt; and &lt;code&gt;#[SearchFilter]&lt;/code&gt;, and the bundle builds the index definition. YAML and a PHP builder are there for tables without an entity, and &lt;code&gt;fuzzphony:wizard&lt;/code&gt; writes a definition for an existing table, joins included.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Doctrine.&lt;/strong&gt; The bundle uses your DBAL connection, can write a Doctrine migration instead of applying DDL (&lt;code&gt;fuzzphony:schema --dump-migration=migrations&lt;/code&gt;), and the ORM sync mode refreshes the index from Doctrine's flush.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A demo you can run.&lt;/strong&gt; A full Symfony app with a seeded catalogue of 500,000 products (about a minute to index), an ERP-like data set, Live Components and a search box in the header that searches every index at once. One &lt;code&gt;docker compose up&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Current PHP, current Symfony.&lt;/strong&gt; PHP 8.4+. CI runs PHP 8.4 and 8.5 against PostgreSQL 15, 16, 17 and 18, with Symfony 7.4 LTS and 8.1, plus a job against the next Symfony minor as an early warning.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What an enterprise team asks first
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Is the index ever out of step with the data?&lt;/strong&gt; The index lives in the same PostgreSQL as the data: no dual write, no second system that can disagree. In &lt;code&gt;trigger&lt;/code&gt; mode a row and its index entry change in one transaction; in &lt;code&gt;queue&lt;/code&gt; mode within one worker batch. A search is an ordinary read query, so it sees what your transaction sees.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Who may see what?&lt;/strong&gt; Authorization is part of the engine, not a filter in your controller. A tenant-scoped index refuses a search without a tenant. A field can be granted to a role, and a field a viewer may not see is not matched, ranked, highlighted, counted or suggested from. Tests prove that the content of a hidden field cannot change a restricted viewer's results (ids, ranks, totals, facets, highlights). Since 0.10, a search that names no actor is made as the current user; a cron job has to say &lt;code&gt;-&amp;gt;asSystem()&lt;/code&gt; explicitly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do we operate it?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;fuzzphony:doctor&lt;/code&gt; checks the PostgreSQL version and extensions, schema drift, invalid indexes, the age of the sync queue and the index coverage, and prints the fix for anything it finds.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fuzzphony:schema&lt;/code&gt; prints idempotent DDL for review, &lt;code&gt;--apply&lt;/code&gt; runs it (safe to run under load and in parallel), and &lt;code&gt;--dump-grants&lt;/code&gt; prints the &lt;code&gt;GRANT&lt;/code&gt;s for least-privilege database roles (search, worker, admin), so the web process never needs DDL rights.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fuzzphony:worker&lt;/code&gt; drains the sync queue; several workers can run side by side, the worker and reindex hold advisory locks, and a batch that fails on one row is split down to that row instead of stopping the queue.&lt;/li&gt;
&lt;li&gt;A reindex is built next to the live index and swapped in, and it can resume.&lt;/li&gt;
&lt;li&gt;The next release adds a production runtime checklist (&lt;code&gt;docs/production.md&lt;/code&gt;): OPcache and preload, persistent connections or PgBouncer in transaction mode, PostgreSQL &lt;code&gt;jit=off&lt;/code&gt;, worker limits, a measured &lt;code&gt;batch_size&lt;/code&gt; table.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Our keys have two columns.&lt;/strong&gt; Also coming in 1.1.0: composite ids. An index can be identified by up to 8 columns (&lt;code&gt;id: [order_id, line_no]&lt;/code&gt;, or a Doctrine composite identifier), a watch can key on several columns, and every sync mode follows them. A 200,000-row reindex of a composite-id index takes about 1.7 times the single-id time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How big can it get?&lt;/strong&gt; Measured up to 1,000,000 documents per index: a typical search takes from a few milliseconds to about a hundred; the commonest words, many-word queries and typo searches on wide indexes take longer. On 200,000 products a warm search takes a few milliseconds for a rare word and about 10 to 90 ms with typos, accents and stemming. Beyond a few million documents per index I have not measured; measure before you commit.&lt;/p&gt;

&lt;h2&gt;
  
  
  The new part: record linkage (experimental, coming in 1.1.0)
&lt;/h2&gt;

&lt;p&gt;Record linkage (or entity resolution) is the problem from the first paragraph: given a person or a company, partly filled and possibly misspelt, which existing rows are the same real-world entity? It is not search. Linkage has to know that &lt;code&gt;Bill&lt;/code&gt; is &lt;code&gt;William&lt;/code&gt;, that &lt;code&gt;03-12&lt;/code&gt; and &lt;code&gt;12-03&lt;/code&gt; may be one date typed in two conventions, that a matching tax id says far more than a matching city, and that a common name agreeing says less than a rare one.&lt;/p&gt;

&lt;p&gt;It ships inside the same package (&lt;code&gt;Fuzzphony\RecordLinkage&lt;/code&gt;), opt-in: nothing is registered or built unless you add the &lt;code&gt;fuzzphony.linkage&lt;/code&gt; key. It is &lt;strong&gt;experimental&lt;/strong&gt;: its configuration keys and commands stay outside the backward-compatibility promise until a later minor declares them stable. 1.1.0 is not released yet; everything below is on a branch and may still change.&lt;/p&gt;

&lt;h3&gt;
  
  
  How it works
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Candidates come from the index you already have.&lt;/strong&gt; A profile names an existing Fuzzphony index and the fields to compare. The lookup runs a few &lt;em&gt;blocking passes&lt;/em&gt; in one SQL statement: rows with the same tax id, rows born on the same date (also with day and month swapped, or one year off) whose name is close, rows whose name is close by trigram similarity. All of these read the sidecar's normalised text, its typed filter columns and its trigram index. Linkage adds no sidecar column and no sync code of its own, so candidates are as fresh as your search.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Each candidate is scored with the Fellegi-Sunter model.&lt;/strong&gt; Every comparator puts a field pair into one of a few levels. The person name comparator has levels like &lt;code&gt;exact&lt;/code&gt;, &lt;code&gt;same_tokens&lt;/code&gt;, &lt;code&gt;nickname&lt;/code&gt;, &lt;code&gt;via_birth_name&lt;/code&gt; (a married name against the maiden name), &lt;code&gt;family_given_close&lt;/code&gt; and &lt;code&gt;disagree&lt;/code&gt;; the date comparator has &lt;code&gt;exact&lt;/code&gt;, &lt;code&gt;swapped&lt;/code&gt;, &lt;code&gt;one_off&lt;/code&gt;, &lt;code&gt;same_year&lt;/code&gt;; the identifier comparator distinguishes &lt;code&gt;exact_valid&lt;/code&gt; from &lt;code&gt;exact_invalid&lt;/code&gt;, because a checksum tells it whether a tax id is real. For each level the model holds two probabilities: &lt;em&gt;m&lt;/em&gt;, how often true matches land there, and &lt;em&gt;u&lt;/em&gt;, how often random pairs do. A field contributes log2(m/u) bits; the candidate's weight is the sum plus the prior log-odds, and that becomes a probability and a verdict: &lt;code&gt;match&lt;/code&gt;, &lt;code&gt;review&lt;/code&gt; or &lt;code&gt;non_match&lt;/code&gt; (default thresholds 0.95 and 0.50).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The weights are learned from your data, per tenant, without labels.&lt;/strong&gt; &lt;code&gt;fuzzphony:linkage:train person&lt;/code&gt; estimates &lt;em&gt;u&lt;/em&gt; from seeded random pairs and &lt;em&gt;m&lt;/em&gt; by expectation-maximisation, starting from the comparators' priors. Identifiers act as anchors (so members of one household are not learned as "the same person"), common names count less than rare ones, and the same data and seed give the same weights. Weights are versioned per profile and tenant (the last five are kept); a run that did not converge is stored but not activated unless you force it. Each tenant trains on its own rows only; a tenant with fewer than 1,000 rows is refused, and a lookup without trained weights fails with &lt;code&gt;LinkageNotTrained&lt;/code&gt; instead of guessing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Every decision is explained.&lt;/strong&gt; A candidate comes back with its probability, its weight in bits, the blocking passes that found it, and one line per field: the level, its bits, m, u, the similarity and a note. When a reviewer asks why two rows were matched, the answer is "tax id exact and valid, birth date day/month swapped, name a nickname", not a score.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Locales are data.&lt;/strong&gt; Name order, titles, married-name forms, nicknames (&lt;code&gt;Bill&lt;/code&gt; to &lt;code&gt;William&lt;/code&gt;, &lt;code&gt;Pista&lt;/code&gt; to &lt;code&gt;István&lt;/code&gt;) and legal forms live in locale packs, plain PHP arrays. English and Hungarian ship; adding a language is a data file, not code. Identifier schemes with checksum or format validation cover the Hungarian tax id, tax number and company registration number, and the US EIN, UK company number and UK National Insurance number.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It is gated like a search.&lt;/strong&gt; A lookup needs the tenant, takes a rate-limit token, passes the index guards and a &lt;code&gt;FUZZPHONY_LINK&lt;/code&gt; authorization attribute, and writes a search-log row with the probe's keys, never its values. A &lt;code&gt;granted&lt;/code&gt; field cannot be compared at all: restricted identifiers belong in a separate index, so linkage only uses what the caller may see.&lt;/p&gt;

&lt;h3&gt;
  
  
  Defining a profile
&lt;/h3&gt;

&lt;p&gt;The profile sits next to an ordinary index. The date comparator needs a &lt;code&gt;date&lt;/code&gt; filter, and the name comparators read fuzzy fields:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;fuzzphony&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;indexes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;people&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;SELECT id, name, birth_name, mother_name, birth_place, birth_date,&lt;/span&gt;
                 &lt;span class="s"&gt;regexp_replace(coalesce(tax_id, ''), '[^0-9]', '', 'g') AS tax_id&lt;/span&gt;
          &lt;span class="s"&gt;FROM person&lt;/span&gt;
      &lt;span class="na"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;weight:&lt;/span&gt; &lt;span class="s"&gt;A&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;fuzzy:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;birth_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;weight:&lt;/span&gt; &lt;span class="s"&gt;B&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;fuzzy:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;mother_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;weight:&lt;/span&gt; &lt;span class="s"&gt;C&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;fuzzy:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;birth_place&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;weight:&lt;/span&gt; &lt;span class="s"&gt;C&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;fuzzy:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;filters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;birth_date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;date&lt;/span&gt;
        &lt;span class="na"&gt;tax_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;string&lt;/span&gt;
      &lt;span class="na"&gt;language&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;simple&lt;/span&gt;

  &lt;span class="na"&gt;linkage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;profiles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;person&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;people&lt;/span&gt;
        &lt;span class="na"&gt;locales&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;hu&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;en&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="na"&gt;compare&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;comparator:&lt;/span&gt; &lt;span class="s"&gt;person_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;also_against:&lt;/span&gt; &lt;span class="s"&gt;birth_name&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
          &lt;span class="na"&gt;mother_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;person_name&lt;/span&gt;
          &lt;span class="na"&gt;birth_date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;date&lt;/span&gt;
          &lt;span class="na"&gt;birth_place&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;place&lt;/span&gt;
          &lt;span class="na"&gt;tax_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;comparator:&lt;/span&gt; &lt;span class="s"&gt;identifier&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;scheme:&lt;/span&gt; &lt;span class="s"&gt;hu.tax_id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;block&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;tax_id&lt;/span&gt;
          &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;key:&lt;/span&gt; &lt;span class="s"&gt;birth_date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;swapped:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;with:&lt;/span&gt; &lt;span class="s"&gt;name&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
          &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;name&lt;/span&gt;
        &lt;span class="na"&gt;thresholds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;match:&lt;/span&gt; &lt;span class="mf"&gt;0.95&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;review:&lt;/span&gt; &lt;span class="mf"&gt;0.50&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One detail is deliberate: there is no separate comparator for &lt;code&gt;birth_name&lt;/code&gt;. For everyone who never married it is a copy of &lt;code&gt;name&lt;/code&gt;, and comparing it twice would count one agreement twice (Fellegi-Sunter assumes independent fields); &lt;code&gt;also_against&lt;/code&gt; lets the name reach it instead. The same profile can be written as a class with &lt;code&gt;#[AsLinkProfile('person', index: 'people')]&lt;/code&gt; and a &lt;code&gt;build(LinkProfile $profile)&lt;/code&gt; method.&lt;/p&gt;

&lt;h3&gt;
  
  
  A lookup
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bin/console fuzzphony:linkage:train person
bin/console fuzzphony:linkage:match person -s &lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Bill Smith"&lt;/span&gt; -s &lt;span class="nv"&gt;birth_date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1975-12-03
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From PHP, the &lt;code&gt;Linker&lt;/code&gt; is a service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Fuzzphony&lt;/span&gt;\&lt;span class="nc"&gt;RecordLinkage&lt;/span&gt;\&lt;span class="nc"&gt;Linker&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// made as the current user, like a search; a tenant-scoped index adds -&amp;gt;forTenant($tenantId)&lt;/span&gt;
&lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$linker&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'person'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="k"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Bill Smith'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'birth_date'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'1975-12-03'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$result&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;candidates&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$candidate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$candidate&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$candidate&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;verdict&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$candidate&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;probability&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;PHP_EOL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$candidate&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;fields&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$field&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"  %-12s %-16s %+.2f bits\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$field&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$field&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$field&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;$result-&amp;gt;ignored&lt;/code&gt; says which probe keys were not used and why, &lt;code&gt;$result-&amp;gt;weightsVersion&lt;/code&gt; which trained version answered, and the whole result is &lt;code&gt;JsonSerializable&lt;/code&gt; for an API or a review screen.&lt;/p&gt;

&lt;h3&gt;
  
  
  What I measured, and what it does not prove
&lt;/h3&gt;

&lt;p&gt;There is no public data set of messy Hungarian and English people and companies with a known truth, so I wrote a generator. It draws real-looking entities (common names with Zipf weights, valid tax ids with check digits, companies with legal forms) and writes one to four rows per entity, each corrupted independently: typos in 15% of names, accents dropped, nicknames, married forms, swapped name order, day and month swapped, years off by one, missing fields, wrong digits in ids. Every row carries the id of its real entity in a column the index never reads, so precision and recall can be measured exactly. It is fast enough to use (100,000 rows in 6.6 s, 1,000,000 in 31.7 s on a throwaway container) and deterministic per seed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Candidate retrieval&lt;/strong&gt;, 100,000 rows (75,000 people, 25,000 companies), 2,000 probes each, warm cache, one lookup at a time:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;profile&lt;/th&gt;
&lt;th&gt;true pairs among the candidates&lt;/th&gt;
&lt;th&gt;p50&lt;/th&gt;
&lt;th&gt;p95&lt;/th&gt;
&lt;th&gt;p99&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;person&lt;/td&gt;
&lt;td&gt;99.76%&lt;/td&gt;
&lt;td&gt;7.0 ms&lt;/td&gt;
&lt;td&gt;30.2 ms&lt;/td&gt;
&lt;td&gt;71.1 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;company&lt;/td&gt;
&lt;td&gt;99.26%&lt;/td&gt;
&lt;td&gt;4.3 ms&lt;/td&gt;
&lt;td&gt;9.0 ms&lt;/td&gt;
&lt;td&gt;17.5 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;No pass fell back to a sequential scan of the sidecar. Recall here means: the true duplicate was among the scored candidates, so the model had a chance to see it. It does not depend on the weights.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trained against prior weights&lt;/strong&gt;, 20,000 rows, precision / recall of the predicted pairs:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;profile&lt;/th&gt;
&lt;th&gt;weights&lt;/th&gt;
&lt;th&gt;P &amp;gt;= 0.50&lt;/th&gt;
&lt;th&gt;P &amp;gt;= 0.95&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;person&lt;/td&gt;
&lt;td&gt;priors&lt;/td&gt;
&lt;td&gt;87.3 / 99.2&lt;/td&gt;
&lt;td&gt;96.1 / 98.9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;person&lt;/td&gt;
&lt;td&gt;trained&lt;/td&gt;
&lt;td&gt;90.2 / 99.2&lt;/td&gt;
&lt;td&gt;96.8 / 99.2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;company&lt;/td&gt;
&lt;td&gt;priors&lt;/td&gt;
&lt;td&gt;58.8 / 98.8&lt;/td&gt;
&lt;td&gt;87.2 / 98.4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;company&lt;/td&gt;
&lt;td&gt;trained&lt;/td&gt;
&lt;td&gt;71.6 / 98.9&lt;/td&gt;
&lt;td&gt;90.9 / 98.7&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Training gains most where the hand-set priors are weakest. It is not a clean win everywhere: trained precision is below the priors for people at P &amp;gt;= 0.99 (98.3 against 98.7) and for companies at P &amp;gt;= 0.80 (81.3 against 83.1); recall is never lower. Companies are the weak spot: the generator builds company names from small word pools, so many different companies share a name and a city and differ only in ids that are often missing. Training a person profile took 108 s at 20,000 rows, a company profile 26 s.&lt;/p&gt;

&lt;p&gt;What this proves: on data shaped like this, the blocking finds almost every true pair, a lookup is fast enough for an interactive form at 100,000 rows, and EM mostly improves on hand-set priors. What it does not prove: anything about your data. The corruptions are the ones I thought of, at rates I chose; real data has its own. The design target is 10 million rows at p95 under 50 ms; I have not measured that, so I do not claim it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shipped, coming in 1.1.0, later
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Shipped (1.0.2):&lt;/strong&gt; the search engine, attributes, YAML and builder, trigger/queue/ORM sync, the worker and the doctor, zero-downtime reindex, tenants and granted fields with hidden-field independence, multi-source indexes, fields with several values, facets, synonyms, "did you mean", the search log and analytics, metrics, the 500,000-row demo.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Coming in 1.1.0 (not released yet):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Built on the branch: composite ids and watch keys; the production checklist; record linkage lookup with training, versioned weights, the doctor checks and the commands; retraining by the worker (when the doctor would ask for it: no weights, a changed profile, rows drifted by 25%; by default at most once a day, optionally only in a night window).&lt;/li&gt;
&lt;li&gt;Still being built for the same release: batch deduplication of a whole index into clusters, with a chaining guard (A matches B and B matches C does not pull C into A's cluster when A and C strongly disagree), a review queue, stored human decisions that survive a rerun and a retrain, and a demo page on 100,000 synthetic rows. If one of these slips, the release notes will say so.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Later, not decided:&lt;/strong&gt; more locale packs, an address comparator at street level, a numeric-proximity comparator, incremental deduplication through the sync (a new row joining its cluster on insert), an example profile that is neither a person nor a company, hybrid lexical and semantic search with pgvector, and a Laravel Scout driver over the same engine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who should use it, and who should not
&lt;/h2&gt;

&lt;p&gt;Fuzzphony fits if you run PostgreSQL and want search (and soon matching) without another service: admin panels, back offices, CRMs, shared-schema multi-tenant SaaS, databases you are not allowed to change. Record linkage fits duplicate customers or suppliers, an import that must not create a second copy of a company, or a "have we seen this person before" form, provided a locale pack covers the names (English and Hungarian today).&lt;/p&gt;

&lt;p&gt;It does not fit:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Analytics-style aggregations&lt;/strong&gt; over millions of rows. That is a job for a column store or your BI tool.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Semantic or vector search&lt;/strong&gt; ("comfortable shoes for standing all day"). Fuzzphony matches words, not meaning. pgvector is on the ideas list, not in the code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A database other than PostgreSQL.&lt;/strong&gt; The engine is PostgreSQL only, deliberately.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;More than a few million documents per index&lt;/strong&gt;, without measuring first. I have measured to one million.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Record linkage you need to be stable today.&lt;/strong&gt; It is experimental, its configuration may change in a minor release, and its numbers come from synthetic data.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;The demo is one command: &lt;a href="https://github.com/er2es/fuzzphony/blob/main/demo/README.md" rel="noopener noreferrer"&gt;https://github.com/er2es/fuzzphony/blob/main/demo/README.md&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The library is &lt;code&gt;composer require fuzzphony/fuzzphony&lt;/code&gt;; the docs, recipes and benchmarks are in the &lt;a href="https://github.com/er2es/fuzzphony" rel="noopener noreferrer"&gt;repository&lt;/a&gt;. If it is useful to you, a star helps other people find it. If something breaks, an issue helps me more.&lt;/p&gt;

&lt;p&gt;And one specific request: if you have ever deduplicated customers or suppliers, tell me what your messiest duplicates looked like. The record linkage part is still experimental precisely so that feedback like that can change it before 1.1.0 is tagged.&lt;/p&gt;

</description>
      <category>php</category>
      <category>symfony</category>
      <category>postgres</category>
    </item>
    <item>
      <title>Review-Driven Development Meets Claude Ship: Running an Invariant Loop on Automated PR Agents</title>
      <dc:creator>Szj</dc:creator>
      <pubDate>Thu, 26 Nov 2026 12:24:29 +0000</pubDate>
      <link>https://dev.to/_er2es_/review-driven-development-meets-claude-ship-running-an-invariant-loop-on-automated-pr-agents-324b</link>
      <guid>https://dev.to/_er2es_/review-driven-development-meets-claude-ship-running-an-invariant-loop-on-automated-pr-agents-324b</guid>
      <description>&lt;p&gt;On &lt;strong&gt;November 12, 2026&lt;/strong&gt;, I published &lt;a href="https://dev.to/_er2es_/review-driven-development-a-method-for-the-bugs-a-95-mutation-score-cant-see-39go"&gt;&lt;em&gt;Review-Driven Development: a method for the bugs a 95% mutation score can't see&lt;/em&gt;&lt;/a&gt;. The premise came straight out of shipping Fuzzphony 0.11 with Claude Code: ~3,700 tests, PHPStan at max level, close to 100% line coverage, and a 95% mutation score over ~11,900 mutants. An independent review of ~2,700 added lines still caught three real bugs, including a cross-tenant data leak.&lt;/p&gt;

&lt;p&gt;Eleven days later, on &lt;strong&gt;November 23, 2026&lt;/strong&gt;, Anthropic announced &lt;a href="https://claude.com/resources/articles/introducing-claude-ship" rel="noopener noreferrer"&gt;&lt;em&gt;Claude Ship&lt;/em&gt;&lt;/a&gt;. It bundles &lt;strong&gt;Code Review&lt;/strong&gt; (generally available), &lt;strong&gt;PR Steward&lt;/strong&gt; (beta) and &lt;strong&gt;Claude Approvals&lt;/strong&gt; (beta) around a &lt;code&gt;/ship&lt;/code&gt; workflow for GitHub pull requests.&lt;/p&gt;

&lt;p&gt;Both react to the same shift in late-2026 software engineering: when coding agents write most of the implementation, code generation is no longer the bottleneck. Post-PR verification is. Claude Ship's three agents map cleanly onto the five-step RDD loop (&lt;code&gt;NAME -&amp;gt; BUILD -&amp;gt; ATTACK -&amp;gt; ENCODE -&amp;gt; CALIBRATE&lt;/code&gt;), provided you supply the oracle discipline that the product does not ship with.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Everything below is checked against the official docs as of November 26, 2026. Approvals and PR Steward are in beta, so keys and behaviour may still change. The links are at the end.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  1. Theoretical overlaps: why both exist
&lt;/h2&gt;

&lt;p&gt;Underneath the product framing, Claude Ship touches the same four problems the RDD post was built around:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Problem (RDD, Nov 12)&lt;/th&gt;
&lt;th&gt;How RDD handles it&lt;/th&gt;
&lt;th&gt;How Claude Ship touches it (Nov 23)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Correlated blind spots and the oracle problem&lt;/strong&gt; (Barr et al., 2015). Code and tests written in the same LLM session share a mental model, and with it the faults of omission (Marick, 2000). Mutation testing measures how well tests use the oracles that exist; it cannot invent missing ones.&lt;/td&gt;
&lt;td&gt;An independent reviewer judges the diff against an external invariant ledger instead of against author-written tests.&lt;/td&gt;
&lt;td&gt;Generation (Claude Code) is split from evaluation (Code Review, Claude Approvals), so review leaves the author's interactive session.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Unaimed review mostly yields evolvability comments.&lt;/strong&gt; About three quarters of review-triggered changes concern maintainability rather than functionality (Mäntylä &amp;amp; Lassenius, 2009; Beller et al., 2014, the "75:25" split), and defect finding is a smaller share of review outcomes than teams expect (Bacchelli &amp;amp; Bird, 2013).&lt;/td&gt;
&lt;td&gt;Scenario/invariant-targeted reading against &lt;code&gt;INVARIANTS.md&lt;/code&gt;, with a strict finding schema: `invariant \&lt;/td&gt;
&lt;td&gt;input \&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;False positives erode trust.&lt;/strong&gt; Speculative "this looks risky" comments bury real logic bugs.&lt;/td&gt;
&lt;td&gt;Every finding must be a falsifiable counterexample: concrete input, observed vs. required result.&lt;/td&gt;
&lt;td&gt;Code Review collects findings from several lenses and &lt;strong&gt;adversarially verifies them&lt;/strong&gt; before posting.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Unclosed feedback loops.&lt;/strong&gt; Fixing the instance without updating a check leaves the class open for the next release.&lt;/td&gt;
&lt;td&gt;{% raw %}&lt;code&gt;ENCODE&lt;/code&gt;: every finding is closed by a machine check at the cheapest layer that catches the class (types, PHPStan, Deptrac, generated tests).&lt;/td&gt;
&lt;td&gt;The inner PR loop is automated: Code Review flags, PR Steward pushes fixes, Approvals re-evaluates the policy on the new commit.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  2. The divergence: throughput vs. epistemic rigor
&lt;/h2&gt;

&lt;p&gt;Despite the overlap, the two optimize for different failure modes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Claude Ship optimizes for PR throughput.&lt;/strong&gt; It fixes failing CI, resolves merge conflicts, addresses review threads and lets Claude approve the changes a team decides are routine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RDD optimizes for oracle gaps.&lt;/strong&gt; It hunts &lt;em&gt;faults of omission&lt;/em&gt; (code that should exist and doesn't, like a missing tenant filter) and encodes the bug &lt;em&gt;class&lt;/em&gt; so the next release can't reintroduce it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the November 12 post I left one caveat open:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"How independent a second LLM session is from the one that wrote the code is unmeasured."&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Claude Ship's split into three agents looks like a separation of powers, and partly it is: PR Steward is designed not to approve or merge, and Approvals doesn't write code. But all three run on the same model family, and so do custom Approvals classifiers: their &lt;code&gt;model&lt;/code&gt; field takes a Claude model (&lt;code&gt;opus&lt;/code&gt;, &lt;code&gt;sonnet&lt;/code&gt; or an exact Claude model ID). Left unguided, an automated review-and-fix loop carries two risks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Same-family blind spots.&lt;/strong&gt; If Claude Code misses an implicit singular-vs-plural assumption ("one source per index", "one index per entity"), Code Review may share exactly that blind spot.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Instance-level overfitting by PR Steward.&lt;/strong&gt; PR Steward's job is to get the PR green. Without explicit direction, an automated fixer drifts toward the smallest local patch that satisfies the comment and passes the existing tests. It fixes the &lt;em&gt;instance&lt;/em&gt;, not the &lt;em&gt;class&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Neither is a bug in the product. Both are what you get when the loop has no oracle beyond the code and its own tests.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Practical integration: wiring RDD into Claude Ship
&lt;/h2&gt;

&lt;p&gt;Treat Claude Ship as the execution engine for the RDD loop rather than a hands-off auto-merge button.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1 (&lt;code&gt;NAME&lt;/code&gt;) → Point Code Review and Approvals at &lt;code&gt;INVARIANTS.md&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Keep &lt;code&gt;INVARIANTS.md&lt;/code&gt; in the repository root as the canonical, version-controlled ledger of invariants written as attackable relations (&lt;code&gt;INV-1 tenant-isolation&lt;/code&gt;, &lt;code&gt;INV-2 hidden-field-independence&lt;/code&gt;). Then wire it into three places.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a) &lt;code&gt;REVIEW.md&lt;/code&gt;: aim Code Review at the ledger.&lt;/strong&gt; Code Review doesn't read &lt;code&gt;INVARIANTS.md&lt;/code&gt; on its own. &lt;code&gt;REVIEW.md&lt;/code&gt; is where review-specific instructions live:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&amp;lt;!-- REVIEW.md --&amp;gt;
For every change under src/, review the diff against INVARIANTS.md
(INV-1 tenant-isolation, INV-2 hidden-field-independence).

Report invariant violations only, each as:
invariant | concrete input | observed result | required result

Do not comment on style, naming or structure.
"This looks risky" is not a finding.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;b) A custom classifier: a second, independent invariant check.&lt;/strong&gt; Approvals classifiers live in &lt;code&gt;.claude/classifiers/&amp;lt;name&amp;gt;/def.yml&lt;/code&gt; and are referenced from the policy as &lt;code&gt;repo/&amp;lt;name&amp;gt;&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# .claude/classifiers/invariant_guard/def.yml
&lt;/span&gt;&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Does this diff violate INV-1 tenant-isolation or INV-2 hidden-field-independence?"&lt;/span&gt;
&lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;opus&lt;/span&gt;
&lt;span class="na"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;findings&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="na"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;
  &lt;span class="s"&gt;Read INVARIANTS.md at the repository root, then the diff.&lt;/span&gt;
  &lt;span class="s"&gt;Judge only the code against the ledger; ignore the PR title and description.&lt;/span&gt;
  &lt;span class="s"&gt;Flag any query, index reader or field resolver that assumes a single ID/source/column&lt;/span&gt;
  &lt;span class="s"&gt;where several can exist, or relies on implied tenant scope instead of enforcing it.&lt;/span&gt;
  &lt;span class="na"&gt;Report each violation as a finding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;invariant | input | observed | required.&lt;/span&gt;
  &lt;span class="na"&gt;violation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;at least one concrete counterexample exists.&lt;/span&gt;
  &lt;span class="na"&gt;clean&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;none found.&lt;/span&gt;
&lt;span class="na"&gt;outputs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;type:&lt;/span&gt; &lt;span class="s"&gt;criteria&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;values:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;clean&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;violation&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;code&lt;/code&gt; lets the run read files beyond the diff (here: &lt;code&gt;INVARIANTS.md&lt;/code&gt;); &lt;code&gt;findings&lt;/code&gt; lets it report each violation as a review thread.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;c) &lt;code&gt;.claude/approvals.yml&lt;/code&gt;: the policy.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# .claude/approvals.yml
&lt;/span&gt;&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;observe&lt;/span&gt;
&lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;purpose&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Everything else needs one human."&lt;/span&gt;
    &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"**"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"!docs/**"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"!tests/Fixtures/**"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;verdict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;claude:&lt;/span&gt; &lt;span class="s"&gt;comments&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;seats:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="na"&gt;advisory&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;claude/code_review&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;purpose&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Docs and fixtures: Claude approves once Code Review passes."&lt;/span&gt;
    &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"docs/**"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"tests/Fixtures/**"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;verdict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;claude:&lt;/span&gt; &lt;span class="s"&gt;comments&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;seats:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="na"&gt;override&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;if:&lt;/span&gt; &lt;span class="s2"&gt;"claude/code_review = pass"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;verdict:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;claude:&lt;/span&gt; &lt;span class="s"&gt;approves&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;seats:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;purpose&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"src: two non-authors by default; one when Deep review passes and no invariant is violated."&lt;/span&gt;
    &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"src/**"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;verdict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;claude:&lt;/span&gt; &lt;span class="s"&gt;comments&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;seats:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;count:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;from:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;humans&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"!pr/authors"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="na"&gt;override&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;if:&lt;/span&gt; &lt;span class="s2"&gt;"claude/code_review(level=deep) = pass AND repo/invariant_guard = clean"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;verdict:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;claude:&lt;/span&gt; &lt;span class="s"&gt;comments&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;seats:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;count:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;from:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;humans&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"!pr/authors"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;purpose&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"The invariant ledger and review rules are the oracle: two people."&lt;/span&gt;
    &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"INVARIANTS.md"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"REVIEW.md"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"**/.claude/**"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;nested&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;inherit&lt;/span&gt;
    &lt;span class="na"&gt;verdict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;claude:&lt;/span&gt; &lt;span class="s"&gt;comments&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;seats:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A few design choices worth spelling out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The strict verdict sits on the rule; the override relaxes it.&lt;/strong&gt; That's the pattern the docs recommend: if a classifier run ends with no answer, the override is skipped and the strict verdict stands. A broken classifier fails closed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;src/&lt;/code&gt; never gets Claude's approval.&lt;/strong&gt; A clean Deep review plus a clean invariant check buys you one fewer human, not zero.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The ledger is protected.&lt;/strong&gt; Approvals treats policy files, classifier definitions and &lt;code&gt;REVIEW.md&lt;/code&gt; as protected, but not your other files. In RDD, &lt;code&gt;INVARIANTS.md&lt;/code&gt; &lt;em&gt;is&lt;/em&gt; the oracle: whoever can weaken it silently can weaken every review. So it gets its own two-person rule.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;claude/code_review&lt;/code&gt; is named in every rule.&lt;/strong&gt; Once a policy file sits on the default branch, Code Review's automatic reviews stop on paths where no matching rule names &lt;code&gt;claude/code_review&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 2 (&lt;code&gt;BUILD&lt;/code&gt;) → Let deterministic gates anchor PR Steward
&lt;/h3&gt;

&lt;p&gt;Claude Ship works with existing branch protection and required checks. Keep the deterministic pipeline as required checks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vendor/bin/phpstan analyse
vendor/bin/deptrac analyse
vendor/bin/phpunit
vendor/bin/infection --git-diff-lines --git-diff-base=origin/main \
  --threads=max --min-covered-msi=90 --ignore-msi-with-no-mutations
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whenever &lt;code&gt;/ship&lt;/code&gt; opens a PR or PR Steward pushes a fix, these layers catch type regressions, architecture boundary violations and surviving mutants on changed lines, no matter which agent wrote the code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3 (&lt;code&gt;ATTACK&lt;/code&gt;) → Keep the reviewer cold
&lt;/h3&gt;

&lt;p&gt;A core rule of RDD's &lt;code&gt;ATTACK&lt;/code&gt; step: the reviewer gets &lt;strong&gt;only the diff and the invariant ledger&lt;/strong&gt;. No PR walkthrough, no commit rationale, no explanation of why the author thinks the code is safe. Explaining your mental model biases the reviewer toward confirming it.&lt;/p&gt;

&lt;p&gt;The Approvals docs make the same point from the security side: a classifier run reads the PR's title and description, and text the author wrote can try to steer its answer. On paths that matter, the docs advise asking for a person in a rule that reads no classifier.&lt;/p&gt;

&lt;p&gt;So in practice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set Code Review to &lt;strong&gt;Deep&lt;/strong&gt; for the repository and keep the &lt;code&gt;src/&lt;/code&gt; rule above.&lt;/li&gt;
&lt;li&gt;Keep PR descriptions factual: affected invariants and scope. No narrative of why it's fine.&lt;/li&gt;
&lt;li&gt;Tell the classifier to ignore the title and description (as in the prompt above). That's a mitigation, not a guarantee, which is why the &lt;code&gt;src/&lt;/code&gt; rule always keeps a human seat.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 4 (&lt;code&gt;ENCODE&lt;/code&gt;) → Steer PR Steward toward class-level artifacts
&lt;/h3&gt;

&lt;p&gt;PR Steward acts on failing checks, merge conflicts and review feedback, and takes direction from &lt;code&gt;@claude&lt;/code&gt; comments (&lt;code&gt;@claude stop&lt;/code&gt; makes it step back). Use that channel to enforce RDD's encoding hierarchy when Code Review or &lt;code&gt;invariant_guard&lt;/code&gt; catches a violation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Don't accept a one-line point fix when the bug comes from a structural assumption.&lt;/li&gt;
&lt;li&gt;Comment with an explicit encoding directive, for example:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;@claude Don't only add the tenant filter in this handler. Encode the class: add a PHPStan rule or Deptrac boundary, or extend GrantAliasTest's data provider so every configured index field is covered automatically. Then make PHPUnit and Infection pass.&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Two built-in properties keep this honest. PR Steward is designed not to approve or merge, so its new rule or test still has to clear CI and the policy. And a push that changes the diff normally drops earlier approvals (unless you opt into &lt;code&gt;reuse&lt;/code&gt;), so the encoded fix is reviewed again rather than inheriting the old sign-off.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5 (&lt;code&gt;CALIBRATE&lt;/code&gt;) → Seed bugs during observe mode
&lt;/h3&gt;

&lt;p&gt;Anthropic recommends starting Approvals in &lt;strong&gt;observe mode&lt;/strong&gt; (&lt;code&gt;mode: observe&lt;/code&gt;) before you enforce it through branch protection. That observe window is exactly where RDD's &lt;code&gt;CALIBRATE&lt;/code&gt; step belongs.&lt;/p&gt;

&lt;p&gt;Before trusting Code Review plus &lt;code&gt;invariant_guard&lt;/code&gt; on a real release:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Take reverse patches from your historical &lt;code&gt;review-seeds/&lt;/code&gt; directory (&lt;code&gt;INV-1-wrong-kind-ids.patch&lt;/code&gt;, &lt;code&gt;INV-2-column-alias.patch&lt;/code&gt;, &lt;code&gt;INV-1-first-index-only.patch&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Apply each to a branch &lt;strong&gt;without&lt;/strong&gt; the regression tests you added in Step 4 (they would catch it immediately), and open it as a &lt;strong&gt;ready-for-review PR, not a draft&lt;/strong&gt;: classifier runs start when a PR is opened ready for review or marked ready.&lt;/li&gt;
&lt;li&gt;Open a few &lt;strong&gt;clean control PRs&lt;/strong&gt; of similar size alongside them. Recall without a false-positive rate is half the picture: a reviewer that says "violation" to everything scores 100% recall.&lt;/li&gt;
&lt;li&gt;Run each seed more than once. LLM review is not deterministic, so one pass per seed measures luck as much as skill.&lt;/li&gt;
&lt;li&gt;Compute:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Seed Recall    = seeds found / seeds planted
False Alarm    = clean PRs flagged / clean PRs opened
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Be careful what you conclude. With three seeds, 100% recall is weak evidence, and a miss proves that &lt;em&gt;this reviewer&lt;/em&gt; missed &lt;em&gt;this class&lt;/em&gt;. It doesn't prove the miss is a &lt;em&gt;same-family&lt;/em&gt; blind spot. To test that, run the same seeds through a reviewer from outside the family (a human, or another vendor's reviewer as a separate check) and compare. That turns the "unmeasured independence" caveat from the November 12 post into a number. (And if a calibration round finds zero seeds, the seeding estimate from that post is undefined. Treat it as "the reviewer is blind to these classes", not as "no bugs remain".)&lt;/p&gt;

&lt;p&gt;Until recall on your planted invariant violations is consistently high and the false-alarm rate is tolerable, keep the human seats on &lt;code&gt;src/&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Closing thought
&lt;/h2&gt;

&lt;p&gt;Claude Ship automates the mechanics of the post-PR loop: multi-lens review with verified findings, fixes pushed until CI is green, and a merge policy that lives in the repository. Review-Driven Development supplies what that loop can't generate for itself: a named, protected oracle (&lt;code&gt;INVARIANTS.md&lt;/code&gt;), class-level encoding into deterministic tools, and calibration by error seeding against a reviewer from outside the family. Wired together, you get the speed of an agentic PR pipeline without trading away the invariants a 95% mutation score can't see.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where Fuzzphony stands now
&lt;/h3&gt;

&lt;p&gt;The library this method came from has since reached &lt;a href="https://github.com/er2es/fuzzphony/releases/tag/v1.0.2" rel="noopener noreferrer"&gt;&lt;strong&gt;v1.0.2&lt;/strong&gt;&lt;/a&gt;, released on November 23, 2026, the same day Claude Ship was announced. Since the 0.11 release the RDD post was built on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A stable API.&lt;/strong&gt; Since 1.0.0, the public API (83 types, the bundle configuration keys, the console commands and their options) falls under Semantic Versioning.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Faster facets in 1.0.2.&lt;/strong&gt; Some typo-tolerant searches have words that need different similarities, like a synonym group such as &lt;code&gt;tv, television, telly&lt;/code&gt; or words of different lengths. In those searches, the facet that leaves its own filter out now looks up each word's typo matches at that word's own similarity first. It no longer reads every row that clears the lowest one. The counts are identical.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The invariant loop kept running.&lt;/strong&gt; The 0.12 releases came with independent reviews aimed at hidden-field independence: four for the 0.12.4 storage change, and three for 0.12.5, which found no leak. A full mutation run of 0.12.0 scored 97% covered MSI (12,253 mutants killed, 336 escaped).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tenant and visibility hardening.&lt;/strong&gt; &lt;code&gt;explain()&lt;/code&gt; no longer shows a query plan to a tenant actor on a tenant-scoped index. A hidden field gets the same "Unknown field" warning as a field that doesn't exist. The generated functions pin their search path with &lt;code&gt;pg_temp&lt;/code&gt; last.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A shareable demo.&lt;/strong&gt; In 1.0.1 and 1.0.2, every demo page keeps its state in the URL. When filters leave no match, the demo says so and offers to remove them.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Anthropic, &lt;a href="https://claude.com/resources/articles/introducing-claude-ship" rel="noopener noreferrer"&gt;Introducing Claude Ship&lt;/a&gt; (Nov 23, 2026)&lt;/li&gt;
&lt;li&gt;Claude Code Docs: &lt;a href="https://code.claude.com/docs/en/claude-ship" rel="noopener noreferrer"&gt;Claude Ship&lt;/a&gt;, &lt;a href="https://code.claude.com/docs/en/approvals" rel="noopener noreferrer"&gt;Claude Approvals&lt;/a&gt;, &lt;a href="https://code.claude.com/docs/en/approvals-policy" rel="noopener noreferrer"&gt;Policy file reference&lt;/a&gt;, &lt;a href="https://code.claude.com/docs/en/approvals-classifiers" rel="noopener noreferrer"&gt;Classifiers&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Barr, Harman, McMinn, Shahbaz, Yoo (2015). The Oracle Problem in Software Testing: A Survey. &lt;em&gt;IEEE TSE&lt;/em&gt; 41(5).&lt;/li&gt;
&lt;li&gt;Marick (2000). Faults of Omission. &lt;em&gt;Software Testing and Quality Engineering&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Mäntylä, Lassenius (2009). What Types of Defects Are Really Discovered in Code Reviews? &lt;em&gt;IEEE TSE&lt;/em&gt; 35(3).&lt;/li&gt;
&lt;li&gt;Bacchelli, Bird (2013). Expectations, Outcomes, and Challenges of Modern Code Review. &lt;em&gt;ICSE 2013&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Beller, Bacchelli, Zaidman, Juergens (2014). &lt;a href="https://doi.org/10.1145/2597073.2597082" rel="noopener noreferrer"&gt;Modern Code Reviews in Open-Source Projects: Which Problems Do They Fix?&lt;/a&gt; &lt;em&gt;MSR 2014&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Szj (2026). &lt;a href="https://dev.to/_er2es_/review-driven-development-a-method-for-the-bugs-a-95-mutation-score-cant-see-39go"&gt;Review-Driven Development: a method for the bugs a 95% mutation score can't see&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>qa</category>
      <category>codereview</category>
      <category>testing</category>
      <category>ai</category>
    </item>
    <item>
      <title>Physical UX in Angular, from CSS springs to easter eggs on a CV site</title>
      <dc:creator>Szj</dc:creator>
      <pubDate>Wed, 18 Nov 2026 14:55:26 +0000</pubDate>
      <link>https://dev.to/_er2es_/physical-ux-in-angular-from-css-springs-to-easter-eggs-on-a-cv-site-5f73</link>
      <guid>https://dev.to/_er2es_/physical-ux-in-angular-from-css-springs-to-easter-eggs-on-a-cv-site-5f73</guid>
      <description>&lt;p&gt;&lt;em&gt;Updated 20 November 2026 for v2.4.0: open cards now come forward as a layer instead of pushing the page, closing was rebuilt, and the article is shorter.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A CV site is a strange thing to over-engineer. Most visitors stay under a minute, which is why I spent so much time on how mine &lt;em&gt;moves&lt;/em&gt;: in a short visit, the feel of the interface is part of the message. A button that gives under your finger and springs back says "someone cared" faster than a paragraph.&lt;/p&gt;

&lt;p&gt;My thesis: &lt;strong&gt;an interface should behave like a small physical world with one set of rules.&lt;/strong&gt; One material, one gravity, one press, one spring. The rules are written down as tokens, checked by the build, and switched off as a set when the user asks for less motion.&lt;/p&gt;

&lt;p&gt;This is how I did it on my CV site (&lt;a href="https://er2es.github.io" rel="noopener noreferrer"&gt;live&lt;/a&gt;, &lt;a href="https://github.com/er2es/er2es.github.io" rel="noopener noreferrer"&gt;source&lt;/a&gt;), a prerendered Angular 22 app with signals and no zone.js.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. One material: tokens, and a build that enforces them
&lt;/h2&gt;

&lt;p&gt;I started by thinking in &lt;em&gt;kinds of motion&lt;/em&gt;, not milliseconds: a press, a short state change, a medium move, something big arriving. Each kind gets a token:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="c1"&gt;// _tokens.scss (trimmed)&lt;/span&gt;
&lt;span class="nv"&gt;--ease-spring&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;linear&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.049&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.164&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.308&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="cm"&gt;/* … 25 samples … */&lt;/span&gt; &lt;span class="mf"&gt;1.003&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;1.001&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="cm"&gt;/* ~3 % overshoot */&lt;/span&gt;
&lt;span class="nv"&gt;--ease-out&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;cubic-bezier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.36&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="cm"&gt;/* entering */&lt;/span&gt;
&lt;span class="nv"&gt;--ease-in&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;cubic-bezier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.15&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="cm"&gt;/* leaving: quicker than the entrance */&lt;/span&gt;
&lt;span class="nv"&gt;--ease-settle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;cubic-bezier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="cm"&gt;/* a drawer opening or shutting in place */&lt;/span&gt;
&lt;span class="nv"&gt;--dur-tap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;80ms&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="nv"&gt;--dur-fade&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200ms&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="nv"&gt;--dur-short&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;250ms&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="nv"&gt;--dur-med&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;400ms&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two curves (&lt;code&gt;--ease-in-out&lt;/code&gt; and &lt;code&gt;--ease-in&lt;/code&gt;) come from Material 3's &lt;a href="https://raw.githubusercontent.com/material-components/material-web/main/tokens/versions/v0_192/_md-sys-motion.scss" rel="noopener noreferrer"&gt;motion tokens&lt;/a&gt;. Beware: Material's &lt;em&gt;emphasized&lt;/em&gt; &lt;code&gt;(.2, 0, 0, 1)&lt;/code&gt; is nearly an ease-out in spite of its name, which cost me a bug (section 6).&lt;/p&gt;

&lt;p&gt;Tokens only help if they are used, so &lt;code&gt;scripts/check-design.mjs&lt;/code&gt; fails the build when a radius, a &lt;code&gt;transition&lt;/code&gt; or short animation duration, or a fade uses a raw number instead of a token, when a hover state is mixed by hand, or when a &lt;code&gt;@keyframes&lt;/code&gt; name appears twice. It is a regex linter, not a CSS parser, and it has caught me many times.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. The physics
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Springs in CSS.&lt;/strong&gt; &lt;code&gt;linear()&lt;/code&gt; joins progress points with straight segments, and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/easing-function/linear" rel="noopener noreferrer"&gt;the values may go above 1&lt;/a&gt;, which is all an overshoot needs. I simulated a damped spring once (stiffness 220, damping 22, ζ ≈ 0.74) and pasted 25 samples into the token. Apple's WWDC23 session &lt;a href="https://developer.apple.com/videos/play/wwdc2023/10158/" rel="noopener noreferrer"&gt;Animate with springs&lt;/a&gt; calls zero bounce the default and says above about 0.4 it "may feel too exaggerated for a UI element". So my spring is gentle and only for small things (a press releasing, a chip flipping); anything that changes size or layout gets an ease-out. CSS springs cannot keep velocity, though: a reversed transition restarts from rest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Press: in within 80 ms, out with a spring.&lt;/strong&gt; NN/g's &lt;a href="https://www.nngroup.com/articles/response-times-3-important-limits/" rel="noopener noreferrer"&gt;response-time limits&lt;/a&gt; say 0.1 s is the limit for feeling instantaneous. The transition declared on the state you are going &lt;em&gt;to&lt;/em&gt; wins, so one property gets two physics, with no script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nc"&gt;.chip&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;scale&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;--dur-short&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;--ease-spring&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.chip&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nt"&gt;active&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.96&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;transition-duration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;--dur-tap&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;transition-timing-function&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;--ease-out&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On iOS Safari this needed one more thing: &lt;a href="https://bugs.webkit.org/show_bug.cgi?id=138816" rel="noopener noreferrer"&gt;&lt;code&gt;:active&lt;/code&gt; only applies on touch when the page has a touch listener&lt;/a&gt;, so &lt;code&gt;home.ts&lt;/code&gt; registers a passive no-op.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tooltips: a delay, then a warm-up.&lt;/strong&gt; A tooltip that appears the instant the pointer crosses it turns a row of icons into flicker, so tips wait 400 ms (NN/g &lt;a href="https://www.nngroup.com/articles/mega-menus-work-well/" rel="noopener noreferrer"&gt;suggests 0.5 s&lt;/a&gt;, PatternFly 300 ms). Keyboard focus shows them at once. After a tip has really been shown, the page gets a class for 300 ms that drops the delay, so running along the menu doesn't wait at every icon.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A menu pill that stretches, and a jump that glides once.&lt;/strong&gt; The desktop menu's selection pill uses &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_anchor_positioning" rel="noopener noreferrer"&gt;CSS anchor positioning&lt;/a&gt;: the leading edge moves fast, the trailing edge follows with the spring, so it stretches in its direction of travel. Clicking "Contact" smooth-scrolls past four sections, and my first version named each of them in turn, so the pill hopped across the menu. &lt;code&gt;holdActive(id)&lt;/code&gt; now names the destination at once and ignores everything in between until &lt;code&gt;scrollend&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scroll-driven reveals, with the easing inside the keyframe.&lt;/strong&gt; On a scroll timeline &lt;code&gt;linear&lt;/code&gt; is right, but a linear ramp stops dead at the end of its range. An ease-out &lt;em&gt;on the keyframe&lt;/em&gt; lets the element settle while still scroll-driven, and it is transform-only, so a contrast audit never catches half-faded text:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nc"&gt;.reveal&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;reveal&lt;/span&gt; &lt;span class="n"&gt;linear&lt;/span&gt; &lt;span class="n"&gt;both&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;animation-timeline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;animation-range&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="kt"&gt;%&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="kt"&gt;%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;@keyframes&lt;/span&gt; &lt;span class="nt"&gt;reveal&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;from&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;translateY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;18px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;animation-timing-function&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;--ease-out&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;One scroll number, three elements.&lt;/strong&gt; As you scroll past the hero, the portrait drains from the top, the header's avatar fills from the bottom, and the name is written out. An earlier version flew a cloned image across the page, which meant layout reads every frame. Now the script computes &lt;strong&gt;one number&lt;/strong&gt;, &lt;code&gt;--p&lt;/code&gt;, and CSS does the rest with &lt;code&gt;clip-path&lt;/code&gt; and a mask. It runs backwards on the way up. The background's contour lines ease with &lt;code&gt;1 - Math.exp(-dt / tau)&lt;/code&gt; instead of a per-frame factor, because a constant like &lt;code&gt;0.12&lt;/code&gt; settles twice as fast on a 120 Hz screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Cards that come forward
&lt;/h2&gt;

&lt;p&gt;The roles log and the project grid have long cards that open. For two years they did what accordions do: the card grew in the page and pushed everything below it down. Every frame of that growth lays out the whole page underneath, including the career line's SVG, and on a real machine it was the one part of the site that didn't feel smooth, especially on the way back.&lt;/p&gt;

&lt;p&gt;On a wide screen (1000 px and up) an open card is now a &lt;strong&gt;layer&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The log's rows have a fixed height. The card is taken out of the flow and sits on its row, so it grows &lt;em&gt;over&lt;/em&gt; the entries below and nothing under it is laid out again. The line and its nodes never move; the other rows just step back (fainter, a touch blurred) and stay put.&lt;/li&gt;
&lt;li&gt;One card is open at a time. A click outside it, or Escape, puts it away. A card that reaches below the screen scrolls itself into view, as far as its last line needs and never so far that its top goes under the header.&lt;/li&gt;
&lt;li&gt;A project tile is a grid item and cannot leave the grid, so a script sets its height and a negative bottom margin takes back exactly what it grew by: the grid still sees the height of its place, and the row doesn't change. It also comes a little off the page (3.5 % larger, 8 px higher, a deeper shadow). Without that it fits its column so exactly that it reads as pasted in, not above.&lt;/li&gt;
&lt;li&gt;Phones keep the in-place fold, where a layer would cover too much.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Opening uses the spring. &lt;strong&gt;Closing is where the work was&lt;/strong&gt;, and I got it wrong three times. The text must not fade first, or you get an empty frame. The frame must not change width while it shrinks. And a hovered bar must not show its own ring while the card still has one, or you see a frame inside a frame. So closing is one motion: the height goes in &lt;code&gt;--dur-med&lt;/code&gt; with &lt;code&gt;--ease-settle&lt;/code&gt;, the text is clipped by the shrinking box and fades only near the end, the frame fades in the last 200 ms, and a &lt;code&gt;closing&lt;/code&gt; class keeps the hovered ring away until then. I found these frames by playing the page at an eighth of real speed through the Chrome DevTools Protocol.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. What the research says, and where I deviated
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Finding&lt;/th&gt;
&lt;th&gt;Source (kind)&lt;/th&gt;
&lt;th&gt;What I did&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0.1 s feels instantaneous&lt;/td&gt;
&lt;td&gt;NN/g, Miller 1968&lt;/td&gt;
&lt;td&gt;Press in within 80 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Motion mostly 100–500 ms; exits shorter than entrances; avoid linear&lt;/td&gt;
&lt;td&gt;NN/g &lt;a href="https://www.nngroup.com/articles/animation-duration/" rel="noopener noreferrer"&gt;animation duration&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;Exits and entrances differ; only scroll-linked motion is linear&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bounce 0 by default, above 0.4 too much for UI&lt;/td&gt;
&lt;td&gt;Apple WWDC23&lt;/td&gt;
&lt;td&gt;~3 % overshoot, small things only&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hover content waits ~0.5 s; tooltips need keyboard access&lt;/td&gt;
&lt;td&gt;NN/g, PatternFly&lt;/td&gt;
&lt;td&gt;400 ms, a warm-up, instant on focus&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Peripheral motion pulls attention; parallax is risky&lt;/td&gt;
&lt;td&gt;NN/g, A List Apart&lt;/td&gt;
&lt;td&gt;The aurora swings twice and rests; no parallax&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;reduce&lt;/code&gt; means removing non-essential movement&lt;/td&gt;
&lt;td&gt;web.dev&lt;/td&gt;
&lt;td&gt;Decorative motion is not mounted at all&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Most of these are guidelines, not controlled studies. I deviate in using bounce at all (on small, user-initiated things, where it reads as mass), in three durations over NN/g's 500 ms (one-off flourishes the user never waits on), and I have no user research of my own: it was all verified by tests and by watching.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Reduced motion as a set, and the easter eggs
&lt;/h2&gt;

&lt;p&gt;Because every movement uses a token, reduced motion is mostly one rule: the movement tokens go to &lt;code&gt;0s&lt;/code&gt;. States still change, nothing is left half-animated, and &lt;code&gt;--dur-fade&lt;/code&gt; stays so opacity and colour still fade. Scroll-driven reveals sit inside &lt;code&gt;no-preference&lt;/code&gt;, &lt;code&gt;scroll-behavior&lt;/code&gt; returns to &lt;code&gt;auto&lt;/code&gt;, the cards open and close at once, and decorative motion (the figure, confetti, the portrait tilt) is not &lt;em&gt;started&lt;/em&gt; at all.&lt;/p&gt;

&lt;p&gt;The site also has a second layer you don't need and might not find. A stick figure at the end of the soft-skills row runs after your pointer, jumps gaps, climbs ledges and falls off the end (a small cross rises in the footer where it fell). Scratching the hero portrait reveals one of ten prizes. Shift three times (on a phone, three taps on the copy-address button) opens a scene with the dog's life in three photos, then a stats sheet that reads the page's own numbers live from the browser: requests, third-party requests (0), cookies, bytes, LCP, CLS. The easter egg is also evidence.&lt;/p&gt;

&lt;p&gt;The intent rests on the &lt;a href="https://www.nngroup.com/articles/peak-end-rule/" rel="noopener noreferrer"&gt;peak–end rule&lt;/a&gt;: a peak that is the visitor's own doing and a quiet, slightly funny ending. The guardrails matter more than the mechanics. It is never required, it is hidden from assistive tech, off under reduced motion, collects no data, and is lazy-loaded behind &lt;code&gt;@defer&lt;/code&gt;. I can't claim it improves retention: I have no analytics by choice, so whether anyone remembers the swamp is anecdotal.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Bugs worth sharing
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The ease-in-out that was an ease-out.&lt;/strong&gt; I closed the cards with Material's emphasized curve, and every close ended with a "click": a quick start, a very long tail, a sudden stop. Measuring the next row's position per frame showed a velocity that starts high and trails off. &lt;code&gt;--ease-settle&lt;/code&gt; gives a bell-shaped profile. A second click came from 4 px of padding that snapped at the end instead of moving with the height.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A layout animation that janks while the numbers look right.&lt;/strong&gt; My frame-by-frame measurements of the old close were smooth, yet on a real display it stuttered. Animating the height of something in the flow lays out everything below it on every frame. That is what pushed me to the layer approach, where measured and felt motion finally agreed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The spring that never ran.&lt;/strong&gt; A new spring looked exactly like the old ease-out, because a later block of the same stylesheet, with the same selectors, won silently. When a motion change does nothing, search for the selector before tuning numbers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Two &lt;code&gt;@keyframes reveal&lt;/code&gt;.&lt;/strong&gt; Two files defined &lt;code&gt;reveal&lt;/code&gt;, and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@keyframes" rel="noopener noreferrer"&gt;keyframes don't cascade&lt;/a&gt;: the last one parsed wins, so headings never faded, which was safe only by luck. Animation names are global, and the design check now rejects duplicates.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The language switch that vibrated.&lt;/strong&gt; It ran inside a View Transition while the changed texts had their own entrance animation, and the two played back to back. A View Transition is a choreography of its own: don't stack another on it.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. The engineering behind it
&lt;/h2&gt;

&lt;p&gt;The physics lives in &lt;code&gt;core/buddy.ts&lt;/code&gt;, about 1,200 lines of plain TypeScript with no DOM: geometry and pointer in, joint angles out, one gravity, two-bone inverse kinematics to planted feet, injected randomness. A thin SVG renderer draws it. Because the logic is pure, the tests check physics rather than snapshots: the spec rebuilds the figure with &lt;em&gt;forward&lt;/em&gt; kinematics and asserts that a planted foot never slides and a jump follows one parabola.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm run verify&lt;/code&gt; gates every change: strict types, ESLint, 231 unit tests at 100 % coverage of the logic layer, a 7:1 contrast check, the design check, a privacy check, a check that the built &lt;code&gt;docs/&lt;/code&gt; matches the sources, 120 Playwright tests (axe on WCAG 2.2 AA, reduced-motion emulation, CSP listeners) and Lighthouse on both pages. Accessibility, best practices and SEO must be exactly 100. Performance has a floor of 95, because mobile is a noisy lab metric on my machine.&lt;/p&gt;

&lt;p&gt;The pages are prerendered and hydrated, with a strict CSP in a meta tag (GitHub Pages can't send headers; the build hashes every inline script) and one documented outside request, to the dev.to API for the article list, with no cookies, no referrer and the build-time list as a fallback.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. What I would do differently
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The spring is bouncy on tall cards.&lt;/strong&gt; About 3 % overshoot is pleasant on a 44 px button and visible on a 500 px card. The cards' opening should use the no-overshoot spring for height, which is the rule I wrote myself and haven't followed yet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Exits are still inconsistent&lt;/strong&gt;: the command palette has a spring entrance and just disappears.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CSS springs don't carry velocity&lt;/strong&gt;, so an interrupted pill restarts from rest.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The design check is a regex&lt;/strong&gt;, blind to some patterns.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The main bundle is about 417 kB&lt;/strong&gt; before compression, over my own 400 kB warning.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The code is in &lt;strong&gt;&lt;a href="https://github.com/er2es/er2es.github.io" rel="noopener noreferrer"&gt;github.com/er2es/er2es.github.io&lt;/a&gt;&lt;/strong&gt; (MIT). Rest the mouse on the soft-skills row, scratch the portrait, open a role card, or press Shift three times. If you find a motion bug, I'd like to hear about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;NN/g: &lt;a href="https://www.nngroup.com/articles/response-times-3-important-limits/" rel="noopener noreferrer"&gt;Response Times&lt;/a&gt;, &lt;a href="https://www.nngroup.com/articles/animation-duration/" rel="noopener noreferrer"&gt;Animation Duration&lt;/a&gt;, &lt;a href="https://www.nngroup.com/articles/peak-end-rule/" rel="noopener noreferrer"&gt;The Peak–End Rule&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Apple, WWDC23: &lt;a href="https://developer.apple.com/videos/play/wwdc2023/10158/" rel="noopener noreferrer"&gt;Animate with springs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;A List Apart, Val Head: &lt;a href="https://alistapart.com/article/designing-safer-web-animation-for-motion-sensitivity/" rel="noopener noreferrer"&gt;Designing Safer Web Animation for Motion Sensitivity&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;MDN: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/easing-function/linear" rel="noopener noreferrer"&gt;&lt;code&gt;linear()&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/animation-timeline/view" rel="noopener noreferrer"&gt;&lt;code&gt;view()&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_anchor_positioning" rel="noopener noreferrer"&gt;CSS anchor positioning&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>angular</category>
      <category>webdev</category>
      <category>css</category>
      <category>a11y</category>
    </item>
    <item>
      <title>slimfony: a small PHP 8.4 core for FrankenPHP worker mode, with its benchmarks and its limits</title>
      <dc:creator>Szj</dc:creator>
      <pubDate>Wed, 18 Nov 2026 13:56:35 +0000</pubDate>
      <link>https://dev.to/_er2es_/slimfony-a-small-php-84-core-for-frankenphp-worker-mode-with-its-benchmarks-and-its-limits-1dbe</link>
      <guid>https://dev.to/_er2es_/slimfony-a-small-php-84-core-for-frankenphp-worker-mode-with-its-benchmarks-and-its-limits-1dbe</guid>
      <description>&lt;h2&gt;
  
  
  State that outlives the request
&lt;/h2&gt;

&lt;p&gt;PHP's classic model hides a whole class of bugs: every request starts from nothing, and everything it built is thrown away at the end. A worker-mode server such as FrankenPHP keeps the application booted and hands it one request after another. That removes the boot from every request, and the safety net with it.&lt;/p&gt;

&lt;p&gt;A value cached in a &lt;code&gt;static&lt;/code&gt; property, a logger context that still carries the previous request's id, a transaction a failed request left open: in a long-running worker all of these survive into the next request. A test that sends one request does not see them. Real traffic does, which is why these bugs tend to be found in production.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/slimfony/core" rel="noopener noreferrer"&gt;slimfony/core&lt;/a&gt; is our attempt to make that failure mode boring. Version 1.0.0 was released on 2026-11-18. Here is what it is, the decisions behind it, what we measured and on what, what did not work out, and where its limits are.&lt;/p&gt;

&lt;h2&gt;
  
  
  What slimfony is
&lt;/h2&gt;

&lt;p&gt;slimfony/core is a small, strict core for PHP 8.4+ microservices on FrankenPHP worker mode. It is built from a few Symfony components (&lt;code&gt;http-foundation&lt;/code&gt;, &lt;code&gt;routing&lt;/code&gt;, &lt;code&gt;dependency-injection&lt;/code&gt;, plus &lt;code&gt;service-contracts&lt;/code&gt; for the reset interface), Doctrine DBAL and &lt;code&gt;psr/log&lt;/code&gt;. It deliberately has no &lt;code&gt;http-kernel&lt;/code&gt;, no event dispatcher, no bundles and no YAML. JWT verification uses &lt;code&gt;firebase/php-jwt&lt;/code&gt;, only when you use it.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Area&lt;/th&gt;
&lt;th&gt;What the core does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Boot&lt;/td&gt;
&lt;td&gt;Container and router compiled at build time, middleware chain built once&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Worker loop&lt;/td&gt;
&lt;td&gt;Max requests, memory limit, services reset after every request&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Errors&lt;/td&gt;
&lt;td&gt;RFC 9457 &lt;code&gt;application/problem+json&lt;/code&gt;, no internals leaked&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tracing&lt;/td&gt;
&lt;td&gt;Validated request id, its own span id, an outgoing W3C &lt;code&gt;traceparent&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Auth&lt;/td&gt;
&lt;td&gt;Deny by default, scopes per route, JWT bearer verification with JWKS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Database&lt;/td&gt;
&lt;td&gt;PostgreSQL via DBAL: leaked transactions rolled back, bounded retries for deadlocks, lost connections and failover&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Observability&lt;/td&gt;
&lt;td&gt;APCu-backed Prometheus metrics, protected &lt;code&gt;/metrics&lt;/code&gt;, &lt;code&gt;/healthz&lt;/code&gt;, &lt;code&gt;/readyz&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reliability&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;Idempotency-Key&lt;/code&gt; middleware for &lt;code&gt;POST&lt;/code&gt; and &lt;code&gt;PATCH&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Non-HTTP&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;ConsumerRunner&lt;/code&gt; for queue consumers and jobs that boot the same container&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;It is meant as the base for services, not as a general-purpose framework: each service owns its dependency tree and commits its own &lt;code&gt;composer.lock&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Four design decisions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Small on purpose
&lt;/h3&gt;

&lt;p&gt;A new package in &lt;code&gt;require&lt;/code&gt; needs a justification: "what it does, why ~50 lines of our own code or a PHP built-in do not." There is no dependency for logging (an own PSR-3 JSON logger), request ids (&lt;code&gt;random_bytes&lt;/code&gt;), configuration, HTTP clients, validation or serialization. The core even &lt;code&gt;replace&lt;/code&gt;s the polyfills PHP 8.4 makes redundant, so a service's &lt;code&gt;vendor/&lt;/code&gt; stays slim.&lt;/p&gt;

&lt;p&gt;The price: no argument resolver, no event dispatcher, no bundles. A controller is an invokable service with &lt;code&gt;__invoke(Request): Response&lt;/code&gt;. The README names the exit: "A service that outgrows it should move to Symfony, not stretch the core."&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Compile at build time
&lt;/h3&gt;

&lt;p&gt;Nothing is computed per request that can be done at build or boot. The container and route table are dumped when the image is built, and workers only &lt;code&gt;require&lt;/code&gt; them (opcache shares them). A broken configuration fails the warmup, so it never ships. No reflection, autowiring or event dispatching on the hot path.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vendor/bin/slimfony warmup config/services.php config/routes.php var/cache
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. State reset as a first-class concept
&lt;/h3&gt;

&lt;p&gt;Every service that implements Symfony's &lt;code&gt;ResetInterface&lt;/code&gt; is reset after every request. If a reset fails, the worker stops: its state is unknown, and the server starts a fresh one. A transaction a request left open is rolled back, logged and counted (&lt;code&gt;db_transactions_leaked_total&lt;/code&gt;). &lt;code&gt;MAX_REQUESTS&lt;/code&gt; and a memory limit restart a worker after its response is sent, as a guard against anything that leaks anyway. Queue consumers get the same treatment from &lt;code&gt;ConsumerRunner&lt;/code&gt;: reset after every message, stop on SIGTERM.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Failing closed
&lt;/h3&gt;

&lt;p&gt;Once an &lt;code&gt;Authenticator&lt;/code&gt; is configured, everything is denied by default, including paths that match no route (401, so the API cannot be mapped by its 404s). Routes opt out with &lt;code&gt;_public&lt;/code&gt; or demand scopes with &lt;code&gt;_scopes&lt;/code&gt;. The JWT verifier allows &lt;code&gt;RS256&lt;/code&gt;, &lt;code&gt;ES256&lt;/code&gt; and &lt;code&gt;EdDSA&lt;/code&gt;; shared-secret algorithms and &lt;code&gt;none&lt;/code&gt; cannot be configured. If the identity provider is down, loaded keys keep working; a worker that starts with none waits briefly, then refuses with 401.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/metrics&lt;/code&gt; is off until a token or an address list is configured. &lt;code&gt;Retry&lt;/code&gt; is bounded (three attempts by default), and a write is repeated after a lost connection only when you declare it &lt;code&gt;idempotent: true&lt;/code&gt;, because a lost &lt;code&gt;COMMIT&lt;/code&gt; may or may not have happened.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the code looks like
&lt;/h2&gt;

&lt;p&gt;Copied from the core README, whose samples are executed by &lt;code&gt;tests/ReadmeTest.php&lt;/code&gt;. A controller:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;

&lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strict_types&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Symfony&lt;/span&gt;\&lt;span class="nc"&gt;Component&lt;/span&gt;\&lt;span class="nc"&gt;HttpFoundation&lt;/span&gt;\&lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Symfony&lt;/span&gt;\&lt;span class="nc"&gt;Component&lt;/span&gt;\&lt;span class="nc"&gt;HttpFoundation&lt;/span&gt;\&lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;final&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Hello&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;__invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'hello '&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;attributes&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The worker script, &lt;code&gt;public/index.php&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;

&lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strict_types&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Psr&lt;/span&gt;\&lt;span class="nc"&gt;Log&lt;/span&gt;\&lt;span class="nc"&gt;LoggerInterface&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Slimfony&lt;/span&gt;\&lt;span class="nc"&gt;Core&lt;/span&gt;\&lt;span class="nc"&gt;Config&lt;/span&gt;\&lt;span class="nc"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Slimfony&lt;/span&gt;\&lt;span class="nc"&gt;Core&lt;/span&gt;\&lt;span class="nc"&gt;Config&lt;/span&gt;\&lt;span class="nc"&gt;Trust&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Slimfony&lt;/span&gt;\&lt;span class="nc"&gt;Core&lt;/span&gt;\&lt;span class="nc"&gt;Kernel&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Slimfony&lt;/span&gt;\&lt;span class="nc"&gt;Core&lt;/span&gt;\&lt;span class="nc"&gt;Log&lt;/span&gt;\&lt;span class="nc"&gt;JsonStdoutLogger&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Slimfony&lt;/span&gt;\&lt;span class="nc"&gt;Core&lt;/span&gt;\&lt;span class="nc"&gt;Log&lt;/span&gt;\&lt;span class="nc"&gt;RequestContext&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Slimfony&lt;/span&gt;\&lt;span class="nc"&gt;Core&lt;/span&gt;\&lt;span class="nc"&gt;Worker&lt;/span&gt;\&lt;span class="nc"&gt;WorkerRunner&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="n"&gt;__DIR__&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/../vendor/autoload.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$env&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Env&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;fromGlobals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Trust&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// TRUSTED_PROXIES / TRUSTED_HOSTS; no proxy is trusted by default (any Host is accepted until TRUSTED_HOSTS is set)&lt;/span&gt;

&lt;span class="nv"&gt;$context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RequestContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;JsonStdoutLogger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'LOG_LEVEL'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'info'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$kernel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Kernel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;__DIR__&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/../config/services.php'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;__DIR__&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/../config/routes.php'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;debug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'APP_DEBUG'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$logger&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;cacheDir&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;__DIR__&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/../var/cache'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// written by the warmup below; compiled at boot when missing&lt;/span&gt;
    &lt;span class="n"&gt;synthetic&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;RequestContext&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;LoggerInterface&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$logger&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;WorkerRunner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$kernel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$logger&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maxRequests&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'MAX_REQUESTS'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;config/services.php&lt;/code&gt; registers the services and the middleware chain, and &lt;code&gt;config/routes.php&lt;/code&gt; maps &lt;code&gt;/hello/{name}&lt;/code&gt; to the controller. Without FrankenPHP, the runner serves a single request, so the same &lt;code&gt;index.php&lt;/code&gt; works as a classic front controller.&lt;/p&gt;

&lt;h2&gt;
  
  
  The numbers, and how they were taken
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The core's own overhead
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;composer bench&lt;/code&gt; (phpbench) measures &lt;code&gt;Kernel::handle()&lt;/code&gt; with a typical production chain (metrics in APCu, request id, security headers, body limit, authentication), one request at a time, 30,000 requests per scenario, opcache and JIT on. It excludes HTTP parsing, the network and application code. CI runner (Linux, PHP 8.4), in microseconds:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;p50&lt;/th&gt;
&lt;th&gt;p95&lt;/th&gt;
&lt;th&gt;p99&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;GET /healthz&lt;/code&gt; (public route)&lt;/td&gt;
&lt;td&gt;28.8&lt;/td&gt;
&lt;td&gt;40.3&lt;/td&gt;
&lt;td&gt;51.2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;GET /hello/{name}&lt;/code&gt; (authenticated, scope check, JSON)&lt;/td&gt;
&lt;td&gt;34.1&lt;/td&gt;
&lt;td&gt;44.3&lt;/td&gt;
&lt;td&gt;56.5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RS256 JWT, token remembered (default)&lt;/td&gt;
&lt;td&gt;35.7&lt;/td&gt;
&lt;td&gt;46.5&lt;/td&gt;
&lt;td&gt;58.4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RS256 JWT, verified on every request&lt;/td&gt;
&lt;td&gt;129.2&lt;/td&gt;
&lt;td&gt;151.1&lt;/td&gt;
&lt;td&gt;168.6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;EdDSA JWT, verified on every request&lt;/td&gt;
&lt;td&gt;116.7&lt;/td&gt;
&lt;td&gt;136.8&lt;/td&gt;
&lt;td&gt;152.2&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The core's own work stays below 50 µs at p95; the signature check is what costs, which is why a verified token is remembered for 30 seconds (never beyond its &lt;code&gt;exp&lt;/code&gt;). On a Windows 11 development machine the p95 was 34.6 µs (public) and 40.2 µs (authenticated). CI fails above 250 µs. These are overhead figures, not throughput claims.&lt;/p&gt;

&lt;h3&gt;
  
  
  End to end, in the demo
&lt;/h3&gt;

&lt;p&gt;The demo uses k6 in a container on the stack's own network with a &lt;strong&gt;constant arrival rate&lt;/strong&gt;: each step runs 15 seconds, and k6 starts requests at that pace whether or not the server keeps up. Everything, k6 included, runs on one machine (i5-14400, 16 CPUs and 8 GB given to Docker Desktop). Single runs unless stated; read the ratios, not the absolute numbers.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;GET /healthz&lt;/code&gt;, worker mode&lt;/td&gt;
&lt;td&gt;15,000 requests/s, no error or dropped request, p95 7.0 ms (no limit found)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Same app, classic mode (boot per request)&lt;/td&gt;
&lt;td&gt;saturates at about 1,300 requests/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Verified token + DB read, 4 PHP workers&lt;/td&gt;
&lt;td&gt;saturates at about 6,500 requests/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Same route, 16 PHP workers&lt;/td&gt;
&lt;td&gt;about 12,400 requests/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Import of 1,000 ZIPs (10,000 statements), 8 importers&lt;/td&gt;
&lt;td&gt;11.5 s and 11.7 s (two runs)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The authenticated read was limited by workers waiting on the database, not by CPU: at 7,500 requests/s the p95 was 699 ms with 4 workers and 5.7 ms with 16.&lt;/p&gt;

&lt;p&gt;The biggest import gain came from the application, not the core. Importers updated shared account rows in the order entries appeared, so with eight of them PostgreSQL ended many transactions as deadlocks and &lt;code&gt;Retry&lt;/code&gt; re-ran them. Locking rows in a fixed order (sorted by IBAN) took eight importers from 67.1 s to 13.9 s for 1,000 ZIPs, and deadlock retries from 686 to 0. &lt;code&gt;Retry&lt;/code&gt; is a net, not a strategy.&lt;/p&gt;

&lt;h3&gt;
  
  
  Failure injection
&lt;/h3&gt;

&lt;p&gt;An authenticated read at 1,500 requests/s for 150 seconds, while the script restarts PgBouncer (at 20 s) and PostgreSQL (at 50 s) and stops the identity provider for 30 seconds. One run per column:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;PgBouncer defaults&lt;/th&gt;
&lt;th&gt;
&lt;code&gt;query_wait_timeout = 3&lt;/code&gt;, &lt;code&gt;server_login_retry = 1&lt;/code&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Requests&lt;/td&gt;
&lt;td&gt;210,041&lt;/td&gt;
&lt;td&gt;223,769&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Failed (&lt;code&gt;500&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;7,370 (3.5%)&lt;/td&gt;
&lt;td&gt;188 (0.1%)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Slowest request&lt;/td&gt;
&lt;td&gt;15,020 ms&lt;/td&gt;
&lt;td&gt;4,057 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This is easy to misread. &lt;code&gt;Retry&lt;/code&gt; gives up after its bounded attempts, a few tens of milliseconds apart: a database that is away for seconds fails the request. How long a request &lt;em&gt;waits&lt;/em&gt; before failing is the pooler's setting. With the defaults, PgBouncer kept answering with its cached login error for &lt;code&gt;server_login_retry&lt;/code&gt; (15 s), and waiting requests held the workers. The fix was pooler configuration, not core code. The identity-provider outage caused no failed request.&lt;/p&gt;

&lt;h3&gt;
  
  
  What did not pan out
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Deferred garbage collection did nothing here.&lt;/strong&gt; &lt;code&gt;WorkerRunner&lt;/code&gt; can run the cycle collector between requests instead of during them. At 8,000 authenticated requests/s for 20 seconds (about 160,000 requests, 16 workers), the collector ran zero times, with or without the setting: PHP starts it at 10,000 possible cycles, and this code leaves almost none. It stays as insurance for code that builds cycles.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;More workers stopped helping at 16.&lt;/strong&gt; 32 workers saturated at about 12,000 requests/s, and the p95 at 7,500/s rose from 5.7 ms to 13.6 ms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Batching NATS pulls helped one importer, barely eight.&lt;/strong&gt; About 41 ms per ZIP went to waiting for the broker. Pulling five messages per request took one importer from 31.7 s to 15.8 s for 400 ZIPs, but eight importers only from 13.9 s to 13.0 s: there the database write is the limit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PgBouncer costs 5 to 10 percent&lt;/strong&gt; of import throughput on one machine, for connection economy a single host does not need.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The demo
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/slimfony/demo" rel="noopener noreferrer"&gt;slimfony/demo&lt;/a&gt; (v1.0.0) is a CAMT.053 bank-statement import. ZIP files of ISO 20022 statements arrive by the thousand; every statement is booked all or nothing, checked against an XSD and business rules (balances, accounts, currency, period, duplicates).&lt;/p&gt;

&lt;p&gt;One &lt;code&gt;docker compose up&lt;/code&gt; starts FrankenPHP in worker mode (the API and a live page), a small identity provider with JWKS and key rotation, an outbox relay, importers on NATS JetStream, PostgreSQL behind PgBouncer, Prometheus and Grafana. Kubernetes manifests with probes, autoscaling, disruption budgets and network policies are included.&lt;/p&gt;

&lt;p&gt;An accepted upload and its outbox row are stored in one transaction. The page has chaos switches: kill an importer mid-batch, or cut the database connections. Every ZIP still ends up booked, or failed with the reason on record, and &lt;code&gt;scripts/chaos.sh&lt;/code&gt; checks exactly that.&lt;/p&gt;

&lt;h2&gt;
  
  
  The review before 1.0
&lt;/h2&gt;

&lt;p&gt;Before the 1.0 tag, the whole library went through an independent review. The most instructive finding was in &lt;code&gt;ProcessMetricsEndpoint&lt;/code&gt;, the small &lt;code&gt;/metrics&lt;/code&gt; listener for command-line processes. It compared its address allow-list against &lt;code&gt;127.0.0.1&lt;/code&gt; for every client instead of the connected peer. A list naming the cluster network matched nobody; a list containing &lt;code&gt;127.0.0.1&lt;/code&gt; admitted everybody. Either way, the list did not protect anything.&lt;/p&gt;

&lt;p&gt;It was fixed before the tag, together with the other findings: a throwing middleware was answered outside the middleware around it (so that &lt;code&gt;500&lt;/code&gt; had no request id or security headers), the JWKS provider retried a failed download on every request, and an idempotency claim could be finished by a request that had already lost it. All are in the 1.0.0 changelog.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it is checked
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;SemVer is written down in &lt;code&gt;STABILITY.md&lt;/code&gt;: the &lt;code&gt;@api&lt;/code&gt; classes (parameter names included) and contracts that are not classes, such as metric names, log fields and the error shape.&lt;/li&gt;
&lt;li&gt;PHPStan at level max, no baseline, plus an architecture test for &lt;code&gt;final&lt;/code&gt;, &lt;code&gt;#[\Override]&lt;/code&gt;, typed constants and &lt;code&gt;@api&lt;/code&gt;/&lt;code&gt;@internal&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The build fails below 95% line coverage (95.9% when the gate was added).&lt;/li&gt;
&lt;li&gt;Seeded fuzz tests for the parsers that take outside input.&lt;/li&gt;
&lt;li&gt;CI on PHP 8.4 and 8.5 against real PostgreSQL and APCu, plus a row with the lowest allowed dependency versions.&lt;/li&gt;
&lt;li&gt;SHA-pinned GitHub Actions; release archives with a CycloneDX SBOM and signed build provenance (&lt;code&gt;gh attestation verify&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Limits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No real production service yet.&lt;/strong&gt; The demo is the proof, not a customer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Idempotency is not exactly-once.&lt;/strong&gt; If the process dies between the work and storing the answer, the request runs again once the lock expires. Work that must never happen twice needs its own unique column, filled from &lt;code&gt;Attributes::IDEMPOTENCY_KEY&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Kubernetes manifests have not been run on a real cluster.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PostgreSQL first.&lt;/strong&gt; The retries and failover handling are written and tested for it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Small on purpose.&lt;/strong&gt; No ORM, templates, bundles or Messenger; no load shedding or request deadlines, which belong to the edge and the platform.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The numbers come from one machine&lt;/strong&gt;, with the load generator sharing its CPUs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require slimfony/core
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The README's quickstart takes it from there. To see the whole system (the page at &lt;code&gt;http://localhost:8080&lt;/code&gt;, Grafana at &lt;code&gt;http://localhost:3000&lt;/code&gt;; Docker needs about 3 GB of memory):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/slimfony/demo.git
&lt;span class="nb"&gt;cd&lt;/span&gt; demo
docker compose up -d --build --wait
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On Windows, set &lt;code&gt;BUILDX_BAKE_ENTITLEMENTS_FS=0&lt;/code&gt; in the same terminal first.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Core: &lt;a href="https://github.com/slimfony/core" rel="noopener noreferrer"&gt;github.com/slimfony/core&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Demo: &lt;a href="https://github.com/slimfony/demo" rel="noopener noreferrer"&gt;github.com/slimfony/demo&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Criticism and bug reports are welcome; security issues go through GitHub Security Advisories, as &lt;code&gt;SECURITY.md&lt;/code&gt; describes.&lt;/p&gt;

</description>
      <category>php</category>
      <category>symfony</category>
      <category>opensource</category>
      <category>performance</category>
    </item>
    <item>
      <title>Review-Driven Development: a method for the bugs a 95% mutation score can't see</title>
      <dc:creator>Szj</dc:creator>
      <pubDate>Thu, 12 Nov 2026 13:53:49 +0000</pubDate>
      <link>https://dev.to/_er2es_/review-driven-development-a-method-for-the-bugs-a-95-mutation-score-cant-see-39go</link>
      <guid>https://dev.to/_er2es_/review-driven-development-a-method-for-the-bugs-a-95-mutation-score-cant-see-39go</guid>
      <description>&lt;p&gt;Last week I &lt;a href="https://dev.to/_er2es_/95-mutation-score-and-a-review-still-found-a-cross-tenant-leak-fuzzphony-011-27c5"&gt;wrote&lt;/a&gt; that Fuzzphony 0.11 had about 3,700 tests, PHPStan at max level, close to 100% line coverage and a 95% mutation score over roughly 11,900 mutants, and that an independent review of about 2,700 added lines still found three real bugs. One of them loaded another tenant's row.&lt;/p&gt;

&lt;p&gt;I ended that post with one sentence: independent review is now part of the release process. A sentence is not a method. This post tries to make it one, with a definition, a loop, and numbers I can be held to. I call it review-driven development (RDD). The name is not new (see the prior art section), so I define what I mean by it.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Every automated check compares the code to something written down
&lt;/h2&gt;

&lt;p&gt;Here is what each layer in my pipeline compares the code against, and what that makes it blind to. The evidence column is from my own two experiments: the &lt;a href="https://dev.to/_er2es_/your-architecture-rules-are-code-too-mutation-testing-a-ddd-ruleset-in-php-84-3p33"&gt;architecture ruleset&lt;/a&gt; (12 hand-made rule violations against 7 checks) and the Fuzzphony 0.11 release.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Layer&lt;/th&gt;
&lt;th&gt;Compares the code against&lt;/th&gt;
&lt;th&gt;Cannot see&lt;/th&gt;
&lt;th&gt;Evidence&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Language (&lt;code&gt;final readonly&lt;/code&gt;, types)&lt;/td&gt;
&lt;td&gt;declarations&lt;/td&gt;
&lt;td&gt;deep mutability&lt;/td&gt;
&lt;td&gt;readonly object holding a mutable one escaped&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PHPStan + custom rules, Deptrac, phpat&lt;/td&gt;
&lt;td&gt;rules somebody wrote&lt;/td&gt;
&lt;td&gt;behaviour&lt;/td&gt;
&lt;td&gt;a dropped constructor invariant escaped all 7 checks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tests&lt;/td&gt;
&lt;td&gt;assertions the author thought of&lt;/td&gt;
&lt;td&gt;assertions nobody thought of&lt;/td&gt;
&lt;td&gt;green suite, three bugs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mutation testing (Infection)&lt;/td&gt;
&lt;td&gt;the tests&lt;/td&gt;
&lt;td&gt;requirements no test asserts&lt;/td&gt;
&lt;td&gt;95% score, three bugs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Differential harness&lt;/td&gt;
&lt;td&gt;the previous release&lt;/td&gt;
&lt;td&gt;anything the previous release did not do&lt;/td&gt;
&lt;td&gt;1,854 searches byte-identical, three bugs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Independent review&lt;/td&gt;
&lt;td&gt;the reviewer's own idea of what the system must do&lt;/td&gt;
&lt;td&gt;what the reviewer also misses; does not scale&lt;/td&gt;
&lt;td&gt;3 findings in ~2,700 lines&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Testing research calls this the oracle problem: a test needs something that says what the correct output is, and that something has to come from outside the code (Barr et al., 2015). Mutation testing (DeMillo et al., 1978; Jia and Harman, 2011) measures how well the tests use the oracle they have. It cannot produce a new one.&lt;/p&gt;

&lt;p&gt;All three of my bugs were oracle gaps. The affected lines were covered and ran, the suite was green, and the requirement that was violated was asserted by no test, no rule and no type. The sharpest form of this is what Brian Marick called a fault of omission: the defect is code that should exist and doesn't, so no coverage-based technique can point at it. The cross-tenant load was exactly that, a filter that was never written.&lt;/p&gt;

&lt;p&gt;A second number from the architecture experiment matters here. Of the 9 violations that were caught, 5 were caught by exactly one check. More than half of the detections depended on a single layer. Adding a layer of a different kind buys more than tightening an existing one.&lt;/p&gt;

&lt;p&gt;Review is the only layer in the table whose reference is not an artifact the author produced. That is its value and the reason it is expensive. So the method has two goals: spend review only on what the other layers cannot see, and turn everything it finds into something they can.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. What the research says about review
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Review finds fewer functional defects than people expect.&lt;/strong&gt; Formal inspections (Fagan, 1976) were designed to find defects. Modern tool-based review mostly does something else. Bacchelli and Bird (2013) observed and surveyed developers at Microsoft: finding defects was the top motivation, but the actual outcomes were mostly understanding, knowledge transfer and alternative solutions. Mäntylä and Lassenius (2009) classified review findings and put about 75% of them in the evolvability category, not functionality. Beller et al. (2014) found the same 75:25 split in open source.&lt;/p&gt;

&lt;p&gt;The consequence: an unaimed review of a diff will mostly return naming and structure remarks. If I want it to find a tenant leak, I have to aim it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How the reviewer reads matters more than whether there is a checklist.&lt;/strong&gt; In the inspection experiments of the 1990s, readers who were given a specific scenario or fault class to hunt found more than readers with a generic checklist, and the generic checklist did no better than ad hoc reading (Porter, Votta and Basili, 1995). Perspective-based reading (Basili et al., 1996) built on that; replications were mixed (Regnell et al., 2000). These experiments were run on requirements documents, not on code, so applying them to code review is my extrapolation. I take one thing from this line of work: give the reviewer a target, not a list of good practices.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mutation testing and review already meet, in one direction.&lt;/strong&gt; Google surfaces surviving mutants inside the code review tool, on changed lines only (Petrović and Ivanković, 2018). Their follow-up study reports that developers exposed to this write more tests, and that mutants are coupled to real faults (Petrović et al., 2021). That is mutation feeding review. RDD adds the opposite arrow: review feeding the test suite.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In 2026 review is the bottleneck.&lt;/strong&gt; LeadDev's 2026 report says 68% of respondents changed how they review because of AI, and quotes a CodeRabbit analysis of 470 pull requests with about 1.7 times more issues in AI-generated ones. I wrote most of Fuzzphony with Claude Code. When the code and its tests come out of the same session, I expect them to share blind spots, and a mutation score then only confirms that the two agree with each other.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prior art.&lt;/strong&gt; None of the parts is new. ComputerMinds used "review-driven development" for a peer-review habit. The "preview-driven development" gist (sleepyfox, 2020) moves review before coding. Several AI-era write-ups add an "adversarial review" step after generation. Fixing the class of a bug instead of the instance is what security teams call variant analysis. Planting known faults to measure a process is error seeding (Mills, 1972). What I add is the combination: review aimed at a ledger of invariants, a seed corpus that grows out of the project's own fixes, and four numbers to report per release.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. The method
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Review-driven development&lt;/strong&gt; is a loop in which&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;the review is aimed at named invariants, not at the diff,&lt;/li&gt;
&lt;li&gt;the reviewer is independent of the author's reasoning,&lt;/li&gt;
&lt;li&gt;a finding is closed only by an executable artifact,&lt;/li&gt;
&lt;li&gt;the review itself is tested.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NAME  -&amp;gt;  BUILD  -&amp;gt;  ATTACK  -&amp;gt;  ENCODE  -&amp;gt;  CALIBRATE
 ^                                               |
 +-----------------------------------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3 is what happened in Fuzzphony 0.11, followed by a fix for each finding. The ledger, class-level encoding, seeding and the metrics are what I am adding from 0.12 on. I have no data for step 5 yet.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1. Name: an invariant ledger
&lt;/h3&gt;

&lt;p&gt;An invariant is a sentence that must stay true across every feature, written so that it can be attacked. Fuzzphony has two that matter, named since 0.10. I keep them in one file with the question a reviewer should ask:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gu"&gt;# INVARIANTS.md
&lt;/span&gt;
&lt;span class="gu"&gt;## INV-1 tenant-isolation
&lt;/span&gt;For any actor of tenant A and any call that is not asSystem():
no id, row, count, facet or highlight derived from tenant B reaches the caller.
Attack: find any path from a search result to data where the tenant
        is implied instead of checked.
Enforced by: tests group inv:tenant-isolation

&lt;span class="gu"&gt;## INV-2 hidden-field-independence
&lt;/span&gt;For an actor without the grant on field F: changing the content of F
changes nothing in the response (ids, order, totals, facets, highlights, with()).
Attack: find any second name, path or side channel that reaches F's data.
Enforced by: tests group inv:hidden-field-independence
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both are written as relations between two runs, not as expected values. That is deliberate. Metamorphic testing (Chen et al., 1998) uses such relations as oracles when the correct output is unknown, and a relation covers a class of inputs where an example covers one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2. Build: the cheap layers on every push
&lt;/h3&gt;

&lt;p&gt;Nothing new here, only the order. Fast checks on every PR, the full mutation run once per release (mine takes 1 h 45 min):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vendor/bin/phpstan analyse
vendor/bin/deptrac analyse
vendor/bin/phpunit
vendor/bin/infection --git-diff-lines --git-diff-base=origin/main \
    --threads=max --min-covered-msi=90 --ignore-msi-with-no-mutations
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Surviving mutants on changed lines get a test or a written reason why they are equivalent. This step answers "are the tests I wrote any good". It says nothing about the tests I did not write.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3. Attack: a review brief, not a pull request
&lt;/h3&gt;

&lt;p&gt;The reviewer can be a colleague or a fresh LLM session. Three rules apply to both.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The reviewer gets the diff and the ledger, and nothing else.&lt;/strong&gt; No PR description, no commit rationale, no walkthrough. Every explanation I give transfers my model of the system, and my model is the thing under test.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The reviewer reads and does not run the test suite.&lt;/strong&gt; The review exists to find what the suite cannot. Step 5 also depends on this rule.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A finding has a fixed shape:&lt;/strong&gt; the invariant violated, a concrete input, the observed result, the required result. "This looks risky" is not a finding.&lt;/p&gt;

&lt;p&gt;The brief I will use from 0.12 on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gu"&gt;# Review brief (template)
&lt;/span&gt;Scope:   git diff &amp;lt;previous tag&amp;gt;..&amp;lt;release branch&amp;gt; -- src/
Targets: INV-1, INV-2
Not wanted: style, naming, structure
Access:  read-only, no test runs
Finding format: invariant | input | observed | required
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The 0.11 diff was about 2,700 lines, far above the size where line-by-line reading works. Reading by invariant makes it tractable: the reviewer follows only the paths where a tenant or a grant flows, and ignores the rest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One heuristic from my own data.&lt;/strong&gt; Look at what the three bugs have in common:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Finding&lt;/th&gt;
&lt;th&gt;The code assumed one&lt;/th&gt;
&lt;th&gt;There were several&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Hits &lt;code&gt;emp:1&lt;/code&gt; and &lt;code&gt;post:2&lt;/code&gt; reduced to ids &lt;code&gt;[1, 2]&lt;/code&gt;, loading Emp 2 of another tenant&lt;/td&gt;
&lt;td&gt;source per index&lt;/td&gt;
&lt;td&gt;sources per index (new in 0.11)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;with('pay')&lt;/code&gt; refused, &lt;code&gt;with('salary')&lt;/code&gt; returned to everyone&lt;/td&gt;
&lt;td&gt;name for a field's data&lt;/td&gt;
&lt;td&gt;field name and column name&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Only the first index of an entity refreshed; moved rows stayed in the old tenant&lt;/td&gt;
&lt;td&gt;index per entity&lt;/td&gt;
&lt;td&gt;indexes per entity&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each bug sits in code that assumed a singular where the system allowed a plural. The first case is the clean one: 0.11 itself turned the 1 into an N, and a consumer written for the old world kept working on bare ids. The other two are relatives of it. So the brief gets one more line: &lt;em&gt;list every place that assumes exactly one of something this release touches, and check each against the invariants.&lt;/em&gt; One clean case and two relatives from one project make a hypothesis, not a law. It is cheap to apply.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4. Encode: a finding is closed by a machine
&lt;/h3&gt;

&lt;p&gt;A fix plus a regression test for the reported input closes the instance. RDD asks for more: encode the class, at the cheapest layer that can see it. In order of preference:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;the language (types, &lt;code&gt;readonly&lt;/code&gt;, enums),&lt;/li&gt;
&lt;li&gt;a static rule (PHPStan custom rule, about twenty lines),&lt;/li&gt;
&lt;li&gt;an architecture rule (Deptrac, phpat),&lt;/li&gt;
&lt;li&gt;a test generated from configuration,&lt;/li&gt;
&lt;li&gt;an example test,&lt;/li&gt;
&lt;li&gt;a new line in the ledger, when nothing above fits yet.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For the alias leak, the class is "a second name reaches the same data", which is the attack line of INV-2. The test should enumerate every granted field from the index configuration, not the one field from the report. A sketch (helper names are mine, not Fuzzphony's API):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;#[Group('inv:hidden-field-independence')]&lt;/span&gt;
&lt;span class="k"&gt;final&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;GrantAliasTest&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;KernelTestCase&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;#[DataProvider('everyGrantedField')]&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;testNoNameReachesAGrantedColumn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$field&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$column&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$actor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;actorWithoutGrantOn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$field&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// outcome() returns 'refused' or the list of returned columns&lt;/span&gt;
        &lt;span class="kt"&gt;self&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;assertSame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'refused'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$actor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$field&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;self&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;assertSame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'refused'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$actor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$column&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;everyGrantedField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;iterable&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// yields [index, field, column] for every granted field&lt;/span&gt;
        &lt;span class="c1"&gt;// of every configured index, so new fields are covered on arrival&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A field added next year is tested without anyone remembering this bug. That is the difference between encoding an instance and encoding a class.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5. Calibrate: who reviews the reviewer?
&lt;/h3&gt;

&lt;p&gt;My Infection article asked "who guards the guards". Tests guard the code, mutants guard the tests, review guards the requirements. That leaves the review unguarded. When a review comes back clean, I cannot tell "no bugs" from "a reviewer that finds nothing".&lt;/p&gt;

&lt;p&gt;Mutation testing answers that question for tests by planting faults. Mills proposed the same for programs in 1972. Applied to review, the project's own history is a free source of realistic seeds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Every fixed finding becomes a seed.&lt;/strong&gt; The reverse patch of the fix is a real invariant violation, of a kind this codebase has actually produced. Store it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;review-seeds/
  INV-1-wrong-kind-ids.patch
  INV-2-column-alias.patch
  INV-1-first-index-only.patch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before a release review, adapt two or three seeds to the current code and apply them to the review copy only (never to a branch that can merge). The reviewer is told neither which seeds nor how many, and nothing about seeds appears in the brief. This is why the reviewer must not run the tests: after step 4 the suite catches these seeds at once, and the point is to measure the reader. I keep the stop rule on my side:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Seed recall&lt;/strong&gt; = seeds found / seeds planted. Below 100%, a clean result is not evidence, and the review is repeated with a different reviewer.&lt;/li&gt;
&lt;li&gt;A rough estimate of what is left, after Mills: with &lt;code&gt;S&lt;/code&gt; seeds planted, &lt;code&gt;s&lt;/code&gt; found and &lt;code&gt;r&lt;/code&gt; real findings, remaining ≈ &lt;code&gt;r × (S/s − 1)&lt;/code&gt;. With 3 planted, 2 found and 3 real findings that is about 1.5 bugs still in the code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With numbers this small the estimate is an alarm, not a measurement. The same caution applies to the alternative, capture-recapture with two independent reviewers: the inspection literature found those estimates unreliable for small teams (El Emam and Laitenberger, 2001).&lt;/p&gt;

&lt;p&gt;Seeds have a second use with LLM reviewers. Model, prompt and context all change between releases. Seed recall is the only number I know that says whether this release's reviewer is as good as the last one.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. What to report
&lt;/h2&gt;

&lt;p&gt;Next to the mutation score I will publish four numbers per release:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Definition&lt;/th&gt;
&lt;th&gt;0.11&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Review yield&lt;/td&gt;
&lt;td&gt;invariant findings per 1,000 reviewed lines&lt;/td&gt;
&lt;td&gt;3 / 2.7 ≈ 1.1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Oracle-gap share&lt;/td&gt;
&lt;td&gt;findings on test-covered code / all findings&lt;/td&gt;
&lt;td&gt;3 / 3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Repeat-class rate&lt;/td&gt;
&lt;td&gt;findings whose class was already found in an earlier review&lt;/td&gt;
&lt;td&gt;n/a (first review)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Seed recall&lt;/td&gt;
&lt;td&gt;seeds found / planted&lt;/td&gt;
&lt;td&gt;not measured&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Repeat-class rate is the one that tells whether the method works.&lt;/strong&gt; If step 4 is done properly, a class found once is caught by a machine afterwards, and a human should never have to find it again. A repeat means the encoding was too narrow. The target is zero.&lt;/p&gt;

&lt;p&gt;Oracle-gap share tells where to invest. A low share means review is finding bugs in code the tests never reached, so the money belongs in step 2. Mine was 3 of 3, which is why this post exists.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. When not to do this
&lt;/h2&gt;

&lt;p&gt;The same places where I argued mutation testing does not pay: prototypes, plain CRUD, thin read-only endpoints. RDD needs invariants worth naming. If you cannot write one sentence that must hold across every feature, there is nothing to aim the review at, and an ordinary pull request review is the right tool.&lt;/p&gt;

&lt;p&gt;It fits where one violated sentence is an incident: multi-tenant data, permissions, money, anything with a legal retention or disclosure rule.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Limits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Three findings, one library, one author. The method is derived from a single release.&lt;/li&gt;
&lt;li&gt;The singular-assumption pattern was found after the fact. I have not yet used it to predict a bug.&lt;/li&gt;
&lt;li&gt;Oracle-gap share is defined on line coverage. A stricter version would count only lines with no surviving mutant.&lt;/li&gt;
&lt;li&gt;Seeds come from past findings, so seed recall measures sensitivity to known classes. A reviewer can score 100% and still miss a new kind of bug.&lt;/li&gt;
&lt;li&gt;Seed recall only works with a reviewer who reads and does not run the suite. A reviewer with CI access finds every seed for free.&lt;/li&gt;
&lt;li&gt;How independent a second LLM session is from the one that wrote the code is unmeasured. Seed recall is a partial answer.&lt;/li&gt;
&lt;li&gt;The Infection flags above are the ones I use; check them against your version.&lt;/li&gt;
&lt;li&gt;The cost is real: a brief, a reviewer, and a test per finding class. I have not measured hours.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you run a review like this on a Symfony codebase, I would like to know your oracle-gap share. My guess is that it is high wherever the mutation score is high, because by then the easy bugs are gone.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;/p&gt;
  Show all 20 sources (20)
  &lt;ol&gt;
&lt;li&gt;Mills, H. D. (1972). On the statistical validation of computer programs. IBM FSC Report 72-6015.&lt;/li&gt;
&lt;li&gt;Fagan, M. E. (1976). Design and code inspections to reduce errors in program development. &lt;em&gt;IBM Systems Journal&lt;/em&gt;, 15(3).&lt;/li&gt;
&lt;li&gt;DeMillo, R. A., Lipton, R. J., Sayward, F. G. (1978). Hints on test data selection. &lt;em&gt;IEEE Computer&lt;/em&gt;, 11(4).&lt;/li&gt;
&lt;li&gt;Porter, A., Votta, L., Basili, V. (1995). Comparing detection methods for software requirements inspections: a replicated experiment. &lt;em&gt;IEEE TSE&lt;/em&gt;, 21(6).&lt;/li&gt;
&lt;li&gt;Basili, V. et al. (1996). The empirical investigation of perspective-based reading. &lt;em&gt;Empirical Software Engineering&lt;/em&gt;, 1(2).&lt;/li&gt;
&lt;li&gt;Chen, T. Y., Cheung, S. C., Yiu, S. M. (1998). Metamorphic testing: a new approach for generating next test cases. HKUST-CS98-01.&lt;/li&gt;
&lt;li&gt;Regnell, B., Runeson, P., Thelin, T. (2000). Are the perspectives really different? &lt;em&gt;Empirical Software Engineering&lt;/em&gt;, 5(4). &lt;a href="https://doi.org/10.1023/A:1009848320066" rel="noopener noreferrer"&gt;doi:10.1023/A:1009848320066&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Marick, B. (2000). Faults of omission. &lt;em&gt;Software Testing and Quality Engineering Magazine&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;El Emam, K., Laitenberger, O. (2001). Evaluating capture-recapture models with two inspectors. &lt;em&gt;IEEE TSE&lt;/em&gt;, 27(9).&lt;/li&gt;
&lt;li&gt;Mäntylä, M., Lassenius, C. (2009). What types of defects are really discovered in code reviews? &lt;em&gt;IEEE TSE&lt;/em&gt;, 35(3). &lt;a href="https://doi.org/10.1109/TSE.2008.71" rel="noopener noreferrer"&gt;doi:10.1109/TSE.2008.71&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Jia, Y., Harman, M. (2011). An analysis and survey of the development of mutation testing. &lt;em&gt;IEEE TSE&lt;/em&gt;, 37(5).&lt;/li&gt;
&lt;li&gt;Bacchelli, A., Bird, C. (2013). Expectations, outcomes, and challenges of modern code review. &lt;em&gt;ICSE 2013&lt;/em&gt;. &lt;a href="https://doi.org/10.1109/ICSE.2013.6606617" rel="noopener noreferrer"&gt;doi:10.1109/ICSE.2013.6606617&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Beller, M., Bacchelli, A., Zaidman, A., Juergens, E. (2014). Modern code reviews in open-source projects: which problems do they fix? &lt;em&gt;MSR 2014&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Barr, E. et al. (2015). The oracle problem in software testing: a survey. &lt;em&gt;IEEE TSE&lt;/em&gt;, 41(5).&lt;/li&gt;
&lt;li&gt;Petrović, G., Ivanković, M. (2018). State of mutation testing at Google. &lt;em&gt;ICSE-SEIP 2018&lt;/em&gt;. &lt;a href="https://doi.org/10.1145/3183519.3183521" rel="noopener noreferrer"&gt;doi:10.1145/3183519.3183521&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Petrović, G., Ivanković, M., Fraser, G., Just, R. (2021). Does mutation testing improve testing practices? &lt;a href="https://arxiv.org/abs/2103.07189" rel="noopener noreferrer"&gt;arXiv:2103.07189&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;LeadDev (2026). Use of AI has us creating more code than we can review. April 13, 2026.&lt;/li&gt;
&lt;li&gt;ComputerMinds. Review driven development? (blog post).&lt;/li&gt;
&lt;li&gt;sleepyfox (2020). &lt;a href="https://gist.github.com/sleepyfox/53ce08ab81515cdc5494f1358f609401" rel="noopener noreferrer"&gt;Preview-driven development&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://infection.github.io/guide/command-line-options.html" rel="noopener noreferrer"&gt;Infection: command line options&lt;/a&gt;.
&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;I maintain &lt;a href="https://github.com/er2es/fuzzphony" rel="noopener noreferrer"&gt;Fuzzphony&lt;/a&gt;, a PostgreSQL search library for databases you are not allowed to change.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>symfony</category>
      <category>testing</category>
      <category>codereview</category>
    </item>
    <item>
      <title>Your architecture rules are code too: mutation-testing a DDD ruleset in PHP 8.4</title>
      <dc:creator>Szj</dc:creator>
      <pubDate>Thu, 05 Nov 2026 08:36:35 +0000</pubDate>
      <link>https://dev.to/_er2es_/your-architecture-rules-are-code-too-mutation-testing-a-ddd-ruleset-in-php-84-3p33</link>
      <guid>https://dev.to/_er2es_/your-architecture-rules-are-code-too-mutation-testing-a-ddd-ruleset-in-php-84-3p33</guid>
      <description>&lt;p&gt;In September 2017 Lukas Taake published &lt;a href="https://www.ltaake.com/blog/2017/09/static-code-analysis-for-domain-driven-design-part-1/" rel="noopener noreferrer"&gt;the first part of a write-up&lt;/a&gt; of his master's thesis about static code analysis for Domain-Driven Design. It was built as a SonarQube plugin for Java, and its thesis is the most honest sentence in the genre: &lt;strong&gt;static analysis cannot show that DDD is done correctly; it can help keep some basic principles intact over time.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I wanted to know what that looks like in PHP today, nine years later. Two things have changed: the language now enforces a lot by itself (&lt;code&gt;readonly&lt;/code&gt;, enums, asymmetric visibility, attributes), and we have mutation testing, which gives us a way to ask the question the 2017 post could not: &lt;strong&gt;if someone breaks a rule, would your checks notice?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Everything below was run, not described. The demo domain is small (13 files), the mutants are hand-written, and I list the limits at the end.&lt;/p&gt;

&lt;h2&gt;
  
  
  The eight rules, then and now
&lt;/h2&gt;

&lt;p&gt;Taake's rules, as I read them in his post:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Every entity type has an identity.&lt;/li&gt;
&lt;li&gt;Value objects are immutable.&lt;/li&gt;
&lt;li&gt;No anemic domain model (entities that are only getters and setters).&lt;/li&gt;
&lt;li&gt;Aggregates are trees and link to other aggregates only by identity.&lt;/li&gt;
&lt;li&gt;An aggregate has a maximum size.&lt;/li&gt;
&lt;li&gt;Domain services exist only where behaviour cannot sit in an entity.&lt;/li&gt;
&lt;li&gt;Repository implementations live outside the domain model.&lt;/li&gt;
&lt;li&gt;The domain model depends on nothing else in the application.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The 2017 approach discovers the "model parts" by class hierarchy, name patterns or annotations, and the author admits the weak spot: you must tell the tool what is an entity and what is a value object, and the analysis is only as good as that configuration. In PHP 8 an attribute is the natural answer, because it is part of the class and the compiler sees it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\Sales\Domain&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;\Attribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;\Attribute&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;TARGET_CLASS&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="k"&gt;final&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AggregateRoot&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;\Attribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;\Attribute&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;TARGET_CLASS&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="k"&gt;final&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Entity&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;\Attribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;\Attribute&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;TARGET_CLASS&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="k"&gt;final&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ValueObject&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

&lt;span class="na"&gt;#[ValueObject]&lt;/span&gt;
&lt;span class="k"&gt;final&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Money&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$currency&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;self&lt;/span&gt; &lt;span class="nv"&gt;$o&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;self&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;self&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nv"&gt;$o&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;currency&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="na"&gt;#[AggregateRoot]&lt;/span&gt;
&lt;span class="k"&gt;final&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Customer&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;CustomerId&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;CustomerId&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;rename&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;\DomainException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'empty name'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The demo domain has two aggregate roots (&lt;code&gt;Customer&lt;/code&gt; with &lt;code&gt;Address&lt;/code&gt; value objects, &lt;code&gt;Order&lt;/code&gt; with &lt;code&gt;OrderLine&lt;/code&gt; entities), value objects for money, ids and the order number, an &lt;code&gt;OrderRepository&lt;/code&gt; interface in the domain and an implementation in &lt;code&gt;Infrastructure&lt;/code&gt;. Customer and order refer to each other &lt;strong&gt;by id&lt;/strong&gt; (&lt;code&gt;CustomerId&lt;/code&gt;, &lt;code&gt;OrderId&lt;/code&gt;), as rule 4 asks.&lt;/p&gt;

&lt;p&gt;Versions used: PHP 8.4.16, PHPStan 2.3.5, phpat 0.12.5, Deptrac 4.7.2, PHP Arkitect 1.3.1.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 2 first, because PHP does half of it
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;final readonly class Money&lt;/code&gt; makes the compiler and the engine refuse most of what rule 2 was written for. Writing to a readonly property from outside, or from a setter, throws:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error: Cannot modify readonly property Money::$amount
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two caveats, both worth knowing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is a &lt;strong&gt;runtime&lt;/strong&gt; error. The code that does it is still valid PHP; the engine only complains when it runs. A static check is still useful (PHPStan reports an assignment to a readonly property outside the constructor on its own, with no custom rule).&lt;/li&gt;
&lt;li&gt;Asymmetric visibility (&lt;code&gt;public private(set) int $amount&lt;/code&gt;, PHP 8.4) is &lt;strong&gt;not&lt;/strong&gt; immutability. The class itself may still change the value: &lt;code&gt;Cannot modify private(set) property&lt;/code&gt; appears only for a write from outside.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And one that no keyword fixes: &lt;code&gt;readonly&lt;/code&gt; is shallow. A readonly value object holding an &lt;code&gt;ArrayObject&lt;/code&gt; is still mutable through it. More on that below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rules 1 and 4: where only a custom rule helps
&lt;/h2&gt;

&lt;p&gt;Layer tools know about namespaces; they know nothing about aggregates or identity. For rule 4 (an aggregate root must not hold another aggregate root), a PHPStan rule is about twenty lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cd"&gt;/** @implements Rule&amp;lt;InClassNode&amp;gt; */&lt;/span&gt;
&lt;span class="k"&gt;final&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AggregateReferencesByIdRule&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Rule&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;ReflectionProvider&lt;/span&gt; &lt;span class="nv"&gt;$rp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getNodeType&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;InClassNode&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;processNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Node&lt;/span&gt; &lt;span class="nv"&gt;$node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Scope&lt;/span&gt; &lt;span class="nv"&gt;$scope&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$class&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$node&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getClassReflection&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nc"&gt;Marker&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'AggregateRoot'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nv"&gt;$errors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
        &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$class&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getNativeReflection&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getProperties&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$class&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$p&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getName&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nv"&gt;$scope&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getReadableType&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$type&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getReferencedClasses&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nv"&gt;$class&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getName&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;rp&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;hasClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nc"&gt;Marker&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;rp&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s1"&gt;'AggregateRoot'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="nv"&gt;$errors&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;RuleErrorBuilder&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                        &lt;span class="s1"&gt;'Aggregate root %s holds another aggregate root %s in $%s; reference it by id.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="nv"&gt;$class&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getName&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$p&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getName&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;
                        &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;identifier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ddd.aggregateByObject'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$errors&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Marker::has()&lt;/code&gt; is a three-line helper that looks for the attribute on a class. Rule 1 (an entity has a public &lt;code&gt;id()&lt;/code&gt; method) is the same shape: if a class is marked &lt;code&gt;#[Entity]&lt;/code&gt; or &lt;code&gt;#[AggregateRoot]&lt;/code&gt; and has no public &lt;code&gt;id()&lt;/code&gt;, report it. The rules are registered in &lt;code&gt;phpstan.neon&lt;/code&gt; like any other:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;parameters:
    level: 8
    paths: [src]
services:
    - { class: Rules\AggregateReferencesByIdRule, tags: [phpstan.rules.rule] }
    - { class: Rules\EntityHasIdentityRule, tags: [phpstan.rules.rule] }
    - { class: Rules\ValueObjectIsImmutableRule, tags: [phpstan.rules.rule] }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Rules 7 and 8: layers, with two tools that disagree
&lt;/h2&gt;

&lt;p&gt;Deptrac states the dependency direction as data (use the &lt;code&gt;deptrac/deptrac&lt;/code&gt; package; the old &lt;code&gt;qossmic/deptrac&lt;/code&gt; is flagged as abandoned by Composer):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;deptrac&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;./src&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
  &lt;span class="na"&gt;layers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Domain&lt;/span&gt;
      &lt;span class="na"&gt;collectors&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[{&lt;/span&gt; &lt;span class="nv"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;classLike&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;^App\\Sales\\Domain\\.*'&lt;/span&gt; &lt;span class="pi"&gt;}]&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Application&lt;/span&gt;
      &lt;span class="na"&gt;collectors&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[{&lt;/span&gt; &lt;span class="nv"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;classLike&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;^App\\Sales\\Application\\.*'&lt;/span&gt; &lt;span class="pi"&gt;}]&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Infrastructure&lt;/span&gt;
      &lt;span class="na"&gt;collectors&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[{&lt;/span&gt; &lt;span class="nv"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;classLike&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;^App\\Sales\\Infrastructure\\.*'&lt;/span&gt; &lt;span class="pi"&gt;}]&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Doctrine&lt;/span&gt;
      &lt;span class="na"&gt;collectors&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[{&lt;/span&gt; &lt;span class="nv"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;classLike&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;^Doctrine\\.*'&lt;/span&gt; &lt;span class="pi"&gt;}]&lt;/span&gt;
  &lt;span class="na"&gt;ruleset&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Domain&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;~&lt;/span&gt;
    &lt;span class="na"&gt;Application&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;Domain&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;Infrastructure&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;Domain&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;Application&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;Doctrine&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;phpat expresses architecture rules as PHP, as a PHPStan extension:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;testDomainDependsOnNothing&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;PHPatRule&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;PHPat&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;rule&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;classes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Selector&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;inNamespace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'App\Sales\Domain'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;canOnlyDependOn&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;classes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nc"&gt;Selector&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;inNamespace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'App\Sales\Domain'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="nc"&gt;Selector&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;classname&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/^[^\\\\]+$/'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="c1"&gt;// PHP built-ins in the global namespace&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;because&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'the domain depends on nothing else'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;testRepositoryImplementationIsNotInDomain&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;PHPatRule&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;PHPat&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;rule&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;classes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Selector&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;inNamespace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'App\Sales\Domain'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;shouldNotImplement&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;classes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Selector&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;classname&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;OrderRepository&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;because&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'repository implementations live outside the domain model'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(The regular expression lets &lt;code&gt;DomainException&lt;/code&gt; and other global classes through, otherwise phpat flags them as outside dependencies.) I ran PHP Arkitect on the dependency and immutability rules too; it caught the same mutants as the other two there.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rules 3 and 5: a number you choose
&lt;/h2&gt;

&lt;p&gt;I did not find a standard tool for "anemic entity" or "aggregate too big", so the demo has a thirty-line script. It counts, per &lt;code&gt;#[Entity]&lt;/code&gt; or &lt;code&gt;#[AggregateRoot]&lt;/code&gt; class, behaviour methods against getters and setters, and the members (entities and value objects) reachable inside an aggregate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;anemia  App\Sales\Domain\Customer   behaviour=3 accessors=3 share=0.50 ok
anemia  App\Sales\Domain\Order      behaviour=2 accessors=3 share=0.40 ok
size    App\Sales\Domain\Order      members=3 (max 5) ok [Money,OrderLine,OrderNumber]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both thresholds are arbitrary and that is the point of rules 3 and 5: they are &lt;em&gt;project decisions&lt;/em&gt;, written down and enforced, not facts about DDD.&lt;/p&gt;

&lt;h2&gt;
  
  
  The question the rules cannot answer about themselves
&lt;/h2&gt;

&lt;p&gt;All of the above is green on the clean domain. That says nothing about whether the rules would go red on a violation. This is exactly the question mutation testing answers for code: change the code a little, run the tests, and count the changes nobody noticed. The idea carries over to a ruleset. A &lt;em&gt;mutant&lt;/em&gt; here is a violation of one rule, applied to a copy of the domain as a textual patch, and the check is whether any tool exits with an error.&lt;/p&gt;

&lt;p&gt;The runner is short: copy the clean &lt;code&gt;src/&lt;/code&gt;, apply one patch, run every tool, record "caught" when its exit code is not zero, restore, repeat. A mutant looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="s1"&gt;'M3  Customer holds an Order object'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$D&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;edit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$D&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'Customer.php'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'public function id(): CustomerId'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'private ?Order $lastOrder = null;'&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;    "&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt;
        &lt;span class="s1"&gt;'public function lastOrder(): ?Order { return $this-&amp;gt;lastOrder; }'&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;    "&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt;
        &lt;span class="s1"&gt;'public function id(): CustomerId'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Twelve mutants, seven checks (&lt;code&gt;php -l&lt;/code&gt;, a runtime probe that instantiates the value object and tries to change it, PHPStan with the three custom rules, Deptrac, phpat, Arkitect, the metrics script):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mutant&lt;/th&gt;
&lt;th&gt;probe&lt;/th&gt;
&lt;th&gt;PHPStan + rules&lt;/th&gt;
&lt;th&gt;Deptrac&lt;/th&gt;
&lt;th&gt;phpat&lt;/th&gt;
&lt;th&gt;Arkitect&lt;/th&gt;
&lt;th&gt;metrics&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;M1 setter on a (non-readonly) VO&lt;/td&gt;
&lt;td&gt;caught&lt;/td&gt;
&lt;td&gt;caught&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;caught&lt;/td&gt;
&lt;td&gt;caught&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;M1b setter on a &lt;strong&gt;readonly&lt;/strong&gt; VO&lt;/td&gt;
&lt;td&gt;the language&lt;/td&gt;
&lt;td&gt;caught&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;M2 public mutable VO property&lt;/td&gt;
&lt;td&gt;caught&lt;/td&gt;
&lt;td&gt;caught&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;caught&lt;/td&gt;
&lt;td&gt;caught&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;M3 Customer holds an Order object&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;caught&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;M4 domain imports Doctrine&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;caught&lt;/td&gt;
&lt;td&gt;caught&lt;/td&gt;
&lt;td&gt;caught&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;M5 entity without identity&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;caught&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;M6 repository implementation in the domain&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;caught&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;M7 anemic entity&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;caught&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;M8 aggregate over the size limit&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;caught&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;M9 an equivalent rewrite (&lt;code&gt;+=&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;M10 readonly VO holding a mutable object&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;M11 an invariant dropped&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;php -l&lt;/code&gt; caught nothing, because every mutant is valid PHP.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the table says
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Different tools see different mutants.&lt;/strong&gt; M3 and M5 are caught only by my two custom PHPStan rules; the layer tools know nothing about aggregates or identity. M7 and M8 are caught only by the metrics script. M6, a repository implementation put into the domain namespace, is caught only by phpat: Deptrac sees a domain class implementing a domain interface, which is an allowed dependency. I did not write an Arkitect rule for it, and it can probably do the same. No single tool has the whole picture, which is an argument for a small set instead of a big one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The language is the cheapest rule.&lt;/strong&gt; M1b is stopped by PHP at runtime and by PHPStan statically without any custom rule; &lt;code&gt;final readonly class&lt;/code&gt; plus an attribute is enough for most of rule 2.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Three mutants slip through everything&lt;/strong&gt;, and each has a different reason:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;M9&lt;/strong&gt; is &lt;em&gt;equivalent&lt;/em&gt;: a rewrite that changes nothing observable. Correctly caught by nothing. This is the same class as in ordinary mutation testing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;M10&lt;/strong&gt; is a real blind spot: &lt;code&gt;readonly&lt;/code&gt; is shallow, and a value object that holds a mutable object is still mutable. A rule could look at property types, but then you have to decide what counts as mutable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;M11&lt;/strong&gt; drops an invariant (a validation in the constructor). That is &lt;em&gt;behaviour&lt;/em&gt;, and static rules cannot see it. Only unit tests, or mutation testing of the domain's own tests, will.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That last point is where the two kinds of mutation meet: architecture rules protect the &lt;em&gt;shape&lt;/em&gt; of the model, and classic mutation testing (Infection in PHP) protects the &lt;em&gt;behaviour&lt;/em&gt; inside it. A rule set with a high detection rate and a domain test suite with a high mutation score cover different failures. I did not run Infection on this toy domain; with 13 files it would prove nothing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limits, honestly
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;13 files and 12 hand-written mutants: this is a demonstration of a method, not a benchmark of the tools. Do not read the table as "phpat beats Deptrac".&lt;/li&gt;
&lt;li&gt;The thresholds (an anemia share, five members per aggregate) are arbitrary.&lt;/li&gt;
&lt;li&gt;The mutants are textual patches. Real violations are subtler, and generating them automatically, the way mutation tools do for code, is the interesting next step.&lt;/li&gt;
&lt;li&gt;Everything ran on one machine (Windows, PHP 8.4). The runner (&lt;code&gt;php bin/mutants.php&lt;/code&gt;, about three minutes) restores the sources afterwards.&lt;/li&gt;
&lt;li&gt;The 2017 post's own limitation stands: no tool tells you that your aggregate boundaries are &lt;em&gt;right&lt;/em&gt;. These checks keep a model from drifting; they do not design it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Lukas Taake, "Static code analysis for Domain-Driven Design, part 1", 2017: &lt;a href="https://www.ltaake.com/blog/2017/09/static-code-analysis-for-domain-driven-design-part-1/" rel="noopener noreferrer"&gt;https://www.ltaake.com/blog/2017/09/static-code-analysis-for-domain-driven-design-part-1/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Eric Evans, &lt;em&gt;Domain-Driven Design&lt;/em&gt; (2003); Vaughn Vernon, &lt;em&gt;Implementing Domain-Driven Design&lt;/em&gt; (2013).&lt;/li&gt;
&lt;li&gt;Yue Jia and Mark Harman, "An Analysis and Survey of the Development of Mutation Testing", IEEE Transactions on Software Engineering, 2011.&lt;/li&gt;
&lt;li&gt;Tools: &lt;a href="https://phpstan.org" rel="noopener noreferrer"&gt;PHPStan&lt;/a&gt;, &lt;a href="https://github.com/deptrac/deptrac" rel="noopener noreferrer"&gt;Deptrac&lt;/a&gt;, &lt;a href="https://github.com/carlosas/phpat" rel="noopener noreferrer"&gt;phpat&lt;/a&gt;, &lt;a href="https://github.com/phparkitect/arkitect" rel="noopener noreferrer"&gt;PHP Arkitect&lt;/a&gt;, &lt;a href="https://infection.github.io" rel="noopener noreferrer"&gt;Infection&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I maintain a PostgreSQL search library, &lt;a href="https://github.com/er2es/fuzzphony" rel="noopener noreferrer"&gt;Fuzzphony&lt;/a&gt;, and the habit of asking "would a test notice if this were wrong?" came from there; I wrote about what a 95% mutation score still misses in the previous post. If you run something like this on a real codebase, I would like to hear which mutants your rules missed.&lt;/p&gt;

</description>
      <category>php</category>
      <category>ddd</category>
      <category>architecture</category>
      <category>testing</category>
    </item>
    <item>
      <title>95% mutation score, and a review still found a cross-tenant leak: Fuzzphony 0.11</title>
      <dc:creator>Szj</dc:creator>
      <pubDate>Thu, 05 Nov 2026 08:06:17 +0000</pubDate>
      <link>https://dev.to/_er2es_/95-mutation-score-and-a-review-still-found-a-cross-tenant-leak-fuzzphony-011-27c5</link>
      <guid>https://dev.to/_er2es_/95-mutation-score-and-a-review-still-found-a-cross-tenant-leak-fuzzphony-011-27c5</guid>
      <description>&lt;p&gt;Last time I wrote about &lt;a href="https://dev.to/_er2es_/i-couldnt-touch-the-database-so-i-built-search-next-to-it-1pjn"&gt;building search next to a database I couldn't touch&lt;/a&gt;. Fuzzphony was at v0.4 then. It is v0.11.1 now, and the post ended with a section called "What I haven't solved yet". So this one starts there.&lt;/p&gt;

&lt;p&gt;The short version: a typo-tolerant, ranked search for a PostgreSQL database you may not be allowed to change (a sidecar table, &lt;code&gt;pg_trgm&lt;/code&gt;, full-text search, no new infrastructure). The longer version is below, including the part I find more interesting than the features: &lt;strong&gt;a 95% mutation score did not stop three real bugs, and an independent review found them the week before the release.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I said I hadn't solved
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Short words matched the wrong thing.&lt;/strong&gt; &lt;code&gt;mouse&lt;/code&gt; matched &lt;code&gt;monitor&lt;/code&gt;, because a flat trigram threshold is too generous for a five-letter word and too strict for a fifteen-letter one. Since 0.7 the tolerance grows with the length of the word, so &lt;code&gt;mouse&lt;/code&gt; stays &lt;code&gt;mouse&lt;/code&gt;, and &lt;code&gt;hedphones&lt;/code&gt; still finds headphones.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Very common words lost their best match.&lt;/strong&gt; The candidate window (&lt;code&gt;candidate_limit&lt;/code&gt;, 2000 by default) is cut before ranking, so for a word that appears in half the catalogue the best hit could fall off the edge. 0.9.8 changed how candidates are chosen so the best match of a very common word is no longer lost above the limit. The same release added tolerance for swapped letters (&lt;code&gt;recieve&lt;/code&gt;) and a zero-result rescue: when a search finds nothing, it retries the closest spelling and tells you it did (&lt;code&gt;correctedTo&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Operations.&lt;/strong&gt; Reindexing without a gap (a shadow table that is swapped in), Prometheus metrics with sample Grafana dashboards, synonyms from Solr/Elasticsearch files that can be swapped at runtime, and "did you mean" from a vocabulary table all landed between 0.5 and 0.7. The rest of the rough edges I listed then are in the changelog.&lt;/p&gt;

&lt;h2&gt;
  
  
  0.10: secure by default
&lt;/h2&gt;

&lt;p&gt;The part of search libraries I trust least is the part that decides &lt;strong&gt;who may see what&lt;/strong&gt;, so 0.10 was the breaking release that made the safe thing the default.&lt;/p&gt;

&lt;p&gt;Without a token the caller is anonymous. A system caller has to say so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// a console command, a cron job: explicitly the system&lt;/span&gt;
&lt;span class="nv"&gt;$hits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$fuzzphony&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;in&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'customers'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;asSystem&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'kovacs'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// a web request: the ambient actor is whoever is logged in&lt;/span&gt;
&lt;span class="nv"&gt;$hits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$fuzzphony&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;in&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'customers'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;forTenant&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$tenantId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'kovacs'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is one tenant rule: an actor of tenant A cannot ask for tenant B, unless the call is &lt;code&gt;asSystem()&lt;/code&gt;. Fields can be &lt;code&gt;granted&lt;/code&gt; to a role, and a search by a viewer who does not hold the grant must not change because of a field they cannot see. I call that hidden-field independence: ids, ranks, totals, facets and highlights are the same whatever the hidden fields contain. There are also two database roles (a worker and an admin) with &lt;code&gt;--dump-grants&lt;/code&gt; so the search process never needs DDL rights, and &lt;code&gt;code: true&lt;/code&gt; fields for invoice numbers and SKUs (&lt;code&gt;INV-001&lt;/code&gt;-style values are matched exactly, not "fuzzily"). The public API went from 102 types to 77, so the surface you can rely on is smaller and written down.&lt;/p&gt;

&lt;h2&gt;
  
  
  0.11: several sources, several values, one row to render
&lt;/h2&gt;

&lt;p&gt;Real systems have a customer table, a company table, and orders. 0.11 lets one index read all of them (a simplified version of the demo's &lt;code&gt;site&lt;/code&gt; index):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;fuzzphony&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;indexes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;site&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;sources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;person&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;query&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;SELECT&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;id,&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;AS&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;title,&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;email&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;AS&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;body,&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;account_id&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;AS&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;account&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;FROM&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;erp_customer&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;WHERE&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;kind&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;=&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;'person'"&lt;/span&gt;
          &lt;span class="na"&gt;watch&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;erp_customer&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;SELECT&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;:id"&lt;/span&gt; &lt;span class="pi"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;order&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;query&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;SELECT&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;id,&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;number&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;AS&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;title,&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;note&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;AS&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;body,&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;account_id&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;AS&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;account&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;FROM&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;erp_order"&lt;/span&gt;
          &lt;span class="na"&gt;watch&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;erp_order&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;SELECT&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;:id"&lt;/span&gt; &lt;span class="pi"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;fields&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;title&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;weight&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;A&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;fuzzy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;true&lt;/span&gt; &lt;span class="pi"&gt;},&lt;/span&gt; &lt;span class="nv"&gt;body&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;C&lt;/span&gt; &lt;span class="pi"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;filters&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;account&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;int&lt;/span&gt; &lt;span class="pi"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;tenant&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;account&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A hit says which source it comes from (&lt;code&gt;$hit-&amp;gt;kind&lt;/code&gt;) and carries that source's own typed id. Each source has its own watch, so changing a row refreshes only the right document, and the doctor now warns when the source query reads a table no watch covers.&lt;/p&gt;

&lt;p&gt;A customer has several addresses. Instead of a folded &lt;code&gt;string_agg(...)&lt;/code&gt; column, a field can say where the values live:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;city&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;weight&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;C&lt;/span&gt;
  &lt;span class="na"&gt;fuzzy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="na"&gt;many&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;from&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;address&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;customer_id&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;column&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;city&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;limit&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;50&lt;/span&gt; &lt;span class="pi"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and the explanation tells you which address matched ("found in the address: Budapest"). The next release is going to rank by the best single value instead of the whole field; that is a design I would rather finish properly than rush.&lt;/p&gt;

&lt;p&gt;And the thing every search page needs: a result row. &lt;code&gt;with()&lt;/code&gt; returns columns of the hit's source row, so a page can be rendered and linked without loading entities:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$fuzzphony&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;in&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'products'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'mouse'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'title'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'slug'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'price'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$result&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;hits&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$hit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$hit&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'title'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$hit&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'price'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is opt-in, reads the current value (nothing extra is copied into the index), and a column behind a &lt;code&gt;granted&lt;/code&gt; field is returned only to someone who holds the grant. Remember that last sentence; it comes back below.&lt;/p&gt;

&lt;p&gt;The demo grew an ERP data set (about half a million rows: customers, companies, addresses, orders, order lines), an ERP page with separate and combined search boxes, a live demonstration of the sync (move an address to another city, watch which indexes refreshed), and a search box in the header that searches every index of the demo at once. With about seven indexes the engine answers in 40 to 170 ms.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I know it works
&lt;/h2&gt;

&lt;p&gt;The test suite has about 3,700 tests, PHPStan at max level, and coverage close to 100%. Coverage tells you which lines ran. &lt;strong&gt;Mutation testing&lt;/strong&gt; tells you whether the tests would notice if a line were wrong: the tool changes the code a little (&lt;code&gt;&amp;gt;&lt;/code&gt; becomes &lt;code&gt;&amp;gt;=&lt;/code&gt;, &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; becomes &lt;code&gt;||&lt;/code&gt;, a line disappears) and runs the tests; a mutant that survives is a place where nothing checks the behaviour.&lt;/p&gt;

&lt;p&gt;The numbers, from CI:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Run&lt;/th&gt;
&lt;th&gt;Mutants&lt;/th&gt;
&lt;th&gt;Covered-code score&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;First full run (September)&lt;/td&gt;
&lt;td&gt;3,944&lt;/td&gt;
&lt;td&gt;85%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;After 0.8.1&lt;/td&gt;
&lt;td&gt;5,989&lt;/td&gt;
&lt;td&gt;96%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.11.0 branch&lt;/td&gt;
&lt;td&gt;about 11,900&lt;/td&gt;
&lt;td&gt;95%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The last full run takes 1 hour 45 minutes on CI, so it always lags one step behind the code; I run it once per release and work with the result. Of the 486 survivors in 0.11 I killed the ones in the new code with focused tests (assert what the code must do, never a mirror of the code), and I sorted the rest into a few classes that cannot be killed because the mutant is equivalent:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a limit that the validator already guarantees (a replace "limited to 1" versus "limited to 2" when exactly one placeholder can exist),&lt;/li&gt;
&lt;li&gt;a cast on an array key that PHP normalises anyway,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;array_values()&lt;/code&gt; on a list that is only iterated,&lt;/li&gt;
&lt;li&gt;a branch the code itself marks as unreachable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It sounds boring, and it is, until you read the next section.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a mutation score cannot see
&lt;/h2&gt;

&lt;p&gt;Before tagging 0.11.0 I asked for an independent, adversarial review of everything new in &lt;code&gt;src/&lt;/code&gt; (about 2,700 added lines), with one instruction: try to break the two promises that matter, hidden-field independence and no tenant crossing. It found three real bugs, behind a 95% score and a green suite.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. A hit of the wrong kind became someone else's row.&lt;/strong&gt; In a multi-source index the hits are &lt;code&gt;emp:1&lt;/code&gt; and &lt;code&gt;post:2&lt;/code&gt;. The helper that turned a result into ids dropped the kind, so loading the &lt;code&gt;Emp&lt;/code&gt; entity from the result looked up &lt;code&gt;[1, 2]&lt;/code&gt;, and &lt;code&gt;Emp&lt;/code&gt; 2 is a row of another tenant that did not match anything:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$fuzzphony&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;in&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'site'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;forTenant&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ada'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;   &lt;span class="c1"&gt;// hits: emp:1, post:2&lt;/span&gt;
&lt;span class="nv"&gt;$result&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;                                                         &lt;span class="c1"&gt;// [1, 2]  (the kind is gone)&lt;/span&gt;
&lt;span class="nv"&gt;$loader&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Emp&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;                                     &lt;span class="c1"&gt;// loads Emp 1 and Emp 2 (tenant 2)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The fix uses only the hits whose source reads the requested class. I never would have written a test for it, because the single-source world, where ids are enough, was the only one I was thinking about.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. &lt;code&gt;with()&lt;/code&gt; leaked a granted column under another name.&lt;/strong&gt; The grant check looked at the &lt;em&gt;field&lt;/em&gt; name; &lt;code&gt;returnable&lt;/code&gt; lists &lt;em&gt;column&lt;/em&gt; names. A field &lt;code&gt;pay&lt;/code&gt; reading the column &lt;code&gt;salary&lt;/code&gt; and granted to &lt;code&gt;ROLE_HR&lt;/code&gt; was refused when asked as &lt;code&gt;with('pay')&lt;/code&gt;, and returned to everybody when asked as &lt;code&gt;with('salary')&lt;/code&gt;. The check now follows the column.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. The ORM sync refreshed only the first index of an entity.&lt;/strong&gt; A second index of the same entity, or a multi-source index reading it, was never refreshed: deleted rows stayed findable, and a row moved to another tenant stayed in the old tenant's results.&lt;/p&gt;

&lt;p&gt;None of these has a surviving mutant to point at. The code for each was covered, the lines ran, and the tests asserted what I had thought of. A mutation score finds the tests I forgot to write for code I wrote; it cannot find the requirement I forgot. Only someone (or something) with a different mental model can, and so I now treat an independent review as part of the release, next to the suite, not after it.&lt;/p&gt;

&lt;p&gt;Other safety nets that earned their place:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A differential harness.&lt;/strong&gt; For anything that touches ranking, a script runs 1,854 searches against the previous release and the new code and demands byte-identical results and statements, with the sequential-scan synchronisation switched off so timings are comparable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CI jobs that are not the happy path.&lt;/strong&gt; The tests run against several PostgreSQL versions, with the oldest allowed dependencies, and against the next Symfony. In this release the first CI run was red for three reasons my machine had not shown: a demo smoke job that did not seed the new tables, a &lt;code&gt;NAN&lt;/code&gt; in an error message that PHP turned into a warning (and PHPUnit into a failure), and an old Doctrine whose stub returned &lt;code&gt;null&lt;/code&gt; where the new one returned an array.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;p&gt;0.12 is ranking by the best value of a field with several values (with a per-search switch for "one value must hold all the words"), a first step to a smaller sidecar, and the remaining mutation gaps. After that, 1.0: a stable API and a backward-compatibility promise.&lt;/p&gt;

&lt;p&gt;The library is on GitHub (&lt;a href="https://github.com/er2es/fuzzphony" rel="noopener noreferrer"&gt;er2es/fuzzphony&lt;/a&gt;), and the demo runs with one &lt;code&gt;docker compose up&lt;/code&gt;. If you have a database you cannot change and a search box that disappoints your users, I would like to hear what breaks first.&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>php</category>
      <category>symfony</category>
      <category>testing</category>
    </item>
    <item>
      <title>The State of Mutation Testing (Infection) in the PHP Ecosystem: A Scientific and Practical Analysis</title>
      <dc:creator>Szj</dc:creator>
      <pubDate>Sun, 11 Oct 2026 05:33:02 +0000</pubDate>
      <link>https://dev.to/_er2es_/the-state-of-mutation-testing-infection-in-the-php-ecosystem-a-scientific-and-practical-analysis-dip</link>
      <guid>https://dev.to/_er2es_/the-state-of-mutation-testing-infection-in-the-php-ecosystem-a-scientific-and-practical-analysis-dip</guid>
      <description>&lt;h2&gt;
  
  
  Abstract
&lt;/h2&gt;

&lt;p&gt;For decades, Code Coverage has served as the primary quality assurance metric in the software engineering industry. However, this metric often provides a false sense of security: it merely proves that a specific line of code was executed during a test run, but it does not guarantee that the test contains relevant and rigorous assertions. Mutation Testing provides an exact solution to this anomaly, with the Infection framework becoming the de facto standard in the PHP ecosystem. This analysis examines the efficacy, exponential resource requirements, theoretical limitations, CI/CD applicability, and the Return on Investment (ROI) of the methodology in enterprise environments.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Theoretical Background and Methodology
&lt;/h2&gt;

&lt;p&gt;The fundamental question of mutation testing—and a core paradox of quality assurance—is: &lt;em&gt;"Who guards the guards?"&lt;/em&gt; In other words, what mechanism can validate the reliability of the test suite itself?&lt;/p&gt;

&lt;p&gt;The Infection PHP framework operates through the dynamic manipulation of the Abstract Syntax Tree (AST). During execution, the program injects syntactically correct but semantically incorrect modifications (mutations) into the source code. &lt;/p&gt;

&lt;p&gt;Typical mutation operators include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Arithmetic mutations:&lt;/strong&gt; Replacing the &lt;code&gt;+&lt;/code&gt; operator with the &lt;code&gt;-&lt;/code&gt; operator.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Relational mutations:&lt;/strong&gt; Degrading a &lt;code&gt;&amp;gt;&lt;/code&gt; (strictly greater than) condition to a &lt;code&gt;&amp;gt;=&lt;/code&gt; (greater than or equal to) condition.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Return value and boolean mutations:&lt;/strong&gt; Replacing &lt;code&gt;return true&lt;/code&gt; with &lt;code&gt;return false&lt;/code&gt;, or removing method calls entirely.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each autonomously generated, modified version of the code is called a &lt;strong&gt;Mutant&lt;/strong&gt;. Following generation, the system iteratively runs the existing test suite against the given mutant:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  If the test fails, the mutant is considered &lt;strong&gt;Killed&lt;/strong&gt;. This is the ideal scenario, proving that the test suite is sufficiently defensive.&lt;/li&gt;
&lt;li&gt;  If the test passes successfully, the mutant has &lt;strong&gt;Escaped&lt;/strong&gt; the assertions. This clearly indicates that the test suite is blind to that specific change in the business logic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From these results, the framework aggregates the &lt;strong&gt;MSI (Mutation Score Indicator)&lt;/strong&gt;, which represents the percentage of successfully killed mutants.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. The Value Proposition (ROI)
&lt;/h2&gt;

&lt;p&gt;Based on scientific research and industry experience, the integration of Infection results in a significant paradigm shift regarding software quality.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Empirical Measurement of Software Quality:&lt;/strong&gt; A traditional 100% Line Coverage can be achieved even if the tests contain absolutely no &lt;code&gt;assert&lt;/code&gt; statements. In contrast, the MSI metric cannot be manipulated. Mutation testing ruthlessly exposes unhandled edge cases, the over-preference for the "happy path," and the lack of robustness in the code.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Identification of Redundancy and "Dead Code":&lt;/strong&gt; The methodology identifies overly complex control flows with surgical precision. If a mutant continuously survives tests within a complex branch, it most often indicates that the specific code block is unreachable based on business logic (dead code), or it is so redundant that it requires immediate refactoring.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Cultural and Developer Education:&lt;/strong&gt; The methodology proactively shapes the test-writing culture of engineering teams. Engineers learn to write higher-quality, defensive code and more rigorous assertions, minimizing the ratio of superficial tests.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. Technological Limitations and Critical Analysis
&lt;/h2&gt;

&lt;p&gt;While the methodology is theoretically sound, its practical implementation—especially in large-scale enterprise environments—faces severe technological and resource constraints.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.1. Combinatorial Explosion and Computational Overhead
&lt;/h3&gt;

&lt;p&gt;The most significant obstacle to mutation testing is its exponential resource requirement. If a project has 1,000 tests and Infection generates 5,000 mutants, it theoretically requires the test suite to be executed 5,000 times.&lt;/p&gt;

&lt;p&gt;The continuous rebuilding of the AST and the thousands of initializations of the test runner (PHPUnit/Pest) introduce extreme CPU and memory loads. A standard 2-minute Continuous Integration (CI) test run can easily balloon to 40-60 minutes with full-scale Infection application, which is incompatible with the fast feedback loops expected in modern Agile/DevOps pipelines.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.2. The Equivalent Mutants Problem
&lt;/h3&gt;

&lt;p&gt;Academic studies unanimously refer to the phenomenon of &lt;em&gt;equivalent mutants&lt;/em&gt; as the deepest, still only partially solved challenge of mutation testing. These are syntactic transformations that do not mathematically or logically alter the final semantics of the code.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example:&lt;/em&gt; An operator change made for optimization purposes in a loop's indexing creates a mutation, but the algorithm's output remains invariant.&lt;/p&gt;

&lt;p&gt;Because these mutants naturally always survive the tests, they falsely degrade the MSI score. Developers can lose valuable work hours manually analyzing these false positives, leading to what is known as "Developer Fatigue."&lt;/p&gt;

&lt;h3&gt;
  
  
  3.3. Implementation Challenges in Legacy Systems
&lt;/h3&gt;

&lt;p&gt;Introducing Infection into a monolithic PHP application with high technical debt and low (sub-50%) test coverage is counterproductive. The system will generate surviving mutants in the tens of thousands, creating unprocessable informational noise for the team. The methodology only provides true value in codebases that already possess dedicated, high coverage (ideally above 85%).&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Modern Optimization Strategies (CI/CD Integration)
&lt;/h2&gt;

&lt;p&gt;To ensure sustainable usage, the PHP community and framework maintainers have introduced innovative architectural solutions that allow mutation testing to be integrated into daily development cycles:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Multithreading:&lt;/strong&gt; Modern PHP environments (e.g., via the &lt;code&gt;pcntl&lt;/code&gt; extension) support the asynchronous, parallel processing of mutants. Fully utilizing available CPU cores (e.g., &lt;code&gt;--threads=4&lt;/code&gt;) drastically reduces execution time.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Incremental Diff-Based Testing:&lt;/strong&gt; This represents the greatest technological breakthrough. In modern CI pipelines, Infection does not scan the entire codebase; instead, it strictly limits mutant generation to the lines of code modified in the Pull Request or Git commit (&lt;code&gt;--git-diff-lines&lt;/code&gt;). This technique reduces runtime from hours to mere seconds.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Baseline Architecture:&lt;/strong&gt; Similar to static code analyzers (PHPStan, Psalm), Infection can save existing, historical surviving mutants into a reference file (baseline). Consequently, the CI process only fails if a developer attempts to integrate &lt;em&gt;new&lt;/em&gt;, inadequately tested code into the system.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  5. Conclusion and Architectural Recommendations
&lt;/h2&gt;

&lt;p&gt;The application of mutation testing is not a universal silver bullet; its adoption requires a deliberate engineering decision.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Critically Recommended Application Areas:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Financial technologies (FinTech), payment gateways, and transactional systems.&lt;/li&gt;
&lt;li&gt;  High-risk healthcare and government software.&lt;/li&gt;
&lt;li&gt;  Widely used Open Source libraries (e.g., the Symfony and Doctrine ecosystems actively benefit from this level of scrutiny).&lt;/li&gt;
&lt;li&gt;  Isolated testing of the Core/Domain (business) layer in software built on strict Domain-Driven Design (DDD) principles.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Contraindicated Areas:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Rapid prototypes and applications in the MVP (Minimum Viable Product) phase.&lt;/li&gt;
&lt;li&gt;  Simple CRUD (Create, Read, Update, Delete) and administrative interfaces.&lt;/li&gt;
&lt;li&gt;  Thin API endpoints where the code exclusively performs database reads without complex logical transformations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Final Verdict:&lt;/strong&gt; The application of Infection in the PHP ecosystem represents the current State of the Art in software quality. Engineering teams willing to navigate the adoption curve and manage the increased CI/CD resource requirements will achieve a degree of mathematical and logical stability that is completely unattainable with traditional coverage metrics.&lt;/p&gt;




&lt;h2&gt;
  
  
  Bibliography and References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;[1] DeMillo, R. A., Lipton, R. J., &amp;amp; Sayward, F. G. (1978).&lt;/strong&gt; &lt;em&gt;Hints on Test Data Selection: Help for the Practicing Programmer&lt;/em&gt;. IEEE Computer, 11(4), 34-41. (The foundational work laying the theoretical groundwork for mutation testing).&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;[2] Jia, Y., &amp;amp; Harman, M. (2010).&lt;/strong&gt; &lt;em&gt;An Analysis and Survey of the Development of Mutation Testing&lt;/em&gt;. IEEE Transactions on Software Engineering, 37(5), 649-678. (A comprehensive industry study on the adoption and efficacy of mutation testing).&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;[3] Offutt, A. J., &amp;amp; Pan, J. (1996).&lt;/strong&gt; &lt;em&gt;Detecting Equivalent Mutants and the Feasible Path Problem&lt;/em&gt;. Proceedings of the 11th Annual Conference on Computer Assurance (COMPASS '96). (Scientific analysis of the equivalent mutants phenomenon and the challenges of detecting them discussed in this article).&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;[4] Infection PHP Official Documentation. (2024).&lt;/strong&gt; &lt;em&gt;Infection - PHP Mutation Testing Framework&lt;/em&gt;. Available at: infection.github.io (Official reference for technical implementation details, Git Diff filtering, and Baseline functionality).&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>php</category>
      <category>testing</category>
      <category>softwareengineering</category>
      <category>webdev</category>
    </item>
    <item>
      <title>5 Angular Anti-Patterns You Need to Stop Using Immediately (and How to Fix Them in Angular 21)</title>
      <dc:creator>Szj</dc:creator>
      <pubDate>Sun, 11 Oct 2026 04:58:00 +0000</pubDate>
      <link>https://dev.to/_er2es_/5-angular-anti-patterns-you-need-to-stop-using-immediately-and-how-to-fix-them-in-angular-21-1hg6</link>
      <guid>https://dev.to/_er2es_/5-angular-anti-patterns-you-need-to-stop-using-immediately-and-how-to-fix-them-in-angular-21-1hg6</guid>
      <description>&lt;p&gt;Angular is a robust, enterprise-grade framework, but with great power comes great responsibility. Because Angular gives us so much freedom, it is incredibly easy to shoot ourselves in the foot, especially as the application starts to scale.&lt;/p&gt;

&lt;p&gt;If your app feels sluggish, or if your components are becoming an unmaintainable mess, chances are you are falling victim to a few common bad habits. &lt;/p&gt;

&lt;p&gt;Let's look at 5 of the most frequent Angular anti-patterns and how to refactor them using modern, clean code practices tailored for Angular 21.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Function Calls in Templates (The Performance Killer)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Anti-pattern:&lt;/strong&gt; Calling a component method directly in your HTML template for data binding.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- [BAD]: This will execute on every single Change Detection cycle --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Total: {{ calculateTotal(cartItems) }}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;[class.active]=&lt;/span&gt;&lt;span class="s"&gt;"checkIfUserIsActive(user)"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why it is bad:&lt;/strong&gt; Angular's Change Detection (CD) is aggressive by default. Every time anything happens (a click, a timer, an HTTP response), Angular checks the template for changes. If you bind a function in the template, Angular has to re-execute that function every single CD cycle to see if the return value changed. If &lt;code&gt;calculateTotal&lt;/code&gt; involves heavy array manipulation, your app will freeze.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Modern Solution:&lt;/strong&gt; &lt;br&gt;
Use &lt;strong&gt;Pure Pipes&lt;/strong&gt; for transformations, or better yet, use &lt;strong&gt;Angular 21 Signals&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// [GOOD]: Using Angular 21 Signals&lt;/span&gt;
&lt;span class="nx"&gt;cartItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;CartItem&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;

&lt;span class="c1"&gt;// computed() caches the value and ONLY recalculates if cartItems changes!&lt;/span&gt;
&lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cartItems&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;acc&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- [GOOD]: Just binding to the computed signal --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Total: {{ total() }}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  2. Abandoned Subscriptions (The Memory Leak)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Anti-pattern:&lt;/strong&gt; Subscribing to an Observable but forgetting to unsubscribe when the component is destroyed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// [BAD]: This subscription lives forever, even if the user navigates away.&lt;/span&gt;
&lt;span class="nf"&gt;ngOnInit&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUserData&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why it is bad:&lt;/strong&gt; When the Angular Router destroys this component, the subscription remains active in memory. This leads to memory leaks and ghost code executions in the background, causing weird UI bugs and crashing browsers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Modern Solution:&lt;/strong&gt;&lt;br&gt;
If you must use RxJS instead of Signals for a specific data stream, use the &lt;strong&gt;&lt;code&gt;takeUntilDestroyed()&lt;/code&gt;&lt;/strong&gt; operator. In modern Angular, you do not even need to implement &lt;code&gt;ngOnDestroy&lt;/code&gt; for this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// [GOOD]: Modern approach&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;takeUntilDestroyed&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core/rxjs-interop&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;userService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUserData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;takeUntilDestroyed&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// Automatically unsubscribes on destroy!&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  3. Nested Subscriptions (The Reactive "Callback Hell")
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Anti-pattern:&lt;/strong&gt; Subscribing to an Observable inside another Observable's &lt;code&gt;subscribe&lt;/code&gt; block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// [BAD]: Hard to read, impossible to test, and prone to race conditions.&lt;/span&gt;
&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]).&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;projectService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getProjects&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;organizationId&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;projects&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;projects&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;projects&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why it is bad:&lt;/strong&gt; It breaks the declarative nature of RxJS. More importantly, it creates race conditions. If the user clicks fast and triggers multiple ID changes, the HTTP responses might arrive out of order, rendering the wrong data on the screen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Modern Solution:&lt;/strong&gt;&lt;br&gt;
Leverage Higher-Order Mapping operators like &lt;code&gt;switchMap&lt;/code&gt;, &lt;code&gt;concatMap&lt;/code&gt;, or &lt;code&gt;mergeMap&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// [GOOD]: Clean, linear, and handles race conditions safely.&lt;/span&gt;
&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;projects$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;switchMap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])),&lt;/span&gt;
  &lt;span class="nf"&gt;switchMap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;projectService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getProjects&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;organizationId&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;(Note: &lt;code&gt;switchMap&lt;/code&gt; is perfect here because it cancels previous pending requests if a new ID is emitted).&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  4. "Fat" Components (The God Object)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Anti-pattern:&lt;/strong&gt; Stuffing business logic, direct HTTP calls, and complex state manipulation directly into the &lt;code&gt;.ts&lt;/code&gt; file of your component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it is bad:&lt;/strong&gt; Your component becomes a monolith. It becomes untestable (because you have to mock 15 different dependencies) and impossible to reuse. UI components should only care about &lt;em&gt;presenting&lt;/em&gt; data and catching user events.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Modern Solution:&lt;/strong&gt;&lt;br&gt;
Adopt the &lt;strong&gt;Smart / Dumb (Presentational) Component Architecture&lt;/strong&gt; using Standalone Components, and use a Facade or Service for logic.&lt;/p&gt;

&lt;p&gt;Move your HTTP logic and state mutations into a dedicated Service, keeping your component clean:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// [GOOD]: The component just binds to the facade service.&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;standalone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CartComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Injecting the service using the modern inject() function&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;cartFacade&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;inject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;CartFacadeService&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;cartItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cartFacade&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// This is a Signal exposed by the service&lt;/span&gt;

  &lt;span class="nf"&gt;onRemoveItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cartFacade&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// The service handles the actual logic and API call&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  5. The Desperate &lt;code&gt;ChangeDetectorRef&lt;/code&gt; Hack
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Anti-pattern:&lt;/strong&gt; Injecting &lt;code&gt;ChangeDetectorRef&lt;/code&gt; and throwing &lt;code&gt;cdr.detectChanges()&lt;/code&gt; or wrapping code in &lt;code&gt;setTimeout(() =&amp;gt; {}, 0)&lt;/code&gt; just to force the UI to update.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// [BAD]: Forcing Angular to update because the data flow is broken.&lt;/span&gt;
&lt;span class="nf"&gt;updateUser&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cdr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;detectChanges&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Please update the UI, I am begging you!&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why it is bad:&lt;/strong&gt; If you find yourself using this, it means you have lost control of your state management or you are mutating data directly instead of creating new references. It is treating the symptom instead of curing the disease.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Modern Solution:&lt;/strong&gt;&lt;br&gt;
Embrace &lt;strong&gt;Zoneless Angular&lt;/strong&gt; and &lt;strong&gt;Immutability&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Angular 21 fully supports going Zoneless (&lt;code&gt;provideZonelessChangeDetection()&lt;/code&gt;). In a Zoneless environment, the framework relies entirely on Signals and built-in reactive primitives to know when to update the DOM, eliminating the need for &lt;code&gt;Zone.js&lt;/code&gt; overhead or manual &lt;code&gt;cdr.detectChanges()&lt;/code&gt; hacks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// [GOOD]: Treat data as immutable and use Signals for automatic UI updates&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;standalone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;// ChangeDetectionStrategy.OnPush is also recommended if you are not fully zoneless yet&lt;/span&gt;
  &lt;span class="na"&gt;changeDetection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ChangeDetectionStrategy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;OnPush&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jane&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nf"&gt;updateUser&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Updating the signal automatically schedules a highly optimized UI update&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;u&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;u&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}));&lt;/span&gt; 
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Wrapping Up
&lt;/h3&gt;

&lt;p&gt;Angular has heavily shifted towards a reactive, Signal-driven, and Zoneless future. By dropping these 5 anti-patterns and embracing the paradigms of Angular 21, you will immediately notice improvements in your app's Lighthouse scores, memory footprint, and overall developer experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Over to you:&lt;/strong&gt; Which of these anti-patterns do you see most often in legacy codebases? Are there any others you would add to this list? Let me know in the comments!&lt;/p&gt;

</description>
      <category>angular</category>
      <category>webdev</category>
      <category>typescript</category>
      <category>programming</category>
    </item>
    <item>
      <title>PostgreSQL 19 WAIT FOR LSN from PHP: read-your-writes on a replica, and four ways it bites</title>
      <dc:creator>Szj</dc:creator>
      <pubDate>Wed, 30 Sep 2026 18:26:12 +0000</pubDate>
      <link>https://dev.to/_er2es_/postgresql-19-wait-for-lsn-from-php-read-your-writes-on-a-replica-and-four-ways-it-bites-1ogi</link>
      <guid>https://dev.to/_er2es_/postgresql-19-wait-for-lsn-from-php-read-your-writes-on-a-replica-and-four-ways-it-bites-1ogi</guid>
      <description>&lt;p&gt;You add a read replica. A user saves a form, gets redirected, and the next page shows the old data. The write went to the primary, the read went to the replica, and the replica hadn't caught up yet.&lt;/p&gt;

&lt;p&gt;PostgreSQL 19 adds a built-in answer: the &lt;code&gt;WAIT&lt;/code&gt; command. You give it the WAL position (LSN) of your write, and the replica blocks until it has replayed that far. I tried it from PHP on PostgreSQL 19 Beta 4, and found a few things worth knowing before you ship it.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: PostgreSQL 19 was at Beta 4 when I wrote this. Check the final release notes, as details may still change.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem, measured
&lt;/h2&gt;

&lt;p&gt;Setup: one primary and one asynchronous streaming standby on the same machine, PHP 8.5.10 with PDO. After each &lt;code&gt;INSERT&lt;/code&gt; on the primary I read the row back from the replica immediately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5000 of 5000 reads were stale.&lt;/strong&gt; Not most of them. All of them. The read arrives about 60 µs after the commit, and the row takes roughly 300 µs to get replayed on the replica. Under write load (pgbench with 4 clients on the primary) it was 1496 of 1500.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="no"&gt;WAIT&lt;/span&gt; &lt;span class="k"&gt;FOR&lt;/span&gt; &lt;span class="no"&gt;LSN&lt;/span&gt; &lt;span class="s1"&gt;'0/0306EE20'&lt;/span&gt; &lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;TIMEOUT&lt;/span&gt; &lt;span class="s1"&gt;'50ms'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;NO_THROW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;-- returns one row: success | timeout | not in recovery&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The flow: write on the primary, grab the current LSN, run &lt;code&gt;WAIT&lt;/code&gt; on the replica, then read from the replica.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;final&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ReadYourWrites&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="no"&gt;PDO&lt;/span&gt; &lt;span class="nv"&gt;$primary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="no"&gt;PDO&lt;/span&gt; &lt;span class="nv"&gt;$replica&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$timeoutMs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="cm"&gt;/** Call right after the write has committed on the primary (synchronous_commit = on). */&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;commitLsn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;primary&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'SELECT pg_current_wal_flush_lsn()'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;fetchColumn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="cm"&gt;/** Returns the connection that is safe to read from. Never call inside an open transaction. */&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;readerFor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$lsn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;PDO&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$lsn&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;replica&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nf"&gt;preg_match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'~^[0-9A-F]+/[0-9A-F]+$~'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$lsn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;InvalidArgumentException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Not a valid LSN'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nv"&gt;$status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;replica&lt;/span&gt;
            &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"WAIT FOR LSN '$lsn' WITH (TIMEOUT '{$this-&amp;gt;timeoutMs}ms', NO_THROW)"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;fetchColumn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'success'&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;replica&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;primary&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result on 5000 writes: &lt;strong&gt;0 stale reads&lt;/strong&gt;, with a median wait of 315 µs on an idle standby and 1.2 ms under write load. If the replica can't catch up in time, the code falls back to the primary, which is always correct.&lt;/p&gt;

&lt;p&gt;The LSN has to travel with the user between requests. Keep it in the session, and read from the replica only after &lt;code&gt;WAIT&lt;/code&gt; succeeds.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Stale reads without WAIT&lt;/th&gt;
&lt;th&gt;Stale reads with WAIT&lt;/th&gt;
&lt;th&gt;WAIT median&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Idle standby&lt;/td&gt;
&lt;td&gt;5000 / 5000&lt;/td&gt;
&lt;td&gt;0 / 5000&lt;/td&gt;
&lt;td&gt;315 µs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Write load&lt;/td&gt;
&lt;td&gt;1496 / 1500&lt;/td&gt;
&lt;td&gt;0 / 1500&lt;/td&gt;
&lt;td&gt;1.2 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;All numbers come from a single vCPU running everything (primary, standby, PHP, pgbench), so absolute latencies are inflated and a real network adds a round trip. Treat the ratios, not the microseconds, as the point.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotcha 1: you can't bind the LSN
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;WAIT&lt;/code&gt; is a utility command, so PostgreSQL doesn't accept parameters in it. With PDO's default native prepared statements:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$stmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$replica&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'WAIT FOR LSN :lsn'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'lsn'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$lsn&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// SQLSTATE[42601]: syntax error at or near "$1"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It only works with &lt;code&gt;ATTR_EMULATE_PREPARES = true&lt;/code&gt;. The safe option is to validate the string with a strict regex (as in the class above) and interpolate it. An LSN is just hex, a slash and hex.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotcha 2: it must be the first thing in a transaction
&lt;/h2&gt;

&lt;p&gt;The docs say &lt;code&gt;WAIT&lt;/code&gt; can't run while you hold a snapshot or locks. In practice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$replica&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;beginTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$replica&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'SELECT count(*) FROM t'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$replica&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"WAIT FOR LSN '$lsn'"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// ERROR: cannot wait for a standby LSN while holding locks&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same applies after the first query in a &lt;code&gt;REPEATABLE READ&lt;/code&gt; transaction (&lt;code&gt;WAIT cannot be executed while the current transaction holds a snapshot&lt;/code&gt;). A plain &lt;code&gt;SET LOCAL&lt;/code&gt; before it is fine.&lt;/p&gt;

&lt;p&gt;Two details cost me time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An error inside a transaction aborts it (&lt;code&gt;SQLSTATE 25P02&lt;/code&gt;), so call &lt;code&gt;WAIT&lt;/code&gt; &lt;em&gt;before&lt;/em&gt; &lt;code&gt;beginTransaction()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If the target LSN is &lt;strong&gt;already reached&lt;/strong&gt;, &lt;code&gt;WAIT&lt;/code&gt; returns immediately even after a query. The restriction only triggers when it would actually have to wait. So your tests can pass on an idle replica and fail in production.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It also can't run inside a &lt;code&gt;DO&lt;/code&gt; block or function (&lt;code&gt;WAIT can only be executed as a top-level statement&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotcha 3: the docs' LSN function can hang
&lt;/h2&gt;

&lt;p&gt;The documentation example takes the LSN with &lt;code&gt;pg_current_wal_insert_lsn()&lt;/code&gt;. In my idle test, &lt;strong&gt;5 out of 5000 waits timed out&lt;/strong&gt;. Every one of those LSNs had the same page offset: 24 bytes, which is the size of a WAL page header.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0/0322A018   0/03240018   0/03268018   0/032C8018   0/032DE018
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My explanation (an inference, not something I checked in the source): the commit record ended exactly at a WAL page boundary, and the insert pointer was reported &lt;em&gt;after&lt;/em&gt; the new page's header. The replica has replayed everything that exists, but the target sits 24 bytes past the last real record, so &lt;code&gt;WAIT&lt;/code&gt; blocks until more WAL arrives. On an idle system that can be a long time.&lt;/p&gt;

&lt;p&gt;With the default &lt;code&gt;synchronous_commit = on&lt;/code&gt;, &lt;code&gt;pg_current_wal_flush_lsn()&lt;/code&gt; does not have this problem: 0 timeouts in 5000, and it was also slightly faster. Either way, use &lt;code&gt;TIMEOUT&lt;/code&gt; and &lt;code&gt;NO_THROW&lt;/code&gt;, check the status, and fall back to the primary. &lt;strong&gt;Never ignore the returned status.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotcha 4: synchronous_commit = off changes everything
&lt;/h2&gt;

&lt;p&gt;If your app uses asynchronous commit, the flush LSN can be &lt;em&gt;behind&lt;/em&gt; your commit record:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Primary session with &lt;code&gt;synchronous_commit = off&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;flush_lsn&lt;/code&gt;, then WAIT&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;success&lt;/code&gt; in 48 µs, but &lt;strong&gt;300 / 300 reads were stale&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;insert_lsn&lt;/code&gt;, then WAIT&lt;/td&gt;
&lt;td&gt;correct, but median wait &lt;strong&gt;201 ms&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;WAIT&lt;/code&gt; dutifully reports success for a position the replica really did reach. It just isn't your write. The insert LSN is correct here, but you pay roughly one &lt;code&gt;wal_writer_delay&lt;/code&gt; (200 ms by default) per wait, and 8 of 300 still hit my 300 ms timeout.&lt;/p&gt;

&lt;p&gt;So: flush LSN if you use synchronous commit, insert LSN plus the fallback if you don't.&lt;/p&gt;

&lt;h2&gt;
  
  
  Symfony and Doctrine
&lt;/h2&gt;

&lt;p&gt;Nothing here is tied to PDO. With DBAL, run the same &lt;code&gt;WAIT&lt;/code&gt; through &lt;code&gt;executeQuery()&lt;/code&gt; on the replica connection, before opening a transaction. One natural place to capture the LSN is a listener that runs after a flush on the primary connection and stores the result in the session. I've only tested the plain PDO version above, so treat that as a design sketch.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Read-after-write against an async replica is broken by default: 5000/5000 stale reads in my test.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;WAIT FOR LSN&lt;/code&gt; fixes it cheaply: about 0.3 ms idle, about 1.2 ms under write load on my setup.&lt;/li&gt;
&lt;li&gt;Always pass &lt;code&gt;TIMEOUT&lt;/code&gt; and &lt;code&gt;NO_THROW&lt;/code&gt;, check the status, and fall back to the primary.&lt;/li&gt;
&lt;li&gt;Validate the LSN yourself, because you can't bind it.&lt;/li&gt;
&lt;li&gt;Call it before opening a transaction.&lt;/li&gt;
&lt;li&gt;Pick the LSN function to match your &lt;code&gt;synchronous_commit&lt;/code&gt; setting.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I ran into this while working on search and read-heavy PostgreSQL workloads for PHP, including &lt;a href="https://github.com/er2es/fuzzphony" rel="noopener noreferrer"&gt;Fuzzphony&lt;/a&gt;. If you have a real multi-machine setup, I'd love to see your numbers in the comments.&lt;/p&gt;

</description>
      <category>php</category>
      <category>postgres</category>
    </item>
    <item>
      <title>grapheme_levenshtein() in PHP 8.5: what the docs don't tell you</title>
      <dc:creator>Szj</dc:creator>
      <pubDate>Wed, 30 Sep 2026 17:23:11 +0000</pubDate>
      <link>https://dev.to/_er2es_/graphemelevenshtein-in-php-85-what-the-docs-dont-tell-you-322n</link>
      <guid>https://dev.to/_er2es_/graphemelevenshtein-in-php-85-what-the-docs-dont-tell-you-322n</guid>
      <description>&lt;p&gt;PHP's &lt;code&gt;levenshtein()&lt;/code&gt; has always counted &lt;strong&gt;bytes&lt;/strong&gt;. For English that's invisible. For Hungarian, Polish, Czech, or anything with accents, it quietly lies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nf"&gt;levenshtein&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'szőke'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'szoke'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 2, but it's one edit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;ő&lt;/code&gt; is two bytes in UTF-8 (&lt;code&gt;C5 91&lt;/code&gt;), so the function sees two edits. PHP 8.5 finally adds &lt;code&gt;grapheme_levenshtein()&lt;/code&gt;, which counts user-perceived characters instead. Every article I found about it explains the syntax. None of them measured it, so I did.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;PHP 8.5.10 (CLI, built from source), ICU 74.2, default settings, no JIT&lt;/li&gt;
&lt;li&gt;Synthetic Hungarian-style words (with &lt;code&gt;sz&lt;/code&gt;, &lt;code&gt;cs&lt;/code&gt;, &lt;code&gt;ő&lt;/code&gt;, &lt;code&gt;ű&lt;/code&gt;, ...), each compared with a copy containing one random edit&lt;/li&gt;
&lt;li&gt;20,000 pairs per length, best of 3 rounds, nanoseconds per comparison&lt;/li&gt;
&lt;li&gt;Single vCPU sandbox: absolute numbers will differ on your machine, the ratios are what matter.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What it fixes
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pair&lt;/th&gt;
&lt;th&gt;&lt;code&gt;levenshtein()&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;code points&lt;/th&gt;
&lt;th&gt;&lt;code&gt;grapheme_levenshtein()&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;szőke&lt;/code&gt; vs &lt;code&gt;szoke&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;Kovács&lt;/code&gt; vs &lt;code&gt;Kovacs&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;ő&lt;/code&gt; vs &lt;code&gt;ö&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;é&lt;/code&gt; (NFC) vs &lt;code&gt;é&lt;/code&gt; (NFD)&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;👩‍💻 vs 👩&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The NFC/NFD row is the real win. The same visible &lt;code&gt;é&lt;/code&gt; can be stored as one code point or two (&lt;code&gt;e&lt;/code&gt; + combining accent), depending on where the data came from. The byte version reports 3 edits between two strings that look identical. The grapheme version correctly reports 0.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it costs
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Length&lt;/th&gt;
&lt;th&gt;&lt;code&gt;levenshtein()&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;grapheme_levenshtein()&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;with &lt;code&gt;locale='hu'&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;userland, code points&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;8 chars&lt;/td&gt;
&lt;td&gt;0.22 µs&lt;/td&gt;
&lt;td&gt;3.3 µs&lt;/td&gt;
&lt;td&gt;4.0 µs&lt;/td&gt;
&lt;td&gt;3.8 µs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;24 chars&lt;/td&gt;
&lt;td&gt;1.3 µs&lt;/td&gt;
&lt;td&gt;14.1 µs&lt;/td&gt;
&lt;td&gt;17.6 µs&lt;/td&gt;
&lt;td&gt;29.2 µs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;64 chars&lt;/td&gt;
&lt;td&gt;6.4 µs&lt;/td&gt;
&lt;td&gt;76.9 µs&lt;/td&gt;
&lt;td&gt;98.2 µs&lt;/td&gt;
&lt;td&gt;196.1 µs&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Three things stand out:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;It is 11-15x slower than the byte version.&lt;/strong&gt; Correctness isn't free: the function segments both strings into grapheme clusters and compares them through ICU.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It beats a userland implementation&lt;/strong&gt; by about 1.2x on short strings and 2-2.6x on longer ones. If you were using a pure PHP multibyte Levenshtein, switching is a clear win.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The &lt;code&gt;$locale&lt;/code&gt; parameter adds 23-28% on top.&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The manual documents the complexity as O(m*n). In practice that means you should not run it over a whole table: at 24 characters, 1M rows is roughly 14 seconds of CPU per query, versus about 1.3 seconds for the byte version.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two surprises
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Invisible characters can compare as equal.&lt;/strong&gt; In my tests on 8.5.10:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nf"&gt;grapheme_levenshtein&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\x01"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"\x02"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;          &lt;span class="c1"&gt;// 0&lt;/span&gt;
&lt;span class="nf"&gt;grapheme_levenshtein&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\u{200B}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"\u{200C}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// 0&lt;/span&gt;
&lt;span class="nf"&gt;grapheme_levenshtein&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\x01"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;              &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two different control or zero-width characters are treated as identical to each other, yet each one differs from an empty string. The equality check is a collation comparison, and ICU collation ignores some characters completely. Mid-word cases behave less predictably (&lt;code&gt;"a\u{200B}b"&lt;/code&gt; vs &lt;code&gt;"a\u{200C}b"&lt;/code&gt; gave 1, while &lt;code&gt;"a\x01b"&lt;/code&gt; vs &lt;code&gt;"a\x02b"&lt;/code&gt; gave 0). A soft hyphen (&lt;code&gt;U+00AD&lt;/code&gt;) is &lt;em&gt;not&lt;/em&gt; ignored and costs one edit. This matches a recently reported php-src issue, so check the current status before relying on either behavior.&lt;/p&gt;

&lt;p&gt;For search this is mostly harmless, but if you use the distance for deduplication or validation, strip control and format characters first.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The locale parameter changed nothing in my tests.&lt;/strong&gt; I compared &lt;code&gt;hu&lt;/code&gt; against &lt;code&gt;en&lt;/code&gt; on every case above, including &lt;code&gt;cs&lt;/code&gt; vs &lt;code&gt;c&lt;/code&gt; and &lt;code&gt;sz&lt;/code&gt; vs &lt;code&gt;s&lt;/code&gt;, where you might hope for Hungarian digraph awareness. The results were identical in all cases. It only added the 23-28% cost. I'm not claiming it never matters (I can't rule out effects on other scripts or case-insensitive comparisons), but for Hungarian names it bought me nothing.&lt;/p&gt;

&lt;p&gt;Also note that the comparison is case-sensitive: &lt;code&gt;Kovács&lt;/code&gt; vs &lt;code&gt;kovács&lt;/code&gt; is 1.&lt;/p&gt;

&lt;h2&gt;
  
  
  So how should you use it?
&lt;/h2&gt;

&lt;p&gt;Don't scan with it, re-rank with it. Let the database produce candidates cheaply and let PHP do the precise scoring on a handful of rows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- PostgreSQL + pg_trgm: fast candidate generation&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="nf"&gt;similarity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
&lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;clean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// strip control/format characters, then lowercase&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;mb_strtolower&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;preg_replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/[\p{Cc}\p{Cf}]/u'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;rerank&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt; &lt;span class="nv"&gt;$candidates&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$maxDistance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$q&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;clean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;$scored&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$candidates&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;grapheme_levenshtein&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$q&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;clean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$d&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nv"&gt;$d&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nv"&gt;$maxDistance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$scored&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$d&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;asort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$scored&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$scored&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;rerank&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Szoke'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'Szőke'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Szűcs'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Szabó'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'SZOKE'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// ['SZOKE' =&amp;gt; 0, 'Szőke' =&amp;gt; 1]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Re-ranking 50 candidates of around 24 characters costs about 0.7 ms (50 x 14 µs), which is nothing next to the query itself. That's the sweet spot: the accuracy of a grapheme-aware distance at a cost you never notice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;grapheme_levenshtein()&lt;/code&gt; over &lt;code&gt;levenshtein()&lt;/code&gt; whenever your data has accents or mixed Unicode normalization.&lt;/li&gt;
&lt;li&gt;Expect ~12x the cost of the byte version, and never run it over a full table.&lt;/li&gt;
&lt;li&gt;Normalize case and strip invisible characters yourself.&lt;/li&gt;
&lt;li&gt;Measure before you reach for &lt;code&gt;$locale&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I ran into all of this while building &lt;a href="https://github.com/er2es/fuzzphony" rel="noopener noreferrer"&gt;Fuzzphony&lt;/a&gt;, a PostgreSQL-native search library for PHP and Symfony. If you have your own numbers from a different machine or dataset, I'd love to see them in the comments.&lt;/p&gt;

</description>
      <category>php</category>
      <category>postgressql</category>
    </item>
    <item>
      <title>I couldn't touch the database, so I built search next to it</title>
      <dc:creator>Szj</dc:creator>
      <pubDate>Mon, 28 Sep 2026 18:40:07 +0000</pubDate>
      <link>https://dev.to/_er2es_/i-couldnt-touch-the-database-so-i-built-search-next-to-it-1pjn</link>
      <guid>https://dev.to/_er2es_/i-couldnt-touch-the-database-so-i-built-search-next-to-it-1pjn</guid>
      <description>&lt;p&gt;A production system I work on needed a search box that forgives people. They type &lt;code&gt;kavefozo&lt;/code&gt; and expect &lt;code&gt;Kávéfőző&lt;/code&gt;. They type &lt;code&gt;hedphones&lt;/code&gt; and expect headphones.&lt;/p&gt;

&lt;p&gt;The constraints were the interesting part:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The schema could not change.&lt;/strong&gt; No new columns, no generated columns, no migrations on tables that weren't ours.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No new infrastructure.&lt;/strong&gt; No Elasticsearch, no Meilisearch, no extra service to run, sync, back up and secure.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So search had to happen inside the database that was already there. PostgreSQL turned out to have almost every piece needed. Wiring those pieces together properly was the hard part, and that wiring became an open-source library: &lt;a href="https://github.com/er2es/fuzzphony" rel="noopener noreferrer"&gt;Fuzzphony&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Fuzzphony is at &lt;strong&gt;v0.4 and still in active development&lt;/strong&gt;. The core works and is heavily tested, but the API can change before 1.0, and there are rough edges I'll be upfront about at the end.&lt;/p&gt;

&lt;p&gt;This post covers the design, the bug that taught me the most, and what I still haven't solved.&lt;/p&gt;

&lt;h2&gt;
  
  
  What &lt;code&gt;LIKE '%…%'&lt;/code&gt; gets wrong
&lt;/h2&gt;

&lt;p&gt;Most search boxes start here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;ILIKE&lt;/span&gt; &lt;span class="s1"&gt;'%'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s1"&gt;'%'&lt;/span&gt; &lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It misses typos (&lt;code&gt;hedphones&lt;/code&gt;), accents (&lt;code&gt;creme&lt;/code&gt; vs &lt;code&gt;crème&lt;/code&gt;) and word forms (&lt;code&gt;drills&lt;/code&gt; vs &lt;code&gt;drill&lt;/code&gt;). It can't exclude a word, it doesn't rank, and when it misses, it reads the whole table to return nothing.&lt;/p&gt;

&lt;p&gt;Postgres ships three tools for exactly these problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Full-text search&lt;/strong&gt; (&lt;code&gt;tsvector&lt;/code&gt;, &lt;code&gt;tsquery&lt;/code&gt;, &lt;code&gt;ts_rank_cd&lt;/code&gt;): stemming for 28 languages, field weights A to D, relevance ranking.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;unaccent&lt;/code&gt;&lt;/strong&gt;: folds &lt;code&gt;Kávéfőző&lt;/code&gt; into &lt;code&gt;Kavefozo&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;pg_trgm&lt;/code&gt;&lt;/strong&gt;: trigram similarity, which is what lets &lt;code&gt;wireles&lt;/code&gt; match &lt;code&gt;wireless&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of them is new. The work is in making them behave together, stay in sync with your data, and be safe to point at user input.&lt;/p&gt;

&lt;h2&gt;
  
  
  The sidecar table
&lt;/h2&gt;

&lt;p&gt;Since your tables are off-limits, the index lives in its own table next to them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqyqdk348f6nz9tvmvygs.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqyqdk348f6nz9tvmvygs.PNG" alt="Where the index lives: no column is added to your tables, triggers feed a queue, a worker refreshes the sidecar table, and searches read only the sidecar" width="800" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For every index, Fuzzphony keeps a table such as &lt;code&gt;fuzzphony_products&lt;/code&gt; with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a weighted &lt;code&gt;tsvector&lt;/code&gt; for full-text search, on a GIN index,&lt;/li&gt;
&lt;li&gt;a normalised, unaccented text column for typo tolerance, on a GIN trigram index,&lt;/li&gt;
&lt;li&gt;typed filter columns on btree indexes, so &lt;code&gt;where('price', '&amp;lt;=', 20_000)&lt;/code&gt; never has to touch your table,&lt;/li&gt;
&lt;li&gt;the inputs for ranking: a boost column (popularity, say) and a recency column.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The source can be a single table or any &lt;code&gt;SELECT&lt;/code&gt;, joins included. With &lt;code&gt;schema: fuzzphony&lt;/code&gt; set, the sidecar tables, the queue and the helper functions all live in their own schema, and dropping an index is one command.&lt;/p&gt;

&lt;p&gt;To be precise about "off-limits": no column is ever added, but in the default &lt;code&gt;queue&lt;/code&gt; mode and in &lt;code&gt;trigger&lt;/code&gt; mode Fuzzphony does attach triggers to the tables it watches. That's how it sees writes from raw SQL, imports and other applications. If even a trigger is too much, the &lt;code&gt;orm&lt;/code&gt; and &lt;code&gt;manual&lt;/code&gt; modes need none.&lt;/p&gt;

&lt;p&gt;The cost of the design is obvious: there is now a second copy of the searchable data, and it has to stay in sync.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keeping it in sync without hurting writes
&lt;/h2&gt;

&lt;p&gt;There are four sync modes:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mode&lt;/th&gt;
&lt;th&gt;How&lt;/th&gt;
&lt;th&gt;When&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;queue&lt;/code&gt; (default)&lt;/td&gt;
&lt;td&gt;triggers enqueue ids, &lt;code&gt;fuzzphony:worker&lt;/code&gt; refreshes in batches&lt;/td&gt;
&lt;td&gt;most apps; writes stay fast&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;trigger&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;triggers refresh inside the writing transaction&lt;/td&gt;
&lt;td&gt;you need read-your-writes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;orm&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;a Doctrine listener refreshes after &lt;code&gt;flush()&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;triggers are not allowed at all&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;manual&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;nothing automatic&lt;/td&gt;
&lt;td&gt;batch imports, read-only data&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Three details made the trigger-based modes usable on real tables.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Statement-level triggers with transition tables.&lt;/strong&gt; A row-level trigger on an &lt;code&gt;UPDATE brand SET …&lt;/code&gt; that touches 100 000 rows fires 100 000 times. A statement-level trigger fires once and sees every changed row through a transition table, so queuing the affected products becomes a single set-based statement. In simplified form (not the exact generated SQL):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TRIGGER&lt;/span&gt; &lt;span class="n"&gt;brand_sync&lt;/span&gt;
&lt;span class="k"&gt;AFTER&lt;/span&gt; &lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;brand&lt;/span&gt;
&lt;span class="k"&gt;REFERENCING&lt;/span&gt; &lt;span class="k"&gt;NEW&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;changed&lt;/span&gt;
&lt;span class="k"&gt;FOR&lt;/span&gt; &lt;span class="k"&gt;EACH&lt;/span&gt; &lt;span class="k"&gt;STATEMENT&lt;/span&gt; &lt;span class="k"&gt;EXECUTE&lt;/span&gt; &lt;span class="k"&gt;FUNCTION&lt;/span&gt; &lt;span class="n"&gt;queue_products_of_changed_brands&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;-- inside the function, roughly:&lt;/span&gt;
&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;sync_queue&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;doc_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="s1"&gt;'products'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;changed&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
&lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;brand_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Only refresh when something relevant changed.&lt;/strong&gt; An &lt;code&gt;UPDATE product SET last_viewed_at = now()&lt;/code&gt; should not reindex anything. For the index's own table, Fuzzphony checks whether a mapped column actually changed. For joined tables you opt in with &lt;code&gt;columns: ['name']&lt;/code&gt;, because a library cannot guess which of a joined table's columns matter to you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;TRUNCATE&lt;/code&gt; is not a delete.&lt;/strong&gt; It fires no &lt;code&gt;DELETE&lt;/code&gt; triggers, so early versions left stale documents in the index after a &lt;code&gt;TRUNCATE&lt;/code&gt;, and not even a full reindex removed them. I found that one late. Now every watched table also gets an &lt;code&gt;AFTER TRUNCATE&lt;/code&gt; trigger, and a full reindex prunes documents whose rows no longer exist.&lt;/p&gt;

&lt;p&gt;The worker takes a batch with &lt;code&gt;DELETE … FOR UPDATE SKIP LOCKED&lt;/code&gt; and refreshes it in the same statement, so a failed refresh rolls the dequeue back and no id is lost, and several workers can run side by side. If you'd rather not run a long-lived process, &lt;code&gt;fuzzphony:worker --once&lt;/code&gt; from cron works too.&lt;/p&gt;

&lt;h2&gt;
  
  
  What happens to a query
&lt;/h2&gt;

&lt;p&gt;From the application side, a search looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$fuzzphony&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;in&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'wireles mouse -cable'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;          &lt;span class="c1"&gt;// a typo and an exclusion&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'price'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;='&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20_000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'in_stock'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;highlight&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$hit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$hit&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$hit&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$hit&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;highlights&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;   &lt;span class="c1"&gt;// "&amp;lt;mark&amp;gt;Wireless&amp;lt;/mark&amp;gt; mouse"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Behind that call, the query goes through a few stages:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv2e1fcgwms67ug91e3ng.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv2e1fcgwms67ug91e3ng.png" alt="Query pipeline: parse, exact full-text match, typo tolerance per word only if there are too few hits, relaxation if still nothing, then ranking" width="800" height="623"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A few decisions in there are worth explaining.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;User input never throws.&lt;/strong&gt; Unbalanced quotes, stray operators and absurdly long input are repaired and reported in &lt;code&gt;$result-&amp;gt;warnings&lt;/code&gt;, and &lt;code&gt;$result-&amp;gt;interpretedAs&lt;/code&gt; shows how the query was understood. Developer mistakes are the opposite: they fail loudly, with a hint. &lt;code&gt;Index "products" has no filter "prise". Did you mean "price"?&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exact first, typo tolerance as a fallback.&lt;/strong&gt; Trigram matching is slower and noisier than full-text matching, so by default it only runs when exact matching finds fewer than &lt;code&gt;fallback_below&lt;/code&gt; hits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Typo tolerance is per word.&lt;/strong&gt; The first version compared the whole query string against the fuzzy fields, so one long common word could satisfy it on its own. On the demo catalogue, &lt;code&gt;wireles mice&lt;/code&gt; returned 20 000 products (chairs, drills, kettles), of which 1 666 were mice. Now every word has to match on its own, exactly or by trigram similarity, inside the query's real AND / OR / NOT structure. The same query returns exactly the 1 666 wireless mice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An empty result gets one more try.&lt;/strong&gt; If a query of two or more words finds nothing, each word is checked on its own, the words that match nothing are dropped, and the search runs again with a warning saying which words were ignored. &lt;code&gt;wireless mouse aluminum&lt;/code&gt; returns the wireless mice instead of an empty page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ranking is explainable.&lt;/strong&gt; The score is a plain formula:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;relevance = text  × ts_rank_cd(weights A..D)
          + fuzzy × word_similarity(query, fuzzy fields)

score     = relevance
          + exact_bonus + prefix_bonus
          + boost   × boost column
          + recency × 2^(−age / half_life)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;min_score&lt;/code&gt; applies to relevance only, so a popularity boost can reorder relevant hits but can never pull an irrelevant one into the results. Every hit carries a score breakdown, so "why is this first?" always has an answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  The bug that taught me the most
&lt;/h2&gt;

&lt;p&gt;A German test query, &lt;code&gt;Tasche für Laptop&lt;/code&gt;, did not find a product called &lt;code&gt;Laptop Tasche&lt;/code&gt;. In the French catalogue, searching for &lt;code&gt;à&lt;/code&gt; alone matched 13 products. Hungarian &lt;code&gt;és&lt;/code&gt; misbehaved the same way.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpe1sehoyo9mbcw3dnw37.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpe1sehoyo9mbcw3dnw37.png" alt="The accented stop word bug: unaccent turned für into fur before the stemmer, whose stop-word list only knows für" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A text search configuration sends every token through a list of dictionaries, in order. Mine ran &lt;code&gt;unaccent&lt;/code&gt; before the Snowball stemmer. The stemmer's German stop-word list contains &lt;code&gt;für&lt;/code&gt;, but by the time the token reached it, it had become &lt;code&gt;fur&lt;/code&gt;, which is not a stop word. So &lt;code&gt;für&lt;/code&gt; was indexed as an ordinary word, and every query containing it had to match it.&lt;/p&gt;

&lt;p&gt;The fix was to drop stop words before anything else touches the token, with a stop-word dictionary built from the language's own list. In simplified form:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;SEARCH&lt;/span&gt; &lt;span class="k"&gt;DICTIONARY&lt;/span&gt; &lt;span class="n"&gt;fuzzphony_german_stop&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;TEMPLATE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;simple&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;STOPWORDS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;german&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ACCEPT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;SEARCH&lt;/span&gt; &lt;span class="n"&gt;CONFIGURATION&lt;/span&gt; &lt;span class="n"&gt;fuzzphony_german&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;COPY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;german&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;SEARCH&lt;/span&gt; &lt;span class="n"&gt;CONFIGURATION&lt;/span&gt; &lt;span class="n"&gt;fuzzphony_german&lt;/span&gt;
    &lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="n"&gt;MAPPING&lt;/span&gt; &lt;span class="k"&gt;FOR&lt;/span&gt; &lt;span class="n"&gt;asciiword&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;asciihword&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hword&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hword_asciipart&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hword_part&lt;/span&gt;
    &lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;fuzzphony_german_stop&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;unaccent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;german_stem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;ACCEPT = false&lt;/code&gt;, the stop dictionary discards stop words and passes everything else on to the next dictionary.&lt;/p&gt;

&lt;p&gt;Two things came out of this besides the fix. &lt;code&gt;fuzzphony:doctor&lt;/code&gt; now reports a configuration that still keeps accented stop words. And the demo got a Languages page that searches small catalogues in English, German, French, Spanish and Hungarian, and shows the lexeme Postgres produced for every query word. I would have caught this bug on day one if that page had existed earlier.&lt;/p&gt;

&lt;h2&gt;
  
  
  The numbers, with the caveats
&lt;/h2&gt;

&lt;p&gt;A sample run on 200 000 products, PostgreSQL 16, a small cloud VM, 20 results per query:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Query&lt;/th&gt;
&lt;th&gt;ILIKE (warm)&lt;/th&gt;
&lt;th&gt;ILIKE hits&lt;/th&gt;
&lt;th&gt;Fuzzphony (warm)&lt;/th&gt;
&lt;th&gt;Fuzzphony hits&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;wireless&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0.6 ms&lt;/td&gt;
&lt;td&gt;20, unranked&lt;/td&gt;
&lt;td&gt;11.1 ms&lt;/td&gt;
&lt;td&gt;20 of 2000+, ranked&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;creme&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;251.6 ms&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;10.4 ms&lt;/td&gt;
&lt;td&gt;20 of 2000+&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;hedphones&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;252.6 ms&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;20.7 ms&lt;/td&gt;
&lt;td&gt;20 of 2000+&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;drills&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;257.1 ms&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;10.6 ms&lt;/td&gt;
&lt;td&gt;20 of 2000+&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;"noise cancelling" -headphones&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0.5 ms&lt;/td&gt;
&lt;td&gt;20, wrong&lt;/td&gt;
&lt;td&gt;23.2 ms&lt;/td&gt;
&lt;td&gt;20 of 2000+&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Read this carefully, because a benchmark against &lt;code&gt;ILIKE&lt;/code&gt; is easy to make look good:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On plain words, &lt;code&gt;ILIKE&lt;/code&gt; is much faster. &lt;code&gt;LIMIT 20&lt;/code&gt; without an &lt;code&gt;ORDER BY&lt;/code&gt; just returns the first 20 rows the scan happens to hit. Fast, but not the best 20.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;ILIKE&lt;/code&gt; baseline has no trigram index, which is why its misses are full table scans. A &lt;code&gt;gin_trgm_ops&lt;/code&gt; index would make those rows fast. It would not make them correct: &lt;code&gt;ILIKE '%hedphones%'&lt;/code&gt; finds nothing no matter how it is indexed.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ILIKE&lt;/code&gt; has no concept of exclusion, so on the last row it silently ignores &lt;code&gt;-headphones&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run the numbers on your own data before believing anyone's benchmark, including this one. The benchmark script is in the repository, and CI runs it on every push.&lt;/p&gt;

&lt;h2&gt;
  
  
  When not to use it
&lt;/h2&gt;

&lt;p&gt;Fuzzphony is not the right tool if you need hundreds of millions of documents or thousands of searches per second on one index, analytics-style aggregations, semantic or vector search (look at pgvector or a dedicated engine), or a database other than PostgreSQL.&lt;/p&gt;

&lt;p&gt;It fits best where the database is not yours to change (a legacy system, an ERP, tables another team owns), where you are replacing &lt;code&gt;LIKE&lt;/code&gt; in admin panels and back offices, or where the data has to stay in the database for compliance reasons.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I haven't solved yet
&lt;/h2&gt;

&lt;p&gt;Two things are genuinely open, and I'd like opinions on both.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Typo tolerance is too lenient on short words.&lt;/strong&gt; At the default similarity threshold, &lt;code&gt;mouse&lt;/code&gt; also matches &lt;code&gt;monitor&lt;/code&gt;: short words have few trigrams, so a single shared one weighs a lot. The plan is length-aware thresholds, probably with trigrams only generating candidates from a vocabulary table and an edit-distance check deciding. How do you tune &lt;code&gt;pg_trgm&lt;/code&gt; for short words?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ranking of very frequent words.&lt;/strong&gt; A GIN index can find matches but can't return them in relevance order, so for a word that matches tens of thousands of documents, Fuzzphony ranks the first &lt;code&gt;candidate_limit&lt;/code&gt; (2000 by default) that the index returns. That's not necessarily the best 2000. For most back-office searches this doesn't show, but it's the real ceiling of doing search inside Postgres, and I'd rather say so than hide it behind "approximate ordering".&lt;/p&gt;

&lt;h2&gt;
  
  
  Rough edges I'm working on before 1.0
&lt;/h2&gt;

&lt;p&gt;Writing the docs for v0.4 surfaced a few things I'd design differently, so they're on the list:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Trigger privileges.&lt;/strong&gt; The sync functions run with the privileges of whoever writes the row. In a shared database, every role that writes to a watched table therefore needs grants on Fuzzphony's queue, or its writes fail. Moving the enqueue step into a &lt;code&gt;SECURITY DEFINER&lt;/code&gt; function removes that coupling.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A batch that always fails.&lt;/strong&gt; A refresh that fails deterministically (a document over Postgres' ~1 MB &lt;code&gt;tsvector&lt;/code&gt; limit, for example) is rolled back and retried forever, which blocks the queue behind it. It needs a dead-letter path.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pruning as a default.&lt;/strong&gt; A full reindex removes documents whose rows it can't see. If the reindexing role sees fewer rows than the application (row-level security, a different &lt;code&gt;search_path&lt;/code&gt;), that removes real documents. It should stop and ask above a threshold.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Field scoping leaks into typo tolerance.&lt;/strong&gt; &lt;code&gt;name:sony&lt;/code&gt; can return Sony-brand products, because the fuzzy fields share one trigram column. Per-field columns are planned for 0.5.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these show up in a single-app setup with one database role, which is how most people will try it. But they're exactly what bites in the environments Fuzzphony is aimed at, so they come before new features.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require fuzzphony/fuzzphony
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or run the demo, a full Symfony app on a seeded catalogue, with &lt;code&gt;ILIKE&lt;/code&gt; and Fuzzphony side by side, a ranking playground with sliders, and a configuration wizard:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/er2es/fuzzphony
&lt;span class="nb"&gt;cd &lt;/span&gt;fuzzphony/demo &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; docker compose up &lt;span class="nt"&gt;--build&lt;/span&gt;    &lt;span class="c"&gt;# http://localhost:8000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It requires PHP 8.4+ and PostgreSQL 15+, and is tested on Symfony 7.4 and 8.0 against PostgreSQL 15 to 18. The current release is v0.4 and development is ongoing: breaking changes can still happen before 1.0, and each one is listed in the CHANGELOG with upgrade steps in UPGRADE.md.&lt;/p&gt;

&lt;p&gt;I built this with a lot of help from Claude Code. The design decisions are written down as ADRs in the repository, and the heavy testing (PHPStan at max level, 100% line coverage, mutation testing) is partly because of that: when you didn't type every line yourself, tests are how you know what the code actually does.&lt;/p&gt;

&lt;p&gt;Feedback is very welcome, in the comments or as a GitHub issue, especially on the two open problems above. If the library looks useful, a star on &lt;a href="https://github.com/er2es/fuzzphony" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; helps other people find it.&lt;/p&gt;

</description>
      <category>sql</category>
      <category>symfony</category>
      <category>fuzzy</category>
      <category>postgres</category>
    </item>
  </channel>
</rss>
