# Workflow Engine API
A configurable state machine-based workflow engine built with .NET Core Web API. Enables defining, managing, and executing workflow instances with state transition validation and history tracking.
- Define custom workflows with states and actions
- Start and manage workflow instances
- Execute state transitions with validation
- Track complete workflow history
- RESTful API with Swagger documentation
- .NET 8.0 SDK
- Visual Studio 2022 or VS Code
# Clone and run
git clone https://github.com/Chimankarparag/Infonetica_Task.git
cd WorkflowEngine
dotnet restore
dotnet build
dotnet runAccess the application:
- API: http://localhost:5217
- Swagger UI: http://localhost:5217/swagger
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/WorkflowDefinition |
List all definitions |
| GET | /api/WorkflowDefinition/{id} |
Get definition by ID |
| POST | /api/WorkflowDefinition |
Create definition |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/WorkflowInstance |
List all instances |
| GET | /api/WorkflowInstance/{id} |
Get instance by ID |
| POST | /api/WorkflowInstance/start/{definitionId} |
Start instance |
| POST | /api/WorkflowInstance/{id}/execute |
Execute action |
# Start instance
curl -X POST http://localhost:5217/api/WorkflowInstance/start/{definitionId}
# Execute action
curl -X POST http://localhost:5217/api/WorkflowInstance/{instanceId}/execute \
-H "Content-Type: application/json" \
-d '{"actionId": "submit"}'WorkflowEngine/
├── Controllers/
├── Models/
├── Services/
└── Storage/
- .NET 8.0 and ASP.NET Core Web API
- In-memory storage
- RESTful API with JSON payloads
- Swagger/OpenAPI documentation
- Single-user system (no auth)
- In-memory data storage
- Unique IDs within workflows
- Linear workflow progression
- No persistent storage
- No concurrent execution handling
- No workflow versioning
- Basic validation only
- No conditional transitions
- No automatic transitions/timeouts
- Workflow definition validation
- State transition validation
- Action execution validation
- History tracking of all transitions
Endpoint:
POST /api/WorkflowDefinition
Request Body:
{
"name": "Document Approval",
"states": [
{
"id": "draft",
"name": "Draft",
"isInitial": true,
"isFinal": false,
"enabled": true,
"description": "Initial draft stage"
},
{
"id": "review",
"name": "Review",
"isInitial": false,
"isFinal": false,
"enabled": true,
"description": "Under review"
},
{
"id": "approved",
"name": "Approved",
"isInitial": false,
"isFinal": true,
"enabled": true,
"description": "Final approved state"
}
],
"actions": [
{
"id": "submit",
"name": "Submit for Review",
"enabled": true,
"fromStates": ["draft"],
"toState": "review",
"description": "Submit document for review"
},
{
"id": "approve",
"name": "Approve Document",
"enabled": true,
"fromStates": ["review"],
"toState": "approved",
"description": "Approve the document"
}
]
}Expected Response:
Status: 201 Created
Response contains a valid definitionId
Endpoint:
POST /api/WorkflowInstance/start/{definitionId}
Use the definitionId returned from step 1.
Expected Response:
Status: 201 Created
Response contains an instanceId
Endpoint:
GET /api/WorkflowInstance/{id}
Use the instanceId from step 2.
Expected Response:
Shows workflowDefinitionName, currentStateId as draft
History is an empty list
Endpoint:
POST /api/WorkflowInstance/{id}/execute
Request Body:
{
"actionId": "submit"
}Expected Response:
Status: 200 OK
Message: "Action executed successfully"
Instance state changes from draft to review
Endpoint:
POST /api/WorkflowInstance/{id}/execute
Request Body:
{
"actionId": "approve"
}Expected Response:
Status: 200 OK
Message: "Action executed successfully"
Instance state changes from review to approved
Endpoint:
POST /api/WorkflowInstance/{id}/execute
Request Body:
{
"actionId": "submit"
}Expected Response:
Status: 400 Bad Request
Message: "Action cannot be executed from current state: approved"
Endpoint:
GET /api/WorkflowInstance
Expected Response:
List of all instances
Each entry includes id, currentStateId, createdAt, updatedAt
Endpoint:
GET /api/WorkflowDefinition
Expected Response:
List of all defined workflows
Endpoint:
GET /api/WorkflowDefinition/{id}
Use the definitionId from step 1.
Expected Response:
Complete workflow definition with states and actions