one description of your app, for the whole team
Every part of the app has a place, so you only have to write what it does.
$ dotnet new install Trax.Samples.Templates
$ dotnet new trax-hub -n MyApp
Prompt it yourself
Use Trax .NET (traxsharp.net) and React to build Battleship in the browser: one player against the computer. Write the game as features, not code: a glossary and a features/ folder in Gherkin (traxsharp.net/docs/statemachine/write-machines-as-features). Trax derives the state machine, its access rules and its API from them, so write no machine class and no access rule by hand. Read that page and the CheckIn sample it links before you start: the game has the same shape. What the features say: - Each player owns their games. A new game deals both fleets at random: five ships (5, 4, 3, 3, 2) each on a 10x10 board, none overlapping. - On your turn you fire at a square and learn whether it was a miss, a hit or a sunk ship. Firing at a square you have already tried costs you nothing. Then the computer fires back, hunting around a hit instead of firing at random. - You win when the computer's last ship sinks, and lose when yours does. The server owns the game. Dealing and each turn (your shot, then the computer's reply) are workflows the game's states invoke. Everything in the game's context reaches the page, so the computer's fleet stays on the server, out of the context. How to build it: - Backend: `dotnet new trax-hub` (traxsharp.net/docs/reference/templates), switched to SQLite. Derive the machine with `trax machine from-gherkin`, commit machines/ with its access.txt, and serve it with ServeFeatures. - Frontend: `npm create vite@latest -- --template react-ts`. Generate its client with `trax client` from the manifest the host exports (traxsharp.net/docs/reference/cli) and use the generated hooks, with no hand-written fetch or GraphQL. Show both boards with hits and misses, and whose turn it is. No sign-in: the page uses the template's development demo key, and a reload resumes the game. You are done when `trax machine from-gherkin --check` and `trax client --check` pass, `trax machine run` is green, `trax machine missing` lists nothing, `npm run build` has no errors, and you have played a whole game in a browser against the running host, to a win or a loss. Then leave both running and give me the URL to play it.
The server holds the state
Each order is a state machine on the server, which checks every move against its rules and the caller before storing anything. The page reads the same rules to know what it can do next, and the laptop and the phone are both told each change.
- Ordered
- Cooking
- Delivered
Your order
Pizzeria Napoli
Nothing yet
- Cart
- Ordered
- Delivered
The machine and the workflow, lit as it runschanged
94m.In(OrderState.Cart)95 .Context<OrderContext>()96 // Nobody ordered: the server clears the cart by itself, and every screen hears it by push.97 .After(CartWait) // 30 minutes; the demo host shortens it98 .GoTo(OrderState.Cleared)99 .On(OrderTrigger.AddItem)100 .AnyAuthenticated()101 .WithInput<NewItem>()102 .When(Input((NewItem i) => i.Item).IsOneOf([.. Menu.Keys]))103 .Because("That is not on the menu.")104 .Reduce(new Reduction.Custom("order:add-item"))105 .To(OrderState.Cart)106 .On(OrderTrigger.PlaceOrder)107 .AnyAuthenticated()108 .When(Field((OrderContext c) => c.Items).CountAtLeast(1))109 .Because("The cart is empty.")110 .To(OrderState.Ordered);111112m.In(OrderState.Ordered)113 .Context<OrderContext>()114 .Invokes<IDeliverOrderTrain, OrderInput, OrderDelivered>(DeliveryFor)115 .OnDone(OrderState.Delivered)116 .OnFailed(OrderState.Cancelled)117 .OnCancelled(OrderState.Cancelled);
30protected override Task<Either<Exception, OrderDelivered>> Junctions() =>31 Chain<SendToRestaurant>()32 .Chain<ChargeCard>()33 .Chain<Cook>()34 .Chain<PickUp>()35 .Chain<Deliver>()36 .Resolve();
The real code: samples/Recovery, and how to run it
Start with
- OrderMachine.csthe order: its states, events and timer
- DeliverOrderTrain.csthe delivery the order runs
- Program.csthe host: machines, step events and pushes
Run it yourself
$ git clone https://github.com/TraxSharp/Trax.git && cd Trax/Trax.Samples $ docker compose up -d database $ dotnet run --project samples/Recovery/Trax.Samples.Recovery.Api $ cd samples/Recovery/Trax.Samples.Recovery.Client && npm ci && npm run dev
Everyone reads the same features
The feature files are the spec, the tests and the access rules at once, so everyone reads the same thing. Step through a flight check-in to see what each phrase becomes in the machines Trax derives from it.
The derived files and what the colours mean, lit as it runschanged
- who may do it
- a command
- a state
- a guard
- the boarding pass train
- a view
- a policy: one machine moving another
- @agent: roles agent
- @passenger: roles passenger
- booking CheckIn: passenger
- booking GivePassport: passenger
- booking Miss: the server only
- booking OpenCheckIn: the server only
- booking read: passenger
- booking start: passenger
- desk CloseGate: agent
- desk OpenDesk: agent
- desk read: agent
- desk start: agent
- flight CloseGate: the server only
- flight OpenCheckIn: the server only
- view bookings: passenger
- view departures: agent, passenger
The part of the derived files the current line produced.
The real code: samples/CheckIn, and how to run it
Start with
- checking-in.featurethe scenarios shown above
- gate.featurethe gate agent and the flight's timers
- glossary.jsonthe words: actors, states, phrases, guards, views
- booking.ir.jsonthe booking machine, derived
- access.txtevery grant, derived, one line each
- IssueBoardingPassTrain.csthe one piece of C# behind the machines
Run it yourself
$ git clone https://github.com/TraxSharp/Trax.git && cd Trax/Trax.Samples $ samples/CheckIn/demo.sh $ open http://localhost:5281
What each person on the team gets from the featureschanged
Product
Writes the behaviour as scenarios in plain English, and sees which situations nobody has decided yet.
QA
The features are the test suite. They run in memory and against the real host, with no step code to write.
Developers
Write the steps that do real work, like taking a payment, and the UI. The machines, access rules, API and typed clients come from the features.
Reviewers
A pull request shows the sentences that changed, and a list of every permission they grant.
Operators
The console's board links each rule on a running machine back to the scenarios that produced it.
Agents
Write features, which they do well. Trax derives the machines the same way every time, and the server checks the agent as it checks anyone.
Changes reach the people allowed to see them
Each message is a workflow, and when it finishes the server pushes it to everyone subscribed to the room. Someone outside the room is refused until they are added.
No room
Not in the room.
No room
Not in the room.
No room
Not in the room.
What each client sent and received, and the code that ranchanged
Every GraphQL request and response, and every WebSocket frame, appears here as it happens.
11[TraxAuthorize(Roles = nameof(ChatRole.User))]12[TraxMutation(GraphQLOperation.Run, Description = "Sends a message to a chat room")]13public class SendMessageTrain : ServiceTrain<SendMessageInput, SendMessageOutput>, ISendMessageTrain14{15 protected override Task<Either<Exception, SendMessageOutput>> Junctions() =>16 Chain<ValidateSenderJunction>().Chain<PersistMessageJunction>().Resolve();17}
The real code: samples/ChatService, and how to run it
Start with
- SendMessageTrain.csthe workflow each message runs
- ChatLifecycleHook.cspublishes each finished message to the room's topic
- ChatSubscriptions.csonChatEvent, admitting only the room's participants
- Program.csAPI keys, the hook and the subscription wired up
Run it yourself
$ git clone https://github.com/TraxSharp/Trax.git && cd Trax/Trax.Samples $ dotnet run --project samples/ChatService/Trax.Samples.ChatService.Api $ cd samples/ChatService/Trax.Samples.ChatService.Client && npm ci && npm run dev
A workflow can choose its path at run time
A workflow lists its paths, and a model or a rule table picks one at run time. Each answer is saved, so a retry after a crash takes the same path without asking again, unless the data changed. A checkpoint saves the result so far, so a retry after it starts there and does not pay twice.
- Runs
- Breaks
- Recovers
The refund workflow, lit as it runschanged
21protected override Task<Either<Exception, RefundResult>> Junctions() =>22 Chain<LoadRefundCase>()23 // Ask the model: what went wrong with this order?24 .Switch<RefundCase, Problem>(problem =>25 problem26 .When(Problem.Damaged, then => then.Chain<RequestPhotos>())27 .When(Problem.Lost, then => then.Chain<TraceParcel>())28 .When(Problem.Unwanted, then => then.Chain<CheckReturnWindow>())29 )30 // Ask the model: should we pay it?31 .Gate<RefundEvidence, ApproveRefund>(answer =>32 answer33 .Yes(then => then.Chain<IssuePayment>(), atLeast: 0.8)34 .No(then => then.Chain<DeclineRefund>(), below: 0.3)35 .Unsure(then => then.Chain<QueueForReview>())36 )37 // Save progress: a retry starts here, so nobody is paid twice.38 .Checkpoint<RefundOutcome>()39 .Chain<NotifyCustomer>()40 .Resolve();
The real code: samples/Recovery, and how to run it
Start with
- ApproveRefundTrain.csthe refund: two questions and a checkpoint
- Problem.csthe first question the model is asked
- ApproveRefund.csthe second question the model is asked
- DemoDecider.csthe stand-in decision model
- Program.csthe host: decision recording, step events, the scheduler
Run it yourself
$ git clone https://github.com/TraxSharp/Trax.git && cd Trax/Trax.Samples $ docker compose up -d database $ dotnet run --project samples/Recovery/Trax.Samples.Recovery.Api $ cd samples/Recovery/Trax.Samples.Recovery.Client && npm ci && npm run dev
Agents are checked like anyone else
Agents never move a ticket: they send evidence, and the server checks it itself. Here an agent tries to skip ahead and to approve its own fix, and the server refuses both.
The code that refused each movechanged
The real code: samples/Board, and how to run it
Start with
- AssignmentMachine.csan agent's assignment: its events and the checks they run
- TicketMachine.csthe board: lanes only the server moves
- ReproduceTrain.csa check: the server runs the agent's case itself
- scenarios.tsthe scripted agents, on the generated client
Run it yourself
$ git clone https://github.com/TraxSharp/Trax.git && cd Trax/Trax.Samples $ docker compose up -d database $ dotnet run --project samples/Board/Trax.Samples.Board.Api $ cd samples/Board/Trax.Samples.Board.Agents && npm ci && npm run scenario
Every run leaves a record
Every run is saved to Postgres: when it started, how it ended, and the step that failed with its error. You can read it in the dashboard or with SQL.
What gets recorded →- Name
- Trax.Samples.GameServer.Trains.Leaderboard.RecalculateLeaderboard.IRecalculateLeaderboardTrain
- TrainState
- Failed
- StartTime
- 2026-09-29 03:15:00.412
- EndTime
- 2026-09-29 03:15:02.087
- Input
- { "region": "na" }
- FailureJunction
- RankPlayersJunction
- FailureException
- TimeoutException
- FailureReason
- Score service did not answer within 2s
- ManifestId
- 14 (leaderboard-na)
- HostName
- worker-2
Deploy it however you want
Start in one process and split it out as load grows, without rewriting your workflows.
All-in-one
API, scheduler and the jobs they run in a single process.
API + Scheduler
The API queues work, and a separate scheduler picks it up and runs it.
Hub + Workers
A hub serves the API and schedules. Workers take jobs from the database and run them.
Ephemeral dispatch
The API hands work to an AWS Lambda function, which runs it and stops.
Just the scheduler
No API at all. One process runs workflows on a schedule.
Packages
44 packages in one repository, released together at one version, all on NuGet and all MIT licensed. There is no commercial edition, and there will not be one.
Install it and write your first workflow →