# olympusgg/bitwarden-secret-operator architecture

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

- Interactive diagram: https://gitdiagram.com/olympusgg/bitwarden-secret-operator
- Repository: https://github.com/olympusgg/bitwarden-secret-operator

## Overview

##### Main Components
- Kubernetes Cluster & API Server – Represent the external environment where the operator is deployed.
- Custom Resource Definition (CRD) – This is the BitwardenSecret CRD, which triggers the operator’s functionality. It is declared in the charts folder for helm deployment and implemented in the src/Bitwarden.SecretOperator/CRDs directory.
- Bitwarden CLI Wrapper – Inside the operator, the “CliWrapping” module encapsulates calls to the Bitwarden CLI. This helps in performing “bw sync” and retrieval of secrets.
- Healthchecks & Metrics – Separate modules (Healthcheck folder for liveliness/readiness endpoints and Prometheus metrics as described in the README) that expose the operator’s state.
- Configuration & Environment Variables – Represent the configuration management (appsettings files and environment settings injected via Helm charts) that governs aspects like refresh rate and Bitwarden connection details.
- Helm Charts & Deployment Artifacts – Represent the deployment packaging (charts directory; contains helm templates that deploy the operator inside a Kubernetes namespace).

##### Architectural Patterns
- Event-Driven Design: The operator is triggered by events coming from the Kubernetes API (custom resources creation/modification).
- Containerized Deployment: Emphasize that the operator is packaged via Docker (Dockerfile) and deployed using Helm charts, so include external build/deployment pipelines if needed.

##### Relevant Technologies and Frameworks
- .NET (the underlying technology for the operator code)
- KubeOps (dotnet-operator-sdk) as the framework used to implement the operator patterns
- Docker & Helm for deployment and container orchestration
- Prometheus for metrics collection
- Bitwarden CLI for secret syncing

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Components
    K8S["Kubernetes API Server"]:::external

    subgraph "BitwardenSecret CRD"
        CRD_Helm["BitwardenSecret CRD (Helm)"]:::external
        CRD_Impl["BitwardenSecret CRD (Implementation)"]:::external
    end

    %% Operator Internal Components
    subgraph "Operator Internal Components"
        OP["Operator Controller Core"]:::core
        CLI["Bitwarden CLI Wrapper"]:::cli
        HC["Healthcheck & Metrics"]:::health
        CFG["Configuration & Env Vars"]:::config
    end

    %% Deployment and Monitoring Components
    HELM["Helm Charts & Deployment"]:::helm
    PROM["Prometheus Metrics Exporter"]:::monitoring
    MON["Monitoring System"]:::external

    %% Relationships
    K8S -->|"event_notifications"| OP
    CRD_Impl -->|"trigger_events"| OP
    OP -->|"invoke_cli"| CLI
    OP -->|"inject_config"| CFG
    OP -->|"health_checks"| HC
    HELM -->|"deploys"| OP
    HC -->|"exposes_metrics"| PROM
    PROM -->|"scrapes_metrics"| MON

    %% Click Events
    click CRD_Helm "https://github.com/olympusgg/bitwarden-secret-operator/blob/main/charts/bitwarden-secret-operator/crds/bitwarden-secret.yaml"
    click CRD_Impl "https://github.com/olympusgg/bitwarden-secret-operator/blob/main/src/Bitwarden.SecretOperator/CRDs/Secret/BitwardenSecretCrd.cs"
    click OP "https://github.com/olympusgg/bitwarden-secret-operator/blob/main/src/Bitwarden.SecretOperator/Program.cs"
    click OP "https://github.com/olympusgg/bitwarden-secret-operator/blob/main/src/Bitwarden.SecretOperator/BitwardenOperatorOptions.cs"
    click CLI "https://github.com/olympusgg/bitwarden-secret-operator/tree/main/src/Bitwarden.SecretOperator/CliWrapping"
    click HC "https://github.com/olympusgg/bitwarden-secret-operator/tree/main/src/Bitwarden.SecretOperator/Healthcheck"
    click CFG "https://github.com/olympusgg/bitwarden-secret-operator/blob/main/src/Bitwarden.SecretOperator/appsettings.json"
    click CFG "https://github.com/olympusgg/bitwarden-secret-operator/blob/main/src/Bitwarden.SecretOperator/appsettings.Development.json"
    click HELM "https://github.com/olympusgg/bitwarden-secret-operator/tree/main/charts/bitwarden-secret-operator"

    %% Styles
    classDef external fill:#f9c,stroke:#333,stroke-width:2px;
    classDef core fill:#ccf,stroke:#333,stroke-width:2px;
    classDef cli fill:#cfc,stroke:#333,stroke-width:2px;
    classDef health fill:#fcf,stroke:#333,stroke-width:2px;
    classDef config fill:#cff,stroke:#333,stroke-width:2px;
    classDef helm fill:#ffc,stroke:#333,stroke-width:2px;
    classDef monitoring fill:#efe,stroke:#333,stroke-width:2px;
```
