I killed 6 repos and kept my microservices

2026-12-03来源 dev.toEnglish
I killed 6 repos and kept my microservices

Here we go again, story time.

A few months ago I picked up a project I can't name (legal reasons). The day I opened the codebase, I was like, what the duck.

It was AI slop. Spread across 7 different repos.

Now, I have nothing against separate repos. But following one rule everywhere is like using the same sword in war and then for chopping vegetables at dinner. Same tool, very different job.

So I did what you do. I worked with it. For a few months I cleaned the slop, one PR at a time, until it looked like a real codebase. But you know how it is. Once you find a cockroach in your favourite restaurant's kitchen, the food never tastes the same again, no matter how many times they clean it.

Every time I touched something, I could feel the 7 repos behind it.

Why 7 repos hurt when you're alone

Separate repos (polyrepo, if you want the fancy word) exist for a reason. They're great when you have multiple teams. Each team owns its repo, ships at its own pace, and can't break someone else's build by accident. The repo boundary is the team boundary.

I'm not multiple teams. I'm one guy with tea.

And when one person owns all the repos, the boundary stops protecting anything. It only adds friction:

  • One change, many PRs. Rename a field in the API and you're now opening a PR in the backend, then the frontend, then the other frontend, then waiting for each one to merge in the right order. A single logical change, split into pieces that can be half-deployed.
  • The same helper, copied everywhere. An HTTP wrapper here, a date formatter there, the same validation logic in two places. Copies don't stay copies. You fix a bug in one and the other three quietly keep it.
  • Version drift. Repo A is on one version of a library, repo B is two majors behind, repo C pinned something a year ago and nobody remembers why. Upgrading anything means doing it 7 times.
  • 7 sets of config. 7 lint setups, 7 TypeScript configs, 7 CI pipelines, all slightly different, all "almost the same".

None of these is a disaster on its own. Together, it's a tax you pay on every single change. And when you're solo, you're the only one paying it.

So one day, randomly, I decided to put everything in one repo.

Monorepo, not monolith

Before going further, let's clear something up, because people mix these two up all the time.

A monorepo is one git repo holding many apps and shared packages, each app deploying on its own. A monolith is one app with everything inside it, built and shipped as one deploy

  • A monolith is about how your app is built and deployed. One app, one build, everything ships together. Change one line in billing and you redeploy the whole thing.
  • A monorepo is about where your code lives. One git repo, many apps inside it. Each one can still build, test and deploy on its own.

They're two different axes. You can have a monolith split across many repos (please don't), and you can have microservices living in one repo (that's me).

So I didn't merge the apps. The services are still separate services, the frontends are still separate frontends, and each one still deploys on its own. They just share a roof now.

The stack: Bun and Turborepo

Two tools did the heavy lifting.

Bun workspaces handle the "many packages, one repo" part. Every app and every shared package has its own package.json, and the root one lists them as workspaces. One bun install at the root installs everything, with one lockfile for the whole repo. When an app depends on a shared package, Bun links it locally instead of pulling it from a registry. Change the package, and every app using it sees the change immediately. No publishing, no version bumps, no "did I update the dependency in repo C".

(Yes, Bun. Not pnpm, not npm. I've made my choice and I'm at peace with it.)

Turborepo handles the "run things" part. And this is where a monorepo stops being "a big folder" and starts paying you back:

  • It knows the dependency graph. If app A depends on a shared package, Turbo builds the package first, then the app. You don't write that order anywhere. It reads it from your package.json files.
  • It caches everything. Before running a task, Turbo hashes its inputs: the source files, the dependencies, the env vars you tell it about. If that hash has been seen before, it doesn't run the task. It just replays the output and the logs from cache. Running the full build twice in a row takes about as long as reading this sentence.
  • It only does what changed. Touch one app and only that app (and whatever depends on it) gets built, linted and tested. The other apps hit the cache.
  • One command for everything. One dev command starts every app together. One build command builds everything in the right order, in parallel where it can.

And because I was doing this solo, thanks to Claude too. Not a vibe coder, but senior enough to have an unpaid intern.

Copy paste is not a monorepo

Here's the trap I want to warn you about.

The first version of my monorepo was basically copy paste. Every repo's code went into its own folder, same as before, just under one roof. It built. It ran. It was a monorepo in name only.

Because nothing was actually shared. The duplicated helpers were still duplicated. The configs were still 7 slightly different configs. I had moved the mess, not fixed it.

The real benefit only showed up when the copied stuff turned into shared packages:

  • Validation rules shared by frontend and backend. The form in the browser and the API on the server now run the exact same code to decide what's valid. Before, there were two copies, and two copies always disagree eventually.
  • A typed API client generated from the backend. The backend describes its API, the client gets generated from that description, and the frontends import it. Rename a field in the API and the frontend fails at compile time, on my machine, not in production on a user's screen. This alone was worth the move.
  • One config for lint, TypeScript and tests. Each app extends the shared one and overrides only what it really needs. Fix a rule once, it's fixed everywhere.
  • Shared frontend helpers. The HTTP wrapper, error handling, formatting. Written once, imported everywhere, tested once.

That's the line between a real monorepo and a folder of folders: is anything actually shared? If not, you've just made one big repo with all the old problems inside it.

The part that actually hurt: git history

The code moved fast. The history didn't.

Copying files into a new repo takes minutes. But if you just copy, you lose every commit. Every "why is this written like this", every blame, every message that explains a weird fix, gone. And with code that started life as AI slop, the history is often the only explanation you've got.

There are roughly three ways people deal with this:

  1. Rewrite each repo's history into a subfolder, then merge them all. Tools like git filter-repo can rewrite every commit of a repo as if its files had always lived in, say, apps/web/. Then you pull each rewritten repo into the monorepo and merge it with --allow-unrelated-histories. It's the most work, but the result is clean: git log and git blame on any file go all the way back, as if it had always been a monorepo.
  2. git subtree add. One command per repo, history kept. The catch is that old commits still have the old paths, so blame and log on a file tend to stop at the moment it moved.
  3. Copy and start fresh. Archive the old repos as read-only and dig through them when you need history. Fastest by far, and plenty of teams do exactly this.

Getting 7 repos' worth of history into one, without losing who changed what and why, is where most of my 3 days went. Code you can copy. History you have to carry.

Deploying from one repo

"If everything is in one repo, do you deploy everything on every push?"

No. Each app still deploys on its own, and only when it actually changed. The backend goes to AWS with SST. That setup deserves its own post, so I'll leave it there for now. Coming soon.

Was it worth it?

The bill, end to end: 12 cups of tea, 5 packets of snacks and 3 days.

Was it worth it? Yesssss, till the last breath.

One change is one PR again. One upgrade is one upgrade. And when I break a contract between the frontend and the backend, the compiler tells me before a user does.

If you're a solo dev juggling multiple repos for one product, ask yourself one thing: who is that repo boundary protecting? If the answer is "nobody, it's just me", you already know what to do.

What's next

Maybe rewrite parts of it in Rust (why stay behind when the entire tech industry is rewriting everything in Rust), or write some of the services in Go or Rust.

If I do, I'll write about it. The whole story, from the first thought to the final execution to the stats.

That's it. Can't write more without tea, and in Vim.

原文:https://www.a8q9.cn/en/article/i-killed-6-repos-and-kept-my-microservices-73e178.html

相关文章