A simple .NET 8 workflow engine that lets you define state machines and run workflow instances.
- .NET 8 SDK
- python 3.8 or up for tests
dotnet runThe API will start on http://localhost:5291
The Tests run on http://localhost:5292
cd Tests
pip install -r requirements.txt
pytest test_workflow_engine.py -vThe test suite automatically starts a fresh app instance on port 5292 and cleans up JSON files between runs. Unfortunately, running the tests will clear the json file stored in /bin/Debug/net8.0 which destroys all stored data
Refer to Swagger docs at localhost:5291/swagger for parameter requirements and response structures.
{
"states": [
{
"name": "INITIAL_STATE",
"isInitial": true,
"isFinal": false,
"enabled": true
},
{
"name": "FINAL_STATE",
"isInitial": false,
"isFinal": true,
"enabled": true
}
],
"actions": [
{
"name": "ACTION_NAME",
"enabled": true,
"fromStates": ["INITIAL_STATE"],
"toState": "FINAL_STATE"
}
]
}Notes:
idis auto-generated (GUID)nameis required for states and actionsisInitial,isFinal, andenabledare optional with defaults (true, false, true respectively)fromStatesis a list of state names (not IDs)toStateis a single state name (not ID)- Exactly one state must have
isInitial: true - At least one state must have
isFinal: true - State and action names must be unique within the workflow
{
"id": "workflow-id",
"states": [
{
"id": "state-id",
"name": "State Name",
"isInitial": true,
"isFinal": false,
"enabled": true
}
],
"actions": [
{
"id": "action-id",
"name": "Action Name",
"enabled": true,
"fromStates": ["state-id"],
"toState": "target-state-id"
}
]
}- workflow ids are unique
- instance ids are unique
- Workflow instances start in the initial state
- Only one action can be executed at a time per instance
- No authentication: All endpoints are public
- No endpoints for editing workflows Not possible to change the states or actions of existing workflows
- No timeout handling: Instances can stay in states forever
- No rollback capability: Can't undo state transitions
- No error recovery: No retry mechanisms
- JSON files stored in
bin/Debug/net8.0/ - Simple file-based persistence
- No logging framework
- No middleware pipeline
WorkflowEngine/
├── Models/
│ ├── State.cs # State model
│ ├── Action.cs # Action model
│ ├── WorkflowDefinition.cs # Workflow definition model
│ └── WorkflowInstance.cs # Workflow instance model
├── Controllers/
│ ├── WorkflowDefinitionController.cs # Workflow CRUD operations
│ ├── WorkflowInstanceController.cs # Instance management
│ └── HealthController.cs # Health check endpoint
├── Services/
│ └── WorkflowRepository.cs # Data persistence layer
├── Tests/
│ ├── test_workflow_engine.py # Python test suite
│ └── requirements.txt # Python dependencies
├── Program.cs # Application entry point
├── WorkflowEngine.csproj # Project file
└── README.md # This file
- Minimal API: Uses .NET 8 minimal APIs
- Static classes: No dependency injection
- File-based storage: Simple JSON persistence
- Controller pattern: Organized endpoint handlers
- Integration tests: Python pytest suite
- Fresh instances: Each test run gets clean state
- Port isolation: Tests run on separate port (5292)
- Auto cleanup: JSON files cleared between runs
TODO
- tests could cover more cases
- delete/update workflows/instances