Skip to Content
Meubles Morinière

Engineering choicesTechnical case studies6 min read

An ERP too heavy to maintain

An ERP of 600,000 lines, half of them tests, built fast with AI. It was growing four times faster than it was shrinking. There was no big clean-up, the writing rule is what changed.

The problem

On November 9, 2026, a read-only audit counted the ERP (git show b3f1e845d2:docs/allegement-erp.md). It found 605,000 lines of TypeScript, of which 295,000 of code and 302,000 of tests. That’s one line of test per line of code. According to git log, from October 18, when the ERP moved into apps/erp, to November 9, it had gained 331,000 lines and removed 131,000, so 2.5 for one.

Writing cost almost nothing. Keeping, though, cost more and more. The audit found three things that weighed it down.

  1. Texts repeated the code: 32 manual chapters that copied 3,825 screen labels, a decision register where 43 of the 299 file:line sources were broken, and twin files between the ERP and the storefront. Of the five ERP files changed most often in sixty days, four were manual chapters.
  2. Tests copied too: 2,861 element lookups by a hard-coded label, and 51 mocked test files (31,400 lines) that duplicated a suite run on a real database.
  3. Things got added much faster than they got removed, with 15 components over 800 lines.

When you changed a label, it broke a test, a chapter and a card of the register. So everything that got added then cost something at every change.

The constraints

  • I decide alone. Several workstreams move forward at the same time on the same machine, and there’s no hosted CI (ADR 0010).
  • What protects money, the law and security stays: database guards, regression tests, proofs on a real database.
  • The store is running, so features don’t get frozen for the length of a clean-up.
  • Authors follow what’s written. An AI session applies the rules in AGENTS.md. A habit that isn’t written there doesn’t exist for it.

The alternatives

  • Launch a big clean-up. It conflicts with the sessions working at the same time, it’s hard to review, and it doesn’t change the way code gets written. So the weight comes back.
  • Freeze features until the code has slimmed down. That’s impossible for a store in business.
  • Add a check for each kind of drift. Except each check is code to maintain. The audit already counted a series of them, including a 497-line interface doctrine check and a 345-line database verification, changed 27 times in sixty days.
  • Change the writing rule, so that each change pays back a little instead of borrowing. That’s the option that was kept.

The decision

On November 9, 2026, I added a “Maintainability” section to AGENTS.md. Every session reads it:

  • Delete before adding. A change removes, in the same commit, whatever it makes useless: code, a test, a constant, a passage of the manual, a card of the register. And you extend what exists before creating anything.
  • No new copy to keep by hand. What the code knows (a threshold, a label, a list, a status) gets imported or derived. A reference targets a symbol (file.ts#SYMBOL), never a line number, because it shifts with every change.
  • A test checks a behaviour, not a label. It finds an element by its role, with a name imported from the constant that holds the text.
  • A component doesn’t go past about 600 lines. Before adding something to it, you extract the block you’re touching (500 for a service).
  • Comments say why, not the history. The history is in git.

The same audit proposes a rule for checks. A new one only gets added if it protects money, the law or security. The rest goes through review.

The implementation

  • The audit measured by counting (find, grep, git log), without starting a server or running tests, because the machine is already running the sessions.
  • Before reducing the copies, they were made verifiable. pnpm --filter @meublesmoriniere/erp manual:check (apps/erp/scripts/check-manual.mjs, November 11) fails on a section missing from the table of contents, a broken link or anchor, a cited source that can’t be found, an orphan screenshot or an anchor targeted by the code that no longer exists. With --ui, it lists the manual’s labels that aren’t in the code.
  • Dead references went all at once. Citations of deleted documents (docs/fisher-*.md) were in 55 files. On November 10, they were removed from the code, the tests and the scripts.
  • Large components were split where they came apart cleanly. On November 12 (b3f1e845d2), several sessions split product creation, the ⌘K palette, the quote form, the list filters, AdminForm and the purchase draft. They also moved Prisma and business rules out of the actions, and removed the dead code Knip reported. That’s 499 files, 11,218 lines added and 9,865 removed.
  • The rest waits for the next change. A file doesn’t get split just to split it. If it’s too large, it gets cut when someone touches it.

The results

Here’s the count from November 13, 2026 on apps/erp (wc -l, .ts, .tsx and .mts files, tests separated by their path), four days after the audit:

IndicatorNovember 9November 13
Product creation, palette, quote form, filters1,922, 1,707, 1,521, 1,370 lines620, 665, 617, 619 lines
Components over 800 lines158
Decision register module, tests included5,405 lines2,181 lines
Lines added for one line removed2.5 (October 18 – November 9)1.35 (4 days)
Application code, excluding tests295,000 lines292,000 lines
Tests302,000 lines304,000 lines

The pace has changed. The ERP now removes almost as much as it adds, and the files that cost the most at every change have melted. The total volume hasn’t gone down yet, though, because splitting a component spreads its lines without deleting them.

The limits

  • Four days is too early to conclude. The table shows a trend, not a settled result.
  • Tests still weigh as much as the code. The 31,400 lines of mocked tests that duplicate the database suite still have to be sorted, module by module.
  • A written rule depends on who reads it. A session that ignores AGENTS.md can copy a label, and only a few checks (lint, twins, manual) catch it. As of November 13, manual:check wasn’t wired into pnpm check yet.
  • The split components sit just above the ceiling. At about 620 lines, they’ll have to be cut again at the next change.
  • The tools are the same, but the scope isn’t necessarily. The November 9 figures come from the audit, and those of November 13 from a new count. You can compare the orders of magnitude, not the last digits.

On this page