@@ -179,6 +179,86 @@ The workflow engine follows a clean architecture pattern with clear separation o
179179└─────────────────┘ └─────────────────┘
180180```
181181
182+
183+ #### 📝 ** Workflow Builder**
184+ - ** Purpose** : Fluent interface for creating workflow definitions
185+ - ** Responsibilities** :
186+ - Provides method chaining (` .addStep() ` , ` .when() ` , ` .email() ` , etc.)
187+ - Validates workflow structure during construction
188+ - Creates immutable workflow definitions
189+ - Supports conditional steps and common patterns
190+ - ** Example** : ` WorkflowBuilder::create('user-onboarding')->addStep(...)->build() `
191+
192+ #### 📋 ** Workflow Definition**
193+ - ** Purpose** : Immutable data structure representing a complete workflow
194+ - ** Responsibilities** :
195+ - Contains workflow metadata (name, description, version)
196+ - Stores all steps and their relationships
197+ - Defines step execution order and conditions
198+ - Serves as a blueprint for workflow execution
199+ - ** Key data** : Steps, transitions, conditions, metadata
200+
201+ #### ⚡ ** Workflow Engine**
202+ - ** Purpose** : Central orchestrator that manages workflow execution
203+ - ** Responsibilities** :
204+ - Starts new workflow instances from definitions
205+ - Manages workflow lifecycle (start, pause, resume, cancel)
206+ - Coordinates between different components
207+ - Provides API for workflow operations
208+ - ** Main methods** : ` start() ` , ` pause() ` , ` resume() ` , ` cancel() ` , ` getInstance() `
209+
210+ #### 🎯 ** Steps & Actions**
211+ - ** Purpose** : Individual workflow tasks and their implementations
212+ - ** Responsibilities** :
213+ - ** Steps** : Define what should happen (metadata, config, conditions)
214+ - ** Actions** : Implement the actual business logic (` execute() ` method)
215+ - Handle step-specific configuration (timeout, retry, conditions)
216+ - Support compensation actions for rollback scenarios
217+ - ** Examples** : ` SendEmailAction ` , ` CreateUserAction ` , ` ValidateOrderAction `
218+
219+ #### 🎬 ** Executor**
220+ - ** Purpose** : Runtime engine that executes individual workflow steps
221+ - ** Responsibilities** :
222+ - Executes actions in the correct sequence
223+ - Handles conditional execution based on workflow context
224+ - Manages timeouts and retry logic
225+ - Processes step transitions and flow control
226+ - Handles errors and compensation
227+
228+ #### 🗄️ ** State Manager**
229+ - ** Purpose** : Component responsible for workflow instance state persistence
230+ - ** Responsibilities** :
231+ - Saves/loads workflow instances to/from storage
232+ - Tracks workflow execution state (running, paused, completed, failed)
233+ - Manages workflow context data
234+ - Handles state transitions and validation
235+ - Supports different storage adapters (database, file, memory)
236+
237+ #### 📡 ** Events Dispatcher**
238+ - ** Purpose** : Event system for monitoring and integration
239+ - ** Responsibilities** :
240+ - Fires events during workflow execution
241+ - Enables workflow monitoring and logging
242+ - Supports custom event listeners
243+ - Provides hooks for external system integration
244+ - Events: ` WorkflowStarted ` , ` StepCompleted ` , ` WorkflowFailed ` , etc.
245+
246+ ### 🔄 ** Data Flow**
247+ 1 . ** Builder** → creates → ** Definition**
248+ 2 . ** Engine** → uses ** Definition** to create instances
249+ 3 . ** Engine** → delegates to ** Executor** for step execution
250+ 4 . ** Executor** → runs → ** Steps & Actions**
251+ 5 . ** State Manager** → persists → workflow state
252+ 6 . ** Events Dispatcher** → broadcasts → execution events
253+
254+ ### ✅ ** Architecture Benefits**
255+ - ** Separation of concerns** - each component has a single responsibility
256+ - ** Extensibility** - you can swap out storage adapters, add custom actions
257+ - ** Testability** - each component can be tested independently
258+ - ** Framework agnostic** - no dependencies on specific frameworks
259+ - ** Type safety** - full PHP 8.3+ type hints throughout
260+
261+
182262## 🔧 Configuration
183263
184264### Storage Adapters
0 commit comments