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.

1 × Margherita$12.00
0 / 8
  1. Ordered
  2. Cooking
  3. Delivered
Place the order and watch the machine run its train, or step through it with Back and Next.
Timeline
OrderMachine
Cart
Ordered
starts the trainDeliverOrderTrain
SendToRestaurant
ChargeCard
Cook
PickUp
Deliver
its outcome moves the order
Delivered
Cancelled
9:41

Your order

Pizzeria Napoli

Nothing yet

  1. Cart
  2. Ordered
  3. Delivered
The machine and the workflow, lit as it runschanged
Code OrderMachine.cs
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 it
98 .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);
111
112m.In(OrderState.Ordered)
113 .Context<OrderContext>()
114 .Invokes<IDeliverOrderTrain, OrderInput, OrderDelivered>(DeliveryFor)
115 .OnDone(OrderState.Delivered)
116 .OnFailed(OrderState.Cancelled)
117 .OnCancelled(OrderState.Cancelled);
Code DeliverOrderTrain.cs
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

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.

0 / 11
Ada, flight TX101
Play acts the feature out a moment at a time, on the machines derived from it. Back and Next step by hand.
9:41
My trips
Not signed in
features/checking-in.feature
1Feature: Checking in for a flight
2A passenger checks in once check-in opens, with a passport number and a seat, and gets a boarding pass. A
3passenger who has not checked in when the gate closes misses the flight.
5Background:
6Given Ada is a passenger
7And Ada has a booking
56Scenario: Checking in before check-in opens does nothing
57When Ada checks in for her booking in seat "14C"
58Then Ada's booking is still booked
9Scenario: Check-in opens for everyone booked on the flight
10Given the flight is scheduled
11When check-in opens for the flight
12Then the flight is open for check-in
13And Ada's booking is open for check-in
14And Ada's departures show status "Check-in open"
25Scenario: Checking in with no passport number is refused
26Given Ada's booking is open for check-in
27And Ada's booking has no passport number
28When Ada checks in for her booking in seat "14C"
29Then Ada is told "Add your passport number first."
30And Ada's booking is still open for check-in
51Scenario: A passenger gives a passport number
52Given Ada's booking is open for check-in
53When Ada gives passport "X1234567" for her booking
54Then Ada's booking is open for check-in
16Scenario: A passenger checks in and gets a boarding pass
17Given Ada's booking is open for check-in
18And Ada's booking has a passport number
19When Ada checks in for her booking in seat "14C"
20Then Ada's booking is getting a boarding pass
21When the boarding pass is issued
22Then Ada's booking is checked in
23And Ada's bookings show seat "14C"
flight.ir.json, booking.ir.json · derived, not written · the parts this walk usesDeparturesTX101Scheduled
the flightAda's bookingcheck-in opensand opens every Booked bookingopensgives passportchecks inpassport inacceptedScheduledTX101OpenBookedOpenIssuingruns IssueBoardingPassCheckedIn
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
machines/access.txt
  • @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
derived
The part of the derived files the current line produced.
The real code: samples/CheckIn, and how to run it

Start with

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.

Play runs the conversation against the recording, or step through it with Next.
9:41
Alice

No room

Not in the room.

9:41
Bob

No room

Not in the room.

9:41
Charlie

No room

Not in the room.

What each client sent and received, and the code that ranchanged
Under the hood

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>, ISendMessageTrain
14{
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

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.

  1. Runs
  2. Breaks
  3. Recovers
Refund A-1001, $89, arrived broken. The payment is set to crash once, then the email once. Run it.
Timeline
attempt 1
LoadRefundCase
Problem?
RequestPhotos
ApproveRefund?
IssuePayment
Checkpoint
NotifyCustomer
attempt 2
LoadRefundCase
Problem?
RequestPhotos
ApproveRefund?
IssuePayment
Checkpoint
NotifyCustomer
attempt 3
LoadRefundCase
Problem?
RequestPhotos
ApproveRefund?
IssuePayment
Checkpoint
NotifyCustomer
Model
The refund workflow, lit as it runschanged
Code Trains/Refund/ApproveRefundTrain.cs
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 problem
26 .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 answer
33 .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

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.

move 0 / 7
fix-bot asks for the ticket before it reaches Fix, then tries to approve its own fix. The server refuses both, and the ticket carries on as normal.
Trax serverthe board: TicketMachine, which only the server moves
Triage1
triage-bot
T-13Triage
Orders of exactly $40 still pay shipping
new report
unclaimed
Reproduce0
repro-bot
Fix0
fix-bot
QA0
qa-bot
Review0
Sam
Done0
no one
triage-botan agent, works Triageidle
repro-botan agent, works Reproduceidle
fix-botan agent, works Fixidle
qa-botan agent, works QAidle
Sama person, works Reviewidle
The code that refused each movechanged
Nothing was refused, rejected or found on this move.
The real code: samples/Board, and how to run it

Start with

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 →
trax.metadata, id 88213
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.

01

All-in-one

API, scheduler and the jobs they run in a single process.

API
Scheduler
Jobs
Postgres
02

API + Scheduler

The API queues work, and a separate scheduler picks it up and runs it.

API
Scheduler
Postgres
03

Hub + Workers

A hub serves the API and schedules. Workers take jobs from the database and run them.

Hub
Worker
Worker
Worker
Postgres
04

Ephemeral dispatch

The API hands work to an AWS Lambda function, which runs it and stops.

API
Lambda
Postgres
05

Just the scheduler

No API at all. One process runs workflows on a schedule.

Scheduler
Postgres

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 →
Trax.CoreWorkflows and their steps
2 packages›
Trax.EffectRun recording, storage and decisions
13 packages›
Trax.StateMachineState machines for the browser and the server
5 packages›
Trax.MediatorRunning workflows by their input
2 packages›
Trax.SchedulerSchedules, retries and workers
4 packages›
Trax.ApiGraphQL, authentication, the client and the operations console
16 packages›
Trax.CliThe trax command
1 package›
Trax.SamplesTemplates
1 package›