# indeedeng/iwf architecture

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

- Interactive diagram: https://gitdiagram.com/indeedeng/iwf
- Repository: https://github.com/indeedeng/iwf

## Overview

##### Project type and purpose
- This is a Go‐based long‐running workflow orchestration “server” component of the iWF framework.
- It exposes an HTTP API (using OpenAPI/Swagger) that client SDKs (Go/Java/Python) call to start, signal, query, or manage workflows.
- Under the hood, it uses Temporal (or Cadence) as the durable workflow engine, layering abstractions (durable timers, RPC, KV storage, retry policies) on top.

##### File structure
- cmd/server: entrypoint for the iWF server binary.
- config: configuration loading and dynamic config (YAML templates).
- service: core business logic—API HTTP handlers (service/api), client wrappers to Cadence/Temporal (service/client), common utilities (service/common), and interpreter orchestration (service/interpreter).
- gen/iwfidl & openapi-generator: auto‐generated client and API schema code.
- docker-compose & Dockerfile: deployment artifacts to bring up iWF server + Temporal/Cadence + dynamic‐config.
- integ & replayTests: end‐to‐end integration and replay test suites driving workflows via the public API.

##### README for additional insights
- iWF is an API orchestration platform providing a coding framework for durable timers, async execution, KV storage, RPC, message queues.
- It requires a server (this repo) and one of the SDKs to invoke the HTTP endpoints.

##### High‐level components
a. External Clients (SDKs):
– Golang, Java, Python SDKs invoking HTTP/JSON endpoints.
b. API Gateway / HTTP Layer (service/api + gen/iwfidl/api):
– Routers, OpenAPI handlers, request validation.
c. Service Layer (service/service.go + service/common + service/client):
– Business façade managing workflows—translating API calls into interpreter commands.
– Temporal/Cadence client adapters.
d. Interpreter Layer (service/interpreter):
– Core orchestration logic—state machine, durable timers, signal/RPC handling, continue‐as‐new, persistence, local vs. global versioning.
e. Workflow Worker Processes (temp/cadence workers):
– Registered workflow‐and‐activity providers that execute user code.
f. Backend Stateful Services:
– Temporal/Cadence cluster (gRPC endpoints)
– Dynamic Configuration Service (SQL‐backed)
– (Optional) Key‐Value storage if external.
g. Persistence & Metrics:
– Temporal’s internal DB, plus service/log for server logs and metrics output.

##### Relationships and interactions
- SDK → HTTP API → Service Layer → Interpreter
- Interpreter ↔ Cadence/Temporal Client → Temporal Server
- Interpreter schedules timers, local activities, signals via the Temporal SDK
- Dynamic config service consulted by interpreter/config for runtime tuning
- Integration tests invoke the HTTP API and validate end‐to‐end behavior, including replayTests using history files.

##### Architectural patterns & design principles
- Layered Architecture: clear separation among API, service façade, orchestration interpreter, external workflow engine.
- Dependency Injection via interfaces in service/client and interpreter/interfaces for pluggability (Cadence vs. Temporal).
- Code‐Generation: OpenAPI‐IDL for API schema (gen/iwfidl).
- Containerization/Microservice Deployment: Docker images for server, Temporal, dynamic‐config.
- Stateful vs. Stateless: server is stateless (reads config & dynamic‐config), state lives in Temporal.

##### Technologies, frameworks, and libraries
- Go modules (go.mod/go.sum)
- OpenAPI Generator (gen/iwfidl)
- Temporal (or Cadence) Go SDK
- Docker + Docker Compose
- YAML config + dynamic‐config SQL
- CI workflows (.github/workflows) for unit, integration, and E2E tests.

##### Elements
– From “SDK” to “HTTP API Layer” (REST calls)
– API → Service → Interpreter → Temporal gRPC → Temporal DB
– Interpreter ↔ Dynamic Config
– API layer in green
– Service & common utilities in blue
– Interpreter in orange
– External systems (Temporal, DB, dynamic config) in gray
– Rectangles for components

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "External Clients"
        SDK["Client SDKs (Go/Java/Python)"]:::external
    end

    subgraph "API Layer"
        Handler["iWF HTTP API Gateway\n(service/api/handler.go)"]:::api
        Routers["Routers\n(service/api/routers.go)"]:::api
        OpenAPI["OpenAPI Spec\n(gen/iwfidl/api/openapi.yaml)"]:::api
    end

    subgraph "Service Facade"
        Facade["Service Facade\n(service/service.go)"]:::service
        ClientInterfaces["Client Interfaces\n(service/client/interfaces.go)"]:::service
        CadenceAdapter["CadenceClientAdapter\n(service/client/cadence/client.go)"]:::service
        TemporalAdapter["TemporalClientAdapter\n(service/client/temporal/client.go)"]:::service
        CommonUtils["Common Utilities\n(service/common/)"]:::service
    end

    subgraph "Workflow Interpreter"
        StateMachine["State Machine & ContinueAsNew\n(service/interpreter/cont/continueAsNewCounter.go)"]:::interpreter
        Timers["Timers & Scheduling\n(service/interpreter/timers/greedyTimerScheduler.go)"]:::interpreter
        SignalRPC["Signal & RPC Handler\n(service/interpreter/signalReceiver.go)"]:::interpreter
        PersistenceLoader["Persistence Loader\n(service/interpreter/persistence.go)"]:::interpreter
        Configer["Config Loader\n(service/interpreter/config/workflowConfiger.go)"]:::interpreter
        InternalChannel["InternalChannel\n(service/interpreter/InternalChannel.go)"]:::interpreter
        ActivityImpl["Activity Impl\n(service/interpreter/activityImpl.go)"]:::interpreter
        WorkflowImpl["Workflow Impl\n(service/interpreter/workflowImpl.go)"]:::interpreter
        WorkflowUpdater["Workflow Updater\n(service/interpreter/workflowUpdater.go)"]:::interpreter
        Decider["Decider Triggerer\n(service/interpreter/deciderTriggerer.go)"]:::interpreter
        Env["Environment\n(service/interpreter/env/env.go)"]:::interpreter
        Interfaces["Interfaces\n(service/interpreter/interfaces/interfaces.go)"]:::interpreter
        QueryHandler["Query Handler\n(service/interpreter/queryHandler.go)"]:::interpreter
        Utils["Utils\n(service/interpreter/utils.go)"]:::interpreter
    end

    subgraph "Workflow Worker Processes"
        CadenceWorker["Cadence Worker\n(service/interpreter/cadence/worker.go)"]:::service
        TemporalWorker["Temporal Worker\n(service/interpreter/temporal/worker.go)"]:::service
    end

    subgraph "Backend Services & Deployment"
        Compose["Docker Compose\n(docker-compose/docker-compose.yml)"]:::external
        DynamicConfig["Dynamic Config Service\n(docker-compose/dynamicconfig/)"]:::external
        ConfigFiles["Config Templates\n(config/config_template.yaml\nconfig/development.yaml)"]:::external
        TemporalCluster["Temporal Cluster (gRPC)"]:::external
    end

    DB["Temporal DB"]:::db

    subgraph "Persistence & Logging"
        LoggerImpl["Logger Impl\n(service/common/log/loggerimpl/logger.go)"]:::service
        LoggerInterface["Logger Interface\n(service/common/log/interface.go)"]:::service
    end

    SDK -->|"REST/JSON\nOpenAPI"| Handler
    Handler -->|routes| Routers
    Routers -->|uses spec| OpenAPI
    Routers -->|"calls"| Facade
    Facade -->|"uses interfaces"| ClientInterfaces
    Facade -->|"calls"| CadenceAdapter
    Facade -->|"calls"| TemporalAdapter
    Facade -->|"utils"| CommonUtils

    CadenceAdapter -->|orchestrates| StateMachine
    TemporalAdapter -->|orchestrates| StateMachine

    StateMachine --> Timers
    StateMachine --> SignalRPC
    StateMachine --> PersistenceLoader
    StateMachine --> Configer

    Timers -->|schedule| TemporalCluster
    SignalRPC -->|signal/RPC| TemporalCluster
    PersistenceLoader -->|load/save| TemporalCluster

    Configer --> DynamicConfig
    StateMachine --> InternalChannel
    InternalChannel --> ActivityImpl
    ActivityImpl --> WorkflowImpl
    WorkflowImpl --> WorkflowUpdater
    WorkflowUpdater --> Decider
    Decider --> Env
    Env --> Interfaces
    Interfaces --> QueryHandler
    QueryHandler --> Utils

    TemporalCluster -->|writes/reads| DB
    TemporalCluster -->|dispatches| CadenceWorker
    TemporalCluster -->|dispatches| TemporalWorker

    Facade -->|logs/metrics| LoggerImpl
    Facade -->|uses| LoggerInterface

    click SDK "https://github.com/indeedeng/iwf/tree/main/gen/iwfidl"
    click Handler "https://github.com/indeedeng/iwf/blob/main/service/api/handler.go"
    click Routers "https://github.com/indeedeng/iwf/blob/main/service/api/routers.go"
    click OpenAPI "https://github.com/indeedeng/iwf/blob/main/gen/iwfidl/api/openapi.yaml"
    click Facade "https://github.com/indeedeng/iwf/blob/main/service/service.go"
    click ClientInterfaces "https://github.com/indeedeng/iwf/blob/main/service/client/interfaces.go"
    click CadenceAdapter "https://github.com/indeedeng/iwf/blob/main/service/client/cadence/client.go"
    click TemporalAdapter "https://github.com/indeedeng/iwf/blob/main/service/client/temporal/client.go"
    click CommonUtils "https://github.com/indeedeng/iwf/tree/main/service/common"
    click StateMachine "https://github.com/indeedeng/iwf/blob/main/service/interpreter/cont/continueAsNewCounter.go"
    click Timers "https://github.com/indeedeng/iwf/blob/main/service/interpreter/timers/greedyTimerScheduler.go"
    click SignalRPC "https://github.com/indeedeng/iwf/blob/main/service/interpreter/signalReceiver.go"
    click PersistenceLoader "https://github.com/indeedeng/iwf/blob/main/service/interpreter/persistence.go"
    click Configer "https://github.com/indeedeng/iwf/blob/main/service/interpreter/config/workflowConfiger.go"
    click InternalChannel "https://github.com/indeedeng/iwf/blob/main/service/interpreter/InternalChannel.go"
    click ActivityImpl "https://github.com/indeedeng/iwf/blob/main/service/interpreter/activityImpl.go"
    click WorkflowImpl "https://github.com/indeedeng/iwf/blob/main/service/interpreter/workflowImpl.go"
    click WorkflowUpdater "https://github.com/indeedeng/iwf/blob/main/service/interpreter/workflowUpdater.go"
    click Decider "https://github.com/indeedeng/iwf/blob/main/service/interpreter/deciderTriggerer.go"
    click Env "https://github.com/indeedeng/iwf/blob/main/service/interpreter/env/env.go"
    click Interfaces "https://github.com/indeedeng/iwf/blob/main/service/interpreter/interfaces/interfaces.go"
    click QueryHandler "https://github.com/indeedeng/iwf/blob/main/service/interpreter/queryHandler.go"
    click Utils "https://github.com/indeedeng/iwf/blob/main/service/interpreter/utils.go"
    click CadenceWorker "https://github.com/indeedeng/iwf/blob/main/service/interpreter/cadence/worker.go"
    click TemporalWorker "https://github.com/indeedeng/iwf/blob/main/service/interpreter/temporal/worker.go"
    click Compose "https://github.com/indeedeng/iwf/blob/main/docker-compose/docker-compose.yml"
    click DynamicConfig "https://github.com/indeedeng/iwf/tree/main/docker-compose/dynamicconfig/"
    click ConfigFiles "https://github.com/indeedeng/iwf/blob/main/config/config_template.yaml"
    click ConfigFiles "https://github.com/indeedeng/iwf/blob/main/config/development.yaml"
    click LoggerImpl "https://github.com/indeedeng/iwf/blob/main/service/common/log/loggerimpl/logger.go"
    click LoggerInterface "https://github.com/indeedeng/iwf/blob/main/service/common/log/interface.go"

    classDef api fill:#c2f0c2,stroke:#333
    classDef service fill:#cce5ff,stroke:#333
    classDef interpreter fill:#ffe5b4,stroke:#333
    classDef external fill:#d3d3d3,stroke:#333
    classDef db fill:#f2f2f2,stroke:#333
```
