# sogou/workflow architecture

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

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

## Overview

##### Main Components Identification

The system should be divided into these major components:

a) Core Kernel Layer
- Communication Module (src/kernel)
- Thread Pool Management
- I/O Scheduling
- Task Scheduling

b) Protocol Layer (src/protocol)
- HTTP
- Redis
- MySQL
- Kafka
- DNS
- Custom Protocol Support

c) Factory Layer (src/factory)
- Task Creation
- Workflow Management
- Resource Pool
- Message Queue

d) Client/Server Components
- Client implementations
- Server implementations
- Connection management

e) Service Governance Layer
- Name Service
- Load Balancing
- Service Discovery
- Upstream Management

**┌─────────────────────────────────────────────────────────────┐**
- Application Layer                        │
- ┘
- ↑↓
**┌─────────────────────────────────────────────────────────────┐**
- Workflow Factory Layer                    │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐ │
- Task Factory  │  │Graph Tasks  │  │Resource Management  │ │
- ┘
- ↑↓
**┌─────────────────────────────────────────────────────────────┐**
- Protocol Layer                          │
- ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐   │
- HTTP   │ │ Redis  │ │ MySQL  │ │ Kafka  │ │Custom  │   │
- ┘
- ↑↓
**┌─────────────────────────────────────────────────────────────┐**
- Kernel Layer                            │
- ┌──────────┐ ┌───────────┐ ┌──────────┐ ┌─────────────┐  │
- Scheduler │ │Thread Pool│ │Poller    │ │I/O Service  │  │
- ┘

##### Important Elements

a) Task Flow Management:
- How tasks are created, scheduled, and executed
- Parallel and series task relationships
- Error handling paths

b) Communication Patterns:
- Client/Server interaction flows
- Async communication paths
- Protocol handling

c) Resource Management:
- Thread pool allocation
- Connection pooling
- Memory management

##### Specific Implementation Details

- Asynchronous execution model
- Task factory pattern implementation
- Service governance features
- Protocol support architecture
- Resource pooling mechanisms

##### Relationships and Interactions

Key interactions:
- Task creation and scheduling flow
- Protocol handling paths
- Resource allocation patterns
- Error handling paths
- Service discovery and load balancing

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef kernel fill:#e6f3ff,stroke:#333
    classDef protocol fill:#e6ffe6,stroke:#333
    classDef factory fill:#fffff0,stroke:#333
    classDef application fill:#f5f5f5,stroke:#333
    classDef client fill:#fff0e6,stroke:#333
    classDef service fill:#ffe6f3,stroke:#333

    %% Application Layer
    subgraph AppLayer["Application Layer"]
        App[Application Code]:::application
    end

    %% Factory Layer
    subgraph FactoryLayer["Workflow Factory Layer"]
        TaskFactory["Task Factory"]:::factory
        WorkflowMgmt["Workflow Management"]:::factory
        ResourcePool["Resource Pool"]:::factory
        MessageQueue["Message Queue"]:::factory
    end

    %% Protocol Layer
    subgraph ProtocolLayer["Protocol Layer"]
        HTTP["HTTP Protocol"]:::protocol
        Redis["Redis Protocol"]:::protocol
        MySQL["MySQL Protocol"]:::protocol
        Kafka["Kafka Protocol"]:::protocol
        DNS["DNS Protocol"]:::protocol
    end

    %% Kernel Layer
    subgraph KernelLayer["Kernel Layer"]
        ThreadPool["Thread Pool"]:::kernel
        IOScheduling["I/O Scheduling"]:::kernel
        TaskScheduling["Task Scheduling"]:::kernel
        CommModule["Communication Module"]:::kernel
    end

    %% Client/Server Components
    subgraph ClientServer["Client/Server Components"]
        MySQLClient["MySQL Client"]:::client
        KafkaClient["Kafka Client"]:::client
        DNSClient["DNS Client"]:::client
        BaseServer["Base Server"]:::client
        HTTPServer["HTTP Server"]:::client
        MySQLServer["MySQL Server"]:::client
    end

    %% Service Governance
    subgraph ServiceGov["Service Governance Layer"]
        NameService["Name Service"]:::service
        ServiceGovern["Service Governance"]:::service
        UpstreamMgmt["Upstream Management"]:::service
    end

    %% Relationships
    App --> FactoryLayer
    FactoryLayer --> ProtocolLayer
    ProtocolLayer --> KernelLayer
    ClientServer --> ProtocolLayer
    ServiceGov --> ClientServer

    %% Click events
    click ThreadPool "https://github.com/sogou/workflow/blob/master/src/kernel/thrdpool.h"
    click IOScheduling "https://github.com/sogou/workflow/blob/master/src/kernel/IOService_linux.h"
    click TaskScheduling "https://github.com/sogou/workflow/blob/master/src/kernel/CommScheduler.h"
    click CommModule "https://github.com/sogou/workflow/blob/master/src/kernel/Communicator.h"
    
    click HTTP "https://github.com/sogou/workflow/blob/master/src/protocol/HttpMessage.h"
    click Redis "https://github.com/sogou/workflow/blob/master/src/protocol/RedisMessage.h"
    click MySQL "https://github.com/sogou/workflow/blob/master/src/protocol/MySQLMessage.h"
    click Kafka "https://github.com/sogou/workflow/blob/master/src/protocol/KafkaMessage.h"
    click DNS "https://github.com/sogou/workflow/blob/master/src/protocol/DnsMessage.h"
    
    click TaskFactory "https://github.com/sogou/workflow/blob/master/src/factory/WFTaskFactory.h"
    click WorkflowMgmt "https://github.com/sogou/workflow/blob/master/src/factory/Workflow.h"
    click ResourcePool "https://github.com/sogou/workflow/blob/master/src/factory/WFResourcePool.h"
    click MessageQueue "https://github.com/sogou/workflow/blob/master/src/factory/WFMessageQueue.h"
    
    click MySQLClient "https://github.com/sogou/workflow/blob/master/src/client/WFMySQLConnection.h"
    click KafkaClient "https://github.com/sogou/workflow/blob/master/src/client/WFKafkaClient.h"
    click DNSClient "https://github.com/sogou/workflow/blob/master/src/client/WFDnsClient.h"
    click BaseServer "https://github.com/sogou/workflow/blob/master/src/server/WFServer.h"
    click HTTPServer "https://github.com/sogou/workflow/blob/master/src/server/WFHttpServer.h"
    click MySQLServer "https://github.com/sogou/workflow/blob/master/src/server/WFMySQLServer.h"
    
    click NameService "https://github.com/sogou/workflow/blob/master/src/nameservice/WFNameService.h"
    click ServiceGovern "https://github.com/sogou/workflow/blob/master/src/nameservice/WFServiceGovernance.h"
    click UpstreamMgmt "https://github.com/sogou/workflow/blob/master/src/nameservice/UpstreamPolicies.h"
```
