Berlin.rb #2,

The ZARchitecture: How and Why we evolved a fintech for AI-driven development

By Stephen Margheim

Chapters

Summary

This summary was written with AI from the recording, then checked by Berlin.rb and Stephen Margheim. Spotted a mistake? Write to hello@berlinrb.org.

Stephen Margheim reads perhaps 5% of the code he ships to production at ZAR, a stablecoin neobank. He argues that the codebase steers AI agents more than any prompt does, so ZAR keeps one shape and one vocabulary everywhere, lands every change atomically like a database transaction, and lets machines enforce the rules: typed interfaces, architecture checks with ArchSpec in CI, and a test suite pruned with mutation testing until a green build means something. Stephen spends his own attention on the architecture and the database schema, and never outsources the understanding. Working this way, he rewrote ZAR's blockchain integration and its ledger without a single bug.

The codebase is the prompt 6:33

Code is cheap now, and Stephen argues that this makes it matter more. For the first time, a better idea can win on its merits, because the cost of changing existing code no longer outweighs the improvement.

He gives two reasons why the codebase is the prompt. Most of the tokens in an agent session (he bets 70 to 80%) come from reading your code, not from your instructions. And models are trained above all to produce code, so they follow the patterns in your codebase over the wording of your prompt. Ask for elegant Ruby in a codebase full of spaghetti and you get more spaghetti. Quality compounds in both directions.

Abstractions matter for the same reason. A good abstraction is a decision no session has to make again. Without one, every session guesses, and parallel sessions guess differently. Four people handling third-party API errors on the same day leave four patterns behind, and the next session copies whichever one it finds.

Inhale, exhale 10:41

The working rhythm Stephen describes, developed with his colleague Obie Fernandez, has two halves. On the inhale, let the agent explore the problem freely. On the exhale, fold what you learned back into abstractions and conventions, and apply them across the whole codebase in the same pull request.

He compares each breath to a database transaction. Changes should be atomic, because an abstraction introduced in one file but not the others leaves two ways of doing the same thing. The codebase should stay consistent at every moment: "Consistency is more valuable than correctness." Work stays isolated in its session until it can land in one pull request, and pushing it to the shared Git remote makes it durable. That way the roughly 50 sessions running across his team all start from the same state.

Four layers of architecture 16:52

Shape 17:13

Stephen sees codebases as fractal. Functions combine into services, which take a schema and return success or failure. Services combine into subsystems, and subsystems into the app. Each layer has a defined interface, which makes the whole app easy to describe to every session.

Vocabulary 20:52

Rails won on convention over configuration. AI tools are the opposite: every developer's model, mode, skills and memory are slightly different, so shared conventions are worth more than ever. ZAR found three different HTTP status codes for the same provider exception, 16 ways of translating a provider failure, and 69% of services returning unchecked data. Its answer is REST everywhere, even inside the monolith where no HTTP is involved. There are seven fixed verbs, and you only get to invent nouns. A Boundary base class allows exactly those seven methods, so a violation stops the app from booting. For rules that need judgment, ZAR built Praxis, a linter that uses a model to check things like whether a service only returns success for the outcome its name promises.

Types 27:48

"A type is a convention that a machine can check." ZAR types the parameters of every resource in place of strong params, and types every value object, using Literal, the runtime type library by Joel Drapper that Stephen co-maintains.

Enforcement 29:48

ArchSpec by Carmine Paolino checks the architecture in CI. Every subsystem is a closed box. The outside world can only call its resources and gets back values, which are frozen data objects, and only identifiers go in. Stephen prefers ArchSpec to Packwerk because it can express rules in both directions and is fast. ZAR adds its own Prism-based checks on top, and runs some subsystems' test suites without Rails or Postgres in the bundle, so code there cannot reach for the app's User model.

Testing the tests 35:37

Stephen finds that AI mostly writes useless tests, which slow CI down and give false confidence. His fix is mutation testing with Mutineer. The tool changes the source in small ways, such as turning > into >=, and checks that some test fails. He enforces two rules: every test must catch a bug, and it must catch it uniquely. He contributed a kill matrix to Mutineer that finds redundant tests.

With two agent sessions running mostly unattended, he rewrote ZAR's backend and mobile test suites. The backend went from 17,700 test examples to 8,170, with coverage up, CI time down, and real bugs found and fixed along the way.

Two rewrites in production 41:13

Over the month before the talk, Stephen replaced all of ZAR's blockchain code and rolled it out over a week in about 30 deploys behind feature flags, without a single bug. He also rewrote the ledger: about 25 ways money moves and about 15,000 call sites, running in production at the time of the talk. He spent his own attention on the database schema (every table, column, index and trigger) and has not read the Ruby written on top of it.

What comes next

Software foremen, not factories 44:59

Code generation is not the bottleneck. Invest in agents that watch every log and check every change against your guards.

One place for all your data 46:28

The signals for a safe rollout needed business data, telemetry, exceptions and app events from five systems. ZAR is building a data lake behind one MCP server with two tools: describe the schema, and run SQL.

Never outsource the understanding 49:26

Stephen doesn't care whether code uses map or collect, but he knows every module, what it is called and why it exists. Architecture, vocabulary and the data schema stay with the humans.

Takeaways 51:34

From the Q&A 54:14

Background

Short explanations of ideas the talk builds on, written by Berlin.rb.

Mentioned in the talk

Given at Berlin.rb #2 at Techtelmechtel. Want to speak too? Submit a talk.