Skip to Content
Meubles Morinière

Engineering choicesTechnical case studies3 min read

Two applications born from a fork

The storefront started as a trimmed-down copy of the ERP. Here’s how we keep two copies of the same calculation rule from drifting apart, without rewriting everything at once.

The problem

The storefront started as a trimmed-down fork of the ERP. It had the same stack, the same money rules (VAT, discounts, shipping, totals), the same forms and the same schema. Starting from a copy meant the storefront could open quickly, with code that had already proven itself.

But a copy drifts. If you fix a VAT rule in the ERP and forget it in the storefront, the invoice no longer matches the amount collected online. And with a copy, nothing flags that you forgot. Both applications compile and pass their tests, each on its own side.

The constraints

  • Moving all the shared code out at once would have broken the tests. In each application, hundreds of tests mock a file by its path (vi.mock("@/shared/lib/…")). Code moved into a package escapes those mocks.
  • You can’t rely on discipline. Several sessions work on the project in parallel, human or not.
  • The two applications have to stay separate. The storefront is open to the whole Internet, and the ERP handles the money (ADR 0002).

The alternatives

  • Move everything into packages at once. The path-based mocks break by the hundred, and as long as the work lasts, you can’t change anything else.
  • Keep both copies and rely on review. But nothing flags that you forgot, and the sessions that change the code don’t review one another.
  • Merge the two applications. The copy goes away, but you also lose the separation between what a flaw in the storefront can reach and what the ERP protects.
  • Move the shared code out piece by piece, and in the meantime, keep a copy from drifting.

The decision

We move the shared code into packages, one piece at a time. And in the meantime, you can’t push a divergence.

The implementation

  1. The shared code goes into packages/* (domain for the rules, ui for the interface kit, infra for the tooling, contracts for the exchanges). Each application only keeps a one-line relay (export * from "@meublesmoriniere/domain/vat";). That relay sits at the path the imports and the mocks already target, so no test changes. The ESLint rule moriniere/prefer-relay forces you to go through the relay.
  2. A twin check, pnpm check:twins (scripts/check-twins.mjs), compares the two applications file by file.
    • A file that’s identical on both sides is refused, unless it’s on the list of files we still tolerate. That list can only shrink: --write refuses to add a file to it.
    • A file that already differs isn’t free either. Every top-level declaration found on both sides (function, constant, type) has to keep the same text.
    • An intended difference is recorded with the hash of its text in each application. If it moves, the check fails again.
  3. Sometimes the storefront puts a file somewhere else. Its checkout is in modules/checkout, and it matches the ERP’s payments. In that case, a mapping table (SITE_RENAMES) pairs the two paths.

The check runs in the pre-push hook. So a rule fixed on one side only doesn’t reach prod.

sharedDeclarationDriftsscripts/check-twins.mjs · lines 168–183
function sharedDeclarationDrifts() {
	return comparedSources()
		.filter((file) => existsSync(siteFile(file)) && !areIdentical(file))
		.flatMap((file) => {
			const erp = topLevelDeclarations(join(ERP, file));
			const site = topLevelDeclarations(siteFile(file));
			return [...erp]
				.filter(([name, text]) => site.has(name) && site.get(name) !== text)
				.map(([name, text]) => ({
					declaration: `${file}#${name}`,
					erp: fingerprint(text),
					site: fingerprint(site.get(name)),
				}));
		})
		.sort((left, right) => left.declaration.localeCompare(right.declaration));
}

The results

As of November 12, 2026, there are 247 relays pointing to the packages. There are 28 code files still copied and 77 tracked divergences, each recorded with its hash. A calculation fix made on one side only is refused at push. And each file that moves into a package removes an entry from the tolerated list.

The limits

  • Every shared element has two names. When you look for the VAT rule, you first land on a one-line relay. The code organisation audit of November 12 found that only 20 of the 247 relays were actually mocked by a test. It suggests mocking the package directly to get rid of the relays.
  • The forms are still twins. Around 140 test files mock the toast module, and forms moved into a package would slip past those mocks.
  • The check only compares files stored at the same path, or paired by the table. If you copy shared code under another name, it doesn’t see it. The rule is written in the README: shared code moves into a package.

On this page