# gematik/zero-lab architecture

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

- Interactive diagram: https://gitdiagram.com/gematik/zero-lab
- Repository: https://github.com/gematik/zero-lab

## Overview

##### Project Type and Purpose
- This is a Go‑based suite of micro‑services and libraries that together implement Zero Trust security primitives: client registration, attestation (Android Key/ID, Apple DCAppAttest, TPM), DPoP, OpenID Federation (OIDF) relying party, Nonce service, and a Policy Enforcement Point (PEP). It includes both server components (authorization server, PEP, reverse‑proxy plugin) and client‑side tooling (CLI commands, static web assets, libzero library).

##### High‑Level File‑Structure Analysis
- go/authzserver: The Registration & Authorization server with HTTP endpoints under /reg (nonce, auth, registrations, challenges, clients, cert issuance).
- go/cmd: Stand‑alone executables:
- zero‑zerobin: a demo “zerobin” web service (static UI + DPoP flows).
- zero: CLI for identity, registration, TPM, tcl interactions.
- go/libzero: Shared library of security primitives (attestation, nonce, DPoP, OAuth2/OIDC/OIDF, registration API, tcl, util, webclient).
- go/pep: Policy Enforcement Point service—HTTP reverse‑proxy with pattern‑based routing.
- go/zaddy: Caddy plugin (“zero‑caddy”) that enforces PEP policies in Caddy server.
- go/vau: Encryption/Key‑exchange service (EC‑Diffie‑Hellman, KEM) for protecting data in transit.
- static/: Static assets (images). temp/: Scratch code & OpenAPI specs.

##### README Insights
- Implements ACME‑style registration with nonces, JWS, JWK, MTLS certificates.
- Supports multi‑format attestation (Android, Apple, TPM).
- Exposes REST endpoints for each registration step and certificate issuance.
- PEP evolves through iterations—initial reverse proxy, then JWT self‑contained tokens, DPoP & nonce support, PoP‑token verification.

a. Components to include
1. Client App (mobile or browser)
– Contains libzero for nonce, DPoP, attestation, JWK/MTLS key management.
2. Registration & Authorization Server (go/authzserver)
– Nonce Service, Registration API (/reg/*), Certificate issuance.
3. Policy Enforcement Point (go/pep or go/zaddy + Caddy)
– Routes incoming app/API traffic, adds/validates X-ZTA- headers.
4. Reverse‑Proxy (Caddy + zero‑caddy plugin)
5. Demo “zerobin” Web Service (go/cmd/zero‑zerobin)
6. VAU Encryption Service (go/vau)
7. External Identity Providers
– GesundheitsID (OpenID Connect)
– Federated IDPs via OIDF
8. Optional CLI Tools (go/cmd/zero)
9. Shared Library (go/libzero)
10. Static Web Client UI (go/libzero/webclient + go/cmd/zero‑zerobin/static)

b. Relationships & Data Flows
1. Client → PEP/Proxy: initial REST calls (GET nonce, POST JWS‑protected payload).
2. PEP → AuthZ Server: forwards requests to /reg endpoints.
3. AuthZ Server ↔ Nonce Service (internal) for nonce issuance/validation.
4. AuthZ Server ↔ External IDP (OIDC/OIDF) for subject authentication.
5. AuthZ Server → Certificate Authority (built‑in CA in libzero/ca) for MTLS cert issuance.
6. Client → Demo Zerobin Service (for DPoP‑protected endpoints).
7. VAU Service invoked by AuthZ or other services for data encryption/attestation flows.

c. Architectural Patterns & Principles
- Micro‑services (each go/* module can run independently).
- ACME‑style registration: Nonce + JWS + JWK + GET‑over‑POST.
- Plugin architecture (zero‑caddy for Caddy).
- Library‑driven reuse (libzero).
- Zero Trust: no implicit trust, continuous attestation, per‑request verification.

d. Key Technologies & Frameworks
- Go modules & CLI (go/cmd)
- HTTP server (net/http, Echo middleware in libzero/dpop)
- JSON Web Signature (JWS), JOSE, JSON Web Key (JWK)
- DPoP (RFC 9449)
- TPM & DCAppAttest libraries
- OpenID Connect (OAuth2 + OIDF)
- Caddy web server + plugin (zaddy)
- Docker (Dockerfiles in cmd subfolders)

##### Key Elements to Capture
- Nonce issuance & validation service inside AuthZ
- Attestation formats and where they’re plugged in (Android, Apple, TPM)
- OpenID/OIDF interactions for subject identity
- ACME‑style GET‑over‑POST JWS flows
- Policy Enforcement Point placement (edge proxy)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Client Side"
        direction TB
        Libzero["libzero (nonce, DPoP, attestation, JWK)"]:::client
        UI["Web Client UI"]:::client
        CLI["CLI Tools"]:::client
    end

    subgraph "Edge Proxy"
        direction TB
        Caddy["Caddy + zero-caddy"]:::microservice
        PEP["PEP Service"]:::microservice
    end

    subgraph "AuthZ Service"
        direction TB
        AuthZ["AuthZ Server"]:::microservice
        subgraph "Inside AuthZ"
            direction TB
            Nonce["Nonce Service"]:::microservice
            Attest["Attestation Modules"]:::microservice
            DPoP["DPoP Logic"]:::microservice
            OIDC["OIDC Client"]:::microservice
            OIDF["OIDF Client"]:::microservice
            CA["ACME-style CA"]:::microservice
        end
    end

    VAU["VAU Encryption Service"]:::microservice
    Demo["ZeroBin Demo Service"]:::microservice

    subgraph "External Identity Providers"
        direction TB
        GIDP["GesundheitsID (OIDC)"]:::external
        FIDP["Federated IDPs (OIDF)"]:::external
    end

    Libzero -->|HTTPS JWS, DPoP| Caddy
    UI -->|HTTPS JWS, DPoP| Caddy
    CLI -->|HTTPS JWS, DPoP| Caddy

    Caddy --> PEP
    PEP -->|Forward /reg| AuthZ

    AuthZ --> Nonce
    AuthZ --> Attest
    AuthZ --> DPoP
    AuthZ --> OIDC
    AuthZ --> OIDF
    AuthZ --> CA
    AuthZ -.->|optional encrypted data| VAU
    AuthZ --> GIDP
    AuthZ --> FIDP

    Libzero -->|DPoP| Demo
    UI -->|DPoP| Demo
    Demo -->|via PEP| PEP

    click Libzero "https://github.com/gematik/zero-lab/tree/main/go/libzero"
    click UI "https://github.com/gematik/zero-lab/tree/main/go/libzero/webclient"
    click CLI "https://github.com/gematik/zero-lab/tree/main/go/cmd/zero"
    click Caddy "https://github.com/gematik/zero-lab/tree/main/go/zaddy"
    click PEP "https://github.com/gematik/zero-lab/tree/main/go/pep"
    click AuthZ "https://github.com/gematik/zero-lab/tree/main/go/authzserver"
    click Nonce "https://github.com/gematik/zero-lab/tree/main/go/libzero/nonce"
    click Attest "https://github.com/gematik/zero-lab/tree/main/go/libzero/attestation"
    click DPoP "https://github.com/gematik/zero-lab/tree/main/go/libzero/dpop"
    click OIDC "https://github.com/gematik/zero-lab/tree/main/go/libzero/oidc"
    click OIDF "https://github.com/gematik/zero-lab/tree/main/go/libzero/oidf"
    click CA "https://github.com/gematik/zero-lab/tree/main/go/libzero/ca"
    click Demo "https://github.com/gematik/zero-lab/tree/main/go/cmd/zero-zerobin"
    click VAU "https://github.com/gematik/zero-lab/tree/main/go/vau"

    classDef microservice fill:#aed6f1,stroke:#21618c,color:#1b2631
    classDef client fill:#abebc6,stroke:#239b56,color:#1b2631
    classDef external fill:#f9e79f,stroke:#b9770e,color:#1b2631
```
