# I Let Nine AI Agents Rebuild My Unfinished .NET App

> I gave Factory one prompt to finish a .NET app I started in 2022. Nine AI agents moved it to .NET 11, rebuilt the Result type on C# 15 unions, replaced EF Core with Dapper, added a React UI, and wrote 1,048 backend tests. One of them also deleted a file from my machine.

Published: 2026-11-24. Author: Milan Jovanović. Topic: AI for .NET. Tags: ai, csharp, dotnet, vertical-slice-architecture.

Canonical: https://milanjovanovic.tech/blog/ai-agents-rebuild-dotnet-app

I gave [**Factory**](https://factory.com), 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](https://milanjovanovic.tech/blogs/articles/ai-agents-rebuild-dotnet-app/trainer_dashboard.png)

## The Prompt

Here's the first half of my prompt:

```text
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**](https://github.com/DapperLib/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**](https://docs.factory.com/workstreams/overview).
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.](https://milanjovanovic.tech/blogs/articles/ai-agents-rebuild-dotnet-app/agents_and_shared_folder.png)

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.](https://milanjovanovic.tech/blogs/articles/ai-agents-rebuild-dotnet-app/exercise_library.png)

## 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](https://milanjovanovic.tech/blogs/articles/ai-agents-rebuild-dotnet-app/client_today_and_logging.png)

The 29 projects are now four: the API, a shared kernel, and two test projects.
Each feature is a [**vertical slice**](https://milanjovanovic.tech/blog/vertical-slice-architecture) 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**](https://milanjovanovic.tech/blog/implementing-the-outbox-pattern) and inbox tables.
An [**architecture test**](https://milanjovanovic.tech/blog/enforcing-software-architecture-with-architecture-tests) fails if one module's SQL touches another module's schema.

The [**pull request**](https://github.com/m-jovanovic/trainersphere-api/pull/1) 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**](https://milanjovanovic.tech/blog/csharp-union-types-vs-result-pattern), 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`**](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-15#closed-hierarchies) record instead:

```csharp {1}
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:

```csharp
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:

```text
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):

```powershell
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:

```text {3}
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**](https://github.com/m-jovanovic/trainersphere-api).

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.
