Overview

The Engine Gateway provides a RESTful interface to interact with process engines, automatically routing requests to the appropriate BPMN engine based on the process definition and the configured engines.

Gateway Architecture

Features

Architecture

The Gateway module is built on three main components:

1. GatewayServer

The GatewayServer is an abstract class that extends EngineApp and ZIOAppDefault. It provides the HTTP server infrastructure and combines all route handlers.

import orchescala.gateway.*
import orchescala.engine.*
import orchescala.worker.*
import zio.*

abstract class MyGatewayApp extends GatewayServer:
  def config: GatewayConfig = DefaultGatewayConfig(
    engineConfig = DefaultEngineConfig(),
    workerConfig = DefaultWorkerConfig(DefaultEngineConfig()),
    gatewayPort = 8888
  )

2. GatewayConfig

The GatewayConfig trait defines the configuration interface for the gateway:

The DefaultGatewayConfig provides a basic implementation with JWT-based token extraction.

3. Route Handlers

The gateway provides five main route handlers:

Getting Started

Basic Setup

import orchescala.gateway.*
import orchescala.engine.*
import orchescala.worker.*
import zio.*

object MyGatewayApp extends GatewayServer:
  
  def config: GatewayConfig = DefaultGatewayConfig(
    engineConfig = DefaultEngineConfig(),
    workerConfig = DefaultWorkerConfig(DefaultEngineConfig()),
    gatewayPort = 8888
  )

Custom Configuration

You can customize the gateway configuration by overriding the validateToken and extractCorrelation methods:

import orchescala.gateway.*
import orchescala.engine.*
import orchescala.worker.*
import orchescala.domain.*
import zio.*

case class CustomGatewayConfig(
    engineConfig: EngineConfig,
    workerConfig: WorkerConfig,
    gatewayPort: Int = 8888
) extends GatewayConfig:
  
  override def validateToken(token: String): IO[GatewayError, String] =
    // Custom validation logic (e.g., verify JWT signature, check database)
    if token.startsWith("valid-") then
      ZIO.succeed(token)
    else
      ZIO.fail(GatewayError.TokenValidationError("Invalid token format"))
  
  override def extractCorrelation(
      token: String,
      in: JsonObject
  ): IO[GatewayError, IdentityCorrelation] =
    // Custom correlation extraction logic
    ZIO.succeed(IdentityCorrelation(
      username = "extracted-user",
      email = Some("user@example.com")
    ))

OpenAPI Documentation

The gateway automatically generates and serves OpenAPI documentation:

Next Steps