← All work

One shared library, two checkouts · Jan – Mar 2025

Splitting one checkout into two apps and a shared library

One codebase ran two very different checkouts. In one, we were the payment aggregator: the customer paid us, and we processed the payment. In the other, we processed nothing. We were the layer in front, and a rule set decided which processor each transaction went to. As the two grew apart, every change to one risked the other. With a teammate, I split them into two apps that share one private library of components, validators and themes.

Role
Co-led with a teammate
When
Jan – Mar 2025
Where
PayGlocal
Stack
ReactRedux ToolkitTypeScriptViteTailwindAWS

The situation

The two checkouts looked alike but did different jobs. The aggregator checkout owned the whole payment: wallets, multi-currency accounts, payment buttons, and the processing behind them. The orchestration checkout owned the screens and the routing: it collected what the customer chose, then handed the transaction to whichever processor the rules picked, with its own world of bank mandates, standing instructions, one-time mandates, saved cards and fee handling. Both lived in one codebase, and a flag checked in components, state logic and validators decided which one you were in. A fix for one could quietly change the other, every release shipped both, and with one deploy and one set of logs, monitoring couldn’t easily tell which one was in trouble.

What I built

  • A shared library first: we turned scattered helpers into a TypeScript package, built with Vite in library mode, published to a private npm registry on AWS, and installed by both apps.
  • Twenty-four form validators in one place: card number with a Luhn check and caret handling, expiry, CVV, UPI ID, PAN, bank account, phone, email and the billing address. Hardened so either app could pass empty values without a crash.
  • Shared store types, helpers, a storage wrapper, an offline-aware action queue, themes and common components, all in the library.
  • Moved shared constants, helpers, validation and components out of the checkout and imported them from the library instead: about 3,800 lines gone from the app.
  • Then the split: the orchestration checkout got its own repository. We deleted the processing flows it never used, removed the product flag everywhere, and gave it its own routes, build path and server config: about 7,100 more lines gone.
  • The new app got its own deploy path, so each checkout now ships and is monitored on its own. When payments fail, it’s clear whether the problem is in processing or in routing.
Try it

The architecture

Where 10,879 lines went

Lines removed from the checkout codebase, by what happened to them

  • Deleted: processing flows the orchestration checkout never used7,078
  • Moved out: shared code now imported from the library3,801

What the shared library holds

Lines I added to the library, by area

  • Form validators (24)1,597
  • Store types852
  • Helpers204
  • Offline action queue46

When the code moved

My commits in February 2025. With a teammate, testing and rollout, the whole effort took about three months.

  • Build the shared library
  • Move shared code into it
  • Split out the orchestration checkout
375 KBBundle when both products shared one app
335 KBOrchestration checkout on its own, about 11% smaller

Decisions

Split along what each one is responsible for

The line wasn’t “which client uses it”. It was “who moves the money”. Processing code went with the aggregator; screens, rules-driven routing and the recurring-payment journeys went with the orchestration layer. Anything both needed became the library.

Build the shared library before splitting

Splitting first would have meant copying shared code into two places and then untangling it twice. Pulling it into a package first meant the split itself was mostly deletion.

Delete, don’t hide

It was tempting to leave the product flag in place and switch it on. Removing it, and every branch it guarded, made the new app smaller and meant nobody had to wonder which code was live.

Validators that never crash

Once two apps call the same code, you can’t assume what they pass in. The shared validators accept missing values and unknown countries safely instead of throwing on the payment page.

A versioned package, not a copied folder

Publishing the library to a private registry means each app pins a version and upgrades when it’s ready, instead of a change in one place silently landing in both.

Outcome

WhatBeforeAfterDetail
Codebases1 serving 2 checkouts2 apps + 1 libraryseparate releases
Orchestration checkout bundle375 KB335 KB−10.7%
Lines removed from the checkout~10,900moved or deleted
Form validators in one place24shared by both apps

What I learned

Kind words

I worked with Arjun on multiple projects at PayGlocal, from building the Checkout experience to developing dashboards. He has an incredible ability to quickly understand a product and get started independently. His sense of ownership is genuinely impressive, and I never had to handhold him on any task. He understands what’s expected, takes ownership, and gets things done. He’s a true engineer with great technical aptitude, intelligence, and an excellent work ethic. It was an absolute pleasure working with him, and I’d happily work with him again!
Photo of Rahul JoshiRahul JoshiStaff Software EngineerPayGlocal
↑↓ move↵ openesc close