# symfony/workflow architecture

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

- Interactive diagram: https://gitdiagram.com/symfony/workflow
- Repository: https://github.com/symfony/workflow

## Overview

##### Main Components

a) Core Components:
- Workflow Engine (centered around Workflow.php and StateMachine.php)
- Definition Management (Definition.php, DefinitionBuilder.php)
- Marking System (Marking.php, MarkingStore/)
- Transition Management (Transition.php)

b) Supporting Systems:
- Event System (Event/ directory)
- Validation Layer (Validator/ directory)
- Debug & Monitoring (Debug/, DataCollector/)
- Visualization (Dumper/)

**┌─ Application Layer ─────────────────────┐**

- ┌─ Public API ─┐                   │
- WorkflowInterface                │
- Registry     │                   │
- ┘                    │

- Core Layer ──────────────────────────┤

- ┌─ State Management ─┐ ┌─ Events ──┐  │
- Workflow          │ │ Guards     │  │
- StateMachine      │ │ Listeners  │  │
- Marking          │ │ Dispatching│  │
- ┘ └───────────┘  │

- ┌─ Definition ──────┐ ┌─ Transition┐  │
- DefinitionBuilder │ │ Transition │  │
- Validation       │ │ Blockers   │  │
- ┘ └───────────┘  │

- Infrastructure Layer ─────────────────┤

- ┌─ Persistence ────┐ ┌─ Debug ────┐  │
- MarkingStore     │ │ Collectors │  │
- MetadataStore    │ │ Traceable  │  │
- ┘ └───────────┘  │

- ┌─ Visualization ──┐ ┌─ DI ──────┐  │
- GraphvizDumper   │ │ Compiler  │  │
- MermaidDumper    │ │ Passes    │  │
- ┘ └───────────┘  │
- ┘

##### Key Relationships to Highlight

a) Primary Flows:
- WorkflowInterface → Workflow/StateMachine
- Workflow → Definition → Transitions
- Workflow → MarkingStore
- Workflow → EventDispatcher

b) Supporting Flows:
- Guards → Transitions
- Listeners → Events
- Dumpers → Definition

##### Implementation Details

- Use standardized UML notation where applicable
- Notes for important architectural decisions
- Relationship with Symfony's EventDispatcher component

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Application
        WI[WorkflowInterface]:::api
        REG[Registry]:::api
    end

    subgraph Core
        subgraph StateManagement
            WF[Workflow]:::core
            SM[StateMachine]:::core
            MK[Marking]:::core
        end

        subgraph Definition
            DEF[Definition]:::core
            DEFB[DefinitionBuilder]:::core
        end

        subgraph Transition
            TR[Transition]:::core
            TB[TransitionBlocker]:::core
            TBL[TransitionBlockerList]:::core
        end
    end

    subgraph Events
        EV[Event Base]:::event
        GE[Guard Event]:::event
        TE[Transition Event]:::event
        EL[Event Listeners]:::event
    end

    subgraph Validation
        VI[Validator Interface]:::validation
        SMV[State Machine Validator]:::validation
        WV[Workflow Validator]:::validation
    end

    subgraph Infrastructure
        subgraph Storage
            MS[Marking Store]:::storage
            MMS[Method Marking Store]:::storage
            MDS[Metadata Store]:::storage
        end

        subgraph Debug
            TW[Traceable Workflow]:::debug
            WDC[Workflow Data Collector]:::debug
        end

        subgraph Visualization
            DI[Dumper Interface]:::viz
            GD[GraphViz Dumper]:::viz
            MD[Mermaid Dumper]:::viz
            PD[PlantUML Dumper]:::viz
        end
    end

    %% Relationships
    WI --> WF & SM
    REG --> WF & SM
    WF & SM --> DEF
    DEF --> TR
    WF & SM --> MK
    MK --> MS
    TR --> TB
    TB --> TBL
    WF & SM --> EV
    EV --> GE & TE
    GE & TE --> EL
    DEF --> VI
    VI --> SMV & WV
    WF & SM --> TW
    TW --> WDC
    DEF --> DI
    DI --> GD & MD & PD
    WF & SM --> MDS

    %% Styles
    classDef api fill:#2196F3,stroke:#1565C0,color:white
    classDef core fill:#1976D2,stroke:#0D47A1,color:white
    classDef event fill:#4CAF50,stroke:#2E7D32,color:white
    classDef validation fill:#FFA000,stroke:#FF6F00,color:white
    classDef storage fill:#FF5722,stroke:#D84315,color:white
    classDef debug fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef viz fill:#00BCD4,stroke:#00838F,color:white

    %% Click Events
    click WI "https://github.com/symfony/workflow/blob/7.2/WorkflowInterface.php"
    click WF "https://github.com/symfony/workflow/blob/7.2/Workflow.php"
    click SM "https://github.com/symfony/workflow/blob/7.2/StateMachine.php"
    click REG "https://github.com/symfony/workflow/blob/7.2/Registry.php"
    click DEF "https://github.com/symfony/workflow/blob/7.2/Definition.php"
    click DEFB "https://github.com/symfony/workflow/blob/7.2/DefinitionBuilder.php"
    click MK "https://github.com/symfony/workflow/blob/7.2/Marking.php"
    click MS "https://github.com/symfony/workflow/blob/7.2/MarkingStore/MarkingStoreInterface.php"
    click MMS "https://github.com/symfony/workflow/blob/7.2/MarkingStore/MethodMarkingStore.php"
    click TR "https://github.com/symfony/workflow/blob/7.2/Transition.php"
    click TB "https://github.com/symfony/workflow/blob/7.2/TransitionBlocker.php"
    click TBL "https://github.com/symfony/workflow/blob/7.2/TransitionBlockerList.php"
    click EV "https://github.com/symfony/workflow/blob/7.2/Event/Event.php"
    click GE "https://github.com/symfony/workflow/blob/7.2/Event/GuardEvent.php"
    click TE "https://github.com/symfony/workflow/blob/7.2/Event/TransitionEvent.php"
    click EL "https://github.com/symfony/workflow/tree/7.2/EventListener"
    click VI "https://github.com/symfony/workflow/blob/7.2/Validator/DefinitionValidatorInterface.php"
    click SMV "https://github.com/symfony/workflow/blob/7.2/Validator/StateMachineValidator.php"
    click WV "https://github.com/symfony/workflow/blob/7.2/Validator/WorkflowValidator.php"
    click TW "https://github.com/symfony/workflow/blob/7.2/Debug/TraceableWorkflow.php"
    click WDC "https://github.com/symfony/workflow/blob/7.2/DataCollector/WorkflowDataCollector.php"
    click DI "https://github.com/symfony/workflow/blob/7.2/Dumper/DumperInterface.php"
    click GD "https://github.com/symfony/workflow/blob/7.2/Dumper/GraphvizDumper.php"
    click MD "https://github.com/symfony/workflow/blob/7.2/Dumper/MermaidDumper.php"
    click PD "https://github.com/symfony/workflow/blob/7.2/Dumper/PlantUmlDumper.php"
    click MDS "https://github.com/symfony/workflow/blob/7.2/Metadata/MetadataStoreInterface.php"
```
