# uipath/corewf architecture

> Architecture diagram of the GitHub repository uipath/corewf, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/uipath/corewf
- Repository: https://github.com/uipath/corewf

## Overview

This project is a port of the Windows Workflow Foundation (WF) to .NET 6 – essentially a workflow engine that supports activities written either in code or (more commonly) in XAML. It reimplements many of the core WF runtime components (execution, tracking, persistence, XAML parsing/integration) for .NET 6, and even provides support for Visual Basic integration as well as comprehensive test and performance harnesses.

##### Main Components
- Workflow Runtime Engine:
– This is the heart of the system and lives mainly in the “UiPath.Workflow.Runtime” directory. Key classes include WorkflowApplication, WorkflowInvoker, and the various runtime “WorkItem” processing classes.
– Include the process for loading a workflow (using ActivityXamlServices from the XAML integration layer) and invoking it.
- XAML Integration Layer:
– The “System.Xaml” directory and related code are integral for parsing and loading workflow definitions written in XAML.
- Activity and Expression Infrastructure:
– The “UiPath.Workflow” and “Expressions” portions (as well as the code in “CoreWf.EtwTracking” for event tracing) define the activities, expression evaluation, and metadata needed to execute workflows.
– Note that there’s support for both C# and Visual Basic, with VisualBasic-related code under the “VisualBasic” directory.
- Persistence and Durable Instancing:
– Point out the durable instancing modules (within “UiPath.Workflow.Runtime/DurableInstancing”) that handle saving/loading workflow state and participating in persistence.
- Tracking and Diagnostics:
– Include modules for tracking (found in both “UiPath.Workflow.Runtime/Tracking” and “CoreWf.EtwTracking”) which capture execution events, activity states, and performance diagnostics.
- Test, Benchmarks, and Utility Modules:
– The “Test” directory contains extensive test harnesses (unit tests, performance benchmarks, workflow test cases, etc.) that ensure the reliability and conformance of the engine.

##### Relationships and Interactions
- Workflow Definition & Loading:
– Show how a workflow definition (either created programmatically or authored in XAML) is first loaded by ActivityXamlServices in the XAML integration layer.
- Runtime Execution:
– The loaded workflow is then passed to the runtime engine (WorkflowInvoker/WorkflowApplication) where the engine proceeds to execute activities.
– Illustrate the flow between execution, the handling of activities (including nested and composite activities), and the propagation of control signals (begin, suspend, resume, terminate).
- Persistence & Recovery:
- Tracking & Diagnostics:
- Expression Evaluation & Compiler Integration:
- Testing/Performance:
– Illustrate that various tests (unit tests, benchmarks, and custom test harness applications) inject workflows into the runtime engine to verify behavior.

##### Architectural Patterns & Design Principles
- Modularity: The project is broken up into logical components (runtime, XAML integration, persistence, tracking, tests, etc.) that interact via well-defined interfaces.
- Separation of Concerns: The runtime focuses on execution, while the XAML/parsing layer and expression evaluators handle workflow definition interpretation.
- Extensibility: The presence of various “Configurer” and “Extension” classes indicates that the system is designed to be extended (e.g., custom tracking participants, custom activities, expression evaluators).

##### Detail Every Essential Architectural Element
- Don’t be afraid to over-segment:
- Workflow life-cycle: from definition (and design) through to load, execute, state persist, track, and complete/terminate.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Definition & Parsing Layer
    subgraph "Workflow Definition & Parsing Layer"
        WD["Workflow Definition (XAML/Code)"]:::definition
        subgraph "XAML Integration Layer"
            AXS["ActivityXamlServices"]:::integration
            SX["System.Xaml"]:::integration
        end
    end
    WD -->|"loads"| AXS
    AXS -->|"parses via"| SX

    %% Core Runtime Engine Layer
    subgraph "Core Runtime Engine Layer"
        WRE["Workflow Runtime Engine (WorkflowApplication, WorkflowInvoker, WorkItem Processing)"]:::runtime
    end
    SX -->|"creates activity tree"| WRE

    %% Supporting Services Layer
    subgraph "Supporting Services"
        PD["Persistence & Durable Instancing"]:::support
        TD["Tracking & Diagnostics"]:::support
        AEI["Activity & Expression Infrastructure"]:::support
        VB["Visual Basic Integration"]:::support
    end
    WRE -->|"persists state"| PD
    WRE -->|"sends tracking events"| TD
    WRE -->|"evaluates expressions"| AEI
    AEI -->|"supports VB expressions"| VB

    %% Testing & Performance Layer
    subgraph "Testing & Performance"
        TH["Test Harnesses"]:::testing
        PB["Performance Benchmarks"]:::testing
    end
    TH -->|"injects workflows"| WRE
    PB -->|"benchmarks runtime"| WRE

    %% Click Events
    click WRE "https://github.com/uipath/corewf/blob/develop/src/UiPath.Workflow.Runtime"
    click AXS "https://github.com/uipath/corewf/tree/develop/src/UiPath.Workflow/XamlIntegration"
    click SX "https://github.com/uipath/corewf/blob/develop/src/System.Xaml"
    click PD "https://github.com/uipath/corewf/tree/develop/src/UiPath.Workflow.Runtime/DurableInstancing"
    click TD "https://github.com/uipath/corewf/blob/develop/src/CoreWf.EtwTracking"
    click AEI "https://github.com/uipath/corewf/blob/develop/src/UiPath.Workflow"
    click VB "https://github.com/uipath/corewf/tree/develop/src/VisualBasic"
    click TH "https://github.com/uipath/corewf/tree/develop/src/Test"
    click PB "https://github.com/uipath/corewf/tree/develop/src/Perf"

    %% Styles
    classDef definition fill:#ffcccc,stroke:#a33,stroke-width:2px;
    classDef integration fill:#ccebff,stroke:#333,stroke-width:2px;
    classDef runtime fill:#ccffcc,stroke:#339,stroke-width:2px;
    classDef support fill:#ffffcc,stroke:#993,stroke-width:2px;
    classDef testing fill:#ccffff,stroke:#339,stroke-width:2px;
```
