# goharbor/harbor-helm architecture

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

- Interactive diagram: https://gitdiagram.com/goharbor/harbor-helm
- Repository: https://github.com/goharbor/harbor-helm

## Overview

##### Project Type and Purpose
- This is a Kubernetes Helm chart whose purpose is to deploy the full Harbor registry stack in a Kubernetes cluster. It is an “infrastructure-as-code” project that templatizes and configures multiple microservices (Core, Portal, Registry, Jobservice, Trivy, Exporter, Nginx, Database, Redis, etc.) along with their Services, StatefulSets, Deployments, ConfigMaps, Secrets, PVCs, and Ingress/LoadBalancer exposures.

##### File Structure Highlights
- Chart.yaml & values.yaml: chart metadata and default configuration.
- templates/…: subdirectories for each component (core, database, registry, portal, jobservice, trivy, exporter, nginx, ingress, etc.).
- templates/*-cm.yaml: ConfigMaps for environment variables or configuration.
- templates/*-dpl.yaml or *-sts.yaml: Deployments or StatefulSets for each service.
- templates/*-svc.yaml: Kubernetes Services exposing components internally.
- templates/*-pvc.yaml: PersistentVolumeClaims for stateful data (registry storage, database, Redis, job logs, Trivy cache).
- docs/: guidance on high availability, upgrades.
- .github/workflows: CI tests (lint, unit, integration, e2e).

##### README Insights
- Describes prerequisites (K8s 1.20+, Helm 3.2+).
- Explains how to configure service exposure (Ingress, ClusterIP, NodePort, LoadBalancer).
- Enumerates every configurable parameter, revealing the architectural pieces (internal TLS, persistence backend, metrics, tracing).

a. Main Components
- External Traffic Layer: Ingress Controller (or LoadBalancer) → optional Nginx reverse-proxy Deployment.
- Harbor Core Stack:
- Core API Pods (Deployment + Service)
- Portal UI Pods (Deployment + Service)
- Jobservice Pods (Deployment + Service)
- Registry Pods (StatefulSet + Service) + Registry-Controller (registryctl)
- Trivy Adapter Pods (StatefulSet + Service)
- Exporter Pods (Deployment + Service)
- Backing Data Stores:
- PostgreSQL (StatefulSet + Service + PVC)
- Redis (StatefulSet + Service + PVC)
- Supporting Objects:
- ConfigMaps & Secrets (for TLS certs, env vars, credentials)
- PersistentVolumeClaims (registry data, DB, Redis, job logs, Trivy cache)
- Observability (optional):
- Metrics ServiceMonitor & Prometheus
- Tracing (Jaeger or OpenTelemetry)

b. Relationships & Data Flows
- Users → Ingress/LoadBalancer → (optional) Nginx → Portal UI & Core API
- Portal UI ↔ Core API
- Core API ↔ Database (PostgreSQL)
- Core API ↔ Redis (session/cache, quota provider)
- Core API → Registry Service (for image pushes/pulls)
- Registry Service → PVC (object storage)
- Core API ↔ Jobservice (async jobs such as garbage-collection, replication)
- Trivy Pod ↔ Registry Service (to scan images)
- Exporter Pod → harvest metrics from Core, Registry, etc. → Prometheus
- All internal mTLS connections if internalTLS.enabled

c. Architectural Patterns & Principles
- Microservices: each Harbor component runs in its own Deployment/StatefulSet.
- Statefulsets for services requiring stable network IDs and storage (DB, Redis, Registry, Trivy).
- Twelve-Factor config: use ConfigMaps & Secrets for environment and credentials.
- High-availability: configurable replicas, StatefulSet partitioning, persistence policies.
- Clear separation of control plane (Core, Portal, Jobservice) vs. data plane (Registry, PVC).
- Observability hooks (metrics, tracing) as first-class integrations.

d. Key Technologies & Frameworks
- Helm v3 chart templating
- Kubernetes primitives (Deployments, StatefulSets, Services, Ingresses, PVCs)
- PostgreSQL & Redis running as in-cluster services
- Trivy for vulnerability scanning
- Prometheus + ServiceMonitor for metrics
- Optional: Jaeger/OpenTelemetry for tracing

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Traffic Layer
    subgraph "External Traffic Layer"
        LB["Ingress / LoadBalancer"]:::ingress
        Nginx["Nginx Reverse Proxy (Deployment & Service)"]:::ingress
    end
    LB --> Nginx

    %% Control Plane
    subgraph "Control Plane"
        PortalUI["Portal UI (Deployment & Service)"]:::control
        CoreAPI["Core API (Deployment & Service)"]:::control
        Jobservice["Jobservice (Deployment & Service)"]:::control
    end
    Nginx --> PortalUI
    PortalUI -->|UI calls| CoreAPI
    CoreAPI -->|async jobs| Jobservice

    %% Data Plane
    subgraph "Data Plane"
        Registry["Registry (StatefulSet & Service)"]:::data
        Trivy["Trivy Adapter (StatefulSet & Service)"]:::data
        DB["PostgreSQL (StatefulSet & Service)"]:::data
        Redis["Redis (StatefulSet & Service)"]:::data
        %% PVCs
        RegPVC["Registry PVC"]:::pvc
        DBPVC["Database PVC"]:::pvc
        RedisPVC["Redis PVC"]:::pvc
        TrivyPVC["Trivy PVC"]:::pvc
    end
    CoreAPI -->|push/pull| Registry
    Registry -->|store data| RegPVC
    CoreAPI -->|metadata| DB
    DB -->|store data| DBPVC
    CoreAPI -->|cache/session| Redis
    Redis -->|store data| RedisPVC
    Registry -->|scan images| Trivy
    Trivy -->|cache| TrivyPVC

    CoreAPI ---|connects| InternalTLS["Internal TLS (auto-generated)"]:::config

    %% Observability
    subgraph "Observability"
        Exporter["Exporter (Deployment & Service)"]:::obs
        SM["Prometheus ServiceMonitor"]:::obs
        Tracing["Jaeger/OpenTelemetry"]:::obs
    end
    CoreAPI -->|metrics| Exporter
    Registry -->|metrics| Exporter
    Exporter --> SM
    CoreAPI -->|traces| Tracing
    Registry -->|traces| Tracing

    %% Configuration
    subgraph "Configuration & CI/CD"
        ChartMeta["Chart Metadata"]:::config
        Values["Default Configuration"]:::config
        Helpers["Helper Templates"]:::config
        Notes["Release Notes Template"]:::config
    end
    ChartMeta --> Values
    Values --> PortalUI
    Values --> CoreAPI
    Values --> Jobservice
    Values --> Registry
    Values --> Trivy
    Values --> DB
    Values --> Redis
    Helpers --> ChartMeta
    Notes --> ChartMeta

    %% Click Events
    click ChartMeta "https://github.com/goharbor/harbor-helm/blob/main/Chart.yaml"
    click Values "https://github.com/goharbor/harbor-helm/blob/main/values.yaml"
    click CoreAPI "https://github.com/goharbor/harbor-helm/tree/main/templates/core"
    click PortalUI "https://github.com/goharbor/harbor-helm/tree/main/templates/portal"
    click Jobservice "https://github.com/goharbor/harbor-helm/tree/main/templates/jobservice"
    click Registry "https://github.com/goharbor/harbor-helm/tree/main/templates/registry"
    click Trivy "https://github.com/goharbor/harbor-helm/tree/main/templates/trivy"
    click Exporter "https://github.com/goharbor/harbor-helm/tree/main/templates/exporter"
    click Nginx "https://github.com/goharbor/harbor-helm/tree/main/templates/nginx"
    click LB "https://github.com/goharbor/harbor-helm/tree/main/templates/ingress"
    click DB "https://github.com/goharbor/harbor-helm/blob/main/templates/database/database-ss.yaml"
    click Redis "https://github.com/goharbor/harbor-helm/blob/main/templates/redis/statefulset.yaml"
    click InternalTLS "https://github.com/goharbor/harbor-helm/blob/main/templates/internal/auto-tls.yaml"
    click SM "https://github.com/goharbor/harbor-helm/blob/main/templates/metrics/metrics-svcmon.yaml"
    click Helpers "https://github.com/goharbor/harbor-helm/blob/main/templates/_helpers.tpl"
    click Notes "https://github.com/goharbor/harbor-helm/blob/main/templates/NOTES.txt"

    %% Styles
    classDef ingress fill:#f2cbcb,stroke:#a33,stroke-width:1px
    classDef control fill:#cfe2f3,stroke:#3a6,stroke-width:1px
    classDef data fill:#d9ead3,stroke:#3a6,stroke-width:1px
    classDef obs fill:#fff2cc,stroke:#a65,stroke-width:1px
    classDef config fill:#e7e6e6,stroke:#666,stroke-width:1px
    classDef pvc fill:#fadbd8,stroke:#c0392b,stroke-width:1px
```
