# kubescape/operator architecture

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

- Interactive diagram: https://gitdiagram.com/kubescape/operator
- Repository: https://github.com/kubescape/operator

## Overview

##### Main Components

a. Core Components:
- Admission Controller (from /admission directory)
- REST API Handler (from /restapihandler)
- Main Handler (from /mainhandler)
- Continuous Scanning Engine (from /continuousscanning)
- Watcher System (from /watcher)
- Object Cache (from /objectcache)

b. External Components:
- Kubernetes API Server
- Kubescape Scanner
- KubeVuln Scanner
- WebSocket Connections
- External REST API Clients

##### Component Relationships

**[External Clients] → [REST API Handler] ↔ [Main Handler]**
- ↕
**[WebSocket] → [Continuous Scanning] → [Watcher System]**
- ↕
**[Kubernetes API] ← [Admission Controller] → [Object Cache]**
- ↕
- [KubeVuln Scanner] ← [Service Handler]
- [Kubescape Scanner]

##### Component Details

a. REST API Handler:
- Endpoint: /v1/triggerAction
- OpenAPI documentation endpoints
- Action triggering capabilities

b. Admission Controller:
- Webhook server
- Rule binding cache
- Security rule implementations

c. Watcher System:
- Pod watcher
- SBOM watcher
- Application profile watcher
- Commands watcher

d. Main Handler:
- CronJob handler
- Image registry handler
- Kubescape handler
- Vulnerability scan handler

##### Key Interactions to Highlight

- REST API requests flow from external clients through the REST API handler to the main handler
- Continuous scanning engine monitoring Kubernetes resources
- Webhook admission control for security policy enforcement
- Watcher system's interaction with Kubernetes API server
- Communication with external scanning services (Kubescape and KubeVuln)

##### Configuration Elements

A separate section showing configuration sources:
- /etc/config/capabilities.json
- /etc/config/clusterData.json
- /etc/config/config.json
- /etc/config/services.json
- Environment variables

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core["Core Operator Components"]
        REST["REST API Handler"]:::core
        MH["Main Handler"]:::core
        CS["Continuous Scanning Engine"]:::core
        WA["Watcher System"]:::core
        AC["Admission Controller"]:::core
        OC["Object Cache"]:::core
        SH["Service Handler"]:::core

        subgraph Watchers["Watcher Components"]
            PW["Pod Watcher"]:::watcher
            SW["SBOM Watcher"]:::watcher
            AW["Application Profile Watcher"]:::watcher
            CW["Commands Watcher"]:::watcher
        end

        subgraph Handlers["Handler Components"]
            CH["CronJob Handler"]:::handler
            IH["Image Registry Handler"]:::handler
            KH["Kubescape Handler"]:::handler
            VH["Vulnerability Scan Handler"]:::handler
        end
    end

    subgraph Config["Configuration"]
        CC["Capabilities Config"]:::config
        CD["Cluster Data"]:::config
        GC["Global Config"]:::config
        SC["Services Config"]:::config
    end

    %% Relationships
    REST <--> MH
    CS --> WA
    WA --> OC
    AC --> OC
    MH --> SH
    
    %% Watcher Relationships
    WA --> PW
    WA --> SW
    WA --> AW
    WA --> CW
    
    %% Handler Relationships
    MH --> CH
    MH --> IH
    MH --> KH
    MH --> VH

    %% Configuration Relationships
    Config --> MH
    Config --> AC
    Config --> CS

    %% Click Events
    click REST "https://github.com/kubescape/operator/tree/main/restapihandler/"
    click AC "https://github.com/kubescape/operator/tree/main/admission/"
    click MH "https://github.com/kubescape/operator/tree/main/mainhandler/"
    click CS "https://github.com/kubescape/operator/tree/main/continuousscanning/"
    click WA "https://github.com/kubescape/operator/tree/main/watcher/"
    click OC "https://github.com/kubescape/operator/tree/main/objectcache/"
    click SH "https://github.com/kubescape/operator/tree/main/servicehandler/"
    click PW "https://github.com/kubescape/operator/blob/main/watcher/podwatcher.go"
    click SW "https://github.com/kubescape/operator/blob/main/watcher/sbomwatcher.go"
    click AW "https://github.com/kubescape/operator/blob/main/watcher/applicationprofilewatcher.go"
    click CW "https://github.com/kubescape/operator/blob/main/watcher/commandswatcher.go"
    click CH "https://github.com/kubescape/operator/blob/main/mainhandler/cronjobhandler.go"
    click IH "https://github.com/kubescape/operator/blob/main/mainhandler/imageregistryhandler.go"
    click KH "https://github.com/kubescape/operator/blob/main/mainhandler/kubescapehandler.go"
    click VH "https://github.com/kubescape/operator/blob/main/mainhandler/vulnscanhandler.go"
    click CC "https://github.com/kubescape/operator/blob/main/configuration/capabilities.json"
    click GC "https://github.com/kubescape/operator/blob/main/configuration/config.json"

    %% Styling
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef k8s fill:#e67e22,stroke:#d35400,color:white
    classDef scanner fill:#9b59b6,stroke:#8e44ad,color:white
    classDef config fill:#27ae60,stroke:#219a52,color:white
    classDef watcher fill:#1abc9c,stroke:#16a085,color:white
    classDef handler fill:#f1c40f,stroke:#f39c12,color:black
```
