Sample · fictional companyVema · Duplication and architectural drift report · Ferrowick, Inc.Page 1 of 5
Practice 1.2 · Reference DDR-SAMPLE-01 · Excerpt
Duplication and architectural drift report
On the TypeScript monorepo of Ferrowick, Inc., a fictional accounts-payable and payouts platform whose code has been written largely with coding agents since late 2025.
- Codebase
- Ferrowick monorepo:
web, api-gateway, billing, payouts, ledger, shared - Snapshot
- Commit
c41a9d0; history window of 90 days - Access
- Read-only clone; the code was not executed
- Delivered as
- This report, and pull requests to the client’s repository
- This excerpt
- Sections 1, 3, 4, 5, 6, 7 and 9 of 9
1Summary
The codebase is readable and well tested at the level of individual modules. Its debt is not in the quality of any one file. It is in nine places where the same rule now exists in two to four versions, five of them on paths that move money, and in two boundaries that the architecture intends but nothing enforces.
The cause is visible in the history. The shared helpers live in package-level folders an agent working in another package does not search, and the instructions agents receive are split across three rules files that disagree. We recommend one money module, three build-failing rules, three decision records and one root CLAUDE.md. All are proposed below and delivered as pull requests.
Sample notice. This report is a sample prepared by Vema on a fictional company. Every name, figure and line of code in it is invented for illustration.
Sample · fictional companyVema · Duplication and architectural drift report · Ferrowick, Inc.Page 2 of 5
3Findings
Findings are ranked by what the component handles and then by the number of copies. D marks duplication, A architectural drift and R the rules agents are given.
Table 3.1 Findings
| ID | Area | Finding | Copies | Handles | Severity | Proposed action |
| D-01 | Currency formatting | Four implementations of amount formatting across web, billing, payouts and notifications | 4 | Display | Medium | Consolidate in @ferrowick/money |
| D-02 | Rounding to cents | Two implementations that disagree on half-cent amounts (half-up and half-even) | 2 | Money | High | One implementation; CI rule; ADR-0007 |
| D-03 | Idempotency keys | Three key generators; one omits the tenant identifier | 3 | Money | High | One generator in shared/http |
| D-04 | Retry with back-off | Three implementations; one retries a POST that has no idempotency key | 3 | Money | High | withRetry() only; ADR-0009 |
| D-05 | Business-day arithmetic | Two implementations; one ignores US federal holidays | 2 | Money | Medium | One implementation with a holiday calendar |
| A-01 | Layering | The web package imports the database client directly in 11 files | – | Data | Medium | Lint rule; ADR-0003 |
| A-02 | HTTP clients | Two HTTP clients with different timeout defaults | 2 | Integration | Low | One client |
| A-03 | Ledger writes | Six call sites outside the ledger package write ledger entries directly | – | Money | High | Dependency rule; ADR-0005 |
| R-01 | Rules files | .cursorrules and a package-level CLAUDE.md give contradictory error-handling instructions | 2 | Process | Medium | One root CLAUDE.md; others point to it |
Section 2 (method) and section 8 (per-package tables) are omitted from this excerpt. In outline: near-duplicates were found on normalised syntax trees, generated and vendored code and bot commits were excluded, and each cluster was traced through the history to the commit that introduced it.
Sample · fictional companyVema · Duplication and architectural drift report · Ferrowick, Inc.Page 3 of 5
4A near-duplicate pair: finding D-02
4.1Both functions turn a dollar amount into whole cents. The first was written in billing; the second was written four weeks later in payouts, in a commit described as “add fee rounding helper”. The second author did not find the first, because it lives inside the invoice module and is not exported from any shared package.
packages/billing/src/invoice/totals.tsexport function toCents(amount: number): number {
return Math.round(amount * 100);
}
export function invoiceTotal(lines: InvoiceLine[]): number {
return lines.reduce(
(sum, line) => sum + toCents(line.unitPrice * line.quantity),
0,
);
}
packages/payouts/src/fees/calc.tsconst roundHalfEven = (x: number): number => {
const r = Math.round(x);
return Math.abs(x % 1) === 0.5 ? (r % 2 === 0 ? r : r - 1) : r;
};
export function feeInCents(amount: number, rateBps: number): number {
return roundHalfEven((amount * rateBps) / 100);
}
4.2The two disagree on every amount that falls exactly on half a cent: billing rounds up, payouts rounds to the even cent. Both also multiply floating-point dollars, so an amount such as 1.005 is not exactly representable and can round the wrong way before either rule applies.
4.3Replayed against 90 days of fee fixtures supplied by the client, the two functions gave different results on 1,212 of 48,906 calculations, each time by one cent. The invoice preview shown to customers uses billing; the payout ledger uses payouts.
4.4No duplicate-code checker reports this pair. The two functions share no tokens beyond the language’s own, and each passes its own tests.
Sample · fictional companyVema · Duplication and architectural drift report · Ferrowick, Inc.Page 4 of 5
5Proposed CI rules
5.1Three rules fail the build on the patterns found. Each names the decision record that explains it, so that a person or an agent who meets the failure can read why.
eslint.config.js (excerpt), proposed in pull request 1export default [
{
files: ["packages/{billing,payouts,ledger}/src/**/*.ts"],
rules: {
"no-restricted-syntax": ["error", {
selector: "CallExpression[callee.object.name='Math'][callee.property.name='round']",
message: "Monetary rounding goes through @ferrowick/money (ADR-0007).",
}],
},
},
{
files: ["packages/web/src/**/*.{ts,tsx}"],
rules: {
"no-restricted-imports": ["error", {
paths: [{ name: "@prisma/client",
message: "The web package reads data through api-gateway (ADR-0003)." }],
}],
},
},
];
.dependency-cruiser.cjs (excerpt), proposed in pull request 2module.exports = {
forbidden: [
{
name: "ledger-writes-only-in-ledger",
severity: "error",
comment: "Only packages/ledger may use the ledger repository (ADR-0005).",
from: { pathNot: "^packages/ledger/" },
to: { path: "^packages/ledger/src/repository/" },
},
],
};
.github/workflows/architecture.yml, proposed in pull request 3name: architecture
on: [pull_request]
jobs:
guardrails:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 20 }
- run: npm ci
- run: npx eslint . --max-warnings 0
- run: npx depcruise packages --config .dependency-cruiser.cjs
- run: npx jscpd packages --min-tokens 60 --threshold 3
5.2The token-level duplicate check is kept as a backstop. It does not catch pairs such as D-02; the first rule does.
Sample · fictional companyVema · Duplication and architectural drift report · Ferrowick, Inc.Page 5 of 5
6Decision record (excerpt)
6.1The decision behind finding D-02 was never written down; two agents made it differently. ADR-0007 records it.
docs/adr/0007-money-and-rounding.md (excerpt)# ADR-0007: Monetary amounts and rounding
Status: Proposed in this review; to be accepted by the platform lead.
## Context
Amounts are held as floating-point dollars in billing and payouts.
Two rounding rules are in use (finding D-02). Customer previews
and the payout ledger disagree by one cent on half-cent amounts.
## Decision
1. Every amount is an integer number of cents, of type Cents.
2. Amounts enter the system as decimal strings and are parsed once,
in @ferrowick/money.
3. Fees and taxes round half-even, in roundFee() and roundTax().
No other rounding of money is permitted.
## Consequences
toCents() and roundHalfEven() are removed. The lint rule in
eslint.config.js fails the build on Math.round in money packages.
7CLAUDE.md (excerpt)
7.1The root CLAUDE.md encodes the architecture where agents will read it. It replaces the three rules files that disagreed (finding R-01).
CLAUDE.md (root, excerpt), proposed in pull request 4# Ferrowick: architecture for agents and people
## Before writing a helper
Search packages/shared and packages/money first. If a function
that does the job exists, use it. If it nearly does, extend it in
place and say so in the pull request. Do not write a second copy.
## Money
- Amounts are integer cents (Cents, from @ferrowick/money).
- Round only with roundFee() or roundTax(). See ADR-0007.
- Ledger entries are written only through packages/ledger. ADR-0005.
## Layers
web -> api-gateway -> services -> ledger.
The web package never imports @prisma/client. ADR-0003.
## Retries
Use withRetry() from @ferrowick/shared/http. Never retry a POST
without an idempotency key. ADR-0009.
## Rules files
This file is the source of truth. .cursorrules and AGENTS.md
contain one line that points here.
9Limitations
9.1The analysis is static and describes the repository at the snapshot stated on page 1. The code was not executed; finding D-02 was replayed against fixtures supplied by the client, not against production data.
9.2Where the report says code was written with an agent, it relies on commit trailers and the client’s own account, not on any detection of authorship.
9.3This report is not a security audit.
Sample notice. Ferrowick, Inc. and every figure, file and line of code in this report are fictional.