Python, FastAPI, React development

Python, FastAPI, React — and refactoring that blows nothing up.

The real problem

Code in a local AI system has an unpleasant property: it is almost entirely asynchronous and almost entirely bound to scarce resources. One model, one GPU, one memory budget. The resulting bugs — leaked reservations, double loads, orphaned requests — do not reproduce under naive unit tests.

How I solve it

  • Hexagonal architecture: decision logic is pure, side effects live at the boundary. You test decisions without starting a process.
  • Dependency injection through Python Protocols: one extracted package, three heterogeneous consumers, zero cross-imports.
  • Serious asyncio: lock plus double-check on load, in-flight request tracking, cleanup guaranteed by BackgroundTask.
  • Front end: React and Tauri for a desktop dashboard driving the agent locally over WebSocket. Next.js and React where the context calls for it.

A trap learned in the field

Extracting a shared package out of a live system is the operation where you break everything at once. Method used: strangler fig. Extract behind back-compat shims, migrate one consumer at a time, keep both paths alive until the last caller has moved. No big-bang. Validated by ~1,600 tests at every step.

Proof that the abstraction was right did not come from the tests: it came from the second consumer, written later, which used the package without importing a single line of the original project. As long as there is one consumer, you do not know whether you have an abstraction or just a moved file.

What it delivers, measured

  • ~1,600 tests covering the extraction, green at every step
  • 3 heterogeneous consumers of the extracted package
  • Zero dependencies on some projects — MIDI parser and writer hand-written on the standard library
  • Adversarial multi-agent review before the first commit: 10 confirmed issues out of 22 raised

Where it runs in production

This capability is engaged in

BuildAudit

Your data cannot leave the building?

Describe the use case, the data involved and the available hardware. I answer personally within 48 business hours.