Skip to content

A configurable workflow engine and state machine API built with C# and .NET 8 as a software engineer take-home exercise.

Notifications You must be signed in to change notification settings

yashharale-hacker/Infonetica.WorkflowEngine

Repository files navigation

Infonetica - Configurable Workflow Engine

This project is a take-home exercise to implement a minimal backend service for a configurable workflow engine based on state machines. The API allows clients to define workflows, start instances, and transition them between states by executing actions.

Technical Stack

  • Language/Framework: C# / .NET 8
  • API Style: ASP.NET Core Minimal APIs
  • Persistence: Simple in-memory dictionaries. No database is required.
  • Dependencies: The project uses the default ASP.NET Core web SDK and Swashbuckle.AspNetCore for API documentation.

How to Run the Application

Prerequisites

  • .NET 8 SDK

Steps

  1. Clone the repository:

    git clone <your-repo-url>
    cd Infonetica.WorkflowEngine
  2. Ensure Development Environment is Set: This project uses Properties/launchSettings.json to automatically configure the application to run in Development mode. This ensures the Swagger API page is available.

  3. Run the application:

    dotnet run
  4. Access the API:

    • The application will start and listen on http://localhost:5000.
    • You can explore and interact with the API using the built-in Swagger UI at: http://localhost:5000/swagger

Assumptions and Design Notes

  • Persistence: Data is stored in-memory using ConcurrentDictionary. The data will be lost when the application restarts, as allowed by the requirements.
  • IDs: WorkflowDefinition and WorkflowInstance IDs are generated as GUIDs for simplicity. State and Action IDs are expected to be meaningful strings provided by the client.
  • Validation: Validation is performed within the WorkflowService. It rejects invalid definitions and invalid action executions.
  • Known Limitations: The assignment was time-boxed to approximately 2 hours. As such, the code includes // TODO comments for potential improvements that would be addressed with more time.

API Usage Example (via Swagger)

  1. Create a Workflow Definition:

    • Execute POST /api/workflows/definitions
    • Provide the following JSON in the request body:
      {
        "id": "leave-request",
        "states": [
          { "id": "draft", "name": "Draft", "isInitial": true },
          { "id": "submitted", "name": "Submitted for Approval" },
          { "id": "approved", "name": "Approved", "isFinal": true },
          { "id": "rejected", "name": "Rejected", "isFinal": true }
        ],
        "actions": [
          {
            "id": "submit",
            "name": "Submit",
            "fromStates": ["draft"],
            "toState": "submitted"
          },
          {
            "id": "approve",
            "name": "Approve",
            "fromStates": ["submitted"],
            "toState": "approved"
          },
          {
            "id": "reject",
            "name": "Reject",
            "fromStates": ["submitted"],
            "toState": "rejected"
          }
        ]
      }
  2. Start a Workflow Instance:

    • Execute POST /api/workflows/instances
    • Body: {"definitionId": "leave-request"}
    • This returns a new instance in the draft state. Note the id from the response.
  3. Execute an Action:

    • Execute POST /api/workflows/instances/{instanceId}/actions/{actionId}
    • Use the instance id from the previous step for {instanceId} and "submit" for {actionId}.
    • This moves the instance to the submitted state, and its history is updated.

About

A configurable workflow engine and state machine API built with C# and .NET 8 as a software engineer take-home exercise.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages