The Pisa Pattern: Migrating posix based project to Zig 0.16.0

Tofu is

  • an asynchronous Zig messaging library
  • single-threaded Reactor
  • posix based

Zig 0.16 hid posix.

But I wanted to continue developing Tofu on the latest Zig versions

Several possibilities:

  • redesign the networking architecture/adopt new Io,
  • preserve the existing architecture and replace the lower layers.

I chose the last option

It’s similar to the restoration of the Leaning Tower of Pisa.

It was stabilized by working on its foundations while leaving the tower itself in place.

Most of the work happened underneath

The Tofu migration followed a similar idea - just replace

  • posix based networking layer with
  • uSockets based
Public API / Interface
    ↓
Internal Implementation
    ↓
Network Abstractions (comptime)
    ↓
Network Implementations <=== std-posix based|uSockets based
    ↓
Networking Foundation
    ↓
Operating System APIs

Most of the new low-level networking code was written by AI team(Claude Code and Gemini CLI).

They also created many additional low-level tests covering edge cases.

Still, I don’t think the migration succeeded because of AI alone, and I wouldn’t call this “vibe coding”.

It worked because the project already had

  • clear abstraction boundaries
  • a large test suite

And don’t forget who initially developed it.

My role was mostly architecture, integration, review, debugging, and troubleshooting.

In some ways it felt similar to working with a software team.

There were only two unusual things:

  • they asked for a raise almost every day (“please upgrade your subscription”)
  • and nobody took code reviews personally

For those interested in the networking side of the migration:

This migration was done using Zig 0.15.2.

The whole migration took about 3 weeks (less than Pisa’s 11 years, but they didn’t have AI).

Only after successful testing on the full matrix:

os:           linux, windows, macOS
optimization: Debug, ReleaseSafe, ReleaseFast, ReleaseSmall
foundation:   stdposix, usockets

I continued with the actual port to Zig 0.16.0.

Nothing special there — about two days of straightforward work.

I did that part myself, just so I wouldn’t forget how to write code.

One additional note.

I’m not sure I would have started this migration on my own.

In “real life” with deadlines - no problem, but now I am programming for fun

And I don’t hesitate to say - it was great experience