# apache/openwhisk architecture

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

- Interactive diagram: https://gitdiagram.com/apache/openwhisk
- Repository: https://github.com/apache/openwhisk

## Overview

##### Main Components

a. Client-Facing Layer:
- REST API Gateway
- CLI (wsk)
- Web UI (Playground)

b. Core Components:
- Controller (action management, authentication)
- Invoker (action execution)
- Scheduler (resource management)
- Load Balancer

c. Storage Layer:
- CouchDB/Cosmos DB (for state management)
- Kafka (message queue)
- Zookeeper (distributed coordination)

d. Runtime Layer:
- Docker Container Pool
- Various Language Runtimes (Node.js, Python, Java, etc.)

##### Component Relationships

a. Control Flow:
- Client → API Gateway → Controller
- Controller → Load Balancer → Scheduler → Invoker
- Invoker → Container Pool

b. Data Flow:
- Controller ↔ CouchDB (action/auth storage)
- Controller → Kafka → Invoker (activation requests)
- Invoker → CouchDB (activation results)

##### Specific Design Elements

- Blue: External interfaces (API Gateway, CLI)
- Green: Core processing (Controller, Invoker)
- Yellow: Storage (CouchDB, Kafka)
- Orange: Runtime (Container Pool)

b. Component Grouping:
- Separate control plane from data plane

##### Implementation Details

Technical annotations for:
- REST API endpoints
- Kafka topics
- Database collections
- Container lifecycle

##### Architectural Patterns

Highlight:
- Event-driven architecture
- Message-based communication
- Container orchestration
- Distributed system coordination

**[Client Layer]**
- ↓
**[API Gateway Layer]**
- ↓
**[Control Layer (Controller/Scheduler)]**
- ↓
**[Messaging Layer (Kafka)]**
- ↓
**[Execution Layer (Invoker/Containers)]**

- Component types
- State transitions
- Scaling boundaries

Remember to:
##### Monitoring touchpoints

This will provide a complete view of OpenWhisk's architecture while maintaining clarity about component relationships and system flow.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef client fill:#4287f5,stroke:#333,stroke-width:2px
    classDef core fill:#50C878,stroke:#333,stroke-width:2px
    classDef storage fill:#FFD700,stroke:#333,stroke-width:2px
    classDef runtime fill:#FFA500,stroke:#333,stroke-width:2px
    classDef api fill:#4287f5,stroke:#333,stroke-width:2px

    %% Client Layer
    subgraph ClientLayer["Client Layer"]
        CLI["CLI (wsk)"]:::client
        WebUI["Web UI (Playground)"]:::client
        REST["REST Clients"]:::client
    end

    %% API Gateway Layer
    APIGateway["API Gateway"]:::api

    %% Control Layer
    subgraph ControlLayer["Control Layer"]
        Controller["Controller"]:::core
        LoadBalancer["Load Balancer"]:::core
        Scheduler["Scheduler"]:::core
    end

    %% Storage Layer
    subgraph StorageLayer["Storage Layer"]
        CouchDB["CouchDB/Cosmos DB"]:::storage
        Kafka["Kafka"]:::storage
        Zookeeper["Zookeeper"]:::storage
    end

    %% Execution Layer
    subgraph ExecutionLayer["Execution Layer"]
        Invoker["Invoker"]:::core
        ContainerPool["Container Pool"]:::runtime
        Runtimes["Language Runtimes<br/>(Node.js, Python, Java)"]:::runtime
    end

    %% Relationships
    CLI --> APIGateway
    WebUI --> APIGateway
    REST --> APIGateway
    APIGateway --> Controller
    Controller --> LoadBalancer
    LoadBalancer --> Scheduler
    Scheduler --> Invoker
    Controller <--> CouchDB
    Controller --> Kafka
    Kafka --> Invoker
    Invoker --> CouchDB
    Invoker --> ContainerPool
    ContainerPool --> Runtimes
    Zookeeper --- Controller
    Zookeeper --- Invoker

    %% Click events
    click Controller "https://github.com/apache/openwhisk/tree/master/core/controller/"
    click Invoker "https://github.com/apache/openwhisk/tree/master/core/invoker/"
    click Scheduler "https://github.com/apache/openwhisk/tree/master/core/scheduler/"
    click APIGateway "https://github.com/apache/openwhisk/tree/master/ansible/roles/apigateway/"
    click CLI "https://github.com/apache/openwhisk/tree/master/ansible/roles/cli/"
    click WebUI "https://github.com/apache/openwhisk/tree/master/core/standalone/src/main/resources/playground/"
    click ContainerPool "https://github.com/apache/openwhisk/tree/master/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/"
    click LoadBalancer "https://github.com/apache/openwhisk/tree/master/core/controller/src/main/scala/org/apache/openwhisk/core/loadBalancer/"
    click CouchDB "https://github.com/apache/openwhisk/tree/master/ansible/roles/couchdb/"
    click Kafka "https://github.com/apache/openwhisk/tree/master/ansible/roles/kafka/"
    click Zookeeper "https://github.com/apache/openwhisk/tree/master/ansible/roles/zookeeper/"
    click Runtimes "https://github.com/apache/openwhisk/tree/master/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/docker/"

    %% Legend
    subgraph Legend
        Client[Client Components]:::client
        CoreComp[Core Components]:::core
        StorageComp[Storage Components]:::storage
        RuntimeComp[Runtime Components]:::runtime
        APIComp[API Components]:::api
    end
```
