Skip to content

A minimal, fast and flexible **State Machine Engine** built with **ASP.NET Core**. This API allows creating workflows, defining states and actions, and managing state transitions with history tracking.

License

Notifications You must be signed in to change notification settings

arnabara4/STATE_MACHINE_API

Repository files navigation

🧠 STATE_MACHINE_API

A minimal, fast and flexible State Machine Engine built with ASP.NET Core.
This API allows creating workflows, defining states and actions, and managing state transitions with history tracking.


📦 Features

  • Define custom workflows with multiple states and actions.
  • Start workflow instances and track transitions.
  • Transition validation with customizable logic.
  • Minimal API-based routing.
  • In-memory data store.
  • Modular folder structure (Models, Routes, Utils, Validators).

⚙️ Requirements

  • .NET 7 or 8 SDK
  • macOS / Linux / Windows
  • Visual Studio Code / Rider / Visual Studio

🚀 Getting Started

git clone <your-repo-url>
cd STATE_MACHINE_API
dotnet restore
dotnet run

Swagger will launch at:
http://localhost:5206/swagger or https://localhost:7179/swagger


🗂️ Folder Structure

STATE_MACHINE_API/
STATE_MACHINE_API/
├── Data/                   # In-memory data store
│   └── WorkflowDataStore.cs
├── Models/                 # POCOs for your domain
│   ├── Action.cs
│   ├── Instance.cs
│   ├── State.cs
│   └── WorkFlow.cs
├── Routes/                 # All your endpoints
│   └── RouteDefinitions.cs
├── Utils/                  # Validation and helpers
│   └── Validators.cs
├── Properties/
│   └── launchSettings.json
├── Program.cs              # Entry point (Minimal API)
├── appsettings.json        # Configuration
└── .gitignore              # Git ignored files/folders

🔁 Sample Workflow Definition (POST /api/workflow)

{
  "name": "OrderFlow",
  "states": [
    { "name": "Placed", "isInitial": true, "isFinal": false, "isEnabled": true },
    { "name": "Delivered", "isInitial": false, "isFinal": true, "isEnabled": true }
  ],
  "actions": [
    {
      "name": "Deliver",
      "fromStates": ["Placed"],
      "toState": "Delivered",
      "enabled": true
    }
  ]
}

📡 API Endpoints

Method Route Description
POST /api/workflow Create a new workflow definition
GET /api/workflow/{name} Get workflow by name
POST /api/workflow/{name}/start Start a new instance
POST /api/workflow/{workflowName}/action/{actionName} Perform an action on an instance
GET /api/workflow/instance/{workflowName} Get instance details
GET /api/workflows List all workflows
GET /api/workflow/{workflowName}/states List state names in a workflow
GET /api/workflow/{workflowName}/actions List action names in a workflow
GET /api/instances List all running instance names
GET /api/instances/{workflowName} List instances of a specific workflow
DELETE /api/instance/{id} Delete an instance (only if final)

🧪 Testing

Use Swagger UI, Postman, or cURL to test APIs.
Swagger: http://localhost:5206/swagger


📄 License

MIT


✍️ Author

Built by Arnab Jena.

About

A minimal, fast and flexible **State Machine Engine** built with **ASP.NET Core**. This API allows creating workflows, defining states and actions, and managing state transitions with history tracking.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages