# mt-empty/workflow architecture

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

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

## Overview

##### Main Components Identification

a) Core Components:
- Workflow Engine (Main Service)
- Redis Queue (Task Queue)
- PostgreSQL Database (State Storage)
- Event Triggers System
- Task Execution System

b) Supporting Components:
- CLI Interface
- File System (for workflow definitions and logs)
- Docker Container Environment

**[CLI Interface] --> [Workflow Engine]**
**[YAML Workflow Definitions] --> [Parser]**

**[Event Trigger System] <--> [Workflow Engine] <--> [Task Execution System]**

**[Redis Queue] <--> [Workflow Engine] <--> [PostgreSQL Database]**

##### Component Details and Relationships

- Rectangles: Main services (Engine, CLI)
- Hexagons: Event triggers and tasks

##### Key Processes to Highlight

Main workflow processes:
**Workflow Definition --> Parser --> Engine**
**Event Trigger --> Engine --> Task Queue --> Task Execution**

##### Specific Implementation Details

Technical details in annotations:
- Rust-based implementation
- Docker container deployment
- Database migrations using Diesel
- Redis for task queuing
- File-based event triggers and task definitions

##### Distributed Architecture (Future State)

- Multiple engine instances
- Round-robin load balancing
- gRPC streaming
- Container orchestration

##### Additional Elements
- Log storage and management
- Environment configuration flow
- Container networking
- Error handling paths
- Task failure handling

##### The file-based configuration system

For this specific project, focus on showing how the engine handles the flow from event triggering through task execution, as this is the core functionality of the system. Also highlight the CLI interface as it's the primary way users interact with the system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Interface
        CLI["CLI Interface"]:::cli
        YAML["YAML Workflow Definitions"]:::file
        Parser["Parser System"]:::parser
    end

    subgraph Core
        Engine["Workflow Engine"]:::engine
        EventSystem["Event Trigger System"]:::event
        TaskSystem["Task Execution System"]:::task
    end

    subgraph Storage
        Redis[(Redis Queue)]:::storage
        Postgres[(PostgreSQL Database)]:::storage
        Models["Database Models"]:::db
        Schema["Database Schema"]:::db
    end

    subgraph Infrastructure
        Docker["Docker Container"]:::infra
        Logs["Log Storage"]:::infra
    end

    %% Connections
    CLI --> Engine
    YAML --> Parser
    Parser --> Engine
    Engine <--> EventSystem
    Engine <--> TaskSystem
    Engine <--> Redis
    Engine <--> Postgres
    Postgres --- Models
    Postgres --- Schema
    TaskSystem --> Logs
    EventSystem --> Logs

    %% Click Events
    click CLI "https://github.com/mt-empty/workflow/blob/master/src/cli.rs"
    click Engine "https://github.com/mt-empty/workflow/blob/master/src/engine.rs"
    click Parser "https://github.com/mt-empty/workflow/blob/master/src/parser.rs"
    click EventSystem "https://github.com/mt-empty/workflow/blob/master/src/engine/event.rs"
    click TaskSystem "https://github.com/mt-empty/workflow/blob/master/src/engine/task.rs"
    click Models "https://github.com/mt-empty/workflow/blob/master/src/models.rs"
    click Schema "https://github.com/mt-empty/workflow/blob/master/src/schema.rs"
    click YAML "https://github.com/mt-empty/workflow/tree/master/tests/workflows/"
    click Docker "https://github.com/mt-empty/workflow/tree/master/Dockerfile"

    %% Styling
    classDef engine fill:#3498db,stroke:#2980b9,color:white
    classDef cli fill:#9b59b6,stroke:#8e44ad,color:white
    classDef parser fill:#e74c3c,stroke:#c0392b,color:white
    classDef event fill:#f1c40f,stroke:#f39c12,color:black
    classDef task fill:#e67e22,stroke:#d35400,color:white
    classDef storage fill:#2ecc71,stroke:#27ae60,color:white
    classDef db fill:#1abc9c,stroke:#16a085,color:white
    classDef infra fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef file fill:#34495e,stroke:#2c3e50,color:white

    %% Legend
    subgraph Legend
        L1["Core Components"]:::engine
        L2["Interface Elements"]:::cli
        L3["Parser Components"]:::parser
        L4["Event Systems"]:::event
        L5["Task Systems"]:::task
        L6["Storage Systems"]:::storage
        L7["Database Components"]:::db
        L8["Infrastructure"]:::infra
        L9["File Components"]:::file
    end
```
