# cadence-workflow/cadence architecture

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

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

## Overview

##### High-Level Architecture Components

a) Frontend Services Layer:
- Frontend API Service (handles client requests)
- Web UI Service (port 8088)
- CLI Interface
- Client SDKs (Go, Java, Python, Ruby)

b) Core Services Layer:
- History Service (workflow history management)
- Matching Service (task distribution)
- Worker Service (background processing)
- Shard Distributor Service (shard management)

c) Persistence Layer:
- Primary Database (Cassandra/MySQL/PostgreSQL)
- Visibility Store (Elasticsearch)
- Queue Store (Kafka)

##### Service Interactions

a) Client-Side Flow:
- Clients → Frontend Service (workflow operations)
- Web UI → Frontend Service (monitoring/management)
- CLI → Frontend Service (administrative operations)

b) Internal Service Flow:
- Frontend Service → History Service (workflow state management)
- Frontend Service → Matching Service (task routing)
- History Service → Persistence Layer (state storage)
- Matching Service → Worker Service (task distribution)

##### Data Flow Patterns

a) Workflow Execution:
- Client Request → Frontend → History → Persistence
- Task Distribution: History → Matching → Workers
- State Updates: Workers → History → Persistence

b) Visibility Operations:
- Search/Query Requests → Frontend → Elasticsearch
- Event Publishing: History → Kafka → Elasticsearch

##### Cross-Cutting Concerns

Following supporting components:

a) Operational Components:
- Metrics Collection
- Logging System
- Health Monitoring

b) Management Components:
- Domain Management
- Task List Management
- Workflow History Archival

##### Scalability Aspects

Scaling patterns:

a) Sharding:
- History Shard Distribution
- Task List Partitioning
- Database Sharding

b) Load Distribution:
- Service Discovery
- Load Balancing
- Worker Pool Management

##### Additional Elements

Supplementary details:

- Component Types (Services, Databases, Queues)
- State Transitions

b) Annotations:
- Port Numbers
- Protocol Types (gRPC, HTTP)
- Critical Paths

##### Deployment Boundaries

Clear separation between:
- Core Services
- Storage Systems
- External Dependencies
- Client Components

- Core Services (Rectangle)
- Queue Systems (Parallel Lines)
- Client Components (Rounded Rectangle)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef frontend fill:#e1f5fe,stroke:#01579b
    classDef core fill:#e8f5e9,stroke:#2e7d32
    classDef storage fill:#fff3e0,stroke:#ef6c00
    classDef queue fill:#f3e5f5,stroke:#7b1fa2
    classDef monitoring fill:#fce4ec,stroke:#c2185b
    classDef management fill:#f1f8e9,stroke:#558b2f

    %% Client Layer
    subgraph ClientLayer
        CLI["CLI Interface"]:::frontend
        WebUI["Web UI (Port: 8088)"]:::frontend
        SDKs["Client SDKs\n(Go, Java, Python, Ruby)"]:::frontend
    end

    %% Frontend Layer
    subgraph FrontendLayer
        FrontAPI["Frontend API Service"]:::frontend
    end

    %% Core Services Layer
    subgraph CoreServices
        History["History Service"]:::core
        Matching["Matching Service"]:::core
        Worker["Worker Service"]:::core
        ShardDist["Shard Distributor Service"]:::core
    end

    %% Persistence Layer
    subgraph StorageLayer
        DB[(Primary Database)]:::storage
        ES[(Visibility Store)]:::storage
        Kafka[("Queue Store")]:::queue
    end

    %% Cross-Cutting Concerns
    subgraph Operations
        Metrics["Metrics Collection"]:::monitoring
        Logging["Logging System"]:::monitoring
        Health["Health Monitoring"]:::monitoring
    end

    subgraph Management
        Domain["Domain Management"]:::management
        TaskMgmt["Task Management"]:::management
        WFHistory["Workflow History"]:::management
        TaskQueue["Task Queue Management"]:::management
    end

    %% Connections
    CLI --> FrontAPI
    WebUI --> FrontAPI
    SDKs --> FrontAPI
    
    FrontAPI --> History
    FrontAPI --> Matching
    
    History --> DB
    History --> Kafka
    Kafka --> ES
    
    Matching --> Worker
    Worker --> History
    
    ShardDist --> History
    ShardDist --> Matching
    
    %% Click events
    click CLI "https://github.com/cadence-workflow/cadence/tree/master/cmd/tools/cli/"
    click FrontAPI "https://github.com/cadence-workflow/cadence/tree/master/service/frontend/api/"
    click SDKs "https://github.com/cadence-workflow/cadence/tree/master/client/"
    click History "https://github.com/cadence-workflow/cadence/tree/master/service/history/"
    click Matching "https://github.com/cadence-workflow/cadence/tree/master/service/matching/"
    click Worker "https://github.com/cadence-workflow/cadence/tree/master/service/worker/"
    click ShardDist "https://github.com/cadence-workflow/cadence/tree/master/service/sharddistributor/"
    click DB "https://github.com/cadence-workflow/cadence/tree/master/common/persistence/"
    click ES "https://github.com/cadence-workflow/cadence/tree/master/common/elasticsearch/"
    click Kafka "https://github.com/cadence-workflow/cadence/tree/master/common/asyncworkflow/queue/"
    click Metrics "https://github.com/cadence-workflow/cadence/tree/master/common/metrics/"
    click Logging "https://github.com/cadence-workflow/cadence/tree/master/common/log/"
    click Domain "https://github.com/cadence-workflow/cadence/tree/master/common/domain/"
    click TaskMgmt "https://github.com/cadence-workflow/cadence/tree/master/common/task/"
    click WFHistory "https://github.com/cadence-workflow/cadence/tree/master/service/history/execution/"
    click TaskQueue "https://github.com/cadence-workflow/cadence/tree/master/service/matching/tasklist/"

    %% Legend
    subgraph Legend
        L1["Frontend Component"]:::frontend
        L2["Core Service"]:::core
        L3[(Storage System)]:::storage
        L4[("Queue System")]:::queue
        L5["Monitoring"]:::monitoring
        L6["Management"]:::management
    end
```
