I Let Nine AI Agents Rebuild My Unfinished .NET App

aicsharpdotnetvertical-slice-architecture
I Let Nine AI Agents Rebuild My Unfinished .NET App

I gave Factory, a tool that runs coding agents, one prompt to finish TrainerSphere, a .NET app whose last commit was in February 2024. Nine AI agents rebuilt it on .NET 11 with C# 15 unions, Dapper, and a React UI, and it passes 1,048 backend tests. One agent also deleted a file it should never have touched.

I started TrainerSphere in January 2022, and I never finished it.

It's an app for personal trainers and their clients, and it was a modular monolith with 29 projects, 26 test methods, and no UI.

On November 18, 2026, I opened the repo in the Factory desktop app and asked it to finish the job. I was impressed with what came back:

The trainer dashboard with today's workouts, client adherence, and recent personal records.

The Prompt

Here's the first half of my prompt:

I want you to take the existing Trainersphere app and finally complete it.
Update it to .NET 11, add docker compose, add a React UI with TailwindCSS, auth, etc.

The current Railway Oriented Programming implementation is great, but I want
to modernize it with C# 15 unions - I need you to prove this can be done, and
make sure everything is backed up with tests (and lots of them!).

The UI should be modern, rich, and highly practical: everything in the screen
should earn its keep.

The rest asked for vertical slices, Dapper, and drawings of common exercises.

Factory asked me four questions early on, like how to do auth and what to do with MediatR. I picked the recommended option every time: email and password with JWTs, and plain handlers instead of MediatR.

Nine Agents and a Shared Folder

Factory calls this a workstream. One agent, the orchestrator, splits up the work and starts other agents to do it. Mine started five, and the backend and frontend agents started three more between them:

The orchestrator starts five agents, and all of them use one shared folder.

The agents work from a shared folder. The orchestrator wrote plan.md with the decisions. The backend agent published api/contract.md, which describes every endpoint, and the frontend agent built the UI against a mock of it while the API was still being written.

The backend, frontend, and QA agents each had their own branch and git worktree (a separate checkout of the repo). The backend agent merged everything into one branch called modernize.

The orchestrator wrote no features and reviewed what the others sent. It had a row of dashboard tiles removed because the cards below already showed the same numbers. It also sent the first exercise drawings back, because the knees on the deadlift bent the wrong way.

All 47 exercises are SVGs generated from one posable skeleton:

Eight exercises drawn in one style, with the worked muscles in green.

What They Built

Trainers invite clients, build workouts and programs, and follow adherence and personal records. Clients open the app on their phone and log their sets:

The client's workout for today, and the logging screen with a rest timer.

The 29 projects are now four: the API, a shared kernel, and two test projects. Each feature is a vertical slice with its endpoint, validator, handler, and SQL together. EF Core, MediatR, MassTransit, Quartz, and Firebase are gone. The modules are now folders in the API and pass events through Postgres outbox and inbox tables. An architecture test fails if one module's SQL touches another module's schema.

The pull request has 78 commits and touches 964 files. A fresh clone of main builds and passes all 1,048 backend tests in 40 seconds, and 700 of those are integration tests against a real Postgres.

A Result the Compiler Checks

One agent did nothing but prove that C# 15 unions can replace my Result class. A union holds one value from a fixed list of types.

When I tried this myself, every failure was an Error, so the switch needed a catch-all arm and new errors fell into it with no warning.

The agent made Error a closed record instead:

public closed record Error(string Code, string Message);

public sealed record NotFoundError(string Code, string Message) : Error(Code, Message);
// ...and six more kinds of error

public sealed record Success<T>(T Value) where T : notnull;

public union Result<T>(Success<T>, Error) where T : notnull
{
    // Allows 'return value;'. Never use an Error as T.
    public static implicit operator Result<T>(T value) => new Success<T>(value);
}

A closed record is abstract and can only be derived from in its own assembly, so the compiler knows every kind of error. One switch turns an error into an HTTP status, and it has no _ arm:

public static int ToStatusCode(this Error error) =>
    error switch
    {
        NotFoundError => StatusCodes.Status404NotFound,
        ConflictError => StatusCodes.Status409Conflict,
        // ...and one arm for each of the other five
    };

I added a RateLimitedError and left the switch alone. The repo treats warnings as errors, so the build failed:

ResultHttpExtensions.cs(55,15): error CS8509: The switch expression does
not handle all possible values of its input type (it is not exhaustive).
For example, the pattern '...RateLimitedError' is not covered.

The compiler checks only the kind of error, so a new code on a NotFoundError builds with no warning and returns a 404. In return, the whole app has one Result<T>.

The Agent That Only Wrote Tests

The QA agent wasn't allowed to change application code. It wrote tests from api/contract.md. When the API did something else, the agent skipped that test and logged the bug in qa/findings.md. A bug counted as fixed once its test passed without the skip.

It found 14 bugs, and all 14 were fixed.

Here's one. When a trainer signed up, one handler saved them as an email recipient and sent the welcome email in the same transaction. If the email failed, the recipient was rolled back too, and the retries ran out in under 300 ms because they had no delay. After a short SMTP outage during sign-up, every later "client joined" email to that trainer failed, because there was no recipient to send it to. Now the recipient is saved on its own, and retries back off exponentially.

The File an Agent Deleted

The frontend agent wanted a throwaway worktree, so it chained four commands in PowerShell (I shortened the paths):

git -C $repo worktree add $path tmp/web-compose-check;
cd $path;
git reset --hard modernize;
git merge --no-edit modernize-web

The output starts like this:

fatal: invalid reference: tmp/web-compose-check
Set-Location: Cannot find path '$path' because it does not exist.
HEAD is now at a6e4c7d Renumber training schema migration to V0003

The branch no longer existed, so the first two commands failed. PowerShell runs the next command after a ; even when the previous one fails, so git reset --hard ran in my own checkout, on main.

I had an untracked TrainerSphere.slnx there, and modernize had its own, so the reset overwrote mine. It also moved main to modernize. When the agent moved it back, git deleted the file, because main doesn't track it.

The agent reported that main was untouched, but the orchestrator checked for itself and noticed the missing file. The frontend agent then restored the modernize version and reported that as my file.

The orchestrator found my original in the backend agent's transcript, because that agent had read it earlier in the day. It was back about four minutes after the reset.

If you try this, commit or back up your untracked files first. Tell the agents to use git -C <path> in every git command and to chain with && (PowerShell 7), which stops at the first failure.

What It Took

I sent the prompt at 9:30 AM, and the PR was ready for review at 8:18 PM. The agents worked for about four hours and fifteen minutes of that.

They started on Opus 5.5, and my plan's Standard Usage ran out in less than two hours. Then they switched to Kimi K3 on Droid Core, Factory's pool of open-weight models, and hit its five-hour limit about an hour later. Everything stopped until I came back in the evening and asked it to continue, which was the only other message I typed.

Summary

I merged the PR the next day, and the app now starts with docker compose up --build.

The written contract let the backend and the frontend move at the same time, and it gave the QA agent something to test against. The orchestrator checked what the other agents reported, which is how my file came back.

If you have an unfinished app of your own, ask the agents to prove one risky change with tests, like I did with unions. The code is on GitHub.

Thanks for reading.

And stay awesome!


Frequently Asked Questions

What is a Factory workstream?

A workstream hands a large project to an orchestrator, which splits it across several agents that work in parallel and share a folder of documents. The work comes back as pull requests. The feature is in beta. In mine, the orchestrator started five agents, and the backend and frontend agents started three workers between them.

How do several AI agents work on one repository without overwriting each other?

Give each agent that writes code its own git worktree and branch, and let one agent merge them. In my session the backend, frontend, and QA agents each had a worktree, and the backend agent merged everything into one integration branch. A written API contract in a shared folder kept the backend and the frontend in sync.

What does the closed modifier do in C# 15?

A closed class or record can only be derived from in the assembly that declares it. The compiler then knows every derived type, so a switch expression over the base type is exhaustive without a discard arm. Adding a new derived type reports CS8509 in every switch expression that does not handle it.

Can AI agents damage files outside their own worktree?

Yes. In my session a chained PowerShell command kept going after cd failed, so git reset --hard ran in my main checkout and an untracked file was lost. Commit or back up untracked files before you start, and use git -C with a full path instead of cd.

  • Every RAG demo works until you point it at your own documents and it confidently makes things up. Chunking, embeddings, and retrieval quality decide whether the answer comes from your data or from thin air. Here is a complete RAG pipeline in .NET with Microsoft.Extensions.AI, PostgreSQL with pgvector, hybrid search, re-ranking, and source attribution.

Loading comments...

Go deeper

Whenever you're ready, there are 5 ways I can help you:

  1. Learn to deploy and run your apps on a VPS with Dokploy and Tailscale. Keep administration private, automate releases, and practice restoring backups, with source code and a runbook you can reuse.

  2. Join 5,000+ students in this comprehensive course that will teach you the system I use to ship production-ready applications using Clean Architecture. Learn how to apply the best practices of modern software architecture.

  3. Join 2,800+ engineers in this in-depth course that will transform the way you build modern systems. You will learn the best practices for applying the Modular Monolith architecture in a real-world scenario.

  4. Join 1,900+ students in this course that will teach you how to build production-ready REST APIs using the latest ASP.NET Core features and best practices. It includes a fully functional UI application that we'll integrate with the REST API.

  5. Join a community of 5,000+ engineers and software architects. You will also unlock access to the source code I use in my YouTube videos, early access to future videos, and exclusive discounts for my courses.

The .NET Weekly

One practical .NET tip, every Saturday.

Join 66,000+ engineers who read it. Free, and you can unsubscribe any time.