Skip to content

Repository files navigation

Trax.Cli

BuildNuGet VersionNuGet Downloads.NETLicense: MITLast CommitcodecovDocs

CLI tool for Trax. Generates Trax API projects from GraphQL or OpenAPI schemas.

The Trax Stack

Trax is a layered framework split across several repos. You can stop at whatever layer solves your problem. You are here: Trax.Cli.

RepoAdds
Trax.CorePipelines, junctions, railway error propagation
Trax.EffectExecution logging, DI, pluggable storage
Trax.MediatorDecoupled dispatch via TrainBus
Trax.SchedulerCron schedules, retries, dead-letter queues
Trax.ApiGraphQL API for remote access
Trax.DashboardBlazor monitoring UI
Trax.Clitrax-cli project scaffolding tool
Trax.SamplesSample apps and a dotnet new template

Full documentation: traxsharp.net/docs.

What This Does

Takes an existing API schema and scaffolds a Trax project with two parts: a hub project (from the trax-hub template, with API + Scheduler + Dashboard in one process) and a shared trains library with trains, junctions, input/output records, and models. The trains library follows the same structure as the DistributedWorkers sample and can be referenced by an API, scheduler, or standalone workers.

Supports two schema formats:

FormatSourceMapping
GraphQL.graphql / .gql SDL filesQuery fields → [TraxQuery] trains, Mutation fields → [TraxMutation] trains
OpenAPI.json / .yaml / .yml specsGET → [TraxQuery] trains, POST/PUT/DELETE/PATCH → [TraxMutation] trains

Prerequisites

The trax-hub template must be installed:

dotnet new install Trax.Samples

Installation

dotnet tool install --global Trax.Cli

Usage

# Generate from a GraphQL schema
trax generate --schema ./schema.graphql --output ./MyProject --name MyProject
# Generate from an OpenAPI spec
trax generate --schema ./openapi.json --output ./MyProject --name MyProject
# Force schema type (auto-detected from extension by default)
trax generate --schema ./spec.yaml --output ./MyProject --name MyProject --type openapi
# Overwrite existing output
trax generate --schema ./schema.graphql --output ./MyProject --name MyProject --force

Options

OptionRequiredDescription
--schemaYesPath to schema file
--outputYesOutput directory
--nameYesProject name (namespace + csproj)
--typeNoForce graphql or openapi
--forceNoOverwrite existing output directory

Generated Output

Given a schema with createPlayer and getPlayer operations:

MyProject/
├── MyProject.Hub/ # From dotnet new trax-hub
│ ├── MyProject.Hub.csproj # + ProjectReference to trains library
│ ├── Program.cs # Patched: AddMediator scans trains assembly
│ ├── appsettings.json
│ └── Trains/ # Template sample trains (kept as examples)
│ └── ...
├── MyProject.Trains/ # Generated from schema
│ ├── MyProject.Trains.csproj # Class library
│ ├── ManifestNames.cs # Centralized manifest external IDs
│ ├── Models/
│ │ └── Player.cs
│ └── Trains/
│ └── Players/
│ ├── CreatePlayer/
│ │ ├── ICreatePlayerTrain.cs
│ │ ├── CreatePlayerTrain.cs
│ │ ├── CreatePlayerInput.cs
│ │ └── Junctions/
│ │ └── CreatePlayerJunction.cs
│ └── GetPlayer/
│ ├── IGetPlayerTrain.cs
│ ├── GetPlayerTrain.cs
│ ├── GetPlayerInput.cs
│ └── Junctions/
│ └── GetPlayerJunction.cs

Operations are grouped into folders by noun, so createPlayer, getPlayer, deletePlayer all go under Players/.

Each junction contains a throw new NotImplementedException() with a TODO comment. For OpenAPI sources, the original HTTP method and path are included as a comment.

ManifestNames.cs contains const string identifiers for each operation in kebab-case, matching the pattern used in the DistributedWorkers sample for scheduler topology registration.

After Generating

cd MyProject/MyProject.Hub
dotnet restore
# Fill in junction implementations in MyProject.Trains/ (search for TODO)
dotnet run
# Open http://localhost:5000/trax/graphql for GraphQL IDE# Open http://localhost:5000/trax for Dashboard

License

MIT

Trademark & Brand Notice

Trax is an open-source .NET framework provided by TraxSharp. This project is an independent community effort and is not affiliated with, sponsored by, or endorsed by the Utah Transit Authority, Trax Retail, or any other entity using the "Trax" name in other industries.

About

No description, website, or topics provided.

Resources

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages